frontend: save autoload
authornotaz <notasas@gmail.com>
Fri, 30 Aug 2013 21:58:56 +0000 (00:58 +0300)
committernotaz <notasas@gmail.com>
Fri, 30 Aug 2013 21:58:56 +0000 (00:58 +0300)
platform/common/emu.c
platform/common/emu.h
platform/common/menu_pico.c
platform/common/menu_pico.h
platform/libpicofe
platform/pandora/plat.c

index 8bc83af..ebc7c77 100644 (file)
@@ -490,6 +490,30 @@ int emu_reload_rom(const char *rom_fname_in)
        if (currentConfig.EmuOpt & EOPT_EN_SRAM)\r
                emu_save_load_game(1, 1);\r
 \r
+       // state autoload?\r
+       if (g_autostateld_opt) {\r
+               int time, newest = 0, newest_slot = -1;\r
+               int slot;\r
+\r
+               for (slot = 0; slot < 10; slot++) {\r
+                       if (emu_check_save_file(slot, &time)) {\r
+                               if (time > newest) {\r
+                                       newest = time;\r
+                                       newest_slot = slot;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               if (newest_slot >= 0) {\r
+                       lprintf("autoload slot %d\n", newest_slot);\r
+                       state_slot = newest_slot;\r
+                       emu_save_load_game(1, 0);\r
+               }\r
+               else {\r
+                       lprintf("no save to autoload.\n");\r
+               }\r
+       }\r
+\r
        retval = 1;\r
 out:\r
        if (menu_romload_started)\r
@@ -736,19 +760,25 @@ void update_movie(void)
        }\r
 }\r
 \r
-static int try_ropen_file(const char *fname)\r
+static int try_ropen_file(const char *fname, int *time)\r
 {\r
+       struct stat st;\r
        FILE *f;\r
 \r
        f = fopen(fname, "rb");\r
        if (f) {\r
+               if (time != NULL) {\r
+                       *time = 0;\r
+                       if (fstat(fileno(f), &st) == 0)\r
+                               *time = (int)st.st_mtime;\r
+               }\r
                fclose(f);\r
                return 1;\r
        }\r
        return 0;\r
 }\r
 \r
-char *emu_get_save_fname(int load, int is_sram, int slot)\r
+char *emu_get_save_fname(int load, int is_sram, int slot, int *time)\r
 {\r
        char *saveFname = static_buff;\r
        char ext[16];\r
@@ -761,11 +791,11 @@ char *emu_get_save_fname(int load, int is_sram, int slot)
                if (!load)\r
                        return saveFname;\r
 \r
-               if (try_ropen_file(saveFname))\r
+               if (try_ropen_file(saveFname, time))\r
                        return saveFname;\r
 \r
                romfname_ext(saveFname, sizeof(static_buff), NULL, ext);\r
-               if (try_ropen_file(saveFname))\r
+               if (try_ropen_file(saveFname, time))\r
                        return saveFname;\r
        }\r
        else\r
@@ -783,11 +813,11 @@ char *emu_get_save_fname(int load, int is_sram, int slot)
                }\r
                else {\r
                        romfname_ext(saveFname, sizeof(static_buff), "mds" PATH_SEP, ext);\r
-                       if (try_ropen_file(saveFname))\r
+                       if (try_ropen_file(saveFname, time))\r
                                return saveFname;\r
 \r
                        romfname_ext(saveFname, sizeof(static_buff), NULL, ext);\r
-                       if (try_ropen_file(saveFname))\r
+                       if (try_ropen_file(saveFname, time))\r
                                return saveFname;\r
 \r
                        // try the other ext\r
@@ -797,7 +827,7 @@ char *emu_get_save_fname(int load, int is_sram, int slot)
                        strcat(ext, ext_othr);\r
 \r
                        romfname_ext(saveFname, sizeof(static_buff), "mds"PATH_SEP, ext);\r
-                       if (try_ropen_file(saveFname))\r
+                       if (try_ropen_file(saveFname, time))\r
                                return saveFname;\r
                }\r
        }\r
