load state ability from command line
authornotaz <notasas@gmail.com>
Fri, 25 Jul 2008 19:53:23 +0000 (19:53 +0000)
committernotaz <notasas@gmail.com>
Fri, 25 Jul 2008 19:53:23 +0000 (19:53 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@564 be3aeb3a-fb24-0410-a615-afba39da0efa

gp2x/main.c
pandora/main.c
pandora/pandora.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
index 55ece53..010bff9 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
@@ -20,6 +21,7 @@
 \r
 extern int select_exits;\r
 extern char *PicoConfigFile;\r
+static int load_state_slot = -1;\r
 int mmuhack_status = 0; // TODO rm\r
 char **g_argv;\r
 \r
@@ -37,6 +39,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
@@ -62,7 +67,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
@@ -84,6 +90,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
index 2e69798..e6c92d9 100644 (file)
@@ -9,6 +9,7 @@
 #include <sys/stat.h>\r
 #include <sys/ioctl.h>\r
 #include <sys/soundcard.h>\r
+#include <linux/fb.h>\r
 #include <fcntl.h>\r
 #include <errno.h>\r
 \r
 #include "../gp2x/usbjoy.h"\r
 #include "../common/arm_utils.h"\r
 \r
-static volatile unsigned int *memregs;\r
+static volatile unsigned int *memregs = MAP_FAILED;\r
 //static\r
 int memdev = 0;\r
-static int sounddev = -1, mixerdev = -1, touchdev = -1;\r
+static int fbdev = -1, sounddev = -1, mixerdev = -1, touchdev = -1;\r
 static int touchcal[7] = { 6203, 0, -1501397, 0, -4200, 16132680, 65536 };\r
 \r
 //#define SCREEN_MAP_SIZE (((800*(480+11)*2)+0xfff)&~0xfff)\r
 #define SCREEN_MAP_SIZE (800*480*2)\r
-static void *screen;\r
+static void *screen = MAP_FAILED;\r
 void *gp2x_screen;\r
 \r
 \r
@@ -197,8 +198,8 @@ void gp2x_sound_volume(int l, int r)
 /* common */\r
 void gp2x_init(void)\r
 {\r
-//     struct fb_fix_screeninfo fbfix;\r
-       int fbdev;\r
+       struct fb_fix_screeninfo fbfix;\r
+       int ret;\r
 \r
        printf("entering init()\n"); fflush(stdout);\r
 \r
@@ -208,13 +209,27 @@ void gp2x_init(void)
                printf("open(\"/dev/mem\") failed with %i\n", errno);\r
                exit(1);\r
        }\r
-\r
+/*\r
        memregs = mmap(0, 0x01000000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0x48000000);\r
        if (memregs == MAP_FAILED)\r
        {\r
                printf("mmap(memregs) failed with %i\n", errno);\r
                exit(1);\r
        }\r
+*/\r
+       ret = ioctl(fbdev, FBIOGET_FSCREENINFO, &fbfix);\r
+       if (ret == -1)\r
+       {\r
+               printf("ioctl(fbdev) failed with %i\n", errno);\r
+               exit(1);\r
+       }\r
+\r
+       // squidge hack\r
+       if (fbfix.line_length != 800*2)\r
+       {\r
+               gp2x_screen = malloc(800*640*2);\r
+               return;\r
+       }\r
 \r
        fbdev = open("/dev/fb0", O_RDWR);\r
        if (fbdev == -1)\r
@@ -223,14 +238,6 @@ void gp2x_init(void)
                exit(1);\r
        }\r
 \r
-/*\r
-       ret = ioctl(fbdev, FBIOGET_FSCREENINFO, &fbfix);\r
-       if (ret == -1)\r
-       {\r
-               printf("ioctl(fbdev) failed with %i\n", errno);\r
-               exit(1);\r
-       }\r
-*/\r
        screen = mmap(0, SCREEN_MAP_SIZE, PROT_WRITE|PROT_READ, MAP_SHARED, fbdev, 0);\r
        if (screen == MAP_FAILED)\r
        {\r
@@ -269,9 +276,12 @@ void gp2x_deinit(void)
 {\r
        //gp2x_video_changemode(15);\r
 \r
-       munmap(screen, SCREEN_MAP_SIZE);\r
-       munmap((void *)memregs, 0x10000);\r
+       if (screen != MAP_FAILED)\r
+               munmap(screen, SCREEN_MAP_SIZE);\r
+       if (memregs != MAP_FAILED)\r
+               munmap((void *)memregs, 0x10000);\r
        close(memdev);\r
+       if (fbdev >= 0)    close(fbdev);\r
        if (mixerdev >= 0) close(mixerdev);\r
        if (sounddev >= 0) close(sounddev);\r
        if (touchdev >= 0) close(touchdev);\r