diff options
-rw-r--r-- | apps/plugins/pacbox/pacbox.c | 90 |
1 files changed, 66 insertions, 24 deletions
diff --git a/apps/plugins/pacbox/pacbox.c b/apps/plugins/pacbox/pacbox.c index 6c10a20915..9c0285fce1 100644 --- a/apps/plugins/pacbox/pacbox.c +++ b/apps/plugins/pacbox/pacbox.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "arcade.h" | 26 | #include "arcade.h" |
27 | #include "pacbox.h" | 27 | #include "pacbox.h" |
28 | #include "pacbox_lcd.h" | 28 | #include "pacbox_lcd.h" |
29 | #include "lib/configfile.h" | ||
29 | 30 | ||
30 | PLUGIN_HEADER | 31 | PLUGIN_HEADER |
31 | 32 | ||
@@ -39,8 +40,7 @@ extern char iend[]; | |||
39 | 40 | ||
40 | struct plugin_api* rb; | 41 | struct plugin_api* rb; |
41 | 42 | ||
42 | unsigned framesPerSecond = VideoFrequency; | 43 | static unsigned long frame_counter = 0; |
43 | unsigned long frame_counter = 0; | ||
44 | 44 | ||
45 | struct pacman_settings { | 45 | struct pacman_settings { |
46 | int difficulty; | 46 | int difficulty; |
@@ -50,9 +50,29 @@ struct pacman_settings { | |||
50 | int showfps; | 50 | int showfps; |
51 | }; | 51 | }; |
52 | 52 | ||
53 | struct pacman_settings settings; | 53 | static struct pacman_settings settings; |
54 | static struct pacman_settings old_settings; | ||
54 | 55 | ||
55 | bool loadFile( const char * name, unsigned char * buf, int len ) | 56 | #define SETTINGS_VERSION 1 |
57 | #define SETTINGS_MIN_VERSION 1 | ||
58 | #define SETTINGS_FILENAME "pacbox.cfg" | ||
59 | |||
60 | static char* difficulty_options[] = { "Normal", "Hard" }; | ||
61 | static char* numlives_options[] = { "1", "2", "3", "5" }; | ||
62 | static char* bonus_options[] = {"10000", "15000", "20000", "No Bonus"}; | ||
63 | static char* ghostnames_options[] = {"Normal", "Alternate"}; | ||
64 | static char* showfps_options[] = {"No", "Yes"}; | ||
65 | |||
66 | static struct configdata config[] = | ||
67 | { | ||
68 | {TYPE_ENUM, 0, 2, &settings.difficulty, "Difficulty", difficulty_options, NULL}, | ||
69 | {TYPE_ENUM, 0, 4, &settings.numlives, "Pacmen Per Game", numlives_options, NULL}, | ||
70 | {TYPE_ENUM, 0, 4, &settings.bonus, "Bonus", bonus_options, NULL}, | ||
71 | {TYPE_ENUM, 0, 2, &settings.ghostnames, "Ghost Names", ghostnames_options , NULL}, | ||
72 | {TYPE_ENUM, 0, 2, &settings.showfps, "Show FPS", showfps_options, NULL}, | ||
73 | }; | ||
74 | |||
75 | static bool loadFile( const char * name, unsigned char * buf, int len ) | ||
56 | { | 76 | { |
57 | char filename[MAX_PATH]; | 77 | char filename[MAX_PATH]; |
58 | 78 | ||
@@ -75,7 +95,7 @@ bool loadFile( const char * name, unsigned char * buf, int len ) | |||
75 | return true; | 95 | return true; |
76 | } | 96 | } |
77 | 97 | ||
78 | bool loadROMS( void ) | 98 | static bool loadROMS( void ) |
79 | { | 99 | { |
80 | bool romsLoaded = false; | 100 | bool romsLoaded = false; |
81 | 101 | ||
@@ -95,18 +115,18 @@ bool loadROMS( void ) | |||
95 | } | 115 | } |
96 | 116 | ||
97 | /* A buffer to render Pacman's 244x288 screen into */ | 117 | /* A buffer to render Pacman's 244x288 screen into */ |
98 | unsigned char video_buffer[ScreenWidth*ScreenHeight] __attribute__ ((aligned (4))); | 118 | static unsigned char video_buffer[ScreenWidth*ScreenHeight] __attribute__ ((aligned (4))); |
99 | 119 | ||
100 | long start_time; | 120 | static long start_time; |
101 | long sleep_counter = 0; | 121 | static long video_frames = 0; |
102 | long video_frames = 0; | ||
103 | 122 | ||
104 | int dipDifficulty[] = { DipDifficulty_Normal, DipDifficulty_Hard }; | 123 | static int dipDifficulty[] = { DipDifficulty_Normal, DipDifficulty_Hard }; |
105 | int dipLives[] = { DipLives_1, DipLives_2, DipLives_3, DipLives_5 }; | 124 | static int dipLives[] = { DipLives_1, DipLives_2, DipLives_3, DipLives_5 }; |
106 | int dipBonus[] = { DipBonus_10000, DipBonus_15000, DipBonus_20000, DipBonus_None }; | 125 | static int dipBonus[] = { DipBonus_10000, DipBonus_15000, DipBonus_20000, |
107 | int dipGhostNames[] = { DipGhostNames_Normal, DipGhostNames_Alternate }; | 126 | DipBonus_None }; |
127 | static int dipGhostNames[] = { DipGhostNames_Normal, DipGhostNames_Alternate }; | ||
108 | 128 | ||
109 | int settings_to_dip(struct pacman_settings settings) | 129 | static int settings_to_dip(struct pacman_settings settings) |
110 | { | 130 | { |
111 | return ( DipPlay_OneCoinOneGame | | 131 | return ( DipPlay_OneCoinOneGame | |
112 | DipCabinet_Upright | | 132 | DipCabinet_Upright | |
@@ -120,7 +140,7 @@ int settings_to_dip(struct pacman_settings settings) | |||
120 | ); | 140 | ); |
121 | } | 141 | } |
122 | 142 | ||
123 | bool pacbox_menu(void) | 143 | static bool pacbox_menu(void) |
124 | { | 144 | { |
125 | int m; | 145 | int m; |
126 | int result; | 146 | int result; |
@@ -214,7 +234,8 @@ bool pacbox_menu(void) | |||
214 | } | 234 | } |
215 | break; | 235 | break; |
216 | case 4: /* Show FPS */ | 236 | case 4: /* Show FPS */ |
217 | rb->set_option("Display FPS",&settings.showfps,INT, noyes, 2, NULL); | 237 | rb->set_option("Display FPS",&settings.showfps,INT, |
238 | noyes, 2, NULL); | ||
218 | break; | 239 | break; |
219 | case 5: /* Restart */ | 240 | case 5: /* Restart */ |
220 | need_restart=true; | 241 | need_restart=true; |
@@ -244,7 +265,7 @@ bool pacbox_menu(void) | |||
244 | /* | 265 | /* |
245 | Runs the game engine for one frame. | 266 | Runs the game engine for one frame. |
246 | */ | 267 | */ |
247 | int gameProc( void ) | 268 | static int gameProc( void ) |
248 | { | 269 | { |
249 | int x; | 270 | int x; |
250 | int fps; | 271 | int fps; |
@@ -291,15 +312,10 @@ int gameProc( void ) | |||
291 | /* The following functions render the Pacman screen from the contents | 312 | /* The following functions render the Pacman screen from the contents |
292 | of the video and color ram. We first update the background, and | 313 | of the video and color ram. We first update the background, and |
293 | then draw the Sprites on top. | 314 | then draw the Sprites on top. |
294 | |||
295 | Note that we only redraw the parts of the background that have | ||
296 | changed, which is why we need to keep a copy of the background without | ||
297 | the sprites on top. Even with the memcpy, this is faster than redrawing | ||
298 | the whole background. | ||
299 | */ | 315 | */ |
300 | 316 | ||
301 | renderBackground( video_buffer ); | 317 | renderBackground( video_buffer ); |
302 | renderSprites( video_buffer ); | 318 | renderSprites( video_buffer ); |
303 | 319 | ||
304 | blit_display(rb->lcd_framebuffer,video_buffer); | 320 | blit_display(rb->lcd_framebuffer,video_buffer); |
305 | 321 | ||
@@ -351,13 +367,31 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
351 | rb->lcd_clear_display(); | 367 | rb->lcd_clear_display(); |
352 | rb->lcd_update(); | 368 | rb->lcd_update(); |
353 | 369 | ||
354 | /* Set the default settings (we should load these from a file) */ | 370 | /* Set the default settings */ |
355 | settings.difficulty = 0; /* Normal */ | 371 | settings.difficulty = 0; /* Normal */ |
356 | settings.numlives = 2; /* 3 lives */ | 372 | settings.numlives = 2; /* 3 lives */ |
357 | settings.bonus = 0; /* 10000 points */ | 373 | settings.bonus = 0; /* 10000 points */ |
358 | settings.ghostnames = 0; /* Normal names */ | 374 | settings.ghostnames = 0; /* Normal names */ |
359 | settings.showfps = 0; /* Do not show FPS */ | 375 | settings.showfps = 0; /* Do not show FPS */ |
360 | 376 | ||
377 | configfile_init(rb); | ||
378 | |||
379 | if (configfile_load(SETTINGS_FILENAME, config, | ||
380 | sizeof(config)/sizeof(*config), | ||
381 | SETTINGS_MIN_VERSION | ||
382 | ) < 0) | ||
383 | { | ||
384 | /* If the loading failed, save a new config file (as the disk is | ||
385 | already spinning) */ | ||
386 | configfile_save(SETTINGS_FILENAME, config, | ||
387 | sizeof(config)/sizeof(*config), | ||
388 | SETTINGS_VERSION); | ||
389 | } | ||
390 | |||
391 | /* Keep a copy of the saved version of the settings - so we can check if | ||
392 | the settings have changed when we quit */ | ||
393 | old_settings = settings; | ||
394 | |||
361 | /* Initialise the hardware */ | 395 | /* Initialise the hardware */ |
362 | init_PacmanMachine(settings_to_dip(settings)); | 396 | init_PacmanMachine(settings_to_dip(settings)); |
363 | 397 | ||
@@ -367,6 +401,14 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
367 | do { | 401 | do { |
368 | status = gameProc(); | 402 | status = gameProc(); |
369 | } while (!status); | 403 | } while (!status); |
404 | |||
405 | /* Save the user settings if they have changed */ | ||
406 | if (rb->memcmp(&settings,&old_settings,sizeof(settings))!=0) { | ||
407 | rb->splash(0,true,"Saving settings..."); | ||
408 | configfile_save(SETTINGS_FILENAME, config, | ||
409 | sizeof(config)/sizeof(*config), | ||
410 | SETTINGS_VERSION); | ||
411 | } | ||
370 | } else { | 412 | } else { |
371 | rb->splash(HZ*2,true,"No ROMs in /.rockbox/pacman/"); | 413 | rb->splash(HZ*2,true,"No ROMs in /.rockbox/pacman/"); |
372 | } | 414 | } |