From: notaz Date: Fri, 30 Aug 2013 21:58:56 +0000 (+0300) Subject: frontend: save autoload X-Git-Tag: v1.85~2^2~2 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7074ddb0258ab03b9329bef9930c28ba46ae6da;p=picodrive.git frontend: save autoload --- diff --git a/platform/common/emu.c b/platform/common/emu.c index 8bc83af4..ebc7c773 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -490,6 +490,30 @@ int emu_reload_rom(const char *rom_fname_in) if (currentConfig.EmuOpt & EOPT_EN_SRAM) emu_save_load_game(1, 1); + // state autoload? + if (g_autostateld_opt) { + int time, newest = 0, newest_slot = -1; + int slot; + + for (slot = 0; slot < 10; slot++) { + if (emu_check_save_file(slot, &time)) { + if (time > newest) { + newest = time; + newest_slot = slot; + } + } + } + + if (newest_slot >= 0) { + lprintf("autoload slot %d\n", newest_slot); + state_slot = newest_slot; + emu_save_load_game(1, 0); + } + else { + lprintf("no save to autoload.\n"); + } + } + retval = 1; out: if (menu_romload_started) @@ -736,19 +760,25 @@ void update_movie(void) } } -static int try_ropen_file(const char *fname) +static int try_ropen_file(const char *fname, int *time) { + struct stat st; FILE *f; f = fopen(fname, "rb"); if (f) { + if (time != NULL) { + *time = 0; + if (fstat(fileno(f), &st) == 0) + *time = (int)st.st_mtime; + } fclose(f); return 1; } return 0; } -char *emu_get_save_fname(int load, int is_sram, int slot) +char *emu_get_save_fname(int load, int is_sram, int slot, int *time) { char *saveFname = static_buff; char ext[16]; @@ -761,11 +791,11 @@ char *emu_get_save_fname(int load, int is_sram, int slot) if (!load) return saveFname; - if (try_ropen_file(saveFname)) + if (try_ropen_file(saveFname, time)) return saveFname; romfname_ext(saveFname, sizeof(static_buff), NULL, ext); - if (try_ropen_file(saveFname)) + if (try_ropen_file(saveFname, time)) return saveFname; } else @@ -783,11 +813,11 @@ char *emu_get_save_fname(int load, int is_sram, int slot) } else { romfname_ext(saveFname, sizeof(static_buff), "mds" PATH_SEP, ext); - if (try_ropen_file(saveFname)) + if (try_ropen_file(saveFname, time)) return saveFname; romfname_ext(saveFname, sizeof(static_buff), NULL, ext); - if (try_ropen_file(saveFname)) + if (try_ropen_file(saveFname, time)) return saveFname; // try the other ext @@ -797,7 +827,7 @@ char *emu_get_save_fname(int load, int is_sram, int slot) strcat(ext, ext_othr); romfname_ext(saveFname, sizeof(static_buff), "mds"PATH_SEP, ext); - if (try_ropen_file(saveFname)) + if (try_ropen_file(saveFname, time)) return saveFname; } } @@ -807,7 +837,7 @@ char *emu_get_save_fname(int load, int is_sram, int slot) int emu_check_save_file(int slot, int *time) { - return emu_get_save_fname(1, 0, slot) ? 1 : 0; + return emu_get_save_fname(1, 0, slot, time) ? 1 : 0; } int emu_save_load_game(int load, int sram) @@ -816,7 +846,7 @@ int emu_save_load_game(int load, int sram) char *saveFname; // make save filename - saveFname = emu_get_save_fname(load, sram, state_slot); + saveFname = emu_get_save_fname(load, sram, state_slot, NULL); if (saveFname == NULL) { if (!sram) emu_status_msg(load ? "LOAD FAILED (missing file)" : "SAVE FAILED"); diff --git a/platform/common/emu.h b/platform/common/emu.h index 93787c77..8f8f61f4 100644 --- a/platform/common/emu.h +++ b/platform/common/emu.h @@ -121,7 +121,7 @@ void emu_set_defconfig(void); int emu_read_config(const char *rom_fname, int no_defaults); int emu_write_config(int game); -char *emu_get_save_fname(int load, int is_sram, int slot); +char *emu_get_save_fname(int load, int is_sram, int slot, int *time); int emu_check_save_file(int slot, int *time); void emu_text_out8 (int x, int y, const char *text); diff --git a/platform/common/menu_pico.c b/platform/common/menu_pico.c index 8e723ff6..44b5bdd5 100644 --- a/platform/common/menu_pico.c +++ b/platform/common/menu_pico.c @@ -135,7 +135,7 @@ static void draw_savestate_bg(int slot) const char *fname; void *tmp_state; - fname = emu_get_save_fname(1, 0, slot); + fname = emu_get_save_fname(1, 0, slot, NULL); if (!fname) return; @@ -1166,6 +1166,7 @@ void menu_update_msg(const char *msg) static menu_entry e_menu_hidden[] = { mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoOpt, 0x080), + mee_onoff("autoload savestates", MA_OPT_AUTOLOAD_SAVE, g_autostateld_opt, 1), mee_end, }; diff --git a/platform/common/menu_pico.h b/platform/common/menu_pico.h index 583a77cf..b5bd602d 100644 --- a/platform/common/menu_pico.h +++ b/platform/common/menu_pico.h @@ -41,6 +41,7 @@ typedef enum MA_OPT_ROTATION, /* uiq */ MA_OPT_TEARING_FIX, /* wiz */ MA_OPT_VOUT_MODE, + MA_OPT_AUTOLOAD_SAVE, MA_OPT2_GAMMA, MA_OPT2_A_SN_GAMMA, MA_OPT2_DBLBUFF, /* giz */ diff --git a/platform/libpicofe b/platform/libpicofe index 7ceadd99..9089665c 160000 --- a/platform/libpicofe +++ b/platform/libpicofe @@ -1 +1 @@ -Subproject commit 7ceadd9993ea84078e9d74d79215419e06496f90 +Subproject commit 9089665ca1260c338c4239583f59de981bc80c1c diff --git a/platform/pandora/plat.c b/platform/pandora/plat.c index 306f2c36..bbe88137 100644 --- a/platform/pandora/plat.c +++ b/platform/pandora/plat.c @@ -74,16 +74,21 @@ static struct in_default_bind in_evdev_defbinds[] = { KEY_D, IN_BINDTYPE_PLAYER12, GBTN_C }, { KEY_ENTER, IN_BINDTYPE_PLAYER12, GBTN_START }, { KEY_F, IN_BINDTYPE_EMU, PEVB_FF }, - { KEY_BACKSLASH, IN_BINDTYPE_EMU, PEVB_MENU }, + { KEY_BACKSPACE,IN_BINDTYPE_EMU, PEVB_FF }, + { KEY_BACKSLASH,IN_BINDTYPE_EMU, PEVB_MENU }, { KEY_SPACE, IN_BINDTYPE_EMU, PEVB_MENU }, - /* Pandora */ + { KEY_LEFTCTRL, IN_BINDTYPE_EMU, PEVB_MENU }, { KEY_HOME, IN_BINDTYPE_PLAYER12, GBTN_A }, { KEY_PAGEDOWN, IN_BINDTYPE_PLAYER12, GBTN_B }, { KEY_END, IN_BINDTYPE_PLAYER12, GBTN_C }, { KEY_LEFTALT, IN_BINDTYPE_PLAYER12, GBTN_START }, - { KEY_RIGHTSHIFT,IN_BINDTYPE_EMU, PEVB_STATE_SAVE }, - { KEY_RIGHTCTRL, IN_BINDTYPE_EMU, PEVB_STATE_LOAD }, - { KEY_LEFTCTRL, IN_BINDTYPE_EMU, PEVB_MENU }, + { KEY_1, IN_BINDTYPE_EMU, PEVB_STATE_SAVE }, + { KEY_2, IN_BINDTYPE_EMU, PEVB_STATE_LOAD }, + { KEY_3, IN_BINDTYPE_EMU, PEVB_SSLOT_PREV }, + { KEY_4, IN_BINDTYPE_EMU, PEVB_SSLOT_NEXT }, + { KEY_5, IN_BINDTYPE_EMU, PEVB_PICO_PPREV }, + { KEY_6, IN_BINDTYPE_EMU, PEVB_PICO_PNEXT }, + { KEY_7, IN_BINDTYPE_EMU, PEVB_PICO_SWINP }, { 0, 0, 0 } };