summaryrefslogtreecommitdiff
path: root/apps/plugins/zxbox/zxbox.c
blob: edaa7cfbaa34844978bde5fc3fdc41f32f6d297a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (c) 2006 Anton Romanov
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#include "zxconfig.h"
#include "spkey_p.h"

spkeyboard kb_mkey;
bool exit_requested=false;
bool clear_kbd=0;
extern bool zxbox_menu(void);

/* DUMMIES ... to clean */
unsigned int scrmul=0;
int privatemap;
int use_shm = 0;
int small_screen,pause_on_iconify;
int vga_pause_bg;

#include "keymaps.h"
#include "zxvid_com.h"
#include "spmain.h"
#include "spperif.h"

struct zxbox_settings settings;

/* doesn't fit into .ibss */
unsigned char image_array [ HEIGHT * WIDTH ];

static int previous_state;

#ifdef USE_GREY
GREY_INFO_STRUCT_IRAM
static unsigned char *gbuf;
static size_t         gbuf_size = 0;
#endif

long video_frames IBSS_ATTR = 0 ;
long start_time IBSS_ATTR = 0;

enum plugin_status plugin_start(const void* parameter)
{
#if LCD_DEPTH > 1
    rb->lcd_set_backdrop(NULL);
#endif
    rb->splash(HZ, "Welcome to ZXBox");


    sp_init();

#ifdef USE_GREY
    /* get the remainder of the plugin buffer */
    gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
#ifdef USE_BUFFERED_GREY
    grey_init(gbuf, gbuf_size, GREY_BUFFERED|GREY_ON_COP, LCD_WIDTH,
              LCD_HEIGHT, NULL);
#else
    grey_init(gbuf, gbuf_size, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL);
#endif /* USE_BUFFERED_GREY */
    /* switch on greyscale overlay */
    grey_show(true);
#endif /* USE_GREY */


#if defined(HAVE_ADJUSTABLE_CPU_FREQ)
    rb->cpu_boost(true);
#endif

    start_time = *rb->current_tick;

#ifdef RB_PROFILE
   rb->profile_thread();
#endif

    start_spectemu(parameter);

#ifdef RB_PROFILE
   rb->profstop();
#endif

#if defined(HAVE_ADJUSTABLE_CPU_FREQ)
    rb->cpu_boost(false);
#endif

#ifdef USE_GREY
grey_show(false);
grey_release();
#endif 

#if CONFIG_CODEC == SWCODEC && !defined SIMULATOR
    rb->pcm_play_stop();
#endif

return PLUGIN_OK;
}

void init_spect_key(void)
{
  clear_keystates();
  init_basekeys();
}

void spkb_process_events( int evenframe )
{

    if(evenframe){
        int ki;
#if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
    (CONFIG_KEYPAD == IPOD_1G2G_PAD)
        if (rb->button_hold())
        {
#if defined(HAVE_ADJUSTABLE_CPU_FREQ)
            rb->cpu_boost(false);
#endif
            exit_requested=1;
#ifdef USE_GREY
            grey_show(false);
#endif
            return;
        }
#endif
        int buttons = rb->button_status();
        if ( buttons == previous_state )
            return;
        previous_state = buttons;
#if (CONFIG_KEYPAD != IPOD_4G_PAD) && (CONFIG_KEYPAD != IPOD_3G_PAD) && \
    (CONFIG_KEYPAD != IPOD_1G2G_PAD)
        if (buttons & ZX_MENU)
        {
#if defined(HAVE_ADJUSTABLE_CPU_FREQ)
            rb->cpu_boost(false);
#endif
            exit_requested=1;
#ifdef USE_GREY
            grey_show(false);
#endif
            return;
        }
#endif
        spkb_state_changed = 1;
        if (settings.kempston){
            if ( buttons & ZX_RIGHT ){
                 ki = KS_TO_KEY(SK_KP_Right);
                spkb_kbstate[ki].state = 1;
            }
            else if (buttons & ZX_LEFT){
                 ki = KS_TO_KEY(SK_KP_Left);
                spkb_kbstate[ki].state = 1;

            }
            else{
                 ki = KS_TO_KEY(SK_KP_Right);
                spkb_kbstate[ki].state = 0;
                 ki = KS_TO_KEY(SK_KP_Left);
                spkb_kbstate[ki].state = 0;

            }
            if ( buttons & ZX_UP ){
                 ki = KS_TO_KEY(SK_KP_Up);
                spkb_kbstate[ki].state = 1;
            }
            else if (buttons & ZX_DOWN){
                 ki = KS_TO_KEY(SK_KP_Down);
                spkb_kbstate[ki].state = 1;
            }
            else{
                 ki = KS_TO_KEY(SK_KP_Up);
                spkb_kbstate[ki].state = 0;
                 ki = KS_TO_KEY(SK_KP_Down);
                spkb_kbstate[ki].state = 0;
            }

            if ( buttons & ZX_SELECT ){
                 ki = KS_TO_KEY(SK_KP_Insert);
                spkb_kbstate[ki].state = 1;
            }
            else{
                 ki = KS_TO_KEY(SK_KP_Insert);
                spkb_kbstate[ki].state = 0;
            }

        }
        else {

            if ( buttons & ZX_RIGHT ){
                ki = KS_TO_KEY(intkeys[3]);
                spkb_kbstate[ki].state = 1;
            }
            else{
                ki = KS_TO_KEY(intkeys[3]);
                spkb_kbstate[ki].state = 0;
            }
    
            if ( buttons & ZX_LEFT ){
                ki = KS_TO_KEY(intkeys[2]);
                spkb_kbstate[ki].state = 1;
            }
            else{
                ki = KS_TO_KEY(intkeys[2]);
                spkb_kbstate[ki].state = 0;
            }
    
            if ( buttons & ZX_UP ){
                ki = KS_TO_KEY(intkeys[0]);
                spkb_kbstate[ki].state = 1;
            }
            else{
                ki = KS_TO_KEY(intkeys[0]);
                spkb_kbstate[ki].state = 0;
            }
            
            if ( buttons & ZX_DOWN ){
                ki = KS_TO_KEY(intkeys[1]);
                spkb_kbstate[ki].state = 1;
            }
            else{
                ki = KS_TO_KEY(intkeys[1]);
                spkb_kbstate[ki].state = 0;
            }
            
            if ( buttons & ZX_SELECT ){
                ki = KS_TO_KEY(intkeys[4]);
                spkb_kbstate[ki].state = 1;
            }
            else{
                ki = KS_TO_KEY(intkeys[4]);
                spkb_kbstate[ki].state = 0;
            }
        }
        process_keys();
    }
}

void press_key(int c){
    spkb_state_changed = 1;
    int ki;
    if ( c == 'E' )
        ki = KS_TO_KEY(SK_KP_Enter);
    else if (c == 'S' )
        ki = KS_TO_KEY(SK_KP_Space);
    else
        ki = KS_TO_KEY(c);
    spkb_kbstate[ki].state = 1;
    process_keys();
}