diff options
Diffstat (limited to 'libpcsxcore')
-rw-r--r-- | libpcsxcore/cdrom.c | 2 | ||||
-rw-r--r-- | libpcsxcore/cdrom.h | 2 | ||||
-rw-r--r-- | libpcsxcore/mdec.c | 2 | ||||
-rw-r--r-- | libpcsxcore/mdec.h | 2 | ||||
-rw-r--r-- | libpcsxcore/misc.c | 100 | ||||
-rw-r--r-- | libpcsxcore/psxbios.c | 1 | ||||
-rw-r--r-- | libpcsxcore/psxcommon.h | 14 | ||||
-rw-r--r-- | libpcsxcore/psxcounters.c | 2 | ||||
-rw-r--r-- | libpcsxcore/psxcounters.h | 2 | ||||
-rw-r--r-- | libpcsxcore/psxhw.c | 2 | ||||
-rw-r--r-- | libpcsxcore/psxhw.h | 2 | ||||
-rw-r--r-- | libpcsxcore/sio.c | 2 | ||||
-rw-r--r-- | libpcsxcore/sio.h | 2 |
13 files changed, 87 insertions, 48 deletions
diff --git a/libpcsxcore/cdrom.c b/libpcsxcore/cdrom.c index 60f03e7..6b3285c 100644 --- a/libpcsxcore/cdrom.c +++ b/libpcsxcore/cdrom.c @@ -2072,7 +2072,7 @@ void cdrReset() { cdr.AttenuatorRight[1] = 0x00; } -int cdrFreeze(gzFile f, int Mode) { +int cdrFreeze(void *f, int Mode) { u32 tmp; if( Mode == 0 ) { diff --git a/libpcsxcore/cdrom.h b/libpcsxcore/cdrom.h index ab22ccd..5dbf471 100644 --- a/libpcsxcore/cdrom.h +++ b/libpcsxcore/cdrom.h @@ -118,7 +118,7 @@ void cdrWrite0(unsigned char rt); void cdrWrite1(unsigned char rt); void cdrWrite2(unsigned char rt); void cdrWrite3(unsigned char rt); -int cdrFreeze(gzFile f, int Mode); +int cdrFreeze(void *f, int Mode); #ifdef __cplusplus } diff --git a/libpcsxcore/mdec.c b/libpcsxcore/mdec.c index cd8d3bf..bed4e53 100644 --- a/libpcsxcore/mdec.c +++ b/libpcsxcore/mdec.c @@ -671,7 +671,7 @@ void mdec1Interrupt() { } } -int mdecFreeze(gzFile f, int Mode) { +int mdecFreeze(void *f, int Mode) { u8 *base = (u8 *)&psxM[0x100000]; u32 v; diff --git a/libpcsxcore/mdec.h b/libpcsxcore/mdec.h index e04f314..ba38b4b 100644 --- a/libpcsxcore/mdec.h +++ b/libpcsxcore/mdec.h @@ -38,7 +38,7 @@ void psxDma0(u32 madr, u32 bcr, u32 chcr); void psxDma1(u32 madr, u32 bcr, u32 chcr); void mdec0Interrupt(); void mdec1Interrupt(); -int mdecFreeze(gzFile f, int Mode); +int mdecFreeze(void *f, int Mode); #ifdef __cplusplus } diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c index bb55257..3ee794b 100644 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -26,6 +26,7 @@ #include "mdec.h" #include "gpu.h" #include "ppf.h" +#include <zlib.h> char CdromId[10] = ""; char CdromLabel[33] = ""; @@ -523,6 +524,35 @@ int Load(const char *ExePath) { // STATES +static void *zlib_open(const char *name, const char *mode) +{ + return gzopen(name, mode); +} + +static int zlib_read(void *file, void *buf, u32 len) +{ + return gzread(file, buf, len); +} + +static int zlib_write(void *file, const void *buf, u32 len) +{ + return gzwrite(file, buf, len); +} + +static long zlib_seek(void *file, long offs, int whence) +{ + return gzseek(file, offs, whence); +} + +static void zlib_close(void *file) +{ + gzclose(file); +} + +struct PcsxSaveFuncs SaveFuncs = { + zlib_open, zlib_read, zlib_write, zlib_seek, zlib_close +}; + static const char PcsxHeader[32] = "STv4 PCSX v" PACKAGE_VERSION; // Savestate Versioning! @@ -530,50 +560,50 @@ static const char PcsxHeader[32] = "STv4 PCSX v" PACKAGE_VERSION; static const u32 SaveVersion = 0x8b410006; int SaveState(const char *file) { - gzFile f; + void *f; GPUFreeze_t *gpufP; SPUFreeze_t *spufP; int Size; unsigned char *pMem; - f = gzopen(file, "wb"); + f = SaveFuncs.open(file, "wb"); if (f == NULL) return -1; new_dyna_save(); - gzwrite(f, (void *)PcsxHeader, 32); - gzwrite(f, (void *)&SaveVersion, sizeof(u32)); - gzwrite(f, (void *)&Config.HLE, sizeof(boolean)); + SaveFuncs.write(f, (void *)PcsxHeader, 32); + SaveFuncs.write(f, (void *)&SaveVersion, sizeof(u32)); + SaveFuncs.write(f, (void *)&Config.HLE, sizeof(boolean)); pMem = (unsigned char *)malloc(128 * 96 * 3); if (pMem == NULL) return -1; GPU_getScreenPic(pMem); - gzwrite(f, pMem, 128 * 96 * 3); + SaveFuncs.write(f, pMem, 128 * 96 * 3); free(pMem); if (Config.HLE) psxBiosFreeze(1); - gzwrite(f, psxM, 0x00200000); - gzwrite(f, psxR, 0x00080000); - gzwrite(f, psxH, 0x00010000); - gzwrite(f, (void *)&psxRegs, sizeof(psxRegs)); + SaveFuncs.write(f, psxM, 0x00200000); + SaveFuncs.write(f, psxR, 0x00080000); + SaveFuncs.write(f, psxH, 0x00010000); + SaveFuncs.write(f, (void *)&psxRegs, sizeof(psxRegs)); // gpu gpufP = (GPUFreeze_t *)malloc(sizeof(GPUFreeze_t)); gpufP->ulFreezeVersion = 1; GPU_freeze(1, gpufP); - gzwrite(f, gpufP, sizeof(GPUFreeze_t)); + SaveFuncs.write(f, gpufP, sizeof(GPUFreeze_t)); free(gpufP); // spu spufP = (SPUFreeze_t *) malloc(16); SPU_freeze(2, spufP); - Size = spufP->Size; gzwrite(f, &Size, 4); + Size = spufP->Size; SaveFuncs.write(f, &Size, 4); free(spufP); spufP = (SPUFreeze_t *) malloc(Size); SPU_freeze(1, spufP); - gzwrite(f, spufP, Size); + SaveFuncs.write(f, spufP, Size); free(spufP); sioFreeze(f, 1); @@ -582,7 +612,7 @@ int SaveState(const char *file) { psxRcntFreeze(f, 1); mdecFreeze(f, 1); - gzclose(f); + SaveFuncs.close(f); new_dyna_after_save(); @@ -590,7 +620,7 @@ int SaveState(const char *file) { } int LoadState(const char *file) { - gzFile f; + void *f; GPUFreeze_t *gpufP; SPUFreeze_t *spufP; int Size; @@ -598,15 +628,15 @@ int LoadState(const char *file) { u32 version; boolean hle; - f = gzopen(file, "rb"); + f = SaveFuncs.open(file, "rb"); if (f == NULL) return -1; - gzread(f, header, sizeof(header)); - gzread(f, &version, sizeof(u32)); - gzread(f, &hle, sizeof(boolean)); + SaveFuncs.read(f, header, sizeof(header)); + SaveFuncs.read(f, &version, sizeof(u32)); + SaveFuncs.read(f, &hle, sizeof(boolean)); if (strncmp("STv4 PCSX", header, 9) != 0 || version != SaveVersion) { - gzclose(f); + SaveFuncs.close(f); return -1; } Config.HLE = hle; @@ -615,28 +645,28 @@ int LoadState(const char *file) { psxBiosInit(); psxCpu->Reset(); - gzseek(f, 128 * 96 * 3, SEEK_CUR); + SaveFuncs.seek(f, 128 * 96 * 3, SEEK_CUR); - gzread(f, psxM, 0x00200000); - gzread(f, psxR, 0x00080000); - gzread(f, psxH, 0x00010000); - gzread(f, (void *)&psxRegs, sizeof(psxRegs)); + SaveFuncs.read(f, psxM, 0x00200000); + SaveFuncs.read(f, psxR, 0x00080000); + SaveFuncs.read(f, psxH, 0x00010000); + SaveFuncs.read(f, (void *)&psxRegs, sizeof(psxRegs)); if (Config.HLE) psxBiosFreeze(0); // gpu gpufP = (GPUFreeze_t *)malloc(sizeof(GPUFreeze_t)); - gzread(f, gpufP, sizeof(GPUFreeze_t)); + SaveFuncs.read(f, gpufP, sizeof(GPUFreeze_t)); GPU_freeze(0, gpufP); free(gpufP); if (HW_GPU_STATUS == 0) HW_GPU_STATUS = GPU_readStatus(); // spu - gzread(f, &Size, 4); + SaveFuncs.read(f, &Size, 4); spufP = (SPUFreeze_t *)malloc(Size); - gzread(f, spufP, Size); + SaveFuncs.read(f, spufP, Size); SPU_freeze(0, spufP); free(spufP); @@ -646,26 +676,26 @@ int LoadState(const char *file) { psxRcntFreeze(f, 0); mdecFreeze(f, 0); - gzclose(f); + SaveFuncs.close(f); new_dyna_restore(); return 0; } int CheckState(const char *file) { - gzFile f; + void *f; char header[32]; u32 version; boolean hle; - f = gzopen(file, "rb"); + f = SaveFuncs.open(file, "rb"); if (f == NULL) return -1; - gzread(f, header, sizeof(header)); - gzread(f, &version, sizeof(u32)); - gzread(f, &hle, sizeof(boolean)); + SaveFuncs.read(f, header, sizeof(header)); + SaveFuncs.read(f, &version, sizeof(u32)); + SaveFuncs.read(f, &hle, sizeof(boolean)); - gzclose(f); + SaveFuncs.close(f); if (strncmp("STv4 PCSX", header, 9) != 0 || version != SaveVersion) return -1; diff --git a/libpcsxcore/psxbios.c b/libpcsxcore/psxbios.c index 81a40aa..fdc129e 100644 --- a/libpcsxcore/psxbios.c +++ b/libpcsxcore/psxbios.c @@ -26,6 +26,7 @@ #include "psxbios.h" #include "psxhw.h" #include "gpu.h" +#include <zlib.h> #undef SysPrintf #define SysPrintf if (Config.PsxOut) printf diff --git a/libpcsxcore/psxcommon.h b/libpcsxcore/psxcommon.h index 2a3877b..59212f3 100644 --- a/libpcsxcore/psxcommon.h +++ b/libpcsxcore/psxcommon.h @@ -42,7 +42,6 @@ extern "C" { #include <ctype.h> #include <sys/types.h> #include <assert.h> -#include <zlib.h> // Define types typedef int8_t s8; @@ -137,9 +136,18 @@ typedef struct { extern PcsxConfig Config; extern boolean NetOpened; +struct PcsxSaveFuncs { + void *(*open)(const char *name, const char *mode); + int (*read)(void *file, void *buf, u32 len); + int (*write)(void *file, const void *buf, u32 len); + long (*seek)(void *file, long offs, int whence); + void (*close)(void *file); +}; +extern struct PcsxSaveFuncs SaveFuncs; + #define gzfreeze(ptr, size) { \ - if (Mode == 1) gzwrite(f, ptr, size); \ - if (Mode == 0) gzread(f, ptr, size); \ + if (Mode == 1) SaveFuncs.write(f, ptr, size); \ + if (Mode == 0) SaveFuncs.read(f, ptr, size); \ } // Make the timing events trigger faster as we are currently assuming everything diff --git a/libpcsxcore/psxcounters.c b/libpcsxcore/psxcounters.c index 3e6d417..50f1792 100644 --- a/libpcsxcore/psxcounters.c +++ b/libpcsxcore/psxcounters.c @@ -501,7 +501,7 @@ void psxRcntInit() /******************************************************************************/ -s32 psxRcntFreeze( gzFile f, s32 Mode ) +s32 psxRcntFreeze( void *f, s32 Mode ) { u32 count; s32 i; diff --git a/libpcsxcore/psxcounters.h b/libpcsxcore/psxcounters.h index 0aab8f0..4b7b6b4 100644 --- a/libpcsxcore/psxcounters.h +++ b/libpcsxcore/psxcounters.h @@ -52,7 +52,7 @@ u32 psxRcntRcount(u32 index); u32 psxRcntRmode(u32 index); u32 psxRcntRtarget(u32 index); -s32 psxRcntFreeze(gzFile f, s32 Mode); +s32 psxRcntFreeze(void *f, s32 Mode); #ifdef __cplusplus } diff --git a/libpcsxcore/psxhw.c b/libpcsxcore/psxhw.c index ebdff87..1f85278 100644 --- a/libpcsxcore/psxhw.c +++ b/libpcsxcore/psxhw.c @@ -764,6 +764,6 @@ void psxHwWrite32(u32 add, u32 value) { #endif } -int psxHwFreeze(gzFile f, int Mode) { +int psxHwFreeze(void *f, int Mode) { return 0; } diff --git a/libpcsxcore/psxhw.h b/libpcsxcore/psxhw.h index 1d1822f..e83939f 100644 --- a/libpcsxcore/psxhw.h +++ b/libpcsxcore/psxhw.h @@ -80,7 +80,7 @@ u32 psxHwRead32(u32 add); void psxHwWrite8(u32 add, u8 value); void psxHwWrite16(u32 add, u16 value); void psxHwWrite32(u32 add, u32 value); -int psxHwFreeze(gzFile f, int Mode); +int psxHwFreeze(void *f, int Mode); #ifdef __cplusplus } diff --git a/libpcsxcore/sio.c b/libpcsxcore/sio.c index 81fe0ea..ea96e95 100644 --- a/libpcsxcore/sio.c +++ b/libpcsxcore/sio.c @@ -806,7 +806,7 @@ void GetMcdBlockInfo(int mcd, int block, McdBlock *Info) { strncpy(Info->Name, ptr, 16); } -int sioFreeze(gzFile f, int Mode) { +int sioFreeze(void *f, int Mode) { gzfreeze(buf, sizeof(buf)); gzfreeze(&StatReg, sizeof(StatReg)); gzfreeze(&ModeReg, sizeof(ModeReg)); diff --git a/libpcsxcore/sio.h b/libpcsxcore/sio.h index cc8d925..eff1746 100644 --- a/libpcsxcore/sio.h +++ b/libpcsxcore/sio.h @@ -50,7 +50,7 @@ unsigned short sioReadBaud16(); void netError(); void sioInterrupt(); -int sioFreeze(gzFile f, int Mode); +int sioFreeze(void *f, int Mode); void LoadMcd(int mcd, char *str); void LoadMcds(char *mcd1, char *mcd2); |