mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
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 const char *romfile;
|
||||||
static char sramfile[500];
|
static char sramfile[500];
|
||||||
static char rtcfile[500];
|
static char rtcfile[500];
|
||||||
|
static char snfile[500];
|
||||||
static char saveprefix[500];
|
static char saveprefix[500];
|
||||||
|
|
||||||
static int forcebatt, nobatt;
|
static int forcebatt, nobatt;
|
||||||
|
@ -269,6 +270,24 @@ static void rtc_load(void)
|
||||||
close(fd);
|
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)
|
void cleanup(void)
|
||||||
{
|
{
|
||||||
sram_save();
|
sram_save();
|
||||||
|
@ -289,6 +308,8 @@ void loader_init(const char *s)
|
||||||
|
|
||||||
strcpy(rtcfile, saveprefix);
|
strcpy(rtcfile, saveprefix);
|
||||||
strcat(rtcfile, ".rtc");
|
strcat(rtcfile, ".rtc");
|
||||||
|
strcpy(snfile, saveprefix);
|
||||||
|
strcat(snfile, ".sn");
|
||||||
|
|
||||||
sram_load();
|
sram_load();
|
||||||
rtc_load();
|
rtc_load();
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
void loader_init(const char *s);
|
void loader_init(const char *s);
|
||||||
void cleanup(void);
|
void cleanup(void);
|
||||||
|
void sn_load(void);
|
||||||
|
void sn_save(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "rtc-gb.h"
|
#include "rtc-gb.h"
|
||||||
#include "pcm.h"
|
#include "pcm.h"
|
||||||
#include "emu.h"
|
#include "emu.h"
|
||||||
|
#include "loader.h"
|
||||||
|
|
||||||
#define SLOT_COUNT 50
|
#define SLOT_COUNT 50
|
||||||
#define DESC_SIZE 20
|
#define DESC_SIZE 20
|
||||||
|
@ -115,6 +116,7 @@ int do_user_menu(void) {
|
||||||
break;
|
break;
|
||||||
case 4: /* Quit */
|
case 4: /* Quit */
|
||||||
ret = USER_MENU_QUIT;
|
ret = USER_MENU_QUIT;
|
||||||
|
if(options.autosave) sn_save();
|
||||||
done=true;
|
done=true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -416,7 +418,8 @@ static void do_opt_menu(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MENUITEM_STRINGLIST(menu, "Options", NULL,
|
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
|
#ifdef HAVE_LCD_COLOR
|
||||||
"Screen Size", "Screen Rotate", "Set Palette",
|
"Screen Size", "Screen Rotate", "Set Palette",
|
||||||
#endif
|
#endif
|
||||||
|
@ -437,32 +440,35 @@ static void do_opt_menu(void)
|
||||||
rb->set_option("Max Frameskip", &options.maxskip, INT, frameskip,
|
rb->set_option("Max Frameskip", &options.maxskip, INT, frameskip,
|
||||||
sizeof(frameskip)/sizeof(*frameskip), NULL );
|
sizeof(frameskip)/sizeof(*frameskip), NULL );
|
||||||
break;
|
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;
|
if(options.sound>1) options.sound=1;
|
||||||
rb->set_option("Sound", &options.sound, INT, onoff, 2, NULL );
|
rb->set_option("Sound", &options.sound, INT, onoff, 2, NULL );
|
||||||
if(options.sound) sound_dirty();
|
if(options.sound) sound_dirty();
|
||||||
break;
|
break;
|
||||||
case 2: /* Volume */
|
case 3: /* Volume */
|
||||||
rb->option_screen((struct settings_list*)vol, parentvp, false, "Volume");
|
rb->option_screen((struct settings_list*)vol, parentvp, false, "Volume");
|
||||||
break;
|
break;
|
||||||
case 3: /* Stats */
|
case 4: /* Stats */
|
||||||
rb->set_option("Stats", &options.showstats, INT, stats, 3, NULL );
|
rb->set_option("Stats", &options.showstats, INT, stats, 3, NULL );
|
||||||
break;
|
break;
|
||||||
case 4: /* Keys */
|
case 5: /* Keys */
|
||||||
setupkeys();
|
setupkeys();
|
||||||
break;
|
break;
|
||||||
#ifdef HAVE_LCD_COLOR
|
#ifdef HAVE_LCD_COLOR
|
||||||
case 5: /* Screen Size */
|
case 6: /* Screen Size */
|
||||||
rb->set_option("Screen Size", &options.scaling, INT, scaling,
|
rb->set_option("Screen Size", &options.scaling, INT, scaling,
|
||||||
sizeof(scaling)/sizeof(*scaling), NULL );
|
sizeof(scaling)/sizeof(*scaling), NULL );
|
||||||
setvidmode();
|
setvidmode();
|
||||||
break;
|
break;
|
||||||
case 6: /* Screen rotate */
|
case 7: /* Screen rotate */
|
||||||
rb->set_option("Screen Rotate", &options.rotate, INT, rotate,
|
rb->set_option("Screen Rotate", &options.rotate, INT, rotate,
|
||||||
sizeof(rotate)/sizeof(*rotate), NULL );
|
sizeof(rotate)/sizeof(*rotate), NULL );
|
||||||
setvidmode();
|
setvidmode();
|
||||||
break;
|
break;
|
||||||
case 7: /* Palette */
|
case 8: /* Palette */
|
||||||
rb->set_option("Set Palette", &options.pal, INT, palette, 17, NULL );
|
rb->set_option("Set Palette", &options.pal, INT, palette, 17, NULL );
|
||||||
set_pal();
|
set_pal();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -71,8 +71,17 @@ static void setoptions (void)
|
||||||
snprintf(optionsave, sizeof(optionsave), "%s/%s", savedir, optionname);
|
snprintf(optionsave, sizeof(optionsave), "%s/%s", savedir, optionname);
|
||||||
|
|
||||||
fd = open(optionsave, O_RDONLY);
|
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
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
options.LEFT = BUTTON_MIDLEFT;
|
options.LEFT = BUTTON_MIDLEFT;
|
||||||
options.RIGHT = BUTTON_MIDRIGHT;
|
options.RIGHT = BUTTON_MIDRIGHT;
|
||||||
|
@ -378,6 +387,7 @@ static int gnuboy_main(const char *rom)
|
||||||
rb->lcd_puts(0,4,"Emu run");
|
rb->lcd_puts(0,4,"Emu run");
|
||||||
rb->lcd_clear_display();
|
rb->lcd_clear_display();
|
||||||
rb->lcd_update();
|
rb->lcd_update();
|
||||||
|
if(options.autosave) sn_load();
|
||||||
emu_run();
|
emu_run();
|
||||||
|
|
||||||
/* never reached */
|
/* never reached */
|
||||||
|
|
|
@ -91,6 +91,7 @@ struct options {
|
||||||
int UP, DOWN, LEFT, RIGHT;
|
int UP, DOWN, LEFT, RIGHT;
|
||||||
int frameskip, fps, maxskip;
|
int frameskip, fps, maxskip;
|
||||||
int sound, scaling, showstats;
|
int sound, scaling, showstats;
|
||||||
|
int autosave;
|
||||||
int rotate;
|
int rotate;
|
||||||
int pal;
|
int pal;
|
||||||
int dirty;
|
int dirty;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue