From 1c95df1212bd58bd0e2c77a0c4b636608fbec16f Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Fri, 7 Oct 2022 14:46:22 +0800 Subject: [PATCH] Simplify save state handling - size and version parameters are unused in the libretro implementation, so remove them --- src/System.h | 4 ++-- src/gb/GB.cpp | 8 ++++---- src/gb/gbSGB.cpp | 2 +- src/gb/gbSGB.h | 2 +- src/gb/gbSound.cpp | 2 +- src/gb/gbSound.h | 2 +- src/gba/EEprom.cpp | 11 +++-------- src/gba/EEprom.h | 2 +- src/gba/Flash.cpp | 2 +- src/gba/Flash.h | 2 +- src/gba/GBA.cpp | 22 +++++++++------------- src/gba/GBA.h | 2 +- src/gba/Sound.cpp | 2 +- src/gba/Sound.h | 2 +- src/libretro/libretro.cpp | 6 +++--- 15 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/System.h b/src/System.h index 37f76053..e4c2d47b 100644 --- a/src/System.h +++ b/src/System.h @@ -20,9 +20,9 @@ struct EmulatedSystem { bool (*emuWriteBattery)(const char *); #ifdef __LIBRETRO__ // load state - bool (*emuReadState)(const uint8_t *, unsigned); + bool (*emuReadState)(const uint8_t *); // load state - unsigned (*emuWriteState)(uint8_t *, unsigned); + unsigned (*emuWriteState)(uint8_t *); #else // load state bool (*emuReadState)(const char *); diff --git a/src/gb/GB.cpp b/src/gb/GB.cpp index 349b9755..22290897 100644 --- a/src/gb/GB.cpp +++ b/src/gb/GB.cpp @@ -5492,7 +5492,7 @@ bool gbLoadRomData(const char* data, unsigned size) #ifdef __LIBRETRO__ #include -unsigned int gbWriteSaveState(uint8_t* data, unsigned) +unsigned int gbWriteSaveState(uint8_t* data) { uint8_t* orig = data; @@ -5560,7 +5560,7 @@ unsigned int gbWriteSaveState(uint8_t* data, unsigned) return (ptrdiff_t)data - (ptrdiff_t)orig; } -bool gbReadSaveState(const uint8_t* data, unsigned) +bool gbReadSaveState(const uint8_t* data) { int version = utilReadIntMem(data); @@ -5625,7 +5625,7 @@ bool gbReadSaveState(const uint8_t* data, unsigned) utilReadMem(&IFF, data, 2); if (gbSgbMode) { - gbSgbReadGame(data, version); + gbSgbReadGame(data); } else { gbSgbMask = 0; // loading a game at the wrong time causes no display } @@ -5767,7 +5767,7 @@ bool gbReadSaveState(const uint8_t* data, unsigned) gbMemoryMap[0x0d] = &gbWram[value * 0x1000]; } - gbSoundReadGame(data, version); + gbSoundReadGame(data); if (gbCgbMode && gbSgbMode) { gbSgbMode = 0; diff --git a/src/gb/gbSGB.cpp b/src/gb/gbSGB.cpp index fd8f0bb8..7ea60ac8 100644 --- a/src/gb/gbSGB.cpp +++ b/src/gb/gbSGB.cpp @@ -896,7 +896,7 @@ void gbSgbSaveGame(uint8_t*& data) utilWriteMem(data, gbSgbATFList, 45 * 20 * 18); } -void gbSgbReadGame(const uint8_t*& data, int version) +void gbSgbReadGame(const uint8_t*& data) { utilReadDataMem(data, gbSgbSaveStructV3); diff --git a/src/gb/gbSGB.h b/src/gb/gbSGB.h index 3224de62..069b08ea 100644 --- a/src/gb/gbSGB.h +++ b/src/gb/gbSGB.h @@ -10,7 +10,7 @@ void gbSgbDoBitTransfer(uint8_t); void gbSgbRenderBorder(); #ifdef __LIBRETRO__ void gbSgbSaveGame(uint8_t*&); -void gbSgbReadGame(const uint8_t*&, int); +void gbSgbReadGame(const uint8_t*&); #else void gbSgbSaveGame(gzFile); void gbSgbReadGame(gzFile, int version); diff --git a/src/gb/gbSound.cpp b/src/gb/gbSound.cpp index c77f7b89..d2ff1bc0 100644 --- a/src/gb/gbSound.cpp +++ b/src/gb/gbSound.cpp @@ -449,7 +449,7 @@ void gbSoundSaveGame(gzFile out) } #ifdef __LIBRETRO__ -void gbSoundReadGame(const uint8_t*& in, int version) +void gbSoundReadGame(const uint8_t*& in) #else void gbSoundReadGame(int version, gzFile in) #endif diff --git a/src/gb/gbSound.h b/src/gb/gbSound.h index 7c95bfa1..6bbca25e 100644 --- a/src/gb/gbSound.h +++ b/src/gb/gbSound.h @@ -70,7 +70,7 @@ extern int soundTicks; // Number of 16.8 MHz clocks until gbSoundTick() will be // Saves/loads emulator state #ifdef __LIBRETRO__ void gbSoundSaveGame(uint8_t*&); -void gbSoundReadGame(const uint8_t*&, int); +void gbSoundReadGame(const uint8_t*&); #else void gbSoundSaveGame(gzFile out); void gbSoundReadGame(int version, gzFile in); diff --git a/src/gba/EEprom.cpp b/src/gba/EEprom.cpp index a891cbaa..03b9b5ef 100644 --- a/src/gba/EEprom.cpp +++ b/src/gba/EEprom.cpp @@ -51,16 +51,11 @@ void eepromSaveGame(uint8_t*& data) utilWriteMem(data, eepromData, SIZE_EEPROM_8K); } -void eepromReadGame(const uint8_t*& data, int version) +void eepromReadGame(const uint8_t*& data) { utilReadDataMem(data, eepromSaveData); - if (version >= SAVE_GAME_VERSION_3) { - eepromSize = utilReadIntMem(data); - utilReadMem(eepromData, data, SIZE_EEPROM_8K); - } else { - // prior to 0.7.1, only 4K EEPROM was supported - eepromSize = SIZE_EEPROM_512; - } + eepromSize = utilReadIntMem(data); + utilReadMem(eepromData, data, SIZE_EEPROM_8K); } #else // !__LIBRETRO__ diff --git a/src/gba/EEprom.h b/src/gba/EEprom.h index 3e6f1cd2..6c5a5713 100644 --- a/src/gba/EEprom.h +++ b/src/gba/EEprom.h @@ -5,7 +5,7 @@ #ifdef __LIBRETRO__ extern void eepromSaveGame(uint8_t*& data); -extern void eepromReadGame(const uint8_t*& data, int version); +extern void eepromReadGame(const uint8_t*& data); #else // !__LIBRETRO__ extern void eepromSaveGame(gzFile _gzFile); extern void eepromReadGame(gzFile _gzFile, int version); diff --git a/src/gba/Flash.cpp b/src/gba/Flash.cpp index 9d0124e0..2da90b82 100644 --- a/src/gba/Flash.cpp +++ b/src/gba/Flash.cpp @@ -228,7 +228,7 @@ void flashSaveGame(uint8_t*& data) utilWriteDataMem(data, flashSaveData3); } -void flashReadGame(const uint8_t*& data, int) +void flashReadGame(const uint8_t*& data) { utilReadDataMem(data, flashSaveData3); } diff --git a/src/gba/Flash.h b/src/gba/Flash.h index 7f88290e..14d443be 100644 --- a/src/gba/Flash.h +++ b/src/gba/Flash.h @@ -7,7 +7,7 @@ #ifdef __LIBRETRO__ extern void flashSaveGame(uint8_t*& data); -extern void flashReadGame(const uint8_t*& data, int); +extern void flashReadGame(const uint8_t*& data); #else extern void flashSaveGame(gzFile _gzFile); extern void flashReadGame(gzFile _gzFile, int version); diff --git a/src/gba/GBA.cpp b/src/gba/GBA.cpp index 941f17a4..116b09e8 100644 --- a/src/gba/GBA.cpp +++ b/src/gba/GBA.cpp @@ -578,7 +578,7 @@ void CPUUpdateRenderBuffers(bool force) #ifdef __LIBRETRO__ #include -unsigned int CPUWriteState(uint8_t* data, unsigned size) +unsigned int CPUWriteState(uint8_t* data) { uint8_t* orig = data; @@ -608,12 +608,7 @@ unsigned int CPUWriteState(uint8_t* data, unsigned size) return (ptrdiff_t)data - (ptrdiff_t)orig; } -bool CPUWriteMemState(char* memory, int available, long& reserved) -{ - return false; -} - -bool CPUReadState(const uint8_t* data, unsigned size) +bool CPUReadState(const uint8_t* data) { // Don't really care about version. int version = utilReadIntMem(data); @@ -650,9 +645,9 @@ bool CPUReadState(const uint8_t* data, unsigned size) utilReadMem(pix, data, SIZE_PIX); utilReadMem(ioMem, data, SIZE_IOMEM); - eepromReadGame(data, version); - flashReadGame(data, version); - soundReadGame(data, version); + eepromReadGame(data); + flashReadGame(data); + soundReadGame(data); rtcReadGame(data); //// Copypasta stuff ... @@ -4260,14 +4255,15 @@ struct EmulatedSystem GBASystem = { CPUReadState, // emuWriteState CPUWriteState, -// emuReadMemState #ifdef __LIBRETRO__ - NULL, + NULL, // emuReadMemState + NULL, // emuWriteMemState #else + // emuReadMemState CPUReadMemState, -#endif // emuWriteMemState CPUWriteMemState, +#endif #ifdef __LIBRETRO__ NULL, // emuWritePNG NULL, // emuWriteBMP diff --git a/src/gba/GBA.h b/src/gba/GBA.h index bee3ba19..e1d68b5f 100644 --- a/src/gba/GBA.h +++ b/src/gba/GBA.h @@ -136,7 +136,7 @@ extern void CPUUpdateRenderBuffers(bool); extern bool CPUReadMemState(char*, int); extern bool CPUWriteMemState(char*, int); #ifdef __LIBRETRO__ -extern bool CPUReadState(const uint8_t*, unsigned); +extern bool CPUReadState(const uint8_t*); extern unsigned int CPUWriteState(uint8_t* data, unsigned int size); #else extern bool CPUReadState(const char*); diff --git a/src/gba/Sound.cpp b/src/gba/Sound.cpp index d6376ff2..152d0681 100644 --- a/src/gba/Sound.cpp +++ b/src/gba/Sound.cpp @@ -799,7 +799,7 @@ static void soundReadGameOld(gzFile in, int version) #include #ifdef __LIBRETRO__ -void soundReadGame(const uint8_t*& in, int version) +void soundReadGame(const uint8_t*& in) #else void soundReadGame(gzFile in, int version) #endif diff --git a/src/gba/Sound.h b/src/gba/Sound.h index 0ec30235..727f7ad2 100644 --- a/src/gba/Sound.h +++ b/src/gba/Sound.h @@ -78,7 +78,7 @@ extern int soundTicks; // Saves/loads emulator state #ifdef __LIBRETRO__ void soundSaveGame(uint8_t*&); -void soundReadGame(const uint8_t*& in, int version); +void soundReadGame(const uint8_t*& in); #else void soundSaveGame(gzFile); void soundReadGame(gzFile, int version); diff --git a/src/libretro/libretro.cpp b/src/libretro/libretro.cpp index d11f130a..cd06ce50 100644 --- a/src/libretro/libretro.cpp +++ b/src/libretro/libretro.cpp @@ -1438,14 +1438,14 @@ size_t retro_serialize_size(void) bool retro_serialize(void* data, size_t size) { if (size == serialize_size) - return core->emuWriteState((uint8_t*)data, size); + return core->emuWriteState((uint8_t*)data); return false; } bool retro_unserialize(const void* data, size_t size) { if (size == serialize_size) - return core->emuReadState((uint8_t*)data, size); + return core->emuReadState((uint8_t*)data); return false; } @@ -1678,7 +1678,7 @@ bool retro_load_game(const struct retro_game_info *game) update_input_descriptors(); // Initialize input descriptors and info update_variables(false); uint8_t* state_buf = (uint8_t*)malloc(2000000); - serialize_size = core->emuWriteState(state_buf, 2000000); + serialize_size = core->emuWriteState(state_buf); free(state_buf); emulating = 1;