diff options
author | Jens Arnold <amiconn@rockbox.org> | 2004-10-18 21:45:00 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2004-10-18 21:45:00 +0000 |
commit | e35a658ded457698aca2401b699e743a3011cfce (patch) | |
tree | cb89b7785ef2c72f7a293fe165a4d3b76e38227f /apps/plugins | |
parent | d24766675db5faddb67810ca67b37491d49c2313 (diff) |
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/plugins')
-rw-r--r-- | apps/plugins/SOURCES | 22 | ||||
-rw-r--r-- | apps/plugins/flipit.c | 55 | ||||
-rw-r--r-- | apps/plugins/mandelbrot.c | 64 | ||||
-rw-r--r-- | apps/plugins/minesweeper.c | 78 | ||||
-rw-r--r-- | apps/plugins/mosaique.c | 65 | ||||
-rw-r--r-- | apps/plugins/oscillograph.c | 76 | ||||
-rw-r--r-- | apps/plugins/pong.c | 44 | ||||
-rw-r--r-- | apps/plugins/sliding_puzzle.c | 48 | ||||
-rw-r--r-- | apps/plugins/snake.c | 69 | ||||
-rw-r--r-- | apps/plugins/snake2.c | 98 | ||||
-rw-r--r-- | apps/plugins/sokoban.c | 85 |
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 calculator.c chip8.c cube.c +flipit.c grayscale.c jpeg.c +mandelbrot.c +minesweeper.c +mosaique.c +oscillograph.c +pong.c rockblox.c +sliding_puzzle.c +snake.c +snake2.c snow.c +sokoban.c video.c #ifdef HAVE_RTC /* Recorder models only */ calendar.c clock.c -#endif +#endif /* #ifdef HAVE_RTC */ #if CONFIG_KEYPAD != ONDIO_PAD /* gradually bring in the ones not working yet */ -flipit.c -mandelbrot.c -minesweeper.c -mosaique.c -oscillograph.c -pong.c -sliding_puzzle.c -snake.c -snake2.c -sokoban.c solitaire.c splitedit.c star.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 @@ #include "plugin.h" #ifdef HAVE_LCD_BITMAP +/* variable button definitions */ +#if CONFIG_KEYPAD == RECORDER_PAD +#define FLIPIT_QUIT BUTTON_OFF +#define FLIPIT_SHUFFLE BUTTON_F1 +#define FLIPIT_SOLVE BUTTON_F2 +#define FLIPIT_STEP_BY_STEP BUTTON_F3 +#define FLIPIT_TOGGLE BUTTON_PLAY + +#elif CONFIG_KEYPAD == ONDIO_PAD +#define FLIPIT_QUIT BUTTON_OFF +#define FLIPIT_SHUFFLE (BUTTON_MENU | BUTTON_LEFT) +#define FLIPIT_SOLVE (BUTTON_MENU | BUTTON_UP) +#define FLIPIT_STEP_BY_STEP (BUTTON_MENU | BUTTON_RIGHT) +#define FLIPIT_TOGGLE_PRE BUTTON_MENU +#define FLIPIT_TOGGLE (BUTTON_MENU | BUTTON_REL) + +#endif + static struct plugin_api* rb; static int spots[20]; static int toggle[20]; @@ -152,19 +170,23 @@ static void flipit_init(void) { /* the main game loop */ static bool flipit_loop(void) { int i; + int button; + int lastbutton = BUTTON_NONE; + flipit_init(); while(true) { - switch (rb->button_get(true)) { - case BUTTON_OFF: + button = rb->button_get(true); + switch (button) { + case FLIPIT_QUIT: /* get out of here */ return PLUGIN_OK; - case BUTTON_F1: + case FLIPIT_SHUFFLE: /* mix up the pieces */ flipit_init(); break; - case BUTTON_F2: + case FLIPIT_SOLVE: /* solve the puzzle */ if (!flipit_finished()) { for (i=0; i<20; i++) @@ -179,7 +201,7 @@ static bool flipit_loop(void) { } break; - case BUTTON_F3: + case FLIPIT_STEP_BY_STEP: if (!flipit_finished()) { for (i=0; i<20; i++) if (!toggle[i]) { @@ -193,7 +215,11 @@ static bool flipit_loop(void) { } break; - case BUTTON_PLAY: + case FLIPIT_TOGGLE: +#ifdef FLIPIT_TOGGLE_PRE + if (lastbutton != FLIPIT_TOGGLE_PRE) + break; +#endif /* toggle the pieces */ if (!flipit_finished()) { flipit_toggle(); @@ -221,10 +247,13 @@ static bool flipit_loop(void) { move_cursor(0, 1); break; - case SYS_USB_CONNECTED: - rb->usb_screen(); - return PLUGIN_USB_CONNECTED; + default: + if (rb->default_event_handler(button) == SYS_USB_CONNECTED) + return PLUGIN_USB_CONNECTED; + break; } + if (button != BUTTON_NONE) + lastbutton = button; } } @@ -249,11 +278,19 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) /* print instructions */ rb->lcd_clear_display(); rb->lcd_setfont(FONT_SYSFIXED); +#if CONFIG_KEYPAD == RECORDER_PAD rb->lcd_putsxy(2, 8, "[OFF] to stop"); rb->lcd_putsxy(2, 18, "[PLAY] toggle"); rb->lcd_putsxy(2, 28, "[F1] shuffle"); rb->lcd_putsxy(2, 38, "[F2] solution"); rb->lcd_putsxy(2, 48, "[F3] step by step"); +#elif CONFIG_KEYPAD == ONDIO_PAD + rb->lcd_putsxy(2, 8, "[OFF] to stop"); + rb->lcd_putsxy(2, 18, "[MENU] toggle"); + rb->lcd_putsxy(2, 28, "[M-LEFT] shuffle"); + rb->lcd_putsxy(2, 38, "[M-UP] solution"); + rb->lcd_putsxy(2, 48, "[M-RIGHT] step by step"); +#endif rb->lcd_update(); rb->sleep(HZ*3); 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 @@ #ifdef HAVE_LCD_BITMAP // this is not fun on the player # include "gray.h" +/* variable button definitions */ +#if CONFIG_KEYPAD == RECORDER_PAD +#define MANDELBROT_QUIT BUTTON_OFF +#define MANDELBROT_ZOOM_IN BUTTON_PLAY +#define MANDELBROT_ZOOM_OUT BUTTON_ON +#define MANDELBROT_MAXITER_INC BUTTON_F2 +#define MANDELBROT_MAXITER_DEC BUTTON_F1 +#define MANDELBROT_RESET BUTTON_F3 + +#elif CONFIG_KEYPAD == ONDIO_PAD +#define MANDELBROT_QUIT BUTTON_OFF +#define MANDELBROT_ZOOM_IN_PRE BUTTON_MENU +#define MANDELBROT_ZOOM_IN (BUTTON_MENU | BUTTON_REL) +#define MANDELBROT_ZOOM_IN2 (BUTTON_MENU | BUTTON_UP) +#define MANDELBROT_ZOOM_OUT (BUTTON_MENU | BUTTON_DOWN) +#define MANDELBROT_MAXITER_INC (BUTTON_MENU | BUTTON_RIGHT) +#define MANDELBROT_MAXITER_DEC (BUTTON_MENU | BUTTON_LEFT) +#define MANDELBROT_RESET (BUTTON_MENU | BUTTON_OFF) + +#endif + static struct plugin_api* rb; static char buff[32]; static int lcd_aspect_ratio; @@ -101,9 +122,17 @@ void calc_mandelbrot_set(void){ } } +void cleanup(void *parameter) +{ + (void)parameter; + + gray_release_buffer(); +} enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { + int button; + int lastbutton = BUTTON_NONE; int grayscales; bool redraw = true; @@ -141,12 +170,13 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) redraw = false; - switch (rb->button_get(true)) { - case BUTTON_OFF: + button = rb->button_get(true); + switch (button) { + case MANDELBROT_QUIT: gray_release_buffer(); return PLUGIN_OK; - case BUTTON_ON: + case MANDELBROT_ZOOM_OUT: x_min -= ((delta>>13)*(lcd_aspect_ratio>>13)); x_max += ((delta>>13)*(lcd_aspect_ratio>>13)); y_min -= delta; @@ -156,7 +186,14 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) break; - case BUTTON_PLAY: + case MANDELBROT_ZOOM_IN: +#ifdef MANDELBROT_ZOOM_IN_PRE + if (lastbutton != MANDELBROT_ZOOM_IN_PRE) + break; +#endif +#ifdef MANDELBROT_ZOOM_IN2 + case MANDELBROT_ZOOM_IN2: +#endif x_min += ((delta>>13)*(lcd_aspect_ratio>>13)); x_max -= ((delta>>13)*(lcd_aspect_ratio>>13)); y_min += delta; @@ -189,33 +226,36 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) redraw = true; break; - case BUTTON_F1: + case MANDELBROT_MAXITER_DEC: if (max_iter>5){ max_iter -= 5; redraw = true; } break; - case BUTTON_F2: + case MANDELBROT_MAXITER_INC: if (max_iter < 195){ max_iter += 5; redraw = true; } break; - case BUTTON_F3: + case MANDELBROT_RESET: init_mandelbrot_set(); redraw = true; break; - case SYS_USB_CONNECTED: - gray_release_buffer(); - rb->usb_screen(); - return PLUGIN_USB_CONNECTED; + default: + if (rb->default_event_handler_ex(button, cleanup, NULL) + == SYS_USB_CONNECTED) + return PLUGIN_USB_CONNECTED; + break; } + if (button != BUTTON_NONE) + lastbutton = button; } gray_release_buffer(); - return false; + return PLUGIN_OK; } #endif #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) #ifdef HAVE_LCD_BITMAP -//what the minesweeper() function can return +//what the minesweeper() function can return +#define MINESWEEPER_USB 3 #define MINESWEEPER_QUIT 2 #define MINESWEEPER_LOSE 1 #define MINESWEEPER_WIN 0 +/* variable button definitions */ +#if CONFIG_KEYPAD == RECORDER_PAD +#define MINESWP_QUIT BUTTON_OFF +#define MINESWP_START BUTTON_ON +#define MINESWP_TOGGLE BUTTON_PLAY +#define MINESWP_TOGGLE2 BUTTON_F1 +#define MINESWP_DISCOVER BUTTON_ON +#define MINESWP_DISCOVER2 BUTTON_F2 +#define MINESWP_INFO BUTTON_F3 + +#elif CONFIG_KEYPAD == ONDIO_PAD +#define MINESWP_QUIT BUTTON_OFF +#define MINESWP_START BUTTON_MENU +#define MINESWP_TOGGLE_PRE BUTTON_MENU +#define MINESWP_TOGGLE (BUTTON_MENU | BUTTON_REL) +#define MINESWP_DISCOVER (BUTTON_MENU | BUTTON_REPEAT) +#define MINESWP_INFO (BUTTON_MENU | BUTTON_OFF) + +#endif + /* here is a global api struct pointer. while not strictly necessary, 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){ int minesweeper(void) { int i,j; + int button; + int lastbutton = BUTTON_NONE; /* the cursor coordinates */ int x=0,y=0; @@ -277,12 +300,17 @@ int minesweeper(void) rb->snprintf(str, 20, "%d%% mines", p); rb->lcd_putsxy(1,19,str); rb->lcd_putsxy(1,28,"down / up"); +#if CONFIG_KEYPAD == RECORDER_PAD rb->lcd_putsxy(1,44,"ON to start"); +#elif CONFIG_KEYPAD == ONDIO_PAD + rb->lcd_putsxy(1,44,"MENU to start"); +#endif rb->lcd_update(); - switch(rb->button_get(true)){ + button = rb->button_get(true); + switch(button){ case BUTTON_DOWN: case BUTTON_LEFT: p = (p + 98)%100; @@ -293,12 +321,17 @@ int minesweeper(void) p = (p + 2)%100; break; - case BUTTON_ON:/* start playing */ + case MINESWP_START:/* start playing */ i = 1; break; - case BUTTON_OFF:/* quit program */ + case MINESWP_QUIT:/* quit program */ return MINESWEEPER_QUIT; + + default: + if (rb->default_event_handler(button) == SYS_USB_CONNECTED) + return MINESWEEPER_USB; + break; } if(i==1) break; @@ -345,34 +378,41 @@ int minesweeper(void) /* update the screen */ rb->lcd_update(); - switch(rb->button_get(true)){ + button = rb->button_get(true); + switch(button){ /* quit minesweeper (you really shouldn't use this button ...) */ - case BUTTON_OFF: + case MINESWP_QUIT: return MINESWEEPER_QUIT; /* move cursor left */ case BUTTON_LEFT: + case (BUTTON_LEFT | BUTTON_REPEAT): x = (x + width - 1)%width; break; /* move cursor right */ case BUTTON_RIGHT: + case (BUTTON_RIGHT | BUTTON_REPEAT): x = (x + 1)%width; break; /* move cursor down */ case BUTTON_DOWN: + case (BUTTON_DOWN | BUTTON_REPEAT): y = (y + 1)%height; break; /* move cursor up */ case BUTTON_UP: + case (BUTTON_UP | BUTTON_REPEAT): y = (y + height - 1)%height; break; /* discover a tile (and it's neighbors if .neighbors == 0) */ - case BUTTON_ON: - case BUTTON_F2: + case MINESWP_DISCOVER: +#ifdef MINESWP_DISCOVER2 + case MINESWP_DISCOVER2: +#endif if(minefield[y][x].flag) break; /* we put the mines on the first "click" so that you don't */ /* lose on the first "click" */ @@ -393,14 +433,20 @@ int minesweeper(void) break; /* toggle flag under cursor */ - case BUTTON_PLAY: - case BUTTON_F1: + case MINESWP_TOGGLE: +#ifdef MINESWP_TOGGLE_PRE + if (lastbutton != MINESWP_TOGGLE_PRE) + break; +#endif +#ifdef MINESWP_TOGGLE2 + case MINESWP_TOGGLE2: +#endif minefield[y][x].flag = (minefield[y][x].flag + 1)%2; break; /* show how many mines you think you have found and how many */ /* there really are on the game */ - case BUTTON_F3: + case MINESWP_INFO: tiles_left = 0; for(i=0;i<height;i++){ for(j=0;j<width;j++){ @@ -409,7 +455,14 @@ int minesweeper(void) } rb->splash(HZ*2, true, "You found %d mines out of %d", tiles_left, mine_num); break; + + default: + if (rb->default_event_handler(button) == SYS_USB_CONNECTED) + return MINESWEEPER_USB; + break; } + if (button != BUTTON_NONE) + lastbutton = button; } } @@ -431,6 +484,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) case MINESWEEPER_LOSE: rb->splash(HZ*2, true, "You Lost :("); break; + + case MINESWEEPER_USB: + return PLUGIN_USB_CONNECTED; default: 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 @@ #define LARGE 55 #define HAUT 31 +/* variable button definitions */ +#if CONFIG_KEYPAD == RECORDER_PAD +#define MOSAIQUE_QUIT BUTTON_OFF +#define MOSAIQUE_SPEED BUTTON_F1 +#define MOSAIQUE_RESTART BUTTON_PLAY + +#elif CONFIG_KEYPAD == ONDIO_PAD +#define MOSAIQUE_QUIT BUTTON_OFF +#define MOSAIQUE_SPEED BUTTON_LEFT +#define MOSAIQUE_SPEED2 BUTTON_RIGHT +#define MOSAIQUE_RESTART BUTTON_MENU + +#endif enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { @@ -74,32 +87,36 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) rb->sleep(HZ/timer); button = rb->button_get(false); - if ( button == BUTTON_OFF) - { - return false; - } - - if ( button == BUTTON_F1 ) - { - timer = timer+5; - if (timer>20) - timer=5; - } - - if ( button == BUTTON_PLAY ) + switch (button) { - sx = rb->rand()%20+1; - sy = rb->rand()%20+1; - x=0; - y=0; - rb->lcd_clear_display(); - } - - if ( button == SYS_USB_CONNECTED) { - rb->usb_screen(); - return 0; - } + case MOSAIQUE_QUIT: + + return PLUGIN_OK; + + case MOSAIQUE_SPEED: +#ifdef MOSAIQUE_SPEED2 + case MOSAIQUE_SPEED2: +#endif + timer = timer+5; + if (timer>20) + timer=5; + break; + + case MOSAIQUE_RESTART: + sx = rb->rand()%20+1; + sy = rb->rand()%20+1; + x=0; + y=0; + rb->lcd_clear_display(); + break; + + + default: + if (rb->default_event_handler(button) == SYS_USB_CONNECTED) + return PLUGIN_USB_CONNECTED; + break; + } } } 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 @@ #define MAX_PEAK 0x8000 +/* variable button definitions */ +#if CONFIG_KEYPAD == RECORDER_PAD +#define OSCILLOGRAPH_QUIT BUTTON_OFF +#define OSCILLOGRAPH_SPEED_UP BUTTON_UP +#define OSCILLOGRAPH_SPEED_DOWN BUTTON_DOWN +#define OSCILLOGRAPH_ROLL BUTTON_F1 +#define OSCILLOGRAPH_MODE BUTTON_F2 +#define OSCILLOGRAPH_SPEED_RESET BUTTON_F3 +#define OSCILLOGRAPH_PAUSE BUTTON_PLAY + +#elif CONFIG_KEYPAD == ONDIO_PAD +#define OSCILLOGRAPH_QUIT BUTTON_OFF +#define OSCILLOGRAPH_SPEED_UP BUTTON_UP +#define OSCILLOGRAPH_SPEED_DOWN BUTTON_DOWN +#define OSCILLOGRAPH_ROLL BUTTON_RIGHT +#define OSCILLOGRAPH_MODE BUTTON_MENU +#define OSCILLOGRAPH_SPEED_RESET BUTTON_LEFT + +#endif + +/* global api struct pointer */ +static struct plugin_api* rb; /* number of ticks between two volume samples */ static int speed = 1; /* roll == true -> lcd rolls */ @@ -37,12 +59,26 @@ static bool roll = true; static int drawMode = DRAW_MODE_FILLED; /** + * cleanup on return / usb + */ +void cleanup(void *parameter) +{ + (void)parameter; + + /* restore to default roll position. + Looks funny if you forget to do this... */ + rb->lcd_roll(0); + rb->lcd_update(); +} + +/** * Displays a vertically scrolling oscillosgraph using * hardware scrolling of the display. The user can change * speed */ -enum plugin_status plugin_start(struct plugin_api* rb, void* parameter) +enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { + int button; /* stores current volume value left */ int left; /* stores current volume value right */ @@ -57,8 +93,9 @@ enum plugin_status plugin_start(struct plugin_api* rb, void* parameter) bool exit = false; - TEST_PLUGIN_API(rb); + TEST_PLUGIN_API(api); (void)parameter; + rb = api; /* the main loop */ while (!exit) { @@ -135,28 +172,31 @@ enum plugin_status plugin_start(struct plugin_api* rb, void* parameter) it must be ensured that at least 1 is passed. */ /* react to user input */ - switch (rb->button_get_w_tmo(MAX(speed, 1))) { - case BUTTON_UP: + button = rb->button_get_w_tmo(MAX(speed, 1)); + switch (button) { + case OSCILLOGRAPH_SPEED_UP: speed++; draw = true; break; - case BUTTON_DOWN: + case OSCILLOGRAPH_SPEED_DOWN: speed--; draw = true; break; - case BUTTON_PLAY: +#ifdef OSCILLOGRAPH_PAUSE + case OSCILLOGRAPH_PAUSE: /* pause the demo */ rb->button_get(true); break; +#endif - case BUTTON_F1: + case OSCILLOGRAPH_ROLL: /* toggle rolling */ roll = !roll; break; - case BUTTON_F2: + case OSCILLOGRAPH_MODE: /* step through the display modes */ drawMode ++; drawMode = drawMode % DRAW_MODE_COUNT; @@ -170,18 +210,20 @@ enum plugin_status plugin_start(struct plugin_api* rb, void* parameter) rb->lcd_roll(0); break; - case BUTTON_F3: + case OSCILLOGRAPH_SPEED_RESET: speed = 1; draw = true; break; - case BUTTON_OFF: + case OSCILLOGRAPH_QUIT: exit = true; break; - case SYS_USB_CONNECTED: - rb->usb_screen(); - return PLUGIN_USB_CONNECTED; + default: + if (rb->default_event_handler_ex(button, cleanup, NULL) + == SYS_USB_CONNECTED) + return PLUGIN_USB_CONNECTED; + break; } if (draw) { @@ -191,14 +233,10 @@ enum plugin_status plugin_start(struct plugin_api* rb, void* parameter) rb->lcd_update_rect(0, (y + LCD_HEIGHT - 8) % LCD_HEIGHT, LCD_WIDTH, 8); } - } + } } - /* restore to default roll position. - Looks funny if you forget to do this... */ - rb->lcd_roll(0); - rb->lcd_update(); - + cleanup(NULL); /* standard return */ return PLUGIN_OK; } 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 @@ #define MOVE_STEP 2 /* move pad this many steps up/down each move */ +/* variable button definitions */ +#if CONFIG_KEYPAD == RECORDER_PAD +#define PONG_QUIT BUTTON_OFF +#define PONG_LEFT_UP BUTTON_F1 +#define PONG_LEFT_DOWN BUTTON_LEFT +#define PONG_RIGHT_UP BUTTON_F3 +#define PONG_RIGHT_DOWN BUTTON_RIGHT + +#elif CONFIG_KEYPAD == ONDIO_PAD +#define PONG_QUIT BUTTON_OFF +#define PONG_LEFT_UP BUTTON_LEFT +#define PONG_LEFT_DOWN BUTTON_MENU +#define PONG_RIGHT_UP BUTTON_UP +#define PONG_RIGHT_DOWN BUTTON_DOWN + +#endif + static struct plugin_api* rb; struct pong { @@ -232,7 +249,7 @@ void padmove(int *pos, int dir) *pos = 0; } -bool keys(struct pong *p) +int keys(struct pong *p) { int key; @@ -243,22 +260,25 @@ bool keys(struct pong *p) while(end > *rb->current_tick) { key = rb->button_get_w_tmo(end - *rb->current_tick); - if(key & BUTTON_OFF) - return false; /* exit game NOW */ + if(key & PONG_QUIT) + return 0; /* exit game NOW */ - if(key & BUTTON_LEFT) /* player left goes down */ + if(key & PONG_LEFT_DOWN) /* player left goes down */ padmove(&p->w_pad[0], MOVE_STEP); - if(key & BUTTON_F1) /* player left goes up */ - padmove(&p->w_pad[0], - MOVE_STEP); + if(key & PONG_LEFT_UP) /* player left goes up */ + padmove(&p->w_pad[0], -MOVE_STEP); - if(key & BUTTON_RIGHT) /* player right goes down */ + if(key & PONG_RIGHT_DOWN) /* player right goes down */ padmove(&p->w_pad[1], MOVE_STEP); - if(key & BUTTON_F3) /* player right goes up */ + if(key & PONG_RIGHT_UP) /* player right goes up */ padmove(&p->w_pad[1], -MOVE_STEP); + + if(rb->default_event_handler(key) == SYS_USB_CONNECTED) + return -1; /* exit game because of USB */ } - return true; /* return false to exit game */ + return 1; /* return 0 to exit game */ } void showscore(struct pong *p) @@ -273,7 +293,7 @@ void showscore(struct pong *p) enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { struct pong pong; - bool game = true; + int game = 1; /* init the struct with some silly values to start with */ @@ -302,7 +322,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) rb->lcd_clear_display(); /* go go go */ - while(game) { + while(game > 0) { showscore(&pong); pad(&pong, 0); /* draw left pad */ pad(&pong, 1); /* draw right pad */ @@ -313,7 +333,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) game = keys(&pong); /* deal with keys */ } - return PLUGIN_OK; + return (game == 0) ? PLUGIN_OK : PLUGIN_USB_CONNECTED; } #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 @@ #include "plugin.h" #ifdef HAVE_LCD_BITMAP +/* variable button definitions */ +#if CONFIG_KEYPAD == RECORDER_PAD +#define PUZZLE_QUIT BUTTON_OFF +#define PUZZLE_SHUFFLE BUTTON_F1 +#define PUZZLE_PICTURE BUTTON_F2 + +#elif CONFIG_KEYPAD == ONDIO_PAD +#define PUZZLE_QUIT BUTTON_OFF +#define PUZZLE_SHUFFLE_PICTURE_PRE BUTTON_MENU +#define PUZZLE_SHUFFLE (BUTTON_MENU | BUTTON_REPEAT) +#define PUZZLE_PICTURE (BUTTON_MENU | BUTTON_REL) + +#endif + static struct plugin_api* rb; static int spots[20]; static int hole = 19, moves; @@ -232,20 +246,31 @@ static void puzzle_init(void) /* the main game loop */ static int puzzle_loop(void) { + int button; + int lastbutton = BUTTON_NONE; int i; puzzle_init(); while(true) { - switch (rb->button_get(true)) { - case BUTTON_OFF: + button = rb->button_get(true); + switch (button) { + case PUZZLE_QUIT: /* get out of here */ return PLUGIN_OK; - case BUTTON_F1: + case PUZZLE_SHUFFLE: +#ifdef PUZZLE_SHUFFLE_PICTURE_PRE + if (lastbutton != PUZZLE_SHUFFLE_PICTURE_PRE) + break; +#endif /* mix up the pieces */ puzzle_init(); break; - case BUTTON_F2: + case PUZZLE_PICTURE: +#ifdef PUZZLE_SHUFFLE_PICTURE_PRE + if (lastbutton != PUZZLE_SHUFFLE_PICTURE_PRE) + break; +#endif /* change picture */ pic = (pic==true?false:true); for (i=0; i<20; i++) @@ -273,10 +298,13 @@ static int puzzle_loop(void) move_spot(0, 1); break; - case SYS_USB_CONNECTED: - rb->usb_screen(); - return PLUGIN_USB_CONNECTED; + default: + if (rb->default_event_handler(button) == SYS_USB_CONNECTED) + return PLUGIN_USB_CONNECTED; + break; } + if (button != BUTTON_NONE) + lastbutton = button; } } @@ -300,9 +328,15 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) /* print instructions */ rb->lcd_clear_display(); rb->lcd_setfont(FONT_SYSFIXED); +#if CONFIG_KEYPAD == RECORDER_PAD rb->lcd_putsxy(3, 18, "[OFF] to stop"); rb->lcd_putsxy(3, 28, "[F1] shuffle"); rb->lcd_putsxy(3, 38, "[F2] change pic"); +#elif CONFIG_KEYPAD == ONDIO_PAD + rb->lcd_putsxy(0, 18, "[OFF] to stop"); + rb->lcd_putsxy(0, 28, "[MENU..] shuffle"); + rb->lcd_putsxy(0, 38, "[MENU] change pic"); +#endif rb->lcd_update(); rb->sleep(HZ*2); 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; #include "plugin.h" #ifdef HAVE_LCD_BITMAP +/* variable button definitions */ +#if CONFIG_KEYPAD == RECORDER_PAD +#define SNAKE_QUIT BUTTON_OFF +#define SNAKE_PLAYPAUSE BUTTON_PLAY + +#elif CONFIG_KEYPAD == ONDIO_PAD +#define SNAKE_QUIT BUTTON_OFF +#define SNAKE_PLAYPAUSE BUTTON_MENU + +#endif + static int board[28][16],snakelength; static unsigned int score,hiscore=0; static short dir,frames,apple,level=1,dead=0; @@ -156,26 +167,39 @@ void redraw (void) } void game_pause (void) { + int button; rb->lcd_clear_display(); rb->lcd_putsxy(3,12,"Game Paused"); +#if CONFIG_KEYPAD == RECORDER_PAD rb->lcd_putsxy(3,22,"[Play] to resume"); +#elif CONFIG_KEYPAD == ONDIO_PAD + rb->lcd_putsxy(3,22,"[Menu] to resume"); +#endif rb->lcd_putsxy(3,32,"[Off] to quit"); rb->lcd_update(); while (1) { - switch (rb->button_get(true)) { - case BUTTON_OFF: + button=rb->button_get(true); + switch (button) { + case SNAKE_QUIT: dead=1; return; - case BUTTON_PLAY: + case SNAKE_PLAYPAUSE: redraw(); rb->sleep(HZ/2); return; + default: + if (rb->default_event_handler(button)==SYS_USB_CONNECTED) { + dead=2; + return; + } + break; } } } void game (void) { + int button; short x,y; while (1) { frame(); @@ -198,7 +222,8 @@ void game (void) { rb->sleep(HZ/level); - switch (rb->button_get(false)) { + button=rb->button_get(false); + switch (button) { case BUTTON_UP: if (dir!=2) dir=0; break; @@ -211,17 +236,24 @@ void game (void) { case BUTTON_LEFT: if (dir!=1) dir=3; break; - case BUTTON_OFF: + case SNAKE_QUIT: dead=1; return; - case BUTTON_PLAY: + case SNAKE_PLAYPAUSE: game_pause(); break; - } + default: + if (rb->default_event_handler(button)==SYS_USB_CONNECTED) { + dead=2; + return; + } + break; + } } } void game_init(void) { + int button; short x,y; char plevel[10],phscore[20]; @@ -244,12 +276,17 @@ void game_init(void) { rb->lcd_puts(0,0, plevel); rb->lcd_puts(0,1, "(1-slow, 9-fast)"); rb->lcd_puts(0,2, "OFF - quit"); +#if CONFIG_KEYPAD == RECORDER_PAD rb->lcd_puts(0,3, "PLAY - start/pause"); +#elif CONFIG_KEYPAD == ONDIO_PAD + rb->lcd_puts(0,3, "MENU - start/pause"); +#endif rb->lcd_puts(0,4, phscore); rb->lcd_update(); - while (1) { - switch (rb->button_get(true)) { + while (1) { + button=rb->button_get(true); + switch (button) { case BUTTON_RIGHT: case BUTTON_UP: if (level<9) @@ -260,13 +297,19 @@ void game_init(void) { if (level>1) level--; break; - case BUTTON_OFF: + case SNAKE_QUIT: dead=1; return; break; - case BUTTON_PLAY: + case SNAKE_PLAYPAUSE: return; break; + default: + if (rb->default_event_handler(button)==SYS_USB_CONNECTED) { + dead=2; + return; + } + break; } rb->snprintf(plevel,sizeof(plevel),"Level - %d",level); rb->lcd_puts(0,0, plevel); @@ -283,8 +326,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) game_init(); rb->lcd_clear_display(); - game(); - return false; + game(); + return (dead==1)?PLUGIN_OK:PLUGIN_USB_CONNECTED; } #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 #define WIDTH 28 #define HEIGHT 16 +/* variable button definitions */ +#if CONFIG_KEYPAD == RECORDER_PAD +#define SNAKE2_QUIT BUTTON_OFF +#define SNAKE2_LEVEL_UP BUTTON_UP +#define SNAKE2_LEVEL_UP2 BUTTON_RIGHT +#define SNAKE2_LEVEL_DOWN BUTTON_DOWN +#define SNAKE2_LEVEL_DOWN2 BUTTON_LEFT +#define SNAKE2_SELECT_MAZE BUTTON_F1 +#define SNAKE2_SELECT_TYPE BUTTON_F3 +#define SNAKE2_PLAYPAUSE BUTTON_PLAY + +#elif CONFIG_KEYPAD == ONDIO_PAD +#define SNAKE2_QUIT BUTTON_OFF +#define SNAKE2_LEVEL_UP BUTTON_UP +#define SNAKE2_LEVEL_DOWN BUTTON_DOWN +#define SNAKE2_SELECT_MAZE BUTTON_LEFT +#define SNAKE2_SELECT_TYPE BUTTON_RIGHT +#define SNAKE2_PLAYPAUSE BUTTON_MENU + +#endif + static int max_levels = 0; static char (*level_cache)[HEIGHT][WIDTH]; @@ -770,24 +791,37 @@ void frame (void) void game_pause (void) { + int button; + rb->lcd_clear_display(); rb->lcd_putsxy(33,12,"Paused"); rb->lcd_update(); while (1) { - switch (rb->button_get(true)) + button = rb->button_get(true); + switch (button) { - case BUTTON_PLAY: + case SNAKE2_PLAYPAUSE: redraw(); rb->sleep(HZ/2); return; + + default: + if (rb->default_event_handler(button)==SYS_USB_CONNECTED) { + dead = 1; + quit = 2; + return; + } + break; } } } void game (void) { + int button; + redraw(); /*main loop:*/ while (1) @@ -821,7 +855,8 @@ void game (void) rb->sleep(HZ/speed); - switch (rb->button_get(false)) + button = rb->button_get(false); + switch (button) { case BUTTON_UP: case BUTTON_UP | BUTTON_REPEAT: @@ -843,14 +878,21 @@ void game (void) if (dir != EAST) set_direction(WEST); break; - case BUTTON_OFF: + case SNAKE2_QUIT: dead=1; return; - case BUTTON_PLAY: + case SNAKE2_PLAYPAUSE: game_pause(); break; - } + + default: + if (rb->default_event_handler(button)==SYS_USB_CONNECTED) { + quit = 2; + return; + } + break; + } } } @@ -862,37 +904,42 @@ void game_init(void) dead=0; apple=0; score=0; - + int button; clear_board(); load_level( level_from_file ); while (1) { - switch (rb->button_get(true)) + button=rb->button_get(true); + switch (button) { - case BUTTON_RIGHT: - case BUTTON_UP: + case SNAKE2_LEVEL_UP: +#ifdef SNAKE2_LEVEL_UP2 + case SNAKE2_LEVEL_UP2: +#endif if (level<10) level+=1; break; - case BUTTON_LEFT: - case BUTTON_DOWN: + case SNAKE2_LEVEL_DOWN: +#ifdef SNAKE2_LEVEL_DOWN2 + case SNAKE2_LEVEL_DOWN2: +#endif if (level>1) level-=1; break; - case BUTTON_OFF: + case SNAKE2_QUIT: quit=1; return; break; - case BUTTON_PLAY: + case SNAKE2_PLAYPAUSE: speed = level*20; return; break; - case BUTTON_F3: + case SNAKE2_SELECT_TYPE: if(game_type==0)game_type=1; else game_type=0; break; - case BUTTON_F1: + case SNAKE2_SELECT_MAZE: level_from_file++; if(level_from_file > num_levels) @@ -903,6 +950,12 @@ void game_init(void) load_level( level_from_file ); break; + default: + if (rb->default_event_handler(button)==SYS_USB_CONNECTED) { + quit = 2; + return; + } + break; } rb->lcd_clear_display(); @@ -910,13 +963,22 @@ void game_init(void) /*TODO: CENTER ALL TEXT!!!!*/ rb->snprintf(plevel,sizeof(plevel),"Speed - %d",level); rb->lcd_putsxy(LCD_WIDTH/2 - 30,5, plevel); +#if CONFIG_KEYPAD == RECORDER_PAD rb->snprintf(plevel,sizeof(plevel),"F1 - Maze %d",level_from_file); rb->lcd_putsxy(18, 20, plevel); if(game_type==0) rb->lcd_putsxy(18, 30, "F3 - Game A"); else rb->lcd_putsxy(18, 30, "F3 - Game B"); - +#elif CONFIG_KEYPAD == ONDIO_PAD + rb->snprintf(plevel,sizeof(plevel),"Left - Maze %d",level_from_file); + rb->lcd_putsxy(18, 20, plevel); + if(game_type==0) + rb->lcd_putsxy(12, 30, "Right - Game A"); + else + rb->lcd_putsxy(12, 30, "Right - Game B"); +#endif + rb->snprintf(phscore,sizeof(phscore),"Hi Score: %d",hiscore); rb->lcd_putsxy(LCD_WIDTH/2 - 37,50, phscore); rb->lcd_update(); @@ -953,7 +1015,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) } } - return false; + return (quit==1) ? PLUGIN_OK : PLUGIN_USB_CONNECTED; } #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 @@ #define SOKOBAN_LEVEL_SIZE (ROWS*COLS) +/* variable button definitions */ +#if CONFIG_KEYPAD == RECORDER_PAD +#define SOKOBAN_QUIT BUTTON_OFF +#define SOKOBAN_UNDO BUTTON_ON +#define SOKOBAN_LEVEL_UP BUTTON_F3 +#define SOKOBAN_LEVEL_DOWN BUTTON_F1 +#define SOKOBAN_LEVEL_REPEAT BUTTON_F2 + +#elif CONFIG_KEYPAD == ONDIO_PAD +#define SOKOBAN_QUIT BUTTON_OFF +#define SOKOBAN_UNDO_PRE BUTTON_MENU +#define SOKOBAN_UNDO (BUTTON_MENU | BUTTON_REL) +#define SOKOBAN_LEVEL_UP (BUTTON_MENU | BUTTON_RIGHT) +#define SOKOBAN_LEVEL_DOWN (BUTTON_MENU | BUTTON_LEFT) +#define SOKOBAN_LEVEL_REPEAT (BUTTON_MENU | BUTTON_UP) + +#endif + static void init_undo(void); static void undo(void); static void add_undo(int button); @@ -443,7 +461,7 @@ static bool sokoban_loop(void) { char new_spot; bool moved = true; - int i = 0, button = 0; + int i = 0, button = 0, lastbutton = 0; short r = 0, c = 0; current_info.level.level = 1; @@ -465,27 +483,32 @@ static bool sokoban_loop(void) { case BUTTON_OFF: /* get out of here */ - return PLUGIN_OK; + return PLUGIN_OK; - case BUTTON_ON: - case BUTTON_ON | BUTTON_REPEAT: + case SOKOBAN_UNDO: +#ifdef SOKOBAN_UNDO_PRE + if (lastbutton != SOKOBAN_UNDO_PRE) + break; +#else /* repeat can't work here for Ondio */ + case SOKOBAN_UNDO | BUTTON_REPEAT: +#endif /* this is UNDO */ undo(); rb->lcd_clear_display(); - update_screen(); + update_screen(); moved = false; break; - case BUTTON_F3: - case BUTTON_F3 | BUTTON_REPEAT: + case SOKOBAN_LEVEL_UP: + case SOKOBAN_LEVEL_UP | BUTTON_REPEAT: /* increase level */ init_undo(); current_info.level.boxes_to_go=0; moved = true; break; - case BUTTON_F1: - case BUTTON_F1 | BUTTON_REPEAT: + case SOKOBAN_LEVEL_DOWN: + case SOKOBAN_LEVEL_DOWN | BUTTON_REPEAT: /* previous level */ init_undo(); if (current_info.level.level > 1) @@ -495,8 +518,8 @@ static bool sokoban_loop(void) moved = false; break; - case BUTTON_F2: - case BUTTON_F2 | BUTTON_REPEAT: + case SOKOBAN_LEVEL_REPEAT: + case SOKOBAN_LEVEL_REPEAT | BUTTON_REPEAT: /* same level */ init_undo(); draw_level(); @@ -504,7 +527,7 @@ static bool sokoban_loop(void) break; case BUTTON_LEFT: - switch(current_info.board[r][c-1]) + switch(current_info.board[r][c-1]) { case ' ': /* if it is a blank spot */ case '.': /* if it is a home spot */ @@ -527,7 +550,7 @@ static bool sokoban_loop(void) case '.': /* going from a blank to home */ current_info.board[r][c-2] = '%'; current_info.board[r][c-1] = current_info.board[r][c]; - current_info.board[r][c] = current_info.player.spot; + current_info.board[r][c] = current_info.player.spot; current_info.player.spot = ' '; current_info.level.boxes_to_go--; break; @@ -551,7 +574,7 @@ static bool sokoban_loop(void) case '.': /* if we are going from a home to home */ current_info.board[r][c-2] = '%'; current_info.board[r][c-1] = current_info.board[r][c]; - current_info.board[r][c] = current_info.player.spot; + current_info.board[r][c] = current_info.player.spot; current_info.player.spot = '.'; break; @@ -580,7 +603,7 @@ static bool sokoban_loop(void) current_info.player.spot = new_spot; break; - case '$': + case '$': switch(current_info.board[r][c+2]) { case ' ': /* going from blank to blank */ current_info.board[r][c+2] = current_info.board[r][c+1]; @@ -592,7 +615,7 @@ static bool sokoban_loop(void) case '.': /* going from a blank to home */ current_info.board[r][c+2] = '%'; current_info.board[r][c+1] = current_info.board[r][c]; - current_info.board[r][c] = current_info.player.spot; + current_info.board[r][c] = current_info.player.spot; current_info.player.spot = ' '; current_info.level.boxes_to_go--; break; @@ -616,7 +639,7 @@ static bool sokoban_loop(void) case '.': current_info.board[r][c+2] = '%'; current_info.board[r][c+1] = current_info.board[r][c]; - current_info.board[r][c] = current_info.player.spot; + current_info.board[r][c] = current_info.player.spot; current_info.player.spot = '.'; break; @@ -657,7 +680,7 @@ static bool sokoban_loop(void) case '.': /* going from a blank to home */ current_info.board[r-2][c] = '%'; current_info.board[r-1][c] = current_info.board[r][c]; - current_info.board[r][c] = current_info.player.spot; + current_info.board[r][c] = current_info.player.spot; current_info.player.spot = ' '; current_info.level.boxes_to_go--; break; @@ -681,7 +704,7 @@ static bool sokoban_loop(void) case '.': /* if we are going from a home to home */ current_info.board[r-2][c] = '%'; current_info.board[r-1][c] = current_info.board[r][c]; - current_info.board[r][c] = current_info.player.spot; + current_info.board[r][c] = current_info.player.spot; current_info.player.spot = '.'; break; @@ -722,7 +745,7 @@ static bool sokoban_loop(void) case '.': /* going from a blank to home */ current_info.board[r+2][c] = '%'; current_info.board[r+1][c] = current_info.board[r][c]; - current_info.board[r][c] = current_info.player.spot; + current_info.board[r][c] = current_info.player.spot; current_info.player.spot = ' '; current_info.level.boxes_to_go--; break; @@ -746,7 +769,7 @@ static bool sokoban_loop(void) case '.': /* going from a home to home */ current_info.board[r+2][c] = '%'; current_info.board[r+1][c] = current_info.board[r][c]; - current_info.board[r][c] = current_info.player.spot; + current_info.board[r][c] = current_info.player.spot; current_info.player.spot = '.'; break; @@ -765,19 +788,21 @@ static bool sokoban_loop(void) current_info.player.row++; break; - case SYS_USB_CONNECTED: - rb->usb_screen(); - return PLUGIN_USB_CONNECTED; - default: + if (rb->default_event_handler(button) == SYS_USB_CONNECTED) + return PLUGIN_USB_CONNECTED; + moved = false; break; } + if (button != BUTTON_NONE) + lastbutton = button; + if (moved) { current_info.level.moves++; rb->lcd_clear_display(); - update_screen(); + update_screen(); } /* We have completed this level */ @@ -845,11 +870,19 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) rb->lcd_clear_display(); +#if CONFIG_KEYPAD == RECORDER_PAD rb->lcd_putsxy(3, 6, "[OFF] To Stop"); rb->lcd_putsxy(3, 16, "[ON] To Undo"); rb->lcd_putsxy(3, 26, "[F1] - Level"); rb->lcd_putsxy(3, 36, "[F2] Same Level"); rb->lcd_putsxy(3, 46, "[F3] + Level"); +#elif CONFIG_KEYPAD == ONDIO_PAD + rb->lcd_putsxy(3, 6, "[OFF] To Stop"); + rb->lcd_putsxy(3, 16, "[MENU] To Undo"); + rb->lcd_putsxy(3, 26, "[M-LEFT] - Level"); + rb->lcd_putsxy(3, 36, "[M-UP] Same Level"); + rb->lcd_putsxy(3, 46, "[M-RIGHT] + Level"); +#endif rb->lcd_update(); rb->sleep(HZ*2); |