sram bugfix + savestate refactoring
authornotaz <notasas@gmail.com>
Mon, 10 Aug 2009 14:22:50 +0000 (14:22 +0000)
committernotaz <notasas@gmail.com>
Mon, 10 Aug 2009 14:22:50 +0000 (14:22 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@744 be3aeb3a-fb24-0410-a615-afba39da0efa

common/emu.c
common/emu.h
common/menu.c

index 2e813d3..08dbe0b 100644 (file)
@@ -1,4 +1,4 @@
-// (c) Copyright 2006-2007 notaz, All rights reserved.\r
+// (c) Copyright 2006-2009 notaz, All rights reserved.\r
 // Free for non-commercial use.\r
 \r
 // For commercial use, separate licencing terms must be obtained.\r
@@ -22,7 +22,6 @@
 #include <pico/pico_int.h>\r
 #include <pico/patch.h>\r
 #include <pico/cd/cue.h>\r
-#include <zlib/zlib.h>\r
 \r
 \r
 #define STATUS_MSG_TIMEOUT 2000\r
@@ -516,13 +515,14 @@ int emu_reload_rom(char *rom_fname)
                emu_status_msg(Pico.m.pal ? "PAL SYSTEM / 50 FPS" : "NTSC SYSTEM / 60 FPS");\r
        }\r
 \r
+       strncpy(rom_fname_loaded, rom_fname, sizeof(rom_fname_loaded)-1);\r
+       rom_fname_loaded[sizeof(rom_fname_loaded)-1] = 0;\r
+       rom_loaded = 1;\r
+\r
        // load SRAM for this ROM\r
        if (currentConfig.EmuOpt & EOPT_EN_SRAM)\r
                emu_save_load_game(1, 1);\r
 \r
-       strncpy(rom_fname_loaded, rom_fname, sizeof(rom_fname_loaded)-1);\r
-       rom_fname_loaded[sizeof(rom_fname_loaded)-1] = 0;\r
-       rom_loaded = 1;\r
        return 1;\r
 \r
 fail2:\r
@@ -766,18 +766,6 @@ void update_movie(void)
        }\r
 }\r
 \r
-\r
-static size_t gzRead2(void *p, size_t _size, size_t _n, void *file)\r
-{\r
-       return gzread(file, p, _n);\r
-}\r
-\r
-\r
-static size_t gzWrite2(void *p, size_t _size, size_t _n, void *file)\r
-{\r
-       return gzwrite(file, p, _n);\r
-}\r
-\r
 static int try_ropen_file(const char *fname)\r
 {\r
        FILE *f;\r
@@ -842,23 +830,6 @@ int emu_check_save_file(int slot)
        return emu_get_save_fname(1, 0, slot) ? 1 : 0;\r
 }\r
 \r
-void emu_setSaveStateCbs(int gz)\r
-{\r
-       if (gz) {\r
-               areaRead  = gzRead2;\r
-               areaWrite = gzWrite2;\r
-               areaEof   = (areaeof *) gzeof;\r
-               areaSeek  = (areaseek *) gzseek;\r
-               areaClose = (areaclose *) gzclose;\r
-       } else {\r
-               areaRead  = (arearw *) fread;\r
-               areaWrite = (arearw *) fwrite;\r
-               areaEof   = (areaeof *) feof;\r
-               areaSeek  = (areaseek *) fseek;\r
-               areaClose = (areaclose *) fclose;\r
-       }\r
-}\r
-\r
 int emu_save_load_game(int load, int sram)\r
 {\r
        int ret = 0;\r
@@ -929,34 +900,13 @@ int emu_save_load_game(int load, int sram)
        }\r
        else\r
        {\r
-               void *PmovFile = NULL;\r
-               if (strcmp(saveFname + strlen(saveFname) - 3, ".gz") == 0)\r
-               {\r
-                       if( (PmovFile = gzopen(saveFname, load ? "rb" : "wb")) ) {\r
-                               emu_setSaveStateCbs(1);\r
-                               if (!load) gzsetparams(PmovFile, 9, Z_DEFAULT_STRATEGY);\r
-                       }\r
-               }\r
-               else\r
-               {\r
-                       if( (PmovFile = fopen(saveFname, load ? "rb" : "wb")) ) {\r
-                               emu_setSaveStateCbs(0);\r
-                       }\r
-               }\r
-               if(PmovFile) {\r
-                       ret = PmovState(load ? 6 : 5, PmovFile);\r
-                       areaClose(PmovFile);\r
-                       PmovFile = 0;\r
-                       if (load) Pico.m.dirtyPal=1;\r
+               ret = PicoState(saveFname, !load);\r
+               if (!ret) {\r
 #ifndef NO_SYNC\r
-                       else sync();\r
+                       if (!load) sync();\r
 #endif\r
-               }\r
-               else    ret = -1;\r
-               if (!ret)\r
                        emu_status_msg(load ? "STATE LOADED" : "STATE SAVED");\r
-               else\r
-               {\r
+               } else {\r
                        emu_status_msg(load ? "LOAD FAILED" : "SAVE FAILED");\r
                        ret = -1;\r
                }\r
index f08d12a..59fa7a1 100644 (file)
@@ -113,7 +113,6 @@ int   emu_write_config(int game);
 
 char *emu_get_save_fname(int load, int is_sram, int slot);
 int   emu_check_save_file(int slot);
-void  emu_setSaveStateCbs(int gz);
 
 void  emu_text_out8 (int x, int y, const char *text);
 void  emu_text_out16(int x, int y, const char *text);
index 18c4a3f..a81e1bc 100644 (file)
@@ -20,7 +20,6 @@
 \r
 #include <pico/pico_int.h>\r
 #include <pico/patch.h>\r
-#include <zlib/zlib.h>\r
 \r
 #define array_size(x) (sizeof(x) / sizeof(x[0]))\r
 \r
@@ -971,7 +970,7 @@ static void draw_savestate_bg(int slot)
        struct PicoVideo tmp_pv;\r
        unsigned short tmp_cram[0x40];\r
        unsigned short tmp_vsram[0x40];\r
-       void *tmp_vram, *file;\r
+       void *tmp_vram;\r
        char *fname;\r
 \r
        fname = emu_get_save_fname(1, 0, slot);\r
@@ -985,28 +984,7 @@ static void draw_savestate_bg(int slot)
        memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram));\r
        memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video));\r
 \r
-       if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) {\r
-               file = gzopen(fname, "rb");\r
-               emu_setSaveStateCbs(1);\r
-       } else {\r
-               file = fopen(fname, "rb");\r
-               emu_setSaveStateCbs(0);\r
-       }\r
-\r
-       if (file) {\r
-               if (PicoAHW & PAHW_MCD) {\r
-                       PicoCdLoadStateGfx(file);\r
-               } else {\r
-                       areaSeek(file, 0x10020, SEEK_SET);  // skip header and RAM in state file\r
-                       areaRead(Pico.vram, 1, sizeof(Pico.vram), file);\r
-                       areaSeek(file, 0x2000, SEEK_CUR);\r
-                       areaRead(Pico.cram, 1, sizeof(Pico.cram), file);\r
-                       areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file);\r
-                       areaSeek(file, 0x221a0, SEEK_SET);\r
-                       areaRead(&Pico.video, 1, sizeof(Pico.video), file);\r
-               }\r
-               areaClose(file);\r
-       }\r
+       PicoStateLoadVDP(fname);\r
 \r
        /* do a frame and fetch menu bg */\r
        pemu_forced_frame(POPT_EN_SOFTSCALE);\r