summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2004-10-18 21:45:00 +0000
committerJens Arnold <amiconn@rockbox.org>2004-10-18 21:45:00 +0000
commite35a658ded457698aca2401b699e743a3011cfce (patch)
treecb89b7785ef2c72f7a293fe165a4d3b76e38227f /apps
parentd24766675db5faddb67810ca67b37491d49c2313 (diff)
downloadrockbox-e35a658ded457698aca2401b699e743a3011cfce.tar.gz
rockbox-e35a658ded457698aca2401b699e743a3011cfce.zip
Plugin rework 2: (all) Compile-time keyboard configuration, for Ondio adaption. (all) Now using the default event handler, standard placement is now in switch() default case. (minesweeper,pong,snake,snake2) added USB handling. (mandelbrot,mosaique) Fixed return value. (minesweeper) fast moving with button repeat. (oscillograph) Fixed cleanup in USB case.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5304 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/SOURCES22
-rw-r--r--apps/plugins/flipit.c55
-rw-r--r--apps/plugins/mandelbrot.c64
-rw-r--r--apps/plugins/minesweeper.c78
-rw-r--r--apps/plugins/mosaique.c65
-rw-r--r--apps/plugins/oscillograph.c76
-rw-r--r--apps/plugins/pong.c44
-rw-r--r--apps/plugins/sliding_puzzle.c48
-rw-r--r--apps/plugins/snake.c69
-rw-r--r--apps/plugins/snake2.c98
-rw-r--r--apps/plugins/sokoban.c85
11 files changed, 542 insertions, 162 deletions
diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES
index b2f632032c..b6496e4d45 100644
--- a/apps/plugins/SOURCES
+++ b/apps/plugins/SOURCES
@@ -16,29 +16,29 @@ bounce.c
16calculator.c 16calculator.c
17chip8.c 17chip8.c
18cube.c 18cube.c
19flipit.c
19grayscale.c 20grayscale.c
20jpeg.c 21jpeg.c
22mandelbrot.c
23minesweeper.c
24mosaique.c
25oscillograph.c
26pong.c
21rockblox.c 27rockblox.c
28sliding_puzzle.c
29snake.c
30snake2.c
22snow.c 31snow.c
32sokoban.c
23video.c 33video.c
24 34
25#ifdef HAVE_RTC /* Recorder models only */ 35#ifdef HAVE_RTC /* Recorder models only */
26calendar.c 36calendar.c
27clock.c 37clock.c
28#endif 38#endif /* #ifdef HAVE_RTC */
29 39
30#if CONFIG_KEYPAD != ONDIO_PAD 40#if CONFIG_KEYPAD != ONDIO_PAD
31/* gradually bring in the ones not working yet */ 41/* gradually bring in the ones not working yet */
32flipit.c
33mandelbrot.c
34minesweeper.c
35mosaique.c
36oscillograph.c
37pong.c
38sliding_puzzle.c
39snake.c
40snake2.c
41sokoban.c
42solitaire.c 42solitaire.c
43splitedit.c 43splitedit.c
44star.c 44star.c
diff --git a/apps/plugins/flipit.c b/apps/plugins/flipit.c
index 0b7893c969..973e27e299 100644
--- a/apps/plugins/flipit.c
+++ b/apps/plugins/flipit.c
@@ -19,6 +19,24 @@
19#include "plugin.h" 19#include "plugin.h"
20#ifdef HAVE_LCD_BITMAP 20#ifdef HAVE_LCD_BITMAP
21 21
22/* variable button definitions */
23#if CONFIG_KEYPAD == RECORDER_PAD
24#define FLIPIT_QUIT BUTTON_OFF
25#define FLIPIT_SHUFFLE BUTTON_F1
26#define FLIPIT_SOLVE BUTTON_F2
27#define FLIPIT_STEP_BY_STEP BUTTON_F3
28#define FLIPIT_TOGGLE BUTTON_PLAY
29
30#elif CONFIG_KEYPAD == ONDIO_PAD
31#define FLIPIT_QUIT BUTTON_OFF
32#define FLIPIT_SHUFFLE (BUTTON_MENU | BUTTON_LEFT)
33#define FLIPIT_SOLVE (BUTTON_MENU | BUTTON_UP)
34#define FLIPIT_STEP_BY_STEP (BUTTON_MENU | BUTTON_RIGHT)
35#define FLIPIT_TOGGLE_PRE BUTTON_MENU
36#define FLIPIT_TOGGLE (BUTTON_MENU | BUTTON_REL)
37
38#endif
39
22static struct plugin_api* rb; 40static struct plugin_api* rb;
23static int spots[20]; 41static int spots[20];
24static int toggle[20]; 42static int toggle[20];
@@ -152,19 +170,23 @@ static void flipit_init(void) {
152/* the main game loop */ 170/* the main game loop */
153static bool flipit_loop(void) { 171static bool flipit_loop(void) {
154 int i; 172 int i;
173 int button;
174 int lastbutton = BUTTON_NONE;
175
155 flipit_init(); 176 flipit_init();
156 while(true) { 177 while(true) {
157 switch (rb->button_get(true)) { 178 button = rb->button_get(true);
158 case BUTTON_OFF: 179 switch (button) {
180 case FLIPIT_QUIT:
159 /* get out of here */ 181 /* get out of here */
160 return PLUGIN_OK; 182 return PLUGIN_OK;
161 183
162 case BUTTON_F1: 184 case FLIPIT_SHUFFLE:
163 /* mix up the pieces */ 185 /* mix up the pieces */
164 flipit_init(); 186 flipit_init();
165 break; 187 break;
166 188
167 case BUTTON_F2: 189 case FLIPIT_SOLVE:
168 /* solve the puzzle */ 190 /* solve the puzzle */
169 if (!flipit_finished()) { 191 if (!flipit_finished()) {
170 for (i=0; i<20; i++) 192 for (i=0; i<20; i++)
@@ -179,7 +201,7 @@ static bool flipit_loop(void) {
179 } 201 }
180 break; 202 break;
181 203
182 case BUTTON_F3: 204 case FLIPIT_STEP_BY_STEP:
183 if (!flipit_finished()) { 205 if (!flipit_finished()) {
184 for (i=0; i<20; i++) 206 for (i=0; i<20; i++)
185 if (!toggle[i]) { 207 if (!toggle[i]) {
@@ -193,7 +215,11 @@ static bool flipit_loop(void) {
193 } 215 }
194 break; 216 break;
195 217
196 case BUTTON_PLAY: 218 case FLIPIT_TOGGLE:
219#ifdef FLIPIT_TOGGLE_PRE
220 if (lastbutton != FLIPIT_TOGGLE_PRE)
221 break;
222#endif
197 /* toggle the pieces */ 223 /* toggle the pieces */
198 if (!flipit_finished()) { 224 if (!flipit_finished()) {
199 flipit_toggle(); 225 flipit_toggle();
@@ -221,10 +247,13 @@ static bool flipit_loop(void) {
221 move_cursor(0, 1); 247 move_cursor(0, 1);
222 break; 248 break;
223 249
224 case SYS_USB_CONNECTED: 250 default:
225 rb->usb_screen(); 251 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
226 return PLUGIN_USB_CONNECTED; 252 return PLUGIN_USB_CONNECTED;
253 break;
227 } 254 }
255 if (button != BUTTON_NONE)
256 lastbutton = button;
228 } 257 }
229} 258}
230 259
@@ -249,11 +278,19 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
249 /* print instructions */ 278 /* print instructions */
250 rb->lcd_clear_display(); 279 rb->lcd_clear_display();
251 rb->lcd_setfont(FONT_SYSFIXED); 280 rb->lcd_setfont(FONT_SYSFIXED);
281#if CONFIG_KEYPAD == RECORDER_PAD
252 rb->lcd_putsxy(2, 8, "[OFF] to stop"); 282 rb->lcd_putsxy(2, 8, "[OFF] to stop");
253 rb->lcd_putsxy(2, 18, "[PLAY] toggle"); 283 rb->lcd_putsxy(2, 18, "[PLAY] toggle");
254 rb->lcd_putsxy(2, 28, "[F1] shuffle"); 284 rb->lcd_putsxy(2, 28, "[F1] shuffle");
255 rb->lcd_putsxy(2, 38, "[F2] solution"); 285 rb->lcd_putsxy(2, 38, "[F2] solution");
256 rb->lcd_putsxy(2, 48, "[F3] step by step"); 286 rb->lcd_putsxy(2, 48, "[F3] step by step");
287#elif CONFIG_KEYPAD == ONDIO_PAD
288 rb->lcd_putsxy(2, 8, "[OFF] to stop");
289 rb->lcd_putsxy(2, 18, "[MENU] toggle");
290 rb->lcd_putsxy(2, 28, "[M-LEFT] shuffle");
291 rb->lcd_putsxy(2, 38, "[M-UP] solution");
292 rb->lcd_putsxy(2, 48, "[M-RIGHT] step by step");
293#endif
257 rb->lcd_update(); 294 rb->lcd_update();
258 rb->sleep(HZ*3); 295 rb->sleep(HZ*3);
259 296
diff --git a/apps/plugins/mandelbrot.c b/apps/plugins/mandelbrot.c
index 5547d86535..2e9cb97eec 100644
--- a/apps/plugins/mandelbrot.c
+++ b/apps/plugins/mandelbrot.c
@@ -23,6 +23,27 @@
23#ifdef HAVE_LCD_BITMAP // this is not fun on the player 23#ifdef HAVE_LCD_BITMAP // this is not fun on the player
24# include "gray.h" 24# include "gray.h"
25 25
26/* variable button definitions */
27#if CONFIG_KEYPAD == RECORDER_PAD
28#define MANDELBROT_QUIT BUTTON_OFF
29#define MANDELBROT_ZOOM_IN BUTTON_PLAY
30#define MANDELBROT_ZOOM_OUT BUTTON_ON
31#define MANDELBROT_MAXITER_INC BUTTON_F2
32#define MANDELBROT_MAXITER_DEC BUTTON_F1
33#define MANDELBROT_RESET BUTTON_F3
34
35#elif CONFIG_KEYPAD == ONDIO_PAD
36#define MANDELBROT_QUIT BUTTON_OFF
37#define MANDELBROT_ZOOM_IN_PRE BUTTON_MENU
38#define MANDELBROT_ZOOM_IN (BUTTON_MENU | BUTTON_REL)
39#define MANDELBROT_ZOOM_IN2 (BUTTON_MENU | BUTTON_UP)
40#define MANDELBROT_ZOOM_OUT (BUTTON_MENU | BUTTON_DOWN)
41#define MANDELBROT_MAXITER_INC (BUTTON_MENU | BUTTON_RIGHT)
42#define MANDELBROT_MAXITER_DEC (BUTTON_MENU | BUTTON_LEFT)
43#define MANDELBROT_RESET (BUTTON_MENU | BUTTON_OFF)
44
45#endif
46
26static struct plugin_api* rb; 47static struct plugin_api* rb;
27static char buff[32]; 48static char buff[32];
28static int lcd_aspect_ratio; 49static int lcd_aspect_ratio;
@@ -101,9 +122,17 @@ void calc_mandelbrot_set(void){
101 } 122 }
102} 123}
103 124
125void cleanup(void *parameter)
126{
127 (void)parameter;
128
129 gray_release_buffer();
130}
104 131
105enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 132enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
106{ 133{
134 int button;
135 int lastbutton = BUTTON_NONE;
107 int grayscales; 136 int grayscales;
108 bool redraw = true; 137 bool redraw = true;
109 138
@@ -141,12 +170,13 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
141 170
142 redraw = false; 171 redraw = false;
143 172
144 switch (rb->button_get(true)) { 173 button = rb->button_get(true);
145 case BUTTON_OFF: 174 switch (button) {
175 case MANDELBROT_QUIT:
146 gray_release_buffer(); 176 gray_release_buffer();
147 return PLUGIN_OK; 177 return PLUGIN_OK;
148 178
149 case BUTTON_ON: 179 case MANDELBROT_ZOOM_OUT:
150 x_min -= ((delta>>13)*(lcd_aspect_ratio>>13)); 180 x_min -= ((delta>>13)*(lcd_aspect_ratio>>13));
151 x_max += ((delta>>13)*(lcd_aspect_ratio>>13)); 181 x_max += ((delta>>13)*(lcd_aspect_ratio>>13));
152 y_min -= delta; 182 y_min -= delta;
@@ -156,7 +186,14 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
156 break; 186 break;
157 187
158 188
159 case BUTTON_PLAY: 189 case MANDELBROT_ZOOM_IN:
190#ifdef MANDELBROT_ZOOM_IN_PRE
191 if (lastbutton != MANDELBROT_ZOOM_IN_PRE)
192 break;
193#endif
194#ifdef MANDELBROT_ZOOM_IN2
195 case MANDELBROT_ZOOM_IN2:
196#endif
160 x_min += ((delta>>13)*(lcd_aspect_ratio>>13)); 197 x_min += ((delta>>13)*(lcd_aspect_ratio>>13));
161 x_max -= ((delta>>13)*(lcd_aspect_ratio>>13)); 198 x_max -= ((delta>>13)*(lcd_aspect_ratio>>13));
162 y_min += delta; 199 y_min += delta;
@@ -189,33 +226,36 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
189 redraw = true; 226 redraw = true;
190 break; 227 break;
191 228
192 case BUTTON_F1: 229 case MANDELBROT_MAXITER_DEC:
193 if (max_iter>5){ 230 if (max_iter>5){
194 max_iter -= 5; 231 max_iter -= 5;
195 redraw = true; 232 redraw = true;
196 } 233 }
197 break; 234 break;
198 235
199 case BUTTON_F2: 236 case MANDELBROT_MAXITER_INC:
200 if (max_iter < 195){ 237 if (max_iter < 195){
201 max_iter += 5; 238 max_iter += 5;
202 redraw = true; 239 redraw = true;
203 } 240 }
204 break; 241 break;
205 242
206 case BUTTON_F3: 243 case MANDELBROT_RESET:
207 init_mandelbrot_set(); 244 init_mandelbrot_set();
208 redraw = true; 245 redraw = true;
209 break; 246 break;
210 247
211 case SYS_USB_CONNECTED: 248 default:
212 gray_release_buffer(); 249 if (rb->default_event_handler_ex(button, cleanup, NULL)
213 rb->usb_screen(); 250 == SYS_USB_CONNECTED)
214 return PLUGIN_USB_CONNECTED; 251 return PLUGIN_USB_CONNECTED;
252 break;
215 } 253 }
254 if (button != BUTTON_NONE)
255 lastbutton = button;
216 } 256 }
217 gray_release_buffer(); 257 gray_release_buffer();
218 return false; 258 return PLUGIN_OK;
219} 259}
220#endif 260#endif
221#endif 261#endif
diff --git a/apps/plugins/minesweeper.c b/apps/plugins/minesweeper.c
index 127d96d3d5..e60cfb4688 100644
--- a/apps/plugins/minesweeper.c
+++ b/apps/plugins/minesweeper.c
@@ -33,11 +33,32 @@ use F3 to see how many mines are left (supposing all your flags are correct)
33 33
34#ifdef HAVE_LCD_BITMAP 34#ifdef HAVE_LCD_BITMAP
35 35
36//what the minesweeper() function can return 36//what the minesweeper() function can return
37#define MINESWEEPER_USB 3
37#define MINESWEEPER_QUIT 2 38#define MINESWEEPER_QUIT 2
38#define MINESWEEPER_LOSE 1 39#define MINESWEEPER_LOSE 1
39#define MINESWEEPER_WIN 0 40#define MINESWEEPER_WIN 0
40 41
42/* variable button definitions */
43#if CONFIG_KEYPAD == RECORDER_PAD
44#define MINESWP_QUIT BUTTON_OFF
45#define MINESWP_START BUTTON_ON
46#define MINESWP_TOGGLE BUTTON_PLAY
47#define MINESWP_TOGGLE2 BUTTON_F1
48#define MINESWP_DISCOVER BUTTON_ON
49#define MINESWP_DISCOVER2 BUTTON_F2
50#define MINESWP_INFO BUTTON_F3
51
52#elif CONFIG_KEYPAD == ONDIO_PAD
53#define MINESWP_QUIT BUTTON_OFF
54#define MINESWP_START BUTTON_MENU
55#define MINESWP_TOGGLE_PRE BUTTON_MENU
56#define MINESWP_TOGGLE (BUTTON_MENU | BUTTON_REL)
57#define MINESWP_DISCOVER (BUTTON_MENU | BUTTON_REPEAT)
58#define MINESWP_INFO (BUTTON_MENU | BUTTON_OFF)
59
60#endif
61
41 62
42/* here is a global api struct pointer. while not strictly necessary, 63/* here is a global api struct pointer. while not strictly necessary,
43 it's nice not to have to pass the api pointer in all function calls 64 it's nice not to have to pass the api pointer in all function calls
@@ -254,6 +275,8 @@ void minesweeper_putmines(int p, int x, int y){
254int minesweeper(void) 275int minesweeper(void)
255{ 276{
256 int i,j; 277 int i,j;
278 int button;
279 int lastbutton = BUTTON_NONE;
257 280
258 /* the cursor coordinates */ 281 /* the cursor coordinates */
259 int x=0,y=0; 282 int x=0,y=0;
@@ -277,12 +300,17 @@ int minesweeper(void)
277 rb->snprintf(str, 20, "%d%% mines", p); 300 rb->snprintf(str, 20, "%d%% mines", p);
278 rb->lcd_putsxy(1,19,str); 301 rb->lcd_putsxy(1,19,str);
279 rb->lcd_putsxy(1,28,"down / up"); 302 rb->lcd_putsxy(1,28,"down / up");
303#if CONFIG_KEYPAD == RECORDER_PAD
280 rb->lcd_putsxy(1,44,"ON to start"); 304 rb->lcd_putsxy(1,44,"ON to start");
305#elif CONFIG_KEYPAD == ONDIO_PAD
306 rb->lcd_putsxy(1,44,"MENU to start");
307#endif
281 308
282 rb->lcd_update(); 309 rb->lcd_update();
283 310
284 311
285 switch(rb->button_get(true)){ 312 button = rb->button_get(true);
313 switch(button){
286 case BUTTON_DOWN: 314 case BUTTON_DOWN:
287 case BUTTON_LEFT: 315 case BUTTON_LEFT:
288 p = (p + 98)%100; 316 p = (p + 98)%100;
@@ -293,12 +321,17 @@ int minesweeper(void)
293 p = (p + 2)%100; 321 p = (p + 2)%100;
294 break; 322 break;
295 323
296 case BUTTON_ON:/* start playing */ 324 case MINESWP_START:/* start playing */
297 i = 1; 325 i = 1;
298 break; 326 break;
299 327
300 case BUTTON_OFF:/* quit program */ 328 case MINESWP_QUIT:/* quit program */
301 return MINESWEEPER_QUIT; 329 return MINESWEEPER_QUIT;
330
331 default:
332 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
333 return MINESWEEPER_USB;
334 break;
302 } 335 }
303 if(i==1) 336 if(i==1)
304 break; 337 break;
@@ -345,34 +378,41 @@ int minesweeper(void)
345 /* update the screen */ 378 /* update the screen */
346 rb->lcd_update(); 379 rb->lcd_update();
347 380
348 switch(rb->button_get(true)){ 381 button = rb->button_get(true);
382 switch(button){
349 /* quit minesweeper (you really shouldn't use this button ...) */ 383 /* quit minesweeper (you really shouldn't use this button ...) */
350 case BUTTON_OFF: 384 case MINESWP_QUIT:
351 return MINESWEEPER_QUIT; 385 return MINESWEEPER_QUIT;
352 386
353 /* move cursor left */ 387 /* move cursor left */
354 case BUTTON_LEFT: 388 case BUTTON_LEFT:
389 case (BUTTON_LEFT | BUTTON_REPEAT):
355 x = (x + width - 1)%width; 390 x = (x + width - 1)%width;
356 break; 391 break;
357 392
358 /* move cursor right */ 393 /* move cursor right */
359 case BUTTON_RIGHT: 394 case BUTTON_RIGHT:
395 case (BUTTON_RIGHT | BUTTON_REPEAT):
360 x = (x + 1)%width; 396 x = (x + 1)%width;
361 break; 397 break;
362 398
363 /* move cursor down */ 399 /* move cursor down */
364 case BUTTON_DOWN: 400 case BUTTON_DOWN:
401 case (BUTTON_DOWN | BUTTON_REPEAT):
365 y = (y + 1)%height; 402 y = (y + 1)%height;
366 break; 403 break;
367 404
368 /* move cursor up */ 405 /* move cursor up */
369 case BUTTON_UP: 406 case BUTTON_UP:
407 case (BUTTON_UP | BUTTON_REPEAT):
370 y = (y + height - 1)%height; 408 y = (y + height - 1)%height;
371 break; 409 break;
372 410
373 /* discover a tile (and it's neighbors if .neighbors == 0) */ 411 /* discover a tile (and it's neighbors if .neighbors == 0) */
374 case BUTTON_ON: 412 case MINESWP_DISCOVER:
375 case BUTTON_F2: 413#ifdef MINESWP_DISCOVER2
414 case MINESWP_DISCOVER2:
415#endif
376 if(minefield[y][x].flag) break; 416 if(minefield[y][x].flag) break;
377 /* we put the mines on the first "click" so that you don't */ 417 /* we put the mines on the first "click" so that you don't */
378 /* lose on the first "click" */ 418 /* lose on the first "click" */
@@ -393,14 +433,20 @@ int minesweeper(void)
393 break; 433 break;
394 434
395 /* toggle flag under cursor */ 435 /* toggle flag under cursor */
396 case BUTTON_PLAY: 436 case MINESWP_TOGGLE:
397 case BUTTON_F1: 437#ifdef MINESWP_TOGGLE_PRE
438 if (lastbutton != MINESWP_TOGGLE_PRE)
439 break;
440#endif
441#ifdef MINESWP_TOGGLE2
442 case MINESWP_TOGGLE2:
443#endif
398 minefield[y][x].flag = (minefield[y][x].flag + 1)%2; 444 minefield[y][x].flag = (minefield[y][x].flag + 1)%2;
399 break; 445 break;
400 446
401 /* show how many mines you think you have found and how many */ 447 /* show how many mines you think you have found and how many */
402 /* there really are on the game */ 448 /* there really are on the game */
403 case BUTTON_F3: 449 case MINESWP_INFO:
404 tiles_left = 0; 450 tiles_left = 0;
405 for(i=0;i<height;i++){ 451 for(i=0;i<height;i++){
406 for(j=0;j<width;j++){ 452 for(j=0;j<width;j++){
@@ -409,7 +455,14 @@ int minesweeper(void)
409 } 455 }
410 rb->splash(HZ*2, true, "You found %d mines out of %d", tiles_left, mine_num); 456 rb->splash(HZ*2, true, "You found %d mines out of %d", tiles_left, mine_num);
411 break; 457 break;
458
459 default:
460 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
461 return MINESWEEPER_USB;
462 break;
412 } 463 }
464 if (button != BUTTON_NONE)
465 lastbutton = button;
413 } 466 }
414 467
415} 468}
@@ -431,6 +484,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
431 case MINESWEEPER_LOSE: 484 case MINESWEEPER_LOSE:
432 rb->splash(HZ*2, true, "You Lost :("); 485 rb->splash(HZ*2, true, "You Lost :(");
433 break; 486 break;
487
488 case MINESWEEPER_USB:
489 return PLUGIN_USB_CONNECTED;
434 490
435 default: 491 default:
436 break; 492 break;
diff --git a/apps/plugins/mosaique.c b/apps/plugins/mosaique.c
index ed4ad560c1..09c56c3bc3 100644
--- a/apps/plugins/mosaique.c
+++ b/apps/plugins/mosaique.c
@@ -23,6 +23,19 @@
23#define LARGE 55 23#define LARGE 55
24#define HAUT 31 24#define HAUT 31
25 25
26/* variable button definitions */
27#if CONFIG_KEYPAD == RECORDER_PAD
28#define MOSAIQUE_QUIT BUTTON_OFF
29#define MOSAIQUE_SPEED BUTTON_F1
30#define MOSAIQUE_RESTART BUTTON_PLAY
31
32#elif CONFIG_KEYPAD == ONDIO_PAD
33#define MOSAIQUE_QUIT BUTTON_OFF
34#define MOSAIQUE_SPEED BUTTON_LEFT
35#define MOSAIQUE_SPEED2 BUTTON_RIGHT
36#define MOSAIQUE_RESTART BUTTON_MENU
37
38#endif
26 39
27enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 40enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
28{ 41{
@@ -74,32 +87,36 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
74 rb->sleep(HZ/timer); 87 rb->sleep(HZ/timer);
75 88
76 button = rb->button_get(false); 89 button = rb->button_get(false);
77 if ( button == BUTTON_OFF) 90 switch (button)
78 {
79 return false;
80 }
81
82 if ( button == BUTTON_F1 )
83 {
84 timer = timer+5;
85 if (timer>20)
86 timer=5;
87 }
88
89 if ( button == BUTTON_PLAY )
90 { 91 {
91 sx = rb->rand()%20+1; 92 case MOSAIQUE_QUIT:
92 sy = rb->rand()%20+1; 93
93 x=0; 94 return PLUGIN_OK;
94 y=0; 95
95 rb->lcd_clear_display(); 96 case MOSAIQUE_SPEED:
96 } 97#ifdef MOSAIQUE_SPEED2
97 98 case MOSAIQUE_SPEED2:
98 if ( button == SYS_USB_CONNECTED) { 99#endif
99 rb->usb_screen(); 100 timer = timer+5;
100 return 0; 101 if (timer>20)
101 } 102 timer=5;
103 break;
104
105 case MOSAIQUE_RESTART:
102 106
107 sx = rb->rand()%20+1;
108 sy = rb->rand()%20+1;
109 x=0;
110 y=0;
111 rb->lcd_clear_display();
112 break;
113
114
115 default:
116 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
117 return PLUGIN_USB_CONNECTED;
118 break;
119 }
103 } 120 }
104} 121}
105 122
diff --git a/apps/plugins/oscillograph.c b/apps/plugins/oscillograph.c
index a34aa8bfa9..5beeb8891b 100644
--- a/apps/plugins/oscillograph.c
+++ b/apps/plugins/oscillograph.c
@@ -29,6 +29,28 @@
29 29
30#define MAX_PEAK 0x8000 30#define MAX_PEAK 0x8000
31 31
32/* variable button definitions */
33#if CONFIG_KEYPAD == RECORDER_PAD
34#define OSCILLOGRAPH_QUIT BUTTON_OFF
35#define OSCILLOGRAPH_SPEED_UP BUTTON_UP
36#define OSCILLOGRAPH_SPEED_DOWN BUTTON_DOWN
37#define OSCILLOGRAPH_ROLL BUTTON_F1
38#define OSCILLOGRAPH_MODE BUTTON_F2
39#define OSCILLOGRAPH_SPEED_RESET BUTTON_F3
40#define OSCILLOGRAPH_PAUSE BUTTON_PLAY
41
42#elif CONFIG_KEYPAD == ONDIO_PAD
43#define OSCILLOGRAPH_QUIT BUTTON_OFF
44#define OSCILLOGRAPH_SPEED_UP BUTTON_UP
45#define OSCILLOGRAPH_SPEED_DOWN BUTTON_DOWN
46#define OSCILLOGRAPH_ROLL BUTTON_RIGHT
47#define OSCILLOGRAPH_MODE BUTTON_MENU
48#define OSCILLOGRAPH_SPEED_RESET BUTTON_LEFT
49
50#endif
51
52/* global api struct pointer */
53static struct plugin_api* rb;
32/* number of ticks between two volume samples */ 54/* number of ticks between two volume samples */
33static int speed = 1; 55static int speed = 1;
34/* roll == true -> lcd rolls */ 56/* roll == true -> lcd rolls */
@@ -37,12 +59,26 @@ static bool roll = true;
37static int drawMode = DRAW_MODE_FILLED; 59static int drawMode = DRAW_MODE_FILLED;
38 60
39/** 61/**
62 * cleanup on return / usb
63 */
64void cleanup(void *parameter)
65{
66 (void)parameter;
67
68 /* restore to default roll position.
69 Looks funny if you forget to do this... */
70 rb->lcd_roll(0);
71 rb->lcd_update();
72}
73
74/**
40 * Displays a vertically scrolling oscillosgraph using 75 * Displays a vertically scrolling oscillosgraph using
41 * hardware scrolling of the display. The user can change 76 * hardware scrolling of the display. The user can change
42 * speed 77 * speed
43 */ 78 */
44enum plugin_status plugin_start(struct plugin_api* rb, void* parameter) 79enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
45{ 80{
81 int button;
46 /* stores current volume value left */ 82 /* stores current volume value left */
47 int left; 83 int left;
48 /* stores current volume value right */ 84 /* stores current volume value right */
@@ -57,8 +93,9 @@ enum plugin_status plugin_start(struct plugin_api* rb, void* parameter)
57 93
58 bool exit = false; 94 bool exit = false;
59 95
60 TEST_PLUGIN_API(rb); 96 TEST_PLUGIN_API(api);
61 (void)parameter; 97 (void)parameter;
98 rb = api;
62 99
63 /* the main loop */ 100 /* the main loop */
64 while (!exit) { 101 while (!exit) {
@@ -135,28 +172,31 @@ enum plugin_status plugin_start(struct plugin_api* rb, void* parameter)
135 it must be ensured that at least 1 is passed. */ 172 it must be ensured that at least 1 is passed. */
136 173
137 /* react to user input */ 174 /* react to user input */
138 switch (rb->button_get_w_tmo(MAX(speed, 1))) { 175 button = rb->button_get_w_tmo(MAX(speed, 1));
139 case BUTTON_UP: 176 switch (button) {
177 case OSCILLOGRAPH_SPEED_UP:
140 speed++; 178 speed++;
141 draw = true; 179 draw = true;
142 break; 180 break;
143 181
144 case BUTTON_DOWN: 182 case OSCILLOGRAPH_SPEED_DOWN:
145 speed--; 183 speed--;
146 draw = true; 184 draw = true;
147 break; 185 break;
148 186
149 case BUTTON_PLAY: 187#ifdef OSCILLOGRAPH_PAUSE
188 case OSCILLOGRAPH_PAUSE:
150 /* pause the demo */ 189 /* pause the demo */
151 rb->button_get(true); 190 rb->button_get(true);
152 break; 191 break;
192#endif
153 193
154 case BUTTON_F1: 194 case OSCILLOGRAPH_ROLL:
155 /* toggle rolling */ 195 /* toggle rolling */
156 roll = !roll; 196 roll = !roll;
157 break; 197 break;
158 198
159 case BUTTON_F2: 199 case OSCILLOGRAPH_MODE:
160 /* step through the display modes */ 200 /* step through the display modes */
161 drawMode ++; 201 drawMode ++;
162 drawMode = drawMode % DRAW_MODE_COUNT; 202 drawMode = drawMode % DRAW_MODE_COUNT;
@@ -170,18 +210,20 @@ enum plugin_status plugin_start(struct plugin_api* rb, void* parameter)
170 rb->lcd_roll(0); 210 rb->lcd_roll(0);
171 break; 211 break;
172 212
173 case BUTTON_F3: 213 case OSCILLOGRAPH_SPEED_RESET:
174 speed = 1; 214 speed = 1;
175 draw = true; 215 draw = true;
176 break; 216 break;
177 217
178 case BUTTON_OFF: 218 case OSCILLOGRAPH_QUIT:
179 exit = true; 219 exit = true;
180 break; 220 break;
181 221
182 case SYS_USB_CONNECTED: 222 default:
183 rb->usb_screen(); 223 if (rb->default_event_handler_ex(button, cleanup, NULL)
184 return PLUGIN_USB_CONNECTED; 224 == SYS_USB_CONNECTED)
225 return PLUGIN_USB_CONNECTED;
226 break;
185 } 227 }
186 228
187 if (draw) { 229 if (draw) {
@@ -191,14 +233,10 @@ enum plugin_status plugin_start(struct plugin_api* rb, void* parameter)
191 rb->lcd_update_rect(0, (y + LCD_HEIGHT - 8) % LCD_HEIGHT, 233 rb->lcd_update_rect(0, (y + LCD_HEIGHT - 8) % LCD_HEIGHT,
192 LCD_WIDTH, 8); 234 LCD_WIDTH, 8);
193 } 235 }
194 } 236 }
195 } 237 }
196 238
197 /* restore to default roll position. 239 cleanup(NULL);
198 Looks funny if you forget to do this... */
199 rb->lcd_roll(0);
200 rb->lcd_update();
201
202 /* standard return */ 240 /* standard return */
203 return PLUGIN_OK; 241 return PLUGIN_OK;
204} 242}
diff --git a/apps/plugins/pong.c b/apps/plugins/pong.c
index 705b13b0fa..c7547d6de4 100644
--- a/apps/plugins/pong.c
+++ b/apps/plugins/pong.c
@@ -33,6 +33,23 @@
33 33
34#define MOVE_STEP 2 /* move pad this many steps up/down each move */ 34#define MOVE_STEP 2 /* move pad this many steps up/down each move */
35 35
36/* variable button definitions */
37#if CONFIG_KEYPAD == RECORDER_PAD
38#define PONG_QUIT BUTTON_OFF
39#define PONG_LEFT_UP BUTTON_F1
40#define PONG_LEFT_DOWN BUTTON_LEFT
41#define PONG_RIGHT_UP BUTTON_F3
42#define PONG_RIGHT_DOWN BUTTON_RIGHT
43
44#elif CONFIG_KEYPAD == ONDIO_PAD
45#define PONG_QUIT BUTTON_OFF
46#define PONG_LEFT_UP BUTTON_LEFT
47#define PONG_LEFT_DOWN BUTTON_MENU
48#define PONG_RIGHT_UP BUTTON_UP
49#define PONG_RIGHT_DOWN BUTTON_DOWN
50
51#endif
52
36static struct plugin_api* rb; 53static struct plugin_api* rb;
37 54
38struct pong { 55struct pong {
@@ -232,7 +249,7 @@ void padmove(int *pos, int dir)
232 *pos = 0; 249 *pos = 0;
233} 250}
234 251
235bool keys(struct pong *p) 252int keys(struct pong *p)
236{ 253{
237 int key; 254 int key;
238 255
@@ -243,22 +260,25 @@ bool keys(struct pong *p)
243 while(end > *rb->current_tick) { 260 while(end > *rb->current_tick) {
244 key = rb->button_get_w_tmo(end - *rb->current_tick); 261 key = rb->button_get_w_tmo(end - *rb->current_tick);
245 262
246 if(key & BUTTON_OFF) 263 if(key & PONG_QUIT)
247 return false; /* exit game NOW */ 264 return 0; /* exit game NOW */
248 265
249 if(key & BUTTON_LEFT) /* player left goes down */ 266 if(key & PONG_LEFT_DOWN) /* player left goes down */
250 padmove(&p->w_pad[0], MOVE_STEP); 267 padmove(&p->w_pad[0], MOVE_STEP);
251 268
252 if(key & BUTTON_F1) /* player left goes up */ 269 if(key & PONG_LEFT_UP) /* player left goes up */
253 padmove(&p->w_pad[0], - MOVE_STEP); 270 padmove(&p->w_pad[0], -MOVE_STEP);
254 271
255 if(key & BUTTON_RIGHT) /* player right goes down */ 272 if(key & PONG_RIGHT_DOWN) /* player right goes down */
256 padmove(&p->w_pad[1], MOVE_STEP); 273 padmove(&p->w_pad[1], MOVE_STEP);
257 274
258 if(key & BUTTON_F3) /* player right goes up */ 275 if(key & PONG_RIGHT_UP) /* player right goes up */
259 padmove(&p->w_pad[1], -MOVE_STEP); 276 padmove(&p->w_pad[1], -MOVE_STEP);
277
278 if(rb->default_event_handler(key) == SYS_USB_CONNECTED)
279 return -1; /* exit game because of USB */
260 } 280 }
261 return true; /* return false to exit game */ 281 return 1; /* return 0 to exit game */
262} 282}
263 283
264void showscore(struct pong *p) 284void showscore(struct pong *p)
@@ -273,7 +293,7 @@ void showscore(struct pong *p)
273enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 293enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
274{ 294{
275 struct pong pong; 295 struct pong pong;
276 bool game = true; 296 int game = 1;
277 297
278 /* init the struct with some silly values to start with */ 298 /* init the struct with some silly values to start with */
279 299
@@ -302,7 +322,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
302 rb->lcd_clear_display(); 322 rb->lcd_clear_display();
303 323
304 /* go go go */ 324 /* go go go */
305 while(game) { 325 while(game > 0) {
306 showscore(&pong); 326 showscore(&pong);
307 pad(&pong, 0); /* draw left pad */ 327 pad(&pong, 0); /* draw left pad */
308 pad(&pong, 1); /* draw right pad */ 328 pad(&pong, 1); /* draw right pad */
@@ -313,7 +333,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
313 game = keys(&pong); /* deal with keys */ 333 game = keys(&pong); /* deal with keys */
314 } 334 }
315 335
316 return PLUGIN_OK; 336 return (game == 0) ? PLUGIN_OK : PLUGIN_USB_CONNECTED;
317} 337}
318 338
319#endif /* HAVE_LCD_BITMAP */ 339#endif /* HAVE_LCD_BITMAP */
diff --git a/apps/plugins/sliding_puzzle.c b/apps/plugins/sliding_puzzle.c
index 423ab7fcf1..789e8789e8 100644
--- a/apps/plugins/sliding_puzzle.c
+++ b/apps/plugins/sliding_puzzle.c
@@ -19,6 +19,20 @@
19#include "plugin.h" 19#include "plugin.h"
20#ifdef HAVE_LCD_BITMAP 20#ifdef HAVE_LCD_BITMAP
21 21
22/* variable button definitions */
23#if CONFIG_KEYPAD == RECORDER_PAD
24#define PUZZLE_QUIT BUTTON_OFF
25#define PUZZLE_SHUFFLE BUTTON_F1
26#define PUZZLE_PICTURE BUTTON_F2
27
28#elif CONFIG_KEYPAD == ONDIO_PAD
29#define PUZZLE_QUIT BUTTON_OFF
30#define PUZZLE_SHUFFLE_PICTURE_PRE BUTTON_MENU
31#define PUZZLE_SHUFFLE (BUTTON_MENU | BUTTON_REPEAT)
32#define PUZZLE_PICTURE (BUTTON_MENU | BUTTON_REL)
33
34#endif
35
22static struct plugin_api* rb; 36static struct plugin_api* rb;
23static int spots[20]; 37static int spots[20];
24static int hole = 19, moves; 38static int hole = 19, moves;
@@ -232,20 +246,31 @@ static void puzzle_init(void)
232/* the main game loop */ 246/* the main game loop */
233static int puzzle_loop(void) 247static int puzzle_loop(void)
234{ 248{
249 int button;
250 int lastbutton = BUTTON_NONE;
235 int i; 251 int i;
236 puzzle_init(); 252 puzzle_init();
237 while(true) { 253 while(true) {
238 switch (rb->button_get(true)) { 254 button = rb->button_get(true);
239 case BUTTON_OFF: 255 switch (button) {
256 case PUZZLE_QUIT:
240 /* get out of here */ 257 /* get out of here */
241 return PLUGIN_OK; 258 return PLUGIN_OK;
242 259
243 case BUTTON_F1: 260 case PUZZLE_SHUFFLE:
261#ifdef PUZZLE_SHUFFLE_PICTURE_PRE
262 if (lastbutton != PUZZLE_SHUFFLE_PICTURE_PRE)
263 break;
264#endif
244 /* mix up the pieces */ 265 /* mix up the pieces */
245 puzzle_init(); 266 puzzle_init();
246 break; 267 break;
247 268
248 case BUTTON_F2: 269 case PUZZLE_PICTURE:
270#ifdef PUZZLE_SHUFFLE_PICTURE_PRE
271 if (lastbutton != PUZZLE_SHUFFLE_PICTURE_PRE)
272 break;
273#endif
249 /* change picture */ 274 /* change picture */
250 pic = (pic==true?false:true); 275 pic = (pic==true?false:true);
251 for (i=0; i<20; i++) 276 for (i=0; i<20; i++)
@@ -273,10 +298,13 @@ static int puzzle_loop(void)
273 move_spot(0, 1); 298 move_spot(0, 1);
274 break; 299 break;
275 300
276 case SYS_USB_CONNECTED: 301 default:
277 rb->usb_screen(); 302 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
278 return PLUGIN_USB_CONNECTED; 303 return PLUGIN_USB_CONNECTED;
304 break;
279 } 305 }
306 if (button != BUTTON_NONE)
307 lastbutton = button;
280 } 308 }
281} 309}
282 310
@@ -300,9 +328,15 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
300 /* print instructions */ 328 /* print instructions */
301 rb->lcd_clear_display(); 329 rb->lcd_clear_display();
302 rb->lcd_setfont(FONT_SYSFIXED); 330 rb->lcd_setfont(FONT_SYSFIXED);
331#if CONFIG_KEYPAD == RECORDER_PAD
303 rb->lcd_putsxy(3, 18, "[OFF] to stop"); 332 rb->lcd_putsxy(3, 18, "[OFF] to stop");
304 rb->lcd_putsxy(3, 28, "[F1] shuffle"); 333 rb->lcd_putsxy(3, 28, "[F1] shuffle");
305 rb->lcd_putsxy(3, 38, "[F2] change pic"); 334 rb->lcd_putsxy(3, 38, "[F2] change pic");
335#elif CONFIG_KEYPAD == ONDIO_PAD
336 rb->lcd_putsxy(0, 18, "[OFF] to stop");
337 rb->lcd_putsxy(0, 28, "[MENU..] shuffle");
338 rb->lcd_putsxy(0, 38, "[MENU] change pic");
339#endif
306 rb->lcd_update(); 340 rb->lcd_update();
307 rb->sleep(HZ*2); 341 rb->sleep(HZ*2);
308 342
diff --git a/apps/plugins/snake.c b/apps/plugins/snake.c
index e99cb1c952..242c432e8b 100644
--- a/apps/plugins/snake.c
+++ b/apps/plugins/snake.c
@@ -33,6 +33,17 @@ dir is the current direction of the snake - 0=up, 1=right, 2=down, 3=left;
33#include "plugin.h" 33#include "plugin.h"
34#ifdef HAVE_LCD_BITMAP 34#ifdef HAVE_LCD_BITMAP
35 35
36/* variable button definitions */
37#if CONFIG_KEYPAD == RECORDER_PAD
38#define SNAKE_QUIT BUTTON_OFF
39#define SNAKE_PLAYPAUSE BUTTON_PLAY
40
41#elif CONFIG_KEYPAD == ONDIO_PAD
42#define SNAKE_QUIT BUTTON_OFF
43#define SNAKE_PLAYPAUSE BUTTON_MENU
44
45#endif
46
36static int board[28][16],snakelength; 47static int board[28][16],snakelength;
37static unsigned int score,hiscore=0; 48static unsigned int score,hiscore=0;
38static short dir,frames,apple,level=1,dead=0; 49static short dir,frames,apple,level=1,dead=0;
@@ -156,26 +167,39 @@ void redraw (void)
156} 167}
157 168
158void game_pause (void) { 169void game_pause (void) {
170 int button;
159 rb->lcd_clear_display(); 171 rb->lcd_clear_display();
160 rb->lcd_putsxy(3,12,"Game Paused"); 172 rb->lcd_putsxy(3,12,"Game Paused");
173#if CONFIG_KEYPAD == RECORDER_PAD
161 rb->lcd_putsxy(3,22,"[Play] to resume"); 174 rb->lcd_putsxy(3,22,"[Play] to resume");
175#elif CONFIG_KEYPAD == ONDIO_PAD
176 rb->lcd_putsxy(3,22,"[Menu] to resume");
177#endif
162 rb->lcd_putsxy(3,32,"[Off] to quit"); 178 rb->lcd_putsxy(3,32,"[Off] to quit");
163 rb->lcd_update(); 179 rb->lcd_update();
164 while (1) { 180 while (1) {
165 switch (rb->button_get(true)) { 181 button=rb->button_get(true);
166 case BUTTON_OFF: 182 switch (button) {
183 case SNAKE_QUIT:
167 dead=1; 184 dead=1;
168 return; 185 return;
169 case BUTTON_PLAY: 186 case SNAKE_PLAYPAUSE:
170 redraw(); 187 redraw();
171 rb->sleep(HZ/2); 188 rb->sleep(HZ/2);
172 return; 189 return;
190 default:
191 if (rb->default_event_handler(button)==SYS_USB_CONNECTED) {
192 dead=2;
193 return;
194 }
195 break;
173 } 196 }
174 } 197 }
175} 198}
176 199
177 200
178void game (void) { 201void game (void) {
202 int button;
179 short x,y; 203 short x,y;
180 while (1) { 204 while (1) {
181 frame(); 205 frame();
@@ -198,7 +222,8 @@ void game (void) {
198 222
199 rb->sleep(HZ/level); 223 rb->sleep(HZ/level);
200 224
201 switch (rb->button_get(false)) { 225 button=rb->button_get(false);
226 switch (button) {
202 case BUTTON_UP: 227 case BUTTON_UP:
203 if (dir!=2) dir=0; 228 if (dir!=2) dir=0;
204 break; 229 break;
@@ -211,17 +236,24 @@ void game (void) {
211 case BUTTON_LEFT: 236 case BUTTON_LEFT:
212 if (dir!=1) dir=3; 237 if (dir!=1) dir=3;
213 break; 238 break;
214 case BUTTON_OFF: 239 case SNAKE_QUIT:
215 dead=1; 240 dead=1;
216 return; 241 return;
217 case BUTTON_PLAY: 242 case SNAKE_PLAYPAUSE:
218 game_pause(); 243 game_pause();
219 break; 244 break;
220 } 245 default:
246 if (rb->default_event_handler(button)==SYS_USB_CONNECTED) {
247 dead=2;
248 return;
249 }
250 break;
251 }
221 } 252 }
222} 253}
223 254
224void game_init(void) { 255void game_init(void) {
256 int button;
225 short x,y; 257 short x,y;
226 char plevel[10],phscore[20]; 258 char plevel[10],phscore[20];
227 259
@@ -244,12 +276,17 @@ void game_init(void) {
244 rb->lcd_puts(0,0, plevel); 276 rb->lcd_puts(0,0, plevel);
245 rb->lcd_puts(0,1, "(1-slow, 9-fast)"); 277 rb->lcd_puts(0,1, "(1-slow, 9-fast)");
246 rb->lcd_puts(0,2, "OFF - quit"); 278 rb->lcd_puts(0,2, "OFF - quit");
279#if CONFIG_KEYPAD == RECORDER_PAD
247 rb->lcd_puts(0,3, "PLAY - start/pause"); 280 rb->lcd_puts(0,3, "PLAY - start/pause");
281#elif CONFIG_KEYPAD == ONDIO_PAD
282 rb->lcd_puts(0,3, "MENU - start/pause");
283#endif
248 rb->lcd_puts(0,4, phscore); 284 rb->lcd_puts(0,4, phscore);
249 rb->lcd_update(); 285 rb->lcd_update();
250 286
251 while (1) { 287 while (1) {
252 switch (rb->button_get(true)) { 288 button=rb->button_get(true);
289 switch (button) {
253 case BUTTON_RIGHT: 290 case BUTTON_RIGHT:
254 case BUTTON_UP: 291 case BUTTON_UP:
255 if (level<9) 292 if (level<9)
@@ -260,13 +297,19 @@ void game_init(void) {
260 if (level>1) 297 if (level>1)
261 level--; 298 level--;
262 break; 299 break;
263 case BUTTON_OFF: 300 case SNAKE_QUIT:
264 dead=1; 301 dead=1;
265 return; 302 return;
266 break; 303 break;
267 case BUTTON_PLAY: 304 case SNAKE_PLAYPAUSE:
268 return; 305 return;
269 break; 306 break;
307 default:
308 if (rb->default_event_handler(button)==SYS_USB_CONNECTED) {
309 dead=2;
310 return;
311 }
312 break;
270 } 313 }
271 rb->snprintf(plevel,sizeof(plevel),"Level - %d",level); 314 rb->snprintf(plevel,sizeof(plevel),"Level - %d",level);
272 rb->lcd_puts(0,0, plevel); 315 rb->lcd_puts(0,0, plevel);
@@ -283,8 +326,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
283 326
284 game_init(); 327 game_init();
285 rb->lcd_clear_display(); 328 rb->lcd_clear_display();
286 game(); 329 game();
287 return false; 330 return (dead==1)?PLUGIN_OK:PLUGIN_USB_CONNECTED;
288} 331}
289 332
290#endif 333#endif
diff --git a/apps/plugins/snake2.c b/apps/plugins/snake2.c
index e83e298beb..3f6db5c550 100644
--- a/apps/plugins/snake2.c
+++ b/apps/plugins/snake2.c
@@ -33,6 +33,27 @@ Head and Tail are stored
33#define WIDTH 28 33#define WIDTH 28
34#define HEIGHT 16 34#define HEIGHT 16
35 35
36/* variable button definitions */
37#if CONFIG_KEYPAD == RECORDER_PAD
38#define SNAKE2_QUIT BUTTON_OFF
39#define SNAKE2_LEVEL_UP BUTTON_UP
40#define SNAKE2_LEVEL_UP2 BUTTON_RIGHT
41#define SNAKE2_LEVEL_DOWN BUTTON_DOWN
42#define SNAKE2_LEVEL_DOWN2 BUTTON_LEFT
43#define SNAKE2_SELECT_MAZE BUTTON_F1
44#define SNAKE2_SELECT_TYPE BUTTON_F3
45#define SNAKE2_PLAYPAUSE BUTTON_PLAY
46
47#elif CONFIG_KEYPAD == ONDIO_PAD
48#define SNAKE2_QUIT BUTTON_OFF
49#define SNAKE2_LEVEL_UP BUTTON_UP
50#define SNAKE2_LEVEL_DOWN BUTTON_DOWN
51#define SNAKE2_SELECT_MAZE BUTTON_LEFT
52#define SNAKE2_SELECT_TYPE BUTTON_RIGHT
53#define SNAKE2_PLAYPAUSE BUTTON_MENU
54
55#endif
56
36static int max_levels = 0; 57static int max_levels = 0;
37static char (*level_cache)[HEIGHT][WIDTH]; 58static char (*level_cache)[HEIGHT][WIDTH];
38 59
@@ -770,24 +791,37 @@ void frame (void)
770 791
771void game_pause (void) 792void game_pause (void)
772{ 793{
794 int button;
795
773 rb->lcd_clear_display(); 796 rb->lcd_clear_display();
774 rb->lcd_putsxy(33,12,"Paused"); 797 rb->lcd_putsxy(33,12,"Paused");
775 798
776 rb->lcd_update(); 799 rb->lcd_update();
777 while (1) 800 while (1)
778 { 801 {
779 switch (rb->button_get(true)) 802 button = rb->button_get(true);
803 switch (button)
780 { 804 {
781 case BUTTON_PLAY: 805 case SNAKE2_PLAYPAUSE:
782 redraw(); 806 redraw();
783 rb->sleep(HZ/2); 807 rb->sleep(HZ/2);
784 return; 808 return;
809
810 default:
811 if (rb->default_event_handler(button)==SYS_USB_CONNECTED) {
812 dead = 1;
813 quit = 2;
814 return;
815 }
816 break;
785 } 817 }
786 } 818 }
787} 819}
788 820
789void game (void) 821void game (void)
790{ 822{
823 int button;
824
791 redraw(); 825 redraw();
792 /*main loop:*/ 826 /*main loop:*/
793 while (1) 827 while (1)
@@ -821,7 +855,8 @@ void game (void)
821 855
822 rb->sleep(HZ/speed); 856 rb->sleep(HZ/speed);
823 857
824 switch (rb->button_get(false)) 858 button = rb->button_get(false);
859 switch (button)
825 { 860 {
826 case BUTTON_UP: 861 case BUTTON_UP:
827 case BUTTON_UP | BUTTON_REPEAT: 862 case BUTTON_UP | BUTTON_REPEAT:
@@ -843,14 +878,21 @@ void game (void)
843 if (dir != EAST) set_direction(WEST); 878 if (dir != EAST) set_direction(WEST);
844 break; 879 break;
845 880
846 case BUTTON_OFF: 881 case SNAKE2_QUIT:
847 dead=1; 882 dead=1;
848 return; 883 return;
849 884
850 case BUTTON_PLAY: 885 case SNAKE2_PLAYPAUSE:
851 game_pause(); 886 game_pause();
852 break; 887 break;
853 } 888
889 default:
890 if (rb->default_event_handler(button)==SYS_USB_CONNECTED) {
891 quit = 2;
892 return;
893 }
894 break;
895 }
854 } 896 }
855} 897}
856 898
@@ -862,37 +904,42 @@ void game_init(void)
862 dead=0; 904 dead=0;
863 apple=0; 905 apple=0;
864 score=0; 906 score=0;
865 907 int button;
866 908
867 clear_board(); 909 clear_board();
868 load_level( level_from_file ); 910 load_level( level_from_file );
869 911
870 while (1) 912 while (1)
871 { 913 {
872 switch (rb->button_get(true)) 914 button=rb->button_get(true);
915 switch (button)
873 { 916 {
874 case BUTTON_RIGHT: 917 case SNAKE2_LEVEL_UP:
875 case BUTTON_UP: 918#ifdef SNAKE2_LEVEL_UP2
919 case SNAKE2_LEVEL_UP2:
920#endif
876 if (level<10) 921 if (level<10)
877 level+=1; 922 level+=1;
878 break; 923 break;
879 case BUTTON_LEFT: 924 case SNAKE2_LEVEL_DOWN:
880 case BUTTON_DOWN: 925#ifdef SNAKE2_LEVEL_DOWN2
926 case SNAKE2_LEVEL_DOWN2:
927#endif
881 if (level>1) 928 if (level>1)
882 level-=1; 929 level-=1;
883 break; 930 break;
884 case BUTTON_OFF: 931 case SNAKE2_QUIT:
885 quit=1; 932 quit=1;
886 return; 933 return;
887 break; 934 break;
888 case BUTTON_PLAY: 935 case SNAKE2_PLAYPAUSE:
889 speed = level*20; 936 speed = level*20;
890 return; 937 return;
891 break; 938 break;
892 case BUTTON_F3: 939 case SNAKE2_SELECT_TYPE:
893 if(game_type==0)game_type=1; else game_type=0; 940 if(game_type==0)game_type=1; else game_type=0;
894 break; 941 break;
895 case BUTTON_F1: 942 case SNAKE2_SELECT_MAZE:
896 943
897 level_from_file++; 944 level_from_file++;
898 if(level_from_file > num_levels) 945 if(level_from_file > num_levels)
@@ -903,6 +950,12 @@ void game_init(void)
903 load_level( level_from_file ); 950 load_level( level_from_file );
904 951
905 break; 952 break;
953 default:
954 if (rb->default_event_handler(button)==SYS_USB_CONNECTED) {
955 quit = 2;
956 return;
957 }
958 break;
906 } 959 }
907 960
908 rb->lcd_clear_display(); 961 rb->lcd_clear_display();
@@ -910,13 +963,22 @@ void game_init(void)
910 /*TODO: CENTER ALL TEXT!!!!*/ 963 /*TODO: CENTER ALL TEXT!!!!*/
911 rb->snprintf(plevel,sizeof(plevel),"Speed - %d",level); 964 rb->snprintf(plevel,sizeof(plevel),"Speed - %d",level);
912 rb->lcd_putsxy(LCD_WIDTH/2 - 30,5, plevel); 965 rb->lcd_putsxy(LCD_WIDTH/2 - 30,5, plevel);
966#if CONFIG_KEYPAD == RECORDER_PAD
913 rb->snprintf(plevel,sizeof(plevel),"F1 - Maze %d",level_from_file); 967 rb->snprintf(plevel,sizeof(plevel),"F1 - Maze %d",level_from_file);
914 rb->lcd_putsxy(18, 20, plevel); 968 rb->lcd_putsxy(18, 20, plevel);
915 if(game_type==0) 969 if(game_type==0)
916 rb->lcd_putsxy(18, 30, "F3 - Game A"); 970 rb->lcd_putsxy(18, 30, "F3 - Game A");
917 else 971 else
918 rb->lcd_putsxy(18, 30, "F3 - Game B"); 972 rb->lcd_putsxy(18, 30, "F3 - Game B");
919 973#elif CONFIG_KEYPAD == ONDIO_PAD
974 rb->snprintf(plevel,sizeof(plevel),"Left - Maze %d",level_from_file);
975 rb->lcd_putsxy(18, 20, plevel);
976 if(game_type==0)
977 rb->lcd_putsxy(12, 30, "Right - Game A");
978 else
979 rb->lcd_putsxy(12, 30, "Right - Game B");
980#endif
981
920 rb->snprintf(phscore,sizeof(phscore),"Hi Score: %d",hiscore); 982 rb->snprintf(phscore,sizeof(phscore),"Hi Score: %d",hiscore);
921 rb->lcd_putsxy(LCD_WIDTH/2 - 37,50, phscore); 983 rb->lcd_putsxy(LCD_WIDTH/2 - 37,50, phscore);
922 rb->lcd_update(); 984 rb->lcd_update();
@@ -953,7 +1015,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
953 } 1015 }
954 } 1016 }
955 1017
956 return false; 1018 return (quit==1) ? PLUGIN_OK : PLUGIN_USB_CONNECTED;
957} 1019}
958 1020
959#endif 1021#endif
diff --git a/apps/plugins/sokoban.c b/apps/plugins/sokoban.c
index ff13b470f5..6365e6c3ae 100644
--- a/apps/plugins/sokoban.c
+++ b/apps/plugins/sokoban.c
@@ -33,6 +33,24 @@
33 33
34#define SOKOBAN_LEVEL_SIZE (ROWS*COLS) 34#define SOKOBAN_LEVEL_SIZE (ROWS*COLS)
35 35
36/* variable button definitions */
37#if CONFIG_KEYPAD == RECORDER_PAD
38#define SOKOBAN_QUIT BUTTON_OFF
39#define SOKOBAN_UNDO BUTTON_ON
40#define SOKOBAN_LEVEL_UP BUTTON_F3
41#define SOKOBAN_LEVEL_DOWN BUTTON_F1
42#define SOKOBAN_LEVEL_REPEAT BUTTON_F2
43
44#elif CONFIG_KEYPAD == ONDIO_PAD
45#define SOKOBAN_QUIT BUTTON_OFF
46#define SOKOBAN_UNDO_PRE BUTTON_MENU
47#define SOKOBAN_UNDO (BUTTON_MENU | BUTTON_REL)
48#define SOKOBAN_LEVEL_UP (BUTTON_MENU | BUTTON_RIGHT)
49#define SOKOBAN_LEVEL_DOWN (BUTTON_MENU | BUTTON_LEFT)
50#define SOKOBAN_LEVEL_REPEAT (BUTTON_MENU | BUTTON_UP)
51
52#endif
53
36static void init_undo(void); 54static void init_undo(void);
37static void undo(void); 55static void undo(void);
38static void add_undo(int button); 56static void add_undo(int button);
@@ -443,7 +461,7 @@ static bool sokoban_loop(void)
443{ 461{
444 char new_spot; 462 char new_spot;
445 bool moved = true; 463 bool moved = true;
446 int i = 0, button = 0; 464 int i = 0, button = 0, lastbutton = 0;
447 short r = 0, c = 0; 465 short r = 0, c = 0;
448 466
449 current_info.level.level = 1; 467 current_info.level.level = 1;
@@ -465,27 +483,32 @@ static bool sokoban_loop(void)
465 { 483 {
466 case BUTTON_OFF: 484 case BUTTON_OFF:
467 /* get out of here */ 485 /* get out of here */
468 return PLUGIN_OK; 486 return PLUGIN_OK;
469 487
470 case BUTTON_ON: 488 case SOKOBAN_UNDO:
471 case BUTTON_ON | BUTTON_REPEAT: 489#ifdef SOKOBAN_UNDO_PRE
490 if (lastbutton != SOKOBAN_UNDO_PRE)
491 break;
492#else /* repeat can't work here for Ondio */
493 case SOKOBAN_UNDO | BUTTON_REPEAT:
494#endif
472 /* this is UNDO */ 495 /* this is UNDO */
473 undo(); 496 undo();
474 rb->lcd_clear_display(); 497 rb->lcd_clear_display();
475 update_screen(); 498 update_screen();
476 moved = false; 499 moved = false;
477 break; 500 break;
478 501
479 case BUTTON_F3: 502 case SOKOBAN_LEVEL_UP:
480 case BUTTON_F3 | BUTTON_REPEAT: 503 case SOKOBAN_LEVEL_UP | BUTTON_REPEAT:
481 /* increase level */ 504 /* increase level */
482 init_undo(); 505 init_undo();
483 current_info.level.boxes_to_go=0; 506 current_info.level.boxes_to_go=0;
484 moved = true; 507 moved = true;
485 break; 508 break;
486 509
487 case BUTTON_F1: 510 case SOKOBAN_LEVEL_DOWN:
488 case BUTTON_F1 | BUTTON_REPEAT: 511 case SOKOBAN_LEVEL_DOWN | BUTTON_REPEAT:
489 /* previous level */ 512 /* previous level */
490 init_undo(); 513 init_undo();
491 if (current_info.level.level > 1) 514 if (current_info.level.level > 1)
@@ -495,8 +518,8 @@ static bool sokoban_loop(void)
495 moved = false; 518 moved = false;
496 break; 519 break;
497 520
498 case BUTTON_F2: 521 case SOKOBAN_LEVEL_REPEAT:
499 case BUTTON_F2 | BUTTON_REPEAT: 522 case SOKOBAN_LEVEL_REPEAT | BUTTON_REPEAT:
500 /* same level */ 523 /* same level */
501 init_undo(); 524 init_undo();
502 draw_level(); 525 draw_level();
@@ -504,7 +527,7 @@ static bool sokoban_loop(void)
504 break; 527 break;
505 528
506 case BUTTON_LEFT: 529 case BUTTON_LEFT:
507 switch(current_info.board[r][c-1]) 530 switch(current_info.board[r][c-1])
508 { 531 {
509 case ' ': /* if it is a blank spot */ 532 case ' ': /* if it is a blank spot */
510 case '.': /* if it is a home spot */ 533 case '.': /* if it is a home spot */
@@ -527,7 +550,7 @@ static bool sokoban_loop(void)
527 case '.': /* going from a blank to home */ 550 case '.': /* going from a blank to home */
528 current_info.board[r][c-2] = '%'; 551 current_info.board[r][c-2] = '%';
529 current_info.board[r][c-1] = current_info.board[r][c]; 552 current_info.board[r][c-1] = current_info.board[r][c];
530 current_info.board[r][c] = current_info.player.spot; 553 current_info.board[r][c] = current_info.player.spot;
531 current_info.player.spot = ' '; 554 current_info.player.spot = ' ';
532 current_info.level.boxes_to_go--; 555 current_info.level.boxes_to_go--;
533 break; 556 break;
@@ -551,7 +574,7 @@ static bool sokoban_loop(void)
551 case '.': /* if we are going from a home to home */ 574 case '.': /* if we are going from a home to home */
552 current_info.board[r][c-2] = '%'; 575 current_info.board[r][c-2] = '%';
553 current_info.board[r][c-1] = current_info.board[r][c]; 576 current_info.board[r][c-1] = current_info.board[r][c];
554 current_info.board[r][c] = current_info.player.spot; 577 current_info.board[r][c] = current_info.player.spot;
555 current_info.player.spot = '.'; 578 current_info.player.spot = '.';
556 break; 579 break;
557 580
@@ -580,7 +603,7 @@ static bool sokoban_loop(void)
580 current_info.player.spot = new_spot; 603 current_info.player.spot = new_spot;
581 break; 604 break;
582 605
583 case '$': 606 case '$':
584 switch(current_info.board[r][c+2]) { 607 switch(current_info.board[r][c+2]) {
585 case ' ': /* going from blank to blank */ 608 case ' ': /* going from blank to blank */
586 current_info.board[r][c+2] = current_info.board[r][c+1]; 609 current_info.board[r][c+2] = current_info.board[r][c+1];
@@ -592,7 +615,7 @@ static bool sokoban_loop(void)
592 case '.': /* going from a blank to home */ 615 case '.': /* going from a blank to home */
593 current_info.board[r][c+2] = '%'; 616 current_info.board[r][c+2] = '%';
594 current_info.board[r][c+1] = current_info.board[r][c]; 617 current_info.board[r][c+1] = current_info.board[r][c];
595 current_info.board[r][c] = current_info.player.spot; 618 current_info.board[r][c] = current_info.player.spot;
596 current_info.player.spot = ' '; 619 current_info.player.spot = ' ';
597 current_info.level.boxes_to_go--; 620 current_info.level.boxes_to_go--;
598 break; 621 break;
@@ -616,7 +639,7 @@ static bool sokoban_loop(void)
616 case '.': 639 case '.':
617 current_info.board[r][c+2] = '%'; 640 current_info.board[r][c+2] = '%';
618 current_info.board[r][c+1] = current_info.board[r][c]; 641 current_info.board[r][c+1] = current_info.board[r][c];
619 current_info.board[r][c] = current_info.player.spot; 642 current_info.board[r][c] = current_info.player.spot;
620 current_info.player.spot = '.'; 643 current_info.player.spot = '.';
621 break; 644 break;
622 645
@@ -657,7 +680,7 @@ static bool sokoban_loop(void)
657 case '.': /* going from a blank to home */ 680 case '.': /* going from a blank to home */
658 current_info.board[r-2][c] = '%'; 681 current_info.board[r-2][c] = '%';
659 current_info.board[r-1][c] = current_info.board[r][c]; 682 current_info.board[r-1][c] = current_info.board[r][c];
660 current_info.board[r][c] = current_info.player.spot; 683 current_info.board[r][c] = current_info.player.spot;
661 current_info.player.spot = ' '; 684 current_info.player.spot = ' ';
662 current_info.level.boxes_to_go--; 685 current_info.level.boxes_to_go--;
663 break; 686 break;
@@ -681,7 +704,7 @@ static bool sokoban_loop(void)
681 case '.': /* if we are going from a home to home */ 704 case '.': /* if we are going from a home to home */
682 current_info.board[r-2][c] = '%'; 705 current_info.board[r-2][c] = '%';
683 current_info.board[r-1][c] = current_info.board[r][c]; 706 current_info.board[r-1][c] = current_info.board[r][c];
684 current_info.board[r][c] = current_info.player.spot; 707 current_info.board[r][c] = current_info.player.spot;
685 current_info.player.spot = '.'; 708 current_info.player.spot = '.';
686 break; 709 break;
687 710
@@ -722,7 +745,7 @@ static bool sokoban_loop(void)
722 case '.': /* going from a blank to home */ 745 case '.': /* going from a blank to home */
723 current_info.board[r+2][c] = '%'; 746 current_info.board[r+2][c] = '%';
724 current_info.board[r+1][c] = current_info.board[r][c]; 747 current_info.board[r+1][c] = current_info.board[r][c];
725 current_info.board[r][c] = current_info.player.spot; 748 current_info.board[r][c] = current_info.player.spot;
726 current_info.player.spot = ' '; 749 current_info.player.spot = ' ';
727 current_info.level.boxes_to_go--; 750 current_info.level.boxes_to_go--;
728 break; 751 break;
@@ -746,7 +769,7 @@ static bool sokoban_loop(void)
746 case '.': /* going from a home to home */ 769 case '.': /* going from a home to home */
747 current_info.board[r+2][c] = '%'; 770 current_info.board[r+2][c] = '%';
748 current_info.board[r+1][c] = current_info.board[r][c]; 771 current_info.board[r+1][c] = current_info.board[r][c];
749 current_info.board[r][c] = current_info.player.spot; 772 current_info.board[r][c] = current_info.player.spot;
750 current_info.player.spot = '.'; 773 current_info.player.spot = '.';
751 break; 774 break;
752 775
@@ -765,19 +788,21 @@ static bool sokoban_loop(void)
765 current_info.player.row++; 788 current_info.player.row++;
766 break; 789 break;
767 790
768 case SYS_USB_CONNECTED:
769 rb->usb_screen();
770 return PLUGIN_USB_CONNECTED;
771
772 default: 791 default:
792 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
793 return PLUGIN_USB_CONNECTED;
794
773 moved = false; 795 moved = false;
774 break; 796 break;
775 } 797 }
776 798
799 if (button != BUTTON_NONE)
800 lastbutton = button;
801
777 if (moved) { 802 if (moved) {
778 current_info.level.moves++; 803 current_info.level.moves++;
779 rb->lcd_clear_display(); 804 rb->lcd_clear_display();
780 update_screen(); 805 update_screen();
781 } 806 }
782 807
783 /* We have completed this level */ 808 /* We have completed this level */
@@ -845,11 +870,19 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
845 870
846 rb->lcd_clear_display(); 871 rb->lcd_clear_display();
847 872
873#if CONFIG_KEYPAD == RECORDER_PAD
848 rb->lcd_putsxy(3, 6, "[OFF] To Stop"); 874 rb->lcd_putsxy(3, 6, "[OFF] To Stop");
849 rb->lcd_putsxy(3, 16, "[ON] To Undo"); 875 rb->lcd_putsxy(3, 16, "[ON] To Undo");
850 rb->lcd_putsxy(3, 26, "[F1] - Level"); 876 rb->lcd_putsxy(3, 26, "[F1] - Level");
851 rb->lcd_putsxy(3, 36, "[F2] Same Level"); 877 rb->lcd_putsxy(3, 36, "[F2] Same Level");
852 rb->lcd_putsxy(3, 46, "[F3] + Level"); 878 rb->lcd_putsxy(3, 46, "[F3] + Level");
879#elif CONFIG_KEYPAD == ONDIO_PAD
880 rb->lcd_putsxy(3, 6, "[OFF] To Stop");
881 rb->lcd_putsxy(3, 16, "[MENU] To Undo");
882 rb->lcd_putsxy(3, 26, "[M-LEFT] - Level");
883 rb->lcd_putsxy(3, 36, "[M-UP] Same Level");
884 rb->lcd_putsxy(3, 46, "[M-RIGHT] + Level");
885#endif
853 886
854 rb->lcd_update(); 887 rb->lcd_update();
855 rb->sleep(HZ*2); 888 rb->sleep(HZ*2);