patch/gg support, 1.201 release
[picodrive.git] / platform / gp2x / emu.c
index cdb69b7..c8c4f8a 100644 (file)
@@ -21,8 +21,9 @@
 #include "asmutils.h"\r
 #include "cpuctrl.h"\r
 \r
-#include "Pico/PicoInt.h"\r
-#include "zlib/zlib.h"\r
+#include <Pico/PicoInt.h>\r
+#include <Pico/Patch.h>\r
+#include <zlib/zlib.h>\r
 \r
 \r
 #ifdef BENCHMARK\r
@@ -229,6 +230,8 @@ int emu_ReloadRom(void)
                return 0;\r
        }\r
 \r
+       PicoPatchUnload();\r
+\r
        // check for movie file\r
        if(movie_data) {\r
                free(movie_data);\r
@@ -269,6 +272,16 @@ int emu_ReloadRom(void)
                }\r
                get_ext(romFileName, ext);\r
        }\r
+       else if (!strcmp(ext, ".pat")) {\r
+               int dummy;\r
+               PicoPatchLoad(romFileName);\r
+               dummy = try_rfn_cut() || try_rfn_cut();\r
+               if (!dummy) {\r
+                       sprintf(menuErrorMsg, "Could't find a ROM to patch.");\r
+                       return 0;\r
+               }\r
+               get_ext(romFileName, ext);\r
+       }\r
 \r
        // check for MegaCD image\r
        cd_state = cd_check(ext, &used_rom_name);\r
@@ -351,6 +364,11 @@ int emu_ReloadRom(void)
        strncpy(currentConfig.lastRomFile, romFileName, sizeof(currentConfig.lastRomFile)-1);\r
        currentConfig.lastRomFile[sizeof(currentConfig.lastRomFile)-1] = 0;\r
 \r
+       if (PicoPatches) {\r
+               PicoPatchPrepare();\r
+               PicoPatchApply();\r
+       }\r
+\r
        // additional movie stuff\r
        if(movie_data) {\r
                if(movie_data[0x14] == '6')\r
@@ -424,8 +442,6 @@ static void romfname_ext(char *dst, const char *prefix, const char *ext)
        dst[511-8] = 0;\r
        if (dst[strlen(dst)-4] == '.') dst[strlen(dst)-4] = 0;\r
        if (ext) strcat(dst, ext);\r
-\r
-       printf("romfname_ext: %s\n", dst);\r
 }\r
 \r
 \r
@@ -973,9 +989,9 @@ void emu_forced_frame(void)
        PicoOpt = po_old;\r
 \r
        if (!(Pico.video.reg[12]&1)) {\r
-               vidCpyM2 = vidCpyM2_40col;\r
+               vidCpyM2 = vidCpyM2_32col;\r
                clearArea(1);\r
-       } else  vidCpyM2 = vidCpyM2_32col;\r
+       } else  vidCpyM2 = vidCpyM2_40col;\r
 \r
        vidCpyM2((unsigned char *)gp2x_screen+320*8, framebuff+328*8);\r
        vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
@@ -1369,8 +1385,10 @@ int emu_SaveLoadGame(int load, int sram)
        // make save filename\r
        saveFname = emu_GetSaveFName(load, sram, state_slot);\r
        if (saveFname == NULL) {\r
-               strcpy(noticeMsg, load ? "LOAD FAILED (missing file)" : "SAVE FAILED  ");\r
-               gettimeofday(&noticeMsgTime, 0);\r
+               if (!sram) {\r
+                       strcpy(noticeMsg, load ? "LOAD FAILED (missing file)" : "SAVE FAILED  ");\r
+                       gettimeofday(&noticeMsgTime, 0);\r
+               }\r
                return -1;\r
        }\r
 \r