code police : fix some multiply defined variables
[kugel-rb.git] / apps / plugins / zxbox / zxbox.c
blob3d268dbb1f0274b164e23a448d053744623da2fb
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (c) 2006 Anton Romanov
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "zxconfig.h"
24 PLUGIN_HEADER
25 PLUGIN_IRAM_DECLARE
27 extern const struct plugin_api* rb;
29 #include "spkey_p.h"
31 spkeyboard kb_mkey;
32 bool exit_requested=false;
33 bool clear_kbd=0;
34 extern bool zxbox_menu(void);
36 /* DUMMIES ... to clean */
37 unsigned int scrmul=0;
38 int privatemap;
39 int use_shm = 0;
40 int small_screen,pause_on_iconify;
41 int vga_pause_bg;
43 #include "keymaps.h"
44 #include "zxvid_com.h"
45 #include "spmain.h"
46 #include "spperif.h"
48 struct zxbox_settings settings;
50 /* doesn't fit into .ibss */
51 unsigned char image_array [ HEIGHT * WIDTH ];
53 static int previous_state;
55 #ifdef USE_GREY
56 GREY_INFO_STRUCT_IRAM
57 static unsigned char *gbuf;
58 static size_t gbuf_size = 0;
59 #endif
61 long video_frames IBSS_ATTR = 0 ;
62 long start_time IBSS_ATTR = 0;
64 enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
66 PLUGIN_IRAM_INIT(api)
68 rb = api;
69 #if LCD_DEPTH > 1
70 rb->lcd_set_backdrop(NULL);
71 #endif
72 rb->splash(HZ, "Welcome to ZXBox");
75 sp_init();
77 #ifdef USE_GREY
78 /* get the remainder of the plugin buffer */
79 gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
80 #ifdef USE_BUFFERED_GREY
81 grey_init(rb, gbuf, gbuf_size, GREY_BUFFERED|GREY_ON_COP, LCD_WIDTH,
82 LCD_HEIGHT, NULL);
83 #else
84 grey_init(rb, gbuf, gbuf_size, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL);
85 #endif /* USE_BUFFERED_GREY */
86 /* switch on greyscale overlay */
87 grey_show(true);
88 #endif /* USE_GREY */
91 #if defined(HAVE_ADJUSTABLE_CPU_FREQ)
92 rb->cpu_boost(true);
93 #endif
95 start_time = *rb->current_tick;
97 #ifdef RB_PROFILE
98 rb->profile_thread();
99 #endif
101 start_spectemu(parameter);
103 #ifdef RB_PROFILE
104 rb->profstop();
105 #endif
107 #if defined(HAVE_ADJUSTABLE_CPU_FREQ)
108 rb->cpu_boost(false);
109 #endif
111 #ifdef USE_GREY
112 grey_show(false);
113 grey_release();
114 #endif
116 #if CONFIG_CODEC == SWCODEC && !defined SIMULATOR
117 rb->pcm_play_stop();
118 #endif
120 return PLUGIN_OK;
123 void init_spect_key(void)
125 clear_keystates();
126 init_basekeys();
129 void spkb_process_events( int evenframe )
132 if(evenframe){
133 int ki;
134 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
135 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
136 if (rb->button_hold())
138 #if defined(HAVE_ADJUSTABLE_CPU_FREQ)
139 rb->cpu_boost(false);
140 #endif
141 exit_requested=1;
142 #ifdef USE_GREY
143 grey_show(false);
144 #endif
145 return;
147 #endif
148 int buttons = rb->button_status();
149 if ( buttons == previous_state )
150 return;
151 previous_state = buttons;
152 #if (CONFIG_KEYPAD != IPOD_4G_PAD) && (CONFIG_KEYPAD != IPOD_3G_PAD) && \
153 (CONFIG_KEYPAD != IPOD_1G2G_PAD)
154 if (buttons & ZX_MENU)
156 #if defined(HAVE_ADJUSTABLE_CPU_FREQ)
157 rb->cpu_boost(false);
158 #endif
159 exit_requested=1;
160 #ifdef USE_GREY
161 grey_show(false);
162 #endif
163 return;
165 #endif
166 spkb_state_changed = 1;
167 if (settings.kempston){
168 if ( buttons & ZX_RIGHT ){
169 ki = KS_TO_KEY(SK_KP_Right);
170 spkb_kbstate[ki].state = 1;
172 else if (buttons & ZX_LEFT){
173 ki = KS_TO_KEY(SK_KP_Left);
174 spkb_kbstate[ki].state = 1;
177 else{
178 ki = KS_TO_KEY(SK_KP_Right);
179 spkb_kbstate[ki].state = 0;
180 ki = KS_TO_KEY(SK_KP_Left);
181 spkb_kbstate[ki].state = 0;
184 if ( buttons & ZX_UP ){
185 ki = KS_TO_KEY(SK_KP_Up);
186 spkb_kbstate[ki].state = 1;
188 else if (buttons & ZX_DOWN){
189 ki = KS_TO_KEY(SK_KP_Down);
190 spkb_kbstate[ki].state = 1;
192 else{
193 ki = KS_TO_KEY(SK_KP_Up);
194 spkb_kbstate[ki].state = 0;
195 ki = KS_TO_KEY(SK_KP_Down);
196 spkb_kbstate[ki].state = 0;
199 if ( buttons & ZX_SELECT ){
200 ki = KS_TO_KEY(SK_KP_Insert);
201 spkb_kbstate[ki].state = 1;
203 else{
204 ki = KS_TO_KEY(SK_KP_Insert);
205 spkb_kbstate[ki].state = 0;
209 else {
211 if ( buttons & ZX_RIGHT ){
212 ki = KS_TO_KEY(intkeys[3]);
213 spkb_kbstate[ki].state = 1;
215 else{
216 ki = KS_TO_KEY(intkeys[3]);
217 spkb_kbstate[ki].state = 0;
220 if ( buttons & ZX_LEFT ){
221 ki = KS_TO_KEY(intkeys[2]);
222 spkb_kbstate[ki].state = 1;
224 else{
225 ki = KS_TO_KEY(intkeys[2]);
226 spkb_kbstate[ki].state = 0;
229 if ( buttons & ZX_UP ){
230 ki = KS_TO_KEY(intkeys[0]);
231 spkb_kbstate[ki].state = 1;
233 else{
234 ki = KS_TO_KEY(intkeys[0]);
235 spkb_kbstate[ki].state = 0;
238 if ( buttons & ZX_DOWN ){
239 ki = KS_TO_KEY(intkeys[1]);
240 spkb_kbstate[ki].state = 1;
242 else{
243 ki = KS_TO_KEY(intkeys[1]);
244 spkb_kbstate[ki].state = 0;
247 if ( buttons & ZX_SELECT ){
248 ki = KS_TO_KEY(intkeys[4]);
249 spkb_kbstate[ki].state = 1;
251 else{
252 ki = KS_TO_KEY(intkeys[4]);
253 spkb_kbstate[ki].state = 0;
256 process_keys();
260 void press_key(int c){
261 spkb_state_changed = 1;
262 int ki;
263 if ( c == 'E' )
264 ki = KS_TO_KEY(SK_KP_Enter);
265 else if (c == 'S' )
266 ki = KS_TO_KEY(SK_KP_Space);
267 else
268 ki = KS_TO_KEY(c);
269 spkb_kbstate[ki].state = 1;
270 process_keys();