summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stummvoll <michael@stummi.org>2010-11-25 12:45:13 +0000
committerMichael Stummvoll <michael@stummi.org>2010-11-25 12:45:13 +0000
commit7704a3ccd7b1a3d1092bde0a1ec13ba6196b550b (patch)
treedd39a8d84f0608dfc932a5e344ccf404c3901215
parent8971b230dcee4140e207d7a36fb769f385cebc82 (diff)
downloadrockbox-7704a3ccd7b1a3d1092bde0a1ec13ba6196b550b.tar.gz
rockbox-7704a3ccd7b1a3d1092bde0a1ec13ba6196b550b.zip
Added the snapshot patch for rockboy (FS#11757)
Added a simple filesize-check for the options file before loading to avoid crashes due the changed config git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28664 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/rockboy/loader.c21
-rw-r--r--apps/plugins/rockboy/loader.h2
-rw-r--r--apps/plugins/rockboy/menu.c22
-rw-r--r--apps/plugins/rockboy/rockboy.c12
-rw-r--r--apps/plugins/rockboy/rockmacros.h1
5 files changed, 49 insertions, 9 deletions
diff --git a/apps/plugins/rockboy/loader.c b/apps/plugins/rockboy/loader.c
index 8741dabd12..d843ba8a60 100644
--- a/apps/plugins/rockboy/loader.c
+++ b/apps/plugins/rockboy/loader.c
@@ -102,6 +102,7 @@ static const unsigned char ramsize_table[5] =
102static const char *romfile; 102static const char *romfile;
103static char sramfile[500]; 103static char sramfile[500];
104static char rtcfile[500]; 104static char rtcfile[500];
105static char snfile[500];
105static char saveprefix[500]; 106static char saveprefix[500];
106 107
107static int forcebatt, nobatt; 108static int forcebatt, nobatt;
@@ -269,6 +270,24 @@ static void rtc_load(void)
269 close(fd); 270 close(fd);
270} 271}
271 272
273void sn_save(void)
274{
275 int fd;
276 if ((fd = open(snfile, O_WRONLY | O_CREAT, 0666)) < 0)
277 return;
278 savestate(fd);
279 close(fd);
280}
281
282void sn_load(void)
283{
284 int fd;
285 if ((fd = open(snfile, O_RDONLY, 0666)) < 0)
286 return;
287 loadstate(fd);
288 close(fd);
289}
290
272void cleanup(void) 291void cleanup(void)
273{ 292{
274 sram_save(); 293 sram_save();
@@ -289,6 +308,8 @@ void loader_init(const char *s)
289 308
290 strcpy(rtcfile, saveprefix); 309 strcpy(rtcfile, saveprefix);
291 strcat(rtcfile, ".rtc"); 310 strcat(rtcfile, ".rtc");
311 strcpy(snfile, saveprefix);
312 strcat(snfile, ".sn");
292 313
293 sram_load(); 314 sram_load();
294 rtc_load(); 315 rtc_load();
diff --git a/apps/plugins/rockboy/loader.h b/apps/plugins/rockboy/loader.h
index 5ade6e7d8a..ad93162ff0 100644
--- a/apps/plugins/rockboy/loader.h
+++ b/apps/plugins/rockboy/loader.h
@@ -5,6 +5,8 @@
5 5
6void loader_init(const char *s); 6void loader_init(const char *s);
7void cleanup(void); 7void cleanup(void);
8void sn_load(void);
9void sn_save(void);
8 10
9#endif 11#endif
10 12
diff --git a/apps/plugins/rockboy/menu.c b/apps/plugins/rockboy/menu.c
index da9783cf79..0156a3fdd2 100644
--- a/apps/plugins/rockboy/menu.c
+++ b/apps/plugins/rockboy/menu.c
@@ -12,6 +12,7 @@
12#include "rtc-gb.h" 12#include "rtc-gb.h"
13#include "pcm.h" 13#include "pcm.h"
14#include "emu.h" 14#include "emu.h"
15#include "loader.h"
15 16
16#define SLOT_COUNT 50 17#define SLOT_COUNT 50
17#define DESC_SIZE 20 18#define DESC_SIZE 20
@@ -115,6 +116,7 @@ int do_user_menu(void) {
115 break; 116 break;
116 case 4: /* Quit */ 117 case 4: /* Quit */
117 ret = USER_MENU_QUIT; 118 ret = USER_MENU_QUIT;
119 if(options.autosave) sn_save();
118 done=true; 120 done=true;
119 break; 121 break;
120 default: 122 default:
@@ -416,7 +418,8 @@ static void do_opt_menu(void)
416#endif 418#endif
417 419
418 MENUITEM_STRINGLIST(menu, "Options", NULL, 420 MENUITEM_STRINGLIST(menu, "Options", NULL,
419 "Max Frameskip", "Sound", "Volume", "Stats", "Set Keys (Buggy)", 421 "Max Frameskip", "Autosave", "Sound", "Volume",
422 "Stats", "Set Keys (Buggy)",
420#ifdef HAVE_LCD_COLOR 423#ifdef HAVE_LCD_COLOR
421 "Screen Size", "Screen Rotate", "Set Palette", 424 "Screen Size", "Screen Rotate", "Set Palette",
422#endif 425#endif
@@ -437,32 +440,35 @@ static void do_opt_menu(void)
437 rb->set_option("Max Frameskip", &options.maxskip, INT, frameskip, 440 rb->set_option("Max Frameskip", &options.maxskip, INT, frameskip,
438 sizeof(frameskip)/sizeof(*frameskip), NULL ); 441 sizeof(frameskip)/sizeof(*frameskip), NULL );
439 break; 442 break;
440 case 1: /* Sound */ 443 case 1: /* Autosave */
444 rb->set_option("Autosave", &options.autosave, INT, onoff, 2, NULL );
445 break;
446 case 2: /* Sound */
441 if(options.sound>1) options.sound=1; 447 if(options.sound>1) options.sound=1;
442 rb->set_option("Sound", &options.sound, INT, onoff, 2, NULL ); 448 rb->set_option("Sound", &options.sound, INT, onoff, 2, NULL );
443 if(options.sound) sound_dirty(); 449 if(options.sound) sound_dirty();
444 break; 450 break;
445 case 2: /* Volume */ 451 case 3: /* Volume */
446 rb->option_screen((struct settings_list*)vol, parentvp, false, "Volume"); 452 rb->option_screen((struct settings_list*)vol, parentvp, false, "Volume");
447 break; 453 break;
448 case 3: /* Stats */ 454 case 4: /* Stats */
449 rb->set_option("Stats", &options.showstats, INT, stats, 3, NULL ); 455 rb->set_option("Stats", &options.showstats, INT, stats, 3, NULL );
450 break; 456 break;
451 case 4: /* Keys */ 457 case 5: /* Keys */
452 setupkeys(); 458 setupkeys();
453 break; 459 break;
454#ifdef HAVE_LCD_COLOR 460#ifdef HAVE_LCD_COLOR
455 case 5: /* Screen Size */ 461 case 6: /* Screen Size */
456 rb->set_option("Screen Size", &options.scaling, INT, scaling, 462 rb->set_option("Screen Size", &options.scaling, INT, scaling,
457 sizeof(scaling)/sizeof(*scaling), NULL ); 463 sizeof(scaling)/sizeof(*scaling), NULL );
458 setvidmode(); 464 setvidmode();
459 break; 465 break;
460 case 6: /* Screen rotate */ 466 case 7: /* Screen rotate */
461 rb->set_option("Screen Rotate", &options.rotate, INT, rotate, 467 rb->set_option("Screen Rotate", &options.rotate, INT, rotate,
462 sizeof(rotate)/sizeof(*rotate), NULL ); 468 sizeof(rotate)/sizeof(*rotate), NULL );
463 setvidmode(); 469 setvidmode();
464 break; 470 break;
465 case 7: /* Palette */ 471 case 8: /* Palette */
466 rb->set_option("Set Palette", &options.pal, INT, palette, 17, NULL ); 472 rb->set_option("Set Palette", &options.pal, INT, palette, 17, NULL );
467 set_pal(); 473 set_pal();
468 break; 474 break;
diff --git a/apps/plugins/rockboy/rockboy.c b/apps/plugins/rockboy/rockboy.c
index 0364f47faa..5464a2a416 100644
--- a/apps/plugins/rockboy/rockboy.c
+++ b/apps/plugins/rockboy/rockboy.c
@@ -71,8 +71,17 @@ static void setoptions (void)
71 snprintf(optionsave, sizeof(optionsave), "%s/%s", savedir, optionname); 71 snprintf(optionsave, sizeof(optionsave), "%s/%s", savedir, optionname);
72 72
73 fd = open(optionsave, O_RDONLY); 73 fd = open(optionsave, O_RDONLY);
74 if(fd < 0) /* no options to read, set defaults */ 74
75 int optionssize = sizeof(options);
76 int filesize = 0;
77 if(fd >= 0)
78 filesize = rb->filesize(fd);
79
80 /* don't read the option file if the size
81 * is not as expected to avoid crash */
82 if(fd < 0 || filesize!=optionssize)
75 { 83 {
84 // no options to read, set defaults
76#ifdef HAVE_TOUCHSCREEN 85#ifdef HAVE_TOUCHSCREEN
77 options.LEFT = BUTTON_MIDLEFT; 86 options.LEFT = BUTTON_MIDLEFT;
78 options.RIGHT = BUTTON_MIDRIGHT; 87 options.RIGHT = BUTTON_MIDRIGHT;
@@ -378,6 +387,7 @@ static int gnuboy_main(const char *rom)
378 rb->lcd_puts(0,4,"Emu run"); 387 rb->lcd_puts(0,4,"Emu run");
379 rb->lcd_clear_display(); 388 rb->lcd_clear_display();
380 rb->lcd_update(); 389 rb->lcd_update();
390 if(options.autosave) sn_load();
381 emu_run(); 391 emu_run();
382 392
383 /* never reached */ 393 /* never reached */
diff --git a/apps/plugins/rockboy/rockmacros.h b/apps/plugins/rockboy/rockmacros.h
index f68a613978..4a6822d410 100644
--- a/apps/plugins/rockboy/rockmacros.h
+++ b/apps/plugins/rockboy/rockmacros.h
@@ -91,6 +91,7 @@ struct options {
91 int UP, DOWN, LEFT, RIGHT; 91 int UP, DOWN, LEFT, RIGHT;
92 int frameskip, fps, maxskip; 92 int frameskip, fps, maxskip;
93 int sound, scaling, showstats; 93 int sound, scaling, showstats;
94 int autosave;
94 int rotate; 95 int rotate;
95 int pal; 96 int pal;
96 int dirty; 97 int dirty;