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
This commit is contained in:
parent
8971b230dc
commit
7704a3ccd7
5 changed files with 49 additions and 9 deletions
|
@ -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();
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
void loader_init(const char *s);
|
||||
void cleanup(void);
|
||||
void sn_load(void);
|
||||
void sn_save(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue