summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2007-08-31 21:53:32 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2007-08-31 21:53:32 +0000
commitfd3b0d95d8ee36de88612e77f4042f84af570426 (patch)
tree751635654d2620225e1d36dcf4db22c0f7a976af
parent4a346f43cddcf3a5ab34df61cb1f0215f943a9dc (diff)
downloadrockbox-fd3b0d95d8ee36de88612e77f4042f84af570426.tar.gz
rockbox-fd3b0d95d8ee36de88612e77f4042f84af570426.zip
Fix FS #7685 by using the backlight helper functions. Some code policing and cleaning. Still contains a potential crash although this version does not crash atm.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14559 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/maze.c76
1 files changed, 49 insertions, 27 deletions
diff --git a/apps/plugins/maze.c b/apps/plugins/maze.c
index 952edff9c7..b5d4f08e9f 100644
--- a/apps/plugins/maze.c
+++ b/apps/plugins/maze.c
@@ -30,6 +30,7 @@
30 30
31#include "plugin.h" 31#include "plugin.h"
32#include "pluginlib_actions.h" 32#include "pluginlib_actions.h"
33#include "helper.h"
33 34
34PLUGIN_HEADER 35PLUGIN_HEADER
35 36
@@ -93,43 +94,51 @@ const struct button_mapping *plugin_contexts[]
93#define MAZE_HEIGHT 24 94#define MAZE_HEIGHT 24
94#endif 95#endif
95 96
96struct coord_stack{ 97struct coord_stack
98{
97 int data[MAZE_WIDTH*MAZE_HEIGHT]; 99 int data[MAZE_WIDTH*MAZE_HEIGHT];
98 int stp; 100 int stp;
99}; 101};
100 102
101void coord_stack_init(struct coord_stack* stack){ 103void coord_stack_init(struct coord_stack* stack)
104{
102 stack->stp=0; 105 stack->stp=0;
103} 106}
104 107
105void coord_stack_push(struct coord_stack* stack, int x, int y){ 108void coord_stack_push(struct coord_stack* stack, int x, int y)
109{
106 stack->data[stack->stp] = ((x<<8)|y); 110 stack->data[stack->stp] = ((x<<8)|y);
107 stack->stp++; 111 stack->stp++;
108} 112}
109 113
110void coord_stack_get(struct coord_stack* stack, int index, int* x, int* y){ 114void coord_stack_get(struct coord_stack* stack, int index, int* x, int* y)
115 {
111 *y = stack->data[index]; 116 *y = stack->data[index];
112 *y &= 0xff; 117 *y &= 0xff;
113 *x = (stack->data[index])>>8; 118 *x = (stack->data[index])>>8;
114} 119}
115 120
116void coord_stack_pop(struct coord_stack* stack, int* x, int* y){ 121void coord_stack_pop(struct coord_stack* stack, int* x, int* y)
122{
117 stack->stp--; 123 stack->stp--;
118 coord_stack_get(stack, stack->stp, x, y); 124 coord_stack_get(stack, stack->stp, x, y);
119} 125}
120 126
121int coord_stack_count(struct coord_stack* stack){ 127int coord_stack_count(struct coord_stack* stack)
128{
122 return(stack->stp); 129 return(stack->stp);
123} 130}
124 131
125struct maze{ 132struct maze
126 unsigned short maze[MAZE_WIDTH][MAZE_HEIGHT]; 133{
127 int solved; 134 int solved;
128 int player_x; 135 int player_x;
129 int player_y; 136 int player_y;
137 unsigned short maze[MAZE_WIDTH][MAZE_HEIGHT];
130}; 138};
131 139
132void maze_init(struct maze* maze){ 140void maze_init(struct maze* maze)
141{
133 int x, y; 142 int x, y;
134 rb->memset(maze->maze, 0, sizeof(maze->maze)); 143 rb->memset(maze->maze, 0, sizeof(maze->maze));
135 maze->solved = false; 144 maze->solved = false;
@@ -155,7 +164,8 @@ void maze_init(struct maze* maze){
155 } 164 }
156} 165}
157 166
158void maze_draw(struct maze* maze, struct screen* display){ 167void maze_draw(struct maze* maze, struct screen* display)
168{
159 int x, y; 169 int x, y;
160 int wx, wy; 170 int wx, wy;
161 int point_width, point_height, point_offset_x, point_offset_y; 171 int point_width, point_height, point_offset_x, point_offset_y;
@@ -254,7 +264,8 @@ void maze_draw(struct maze* maze, struct screen* display){
254 264
255 265
256int maze_pick_random_neighbour_cell_with_walls(struct maze* maze, 266int maze_pick_random_neighbour_cell_with_walls(struct maze* maze,
257 int x, int y, int *pnx, int *pny){ 267 int x, int y, int *pnx, int *pny)
268{
258 269
259 int ncount = 0; 270 int ncount = 0;
260 struct coord_stack neighbours; 271 struct coord_stack neighbours;
@@ -299,7 +310,8 @@ int maze_pick_random_neighbour_cell_with_walls(struct maze* maze,
299} 310}
300 311
301/* Removes the wall between the cell (x,y) and the cell (nx,ny) */ 312/* Removes the wall between the cell (x,y) and the cell (nx,ny) */
302void maze_remove_wall(struct maze* maze, int x, int y, int nx, int ny){ 313void maze_remove_wall(struct maze* maze, int x, int y, int nx, int ny)
314{
303 /* where is our neighbour? */ 315 /* where is our neighbour? */
304 316
305 /* north or south */ 317 /* north or south */
@@ -329,7 +341,8 @@ void maze_remove_wall(struct maze* maze, int x, int y, int nx, int ny){
329 } 341 }
330} 342}
331 343
332void maze_generate(struct maze* maze){ 344void maze_generate(struct maze* maze)
345{
333 int total_cells = MAZE_WIDTH * MAZE_HEIGHT; 346 int total_cells = MAZE_WIDTH * MAZE_HEIGHT;
334 int visited_cells; 347 int visited_cells;
335 int available_neighbours; 348 int available_neighbours;
@@ -366,11 +379,12 @@ void maze_generate(struct maze* maze){
366} 379}
367 380
368 381
369void maze_solve(struct maze* maze){ 382void maze_solve(struct maze* maze)
383{
370 int x, y; 384 int x, y;
385 int dead_ends = 1;
371 unsigned short cell; 386 unsigned short cell;
372 unsigned short w; 387 unsigned short w;
373 int dead_ends = 1;
374 unsigned short solved_maze[MAZE_WIDTH][MAZE_HEIGHT]; 388 unsigned short solved_maze[MAZE_WIDTH][MAZE_HEIGHT];
375 389
376 maze->solved = ~(maze->solved); 390 maze->solved = ~(maze->solved);
@@ -414,7 +428,8 @@ void maze_solve(struct maze* maze){
414 } 428 }
415} 429}
416 430
417void maze_move_player_down(struct maze* maze){ 431void maze_move_player_down(struct maze* maze)
432{
418 unsigned short cell=maze->maze[maze->player_x][maze->player_y]; 433 unsigned short cell=maze->maze[maze->player_x][maze->player_y];
419 if( !(cell & WALL_S) && 434 if( !(cell & WALL_S) &&
420 !(cell & BORDER_S)){ 435 !(cell & BORDER_S)){
@@ -422,7 +437,8 @@ void maze_move_player_down(struct maze* maze){
422 } 437 }
423} 438}
424 439
425void maze_move_player_up(struct maze* maze){ 440void maze_move_player_up(struct maze* maze)
441{
426 unsigned short cell=maze->maze[maze->player_x][maze->player_y]; 442 unsigned short cell=maze->maze[maze->player_x][maze->player_y];
427 if( !(cell & WALL_N) && 443 if( !(cell & WALL_N) &&
428 !(cell & BORDER_N)){ 444 !(cell & BORDER_N)){
@@ -430,7 +446,8 @@ void maze_move_player_up(struct maze* maze){
430 } 446 }
431} 447}
432 448
433void maze_move_player_left(struct maze* maze){ 449void maze_move_player_left(struct maze* maze)
450{
434 unsigned short cell=maze->maze[maze->player_x][maze->player_y]; 451 unsigned short cell=maze->maze[maze->player_x][maze->player_y];
435 if( !(cell & WALL_W) && 452 if( !(cell & WALL_W) &&
436 !(cell & BORDER_W)){ 453 !(cell & BORDER_W)){
@@ -438,7 +455,8 @@ void maze_move_player_left(struct maze* maze){
438 } 455 }
439} 456}
440 457
441void maze_move_player_right(struct maze* maze){ 458void maze_move_player_right(struct maze* maze)
459{
442 unsigned short cell=maze->maze[maze->player_x][maze->player_y]; 460 unsigned short cell=maze->maze[maze->player_x][maze->player_y];
443 if( !(cell & WALL_E) && 461 if( !(cell & WALL_E) &&
444 !(cell & BORDER_E)){ 462 !(cell & BORDER_E)){
@@ -448,7 +466,8 @@ void maze_move_player_right(struct maze* maze){
448/**********************************/ 466/**********************************/
449/* this is the plugin entry point */ 467/* this is the plugin entry point */
450/**********************************/ 468/**********************************/
451enum plugin_status plugin_start(struct plugin_api* api, void* parameter){ 469enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
470{
452 int button, lastbutton = BUTTON_NONE; 471 int button, lastbutton = BUTTON_NONE;
453 int quit = 0; 472 int quit = 0;
454 int i; 473 int i;
@@ -456,7 +475,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter){
456 (void)parameter; 475 (void)parameter;
457 rb = api; 476 rb = api;
458 477
459 rb->backlight_set_timeout(1); 478 /* Turn off backlight timeout */
479 backlight_force_on(rb); /* backlight control in lib/helper.c */
460 480
461#if LCD_DEPTH > 1 481#if LCD_DEPTH > 1
462 rb->lcd_set_backdrop(NULL); 482 rb->lcd_set_backdrop(NULL);
@@ -520,19 +540,21 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter){
520 break; 540 break;
521 case MAZE_QUIT: 541 case MAZE_QUIT:
522 /* quit plugin */ 542 /* quit plugin */
523 quit=true; 543 quit=1;
524 return PLUGIN_OK;
525 break; 544 break;
526 default: 545 default:
527 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { 546 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
528 return PLUGIN_USB_CONNECTED; 547 /* quit plugin */
548 quit=2;
529 } 549 }
530 break; 550 break;
531 } 551 }
532 if( button != BUTTON_NONE ) 552 if( button != BUTTON_NONE )
533 lastbutton = button; 553 lastbutton = button;
534 rb->yield(); 554 if(!quit)
555 rb->yield(); /* BUG alert: always yielding causes data abort */
535 } 556 }
536 rb->backlight_set_timeout(rb->global_settings->backlight_timeout); 557 /* Turn on backlight timeout (revert to settings) */
537 return PLUGIN_OK; 558 backlight_use_settings(rb); /* backlight control in lib/helper.c */
559 return ((quit == 1) ? PLUGIN_OK : PLUGIN_USB_CONNECTED);
538} 560}