From 7704a3ccd7b1a3d1092bde0a1ec13ba6196b550b Mon Sep 17 00:00:00 2001 From: Michael Stummvoll Date: Thu, 25 Nov 2010 12:45:13 +0000 Subject: 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 --- apps/plugins/rockboy/loader.c | 21 +++++++++++++++++++++ apps/plugins/rockboy/loader.h | 2 ++ apps/plugins/rockboy/menu.c | 22 ++++++++++++++-------- apps/plugins/rockboy/rockboy.c | 12 +++++++++++- apps/plugins/rockboy/rockmacros.h | 1 + 5 files changed, 49 insertions(+), 9 deletions(-) (limited to 'apps/plugins/rockboy') 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] = static const char *romfile; static char sramfile[500]; static char rtcfile[500]; +static char snfile[500]; static char saveprefix[500]; static int forcebatt, nobatt; @@ -269,6 +270,24 @@ static void rtc_load(void) close(fd); } +void sn_save(void) +{ + int fd; + if ((fd = open(snfile, O_WRONLY | O_CREAT, 0666)) < 0) + return; + savestate(fd); + close(fd); +} + +void sn_load(void) +{ + int fd; + if ((fd = open(snfile, O_RDONLY, 0666)) < 0) + return; + loadstate(fd); + close(fd); +} + void cleanup(void) { sram_save(); @@ -289,6 +308,8 @@ void loader_init(const char *s) strcpy(rtcfile, saveprefix); strcat(rtcfile, ".rtc"); + strcpy(snfile, saveprefix); + strcat(snfile, ".sn"); sram_load(); 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 @@ void loader_init(const char *s); void cleanup(void); +void sn_load(void); +void sn_save(void); #endif 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 @@ #include "rtc-gb.h" #include "pcm.h" #include "emu.h" +#include "loader.h" #define SLOT_COUNT 50 #define DESC_SIZE 20 @@ -115,6 +116,7 @@ int do_user_menu(void) { break; case 4: /* Quit */ ret = USER_MENU_QUIT; + if(options.autosave) sn_save(); done=true; break; default: @@ -416,7 +418,8 @@ static void do_opt_menu(void) #endif MENUITEM_STRINGLIST(menu, "Options", NULL, - "Max Frameskip", "Sound", "Volume", "Stats", "Set Keys (Buggy)", + "Max Frameskip", "Autosave", "Sound", "Volume", + "Stats", "Set Keys (Buggy)", #ifdef HAVE_LCD_COLOR "Screen Size", "Screen Rotate", "Set Palette", #endif @@ -437,32 +440,35 @@ static void do_opt_menu(void) rb->set_option("Max Frameskip", &options.maxskip, INT, frameskip, sizeof(frameskip)/sizeof(*frameskip), NULL ); break; - case 1: /* Sound */ + case 1: /* Autosave */ + rb->set_option("Autosave", &options.autosave, INT, onoff, 2, NULL ); + break; + case 2: /* Sound */ if(options.sound>1) options.sound=1; rb->set_option("Sound", &options.sound, INT, onoff, 2, NULL ); if(options.sound) sound_dirty(); break; - case 2: /* Volume */ + case 3: /* Volume */ rb->option_screen((struct settings_list*)vol, parentvp, false, "Volume"); break; - case 3: /* Stats */ + case 4: /* Stats */ rb->set_option("Stats", &options.showstats, INT, stats, 3, NULL ); break; - case 4: /* Keys */ + case 5: /* Keys */ setupkeys(); break; #ifdef HAVE_LCD_COLOR - case 5: /* Screen Size */ + case 6: /* Screen Size */ rb->set_option("Screen Size", &options.scaling, INT, scaling, sizeof(scaling)/sizeof(*scaling), NULL ); setvidmode(); break; - case 6: /* Screen rotate */ + case 7: /* Screen rotate */ rb->set_option("Screen Rotate", &options.rotate, INT, rotate, sizeof(rotate)/sizeof(*rotate), NULL ); setvidmode(); break; - case 7: /* Palette */ + case 8: /* Palette */ rb->set_option("Set Palette", &options.pal, INT, palette, 17, NULL ); set_pal(); 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) snprintf(optionsave, sizeof(optionsave), "%s/%s", savedir, optionname); fd = open(optionsave, O_RDONLY); - if(fd < 0) /* no options to read, set defaults */ + + int optionssize = sizeof(options); + int filesize = 0; + if(fd >= 0) + filesize = rb->filesize(fd); + + /* don't read the option file if the size + * is not as expected to avoid crash */ + if(fd < 0 || filesize!=optionssize) { + // no options to read, set defaults #ifdef HAVE_TOUCHSCREEN options.LEFT = BUTTON_MIDLEFT; options.RIGHT = BUTTON_MIDRIGHT; @@ -378,6 +387,7 @@ static int gnuboy_main(const char *rom) rb->lcd_puts(0,4,"Emu run"); rb->lcd_clear_display(); rb->lcd_update(); + if(options.autosave) sn_load(); emu_run(); /* 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 { int UP, DOWN, LEFT, RIGHT; int frameskip, fps, maxskip; int sound, scaling, showstats; + int autosave; int rotate; int pal; int dirty; -- cgit v1.2.3