From: notaz Date: Sun, 16 Dec 2012 19:22:32 +0000 (+0200) Subject: make non-zlib save compression possible X-Git-Tag: r18~43 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=496d88d4f697ab13e84bf8c40cdac98369bd6a04;p=pcsx_rearmed.git make non-zlib save compression possible --- diff --git a/libpcsxcore/cdrom.c b/libpcsxcore/cdrom.c index 60f03e74..6b3285c1 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 ab22ccd0..5dbf4712 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 cd8d3bf0..bed4e53b 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 e04f3143..ba38b4b6 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 bb552573..3ee794bf 100644 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -26,6 +26,7 @@ #include "mdec.h" #include "gpu.h" #include "ppf.h" +#include 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 81a40aac..fdc129ef 100644 --- a/libpcsxcore/psxbios.c +++ b/libpcsxcore/psxbios.c @@ -26,6 +26,7 @@ #include "psxbios.h" #include "psxhw.h" #include "gpu.h" +#include #undef SysPrintf #define SysPrintf if (Config.PsxOut) printf diff --git a/libpcsxcore/psxcommon.h b/libpcsxcore/psxcommon.h index 2a3877b9..59212f3f 100644 --- a/libpcsxcore/psxcommon.h +++ b/libpcsxcore/psxcommon.h @@ -42,7 +42,6 @@ extern "C" { #include #include #include -#include // 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 3e6d417e..50f17929 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 0aab8f00..4b7b6b41 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 ebdff87c..1f85278d 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 1d1822f8..e83939f2 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 81fe0ea1..ea96e95b 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 cc8d925b..eff1746a 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);