load state ability from command line
[libpicofe.git] / gp2x / main.c
index ed2191c..50210f6 100644 (file)
@@ -4,6 +4,7 @@
 // For commercial use, separate licencing terms must be obtained.\r
 \r
 #include <stdio.h>\r
+#include <stdlib.h>\r
 #include <string.h>\r
 #include <unistd.h>\r
 #include <strings.h>\r
@@ -25,6 +26,7 @@
 extern char *ext_menu, *ext_state;\r
 extern int select_exits;\r
 extern char *PicoConfigFile;\r
+static int load_state_slot = -1;\r
 int mmuhack_status = 0;\r
 char **g_argv;\r
 \r
@@ -48,6 +50,9 @@ void parse_cmd_line(int argc, char *argv[])
                        else if(strcasecmp(argv[x], "-selectexit") == 0) {\r
                                select_exits = 1;\r
                        }\r
+                       else if(strcasecmp(argv[x], "-loadstate") == 0) {\r
+                               if(x+1 < argc) { ++x; load_state_slot = atoi(argv[x]); }\r
+                       }\r
                        else {\r
                                unrecognized = 1;\r
                                break;\r
@@ -73,7 +78,8 @@ void parse_cmd_line(int argc, char *argv[])
                                "-state <param>    pass '-state param' to the menu program\n"\r
                                "-config <file>    use specified config file instead of default 'picoconfig.bin'\n"\r
                                "                  see currentConfig_t structure in emu.h for the file format\n"\r
-                               "-selectexit       pressing SELECT will exit the emu and start 'menu_path'\n");\r
+                               "-selectexit       pressing SELECT will exit the emu and start 'menu_path'\n"\r
+                               "-loadstate <num>  if ROM is specified, try loading slot <num>\n");\r
        }\r
 }\r
 \r
@@ -110,6 +116,17 @@ int main(int argc, char *argv[])
        if (argc > 1)\r
                parse_cmd_line(argc, argv);\r
 \r
+       if (engineState == PGS_ReloadRom)\r
+       {\r
+               if (emu_ReloadRom()) {\r
+                       engineState = PGS_Running;\r
+                       if (load_state_slot >= 0) {\r
+                               state_slot = load_state_slot;\r
+                               emu_SaveLoadGame(1, 0);\r
+                       }\r
+               }\r
+       }\r
+\r
        for (;;)\r
        {\r
                switch (engineState)\r