@@ -807,7 +837,7 @@ char *emu_get_save_fname(int load, int is_sram, int slot)
 \r
 int emu_check_save_file(int slot, int *time)\r
 {\r
-       return emu_get_save_fname(1, 0, slot) ? 1 : 0;\r
+       return emu_get_save_fname(1, 0, slot, time) ? 1 : 0;\r
 }\r
 \r
 int emu_save_load_game(int load, int sram)\r
@@ -816,7 +846,7 @@ int emu_save_load_game(int load, int sram)
        char *saveFname;\r
 \r
        // make save filename\r
-       saveFname = emu_get_save_fname(load, sram, state_slot);\r
+       saveFname = emu_get_save_fname(load, sram, state_slot, NULL);\r
        if (saveFname == NULL) {\r
                if (!sram)\r
                        emu_status_msg(load ? "LOAD FAILED (missing file)" : "SAVE FAILED");\r
index 93787c7..8f8f61f 100644 (file)
@@ -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);
index 8e723ff..44b5bdd 100644 (file)
@@ -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,
 };
 
index 583a77c..b5bd602 100644 (file)
@@ -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 */
index 7ceadd9..9089665 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 7ceadd9993ea84078e9d74d79215419e06496f90
+Subproject commit 9089665ca1260c338c4239583f59de981bc80c1c
index 306f2c3..bbe8813 100644 (file)
@@ -74,16 +74,21 @@ static struct in_default_bind in_evdev_defbinds[] =
        { KEY_D,        IN_BINDTYPE_PLAYER12, GBTN_C },\r
        { KEY_ENTER,    IN_BINDTYPE_PLAYER12, GBTN_START },\r
        { KEY_F,        IN_BINDTYPE_EMU, PEVB_FF },\r
-       { KEY_BACKSLASH, IN_BINDTYPE_EMU, PEVB_MENU },\r
+       { KEY_BACKSPACE,IN_BINDTYPE_EMU, PEVB_FF },\r
+       { KEY_BACKSLASH,IN_BINDTYPE_EMU, PEVB_MENU },\r
        { KEY_SPACE,    IN_BINDTYPE_EMU, PEVB_MENU },\r
-       /* Pandora */\r
+       { KEY_LEFTCTRL, IN_BINDTYPE_EMU, PEVB_MENU },\r
        { KEY_HOME,     IN_BINDTYPE_PLAYER12, GBTN_A },\r
        { KEY_PAGEDOWN, IN_BINDTYPE_PLAYER12, GBTN_B },\r
        { KEY_END,      IN_BINDTYPE_PLAYER12, GBTN_C },\r
        { KEY_LEFTALT,  IN_BINDTYPE_PLAYER12, GBTN_START },\r
-       { KEY_RIGHTSHIFT,IN_BINDTYPE_EMU, PEVB_STATE_SAVE },\r
-       { KEY_RIGHTCTRL, IN_BINDTYPE_EMU, PEVB_STATE_LOAD },\r
-       { KEY_LEFTCTRL,  IN_BINDTYPE_EMU, PEVB_MENU },\r
+       { KEY_1,        IN_BINDTYPE_EMU, PEVB_STATE_SAVE },\r
+       { KEY_2,        IN_BINDTYPE_EMU, PEVB_STATE_LOAD },\r
+       { KEY_3,        IN_BINDTYPE_EMU, PEVB_SSLOT_PREV },\r
+       { KEY_4,        IN_BINDTYPE_EMU, PEVB_SSLOT_NEXT },\r
+       { KEY_5,        IN_BINDTYPE_EMU, PEVB_PICO_PPREV },\r
+       { KEY_6,        IN_BINDTYPE_EMU, PEVB_PICO_PNEXT },\r
+       { KEY_7,        IN_BINDTYPE_EMU, PEVB_PICO_SWINP },\r
        { 0, 0, 0 }\r
 };\r
 \r