Simplify save state handling

- size and version parameters are unused in the libretro implementation,
  so remove them
This commit is contained in:
negativeExponent 2022-10-07 14:46:22 +08:00
parent 3158b73d69
commit 1c95df1212
15 changed files with 31 additions and 40 deletions

View File

@ -20,9 +20,9 @@ struct EmulatedSystem {
bool (*emuWriteBattery)(const char *); bool (*emuWriteBattery)(const char *);
#ifdef __LIBRETRO__ #ifdef __LIBRETRO__
// load state // load state
bool (*emuReadState)(const uint8_t *, unsigned); bool (*emuReadState)(const uint8_t *);
// load state // load state
unsigned (*emuWriteState)(uint8_t *, unsigned); unsigned (*emuWriteState)(uint8_t *);
#else #else
// load state // load state
bool (*emuReadState)(const char *); bool (*emuReadState)(const char *);

View File

@ -5492,7 +5492,7 @@ bool gbLoadRomData(const char* data, unsigned size)
#ifdef __LIBRETRO__ #ifdef __LIBRETRO__
#include <stddef.h> #include <stddef.h>
unsigned int gbWriteSaveState(uint8_t* data, unsigned) unsigned int gbWriteSaveState(uint8_t* data)
{ {
uint8_t* orig = data; uint8_t* orig = data;
@ -5560,7 +5560,7 @@ unsigned int gbWriteSaveState(uint8_t* data, unsigned)
return (ptrdiff_t)data - (ptrdiff_t)orig; return (ptrdiff_t)data - (ptrdiff_t)orig;
} }
bool gbReadSaveState(const uint8_t* data, unsigned) bool gbReadSaveState(const uint8_t* data)
{ {
int version = utilReadIntMem(data); int version = utilReadIntMem(data);
@ -5625,7 +5625,7 @@ bool gbReadSaveState(const uint8_t* data, unsigned)
utilReadMem(&IFF, data, 2); utilReadMem(&IFF, data, 2);
if (gbSgbMode) { if (gbSgbMode) {
gbSgbReadGame(data, version); gbSgbReadGame(data);
} else { } else {
gbSgbMask = 0; // loading a game at the wrong time causes no display 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]; gbMemoryMap[0x0d] = &gbWram[value * 0x1000];
} }
gbSoundReadGame(data, version); gbSoundReadGame(data);
if (gbCgbMode && gbSgbMode) { if (gbCgbMode && gbSgbMode) {
gbSgbMode = 0; gbSgbMode = 0;

View File

@ -896,7 +896,7 @@ void gbSgbSaveGame(uint8_t*& data)
utilWriteMem(data, gbSgbATFList, 45 * 20 * 18); utilWriteMem(data, gbSgbATFList, 45 * 20 * 18);
} }
void gbSgbReadGame(const uint8_t*& data, int version) void gbSgbReadGame(const uint8_t*& data)
{ {
utilReadDataMem(data, gbSgbSaveStructV3); utilReadDataMem(data, gbSgbSaveStructV3);

View File

@ -10,7 +10,7 @@ void gbSgbDoBitTransfer(uint8_t);
void gbSgbRenderBorder(); void gbSgbRenderBorder();
#ifdef __LIBRETRO__ #ifdef __LIBRETRO__
void gbSgbSaveGame(uint8_t*&); void gbSgbSaveGame(uint8_t*&);
void gbSgbReadGame(const uint8_t*&, int); void gbSgbReadGame(const uint8_t*&);
#else #else
void gbSgbSaveGame(gzFile); void gbSgbSaveGame(gzFile);
void gbSgbReadGame(gzFile, int version); void gbSgbReadGame(gzFile, int version);

View File

@ -449,7 +449,7 @@ void gbSoundSaveGame(gzFile out)
} }
#ifdef __LIBRETRO__ #ifdef __LIBRETRO__
void gbSoundReadGame(const uint8_t*& in, int version) void gbSoundReadGame(const uint8_t*& in)
#else #else
void gbSoundReadGame(int version, gzFile in) void gbSoundReadGame(int version, gzFile in)
#endif #endif

View File

@ -70,7 +70,7 @@ extern int soundTicks; // Number of 16.8 MHz clocks until gbSoundTick() will be
// Saves/loads emulator state // Saves/loads emulator state
#ifdef __LIBRETRO__ #ifdef __LIBRETRO__
void gbSoundSaveGame(uint8_t*&); void gbSoundSaveGame(uint8_t*&);
void gbSoundReadGame(const uint8_t*&, int); void gbSoundReadGame(const uint8_t*&);
#else #else
void gbSoundSaveGame(gzFile out); void gbSoundSaveGame(gzFile out);
void gbSoundReadGame(int version, gzFile in); void gbSoundReadGame(int version, gzFile in);

View File

@ -51,16 +51,11 @@ void eepromSaveGame(uint8_t*& data)
utilWriteMem(data, eepromData, SIZE_EEPROM_8K); utilWriteMem(data, eepromData, SIZE_EEPROM_8K);
} }
void eepromReadGame(const uint8_t*& data, int version) void eepromReadGame(const uint8_t*& data)
{ {
utilReadDataMem(data, eepromSaveData); utilReadDataMem(data, eepromSaveData);
if (version >= SAVE_GAME_VERSION_3) {
eepromSize = utilReadIntMem(data); eepromSize = utilReadIntMem(data);
utilReadMem(eepromData, data, SIZE_EEPROM_8K); utilReadMem(eepromData, data, SIZE_EEPROM_8K);
} else {
// prior to 0.7.1, only 4K EEPROM was supported
eepromSize = SIZE_EEPROM_512;
}
} }
#else // !__LIBRETRO__ #else // !__LIBRETRO__

View File

@ -5,7 +5,7 @@
#ifdef __LIBRETRO__ #ifdef __LIBRETRO__
extern void eepromSaveGame(uint8_t*& data); extern void eepromSaveGame(uint8_t*& data);
extern void eepromReadGame(const uint8_t*& data, int version); extern void eepromReadGame(const uint8_t*& data);
#else // !__LIBRETRO__ #else // !__LIBRETRO__
extern void eepromSaveGame(gzFile _gzFile); extern void eepromSaveGame(gzFile _gzFile);
extern void eepromReadGame(gzFile _gzFile, int version); extern void eepromReadGame(gzFile _gzFile, int version);

View File

@ -228,7 +228,7 @@ void flashSaveGame(uint8_t*& data)
utilWriteDataMem(data, flashSaveData3); utilWriteDataMem(data, flashSaveData3);
} }
void flashReadGame(const uint8_t*& data, int) void flashReadGame(const uint8_t*& data)
{ {
utilReadDataMem(data, flashSaveData3); utilReadDataMem(data, flashSaveData3);
} }

View File

@ -7,7 +7,7 @@
#ifdef __LIBRETRO__ #ifdef __LIBRETRO__
extern void flashSaveGame(uint8_t*& data); extern void flashSaveGame(uint8_t*& data);
extern void flashReadGame(const uint8_t*& data, int); extern void flashReadGame(const uint8_t*& data);
#else #else
extern void flashSaveGame(gzFile _gzFile); extern void flashSaveGame(gzFile _gzFile);
extern void flashReadGame(gzFile _gzFile, int version); extern void flashReadGame(gzFile _gzFile, int version);

View File

@ -578,7 +578,7 @@ void CPUUpdateRenderBuffers(bool force)
#ifdef __LIBRETRO__ #ifdef __LIBRETRO__
#include <stddef.h> #include <stddef.h>
unsigned int CPUWriteState(uint8_t* data, unsigned size) unsigned int CPUWriteState(uint8_t* data)
{ {
uint8_t* orig = data; uint8_t* orig = data;
@ -608,12 +608,7 @@ unsigned int CPUWriteState(uint8_t* data, unsigned size)
return (ptrdiff_t)data - (ptrdiff_t)orig; return (ptrdiff_t)data - (ptrdiff_t)orig;
} }
bool CPUWriteMemState(char* memory, int available, long& reserved) bool CPUReadState(const uint8_t* data)
{
return false;
}
bool CPUReadState(const uint8_t* data, unsigned size)
{ {
// Don't really care about version. // Don't really care about version.
int version = utilReadIntMem(data); int version = utilReadIntMem(data);
@ -650,9 +645,9 @@ bool CPUReadState(const uint8_t* data, unsigned size)
utilReadMem(pix, data, SIZE_PIX); utilReadMem(pix, data, SIZE_PIX);
utilReadMem(ioMem, data, SIZE_IOMEM); utilReadMem(ioMem, data, SIZE_IOMEM);
eepromReadGame(data, version); eepromReadGame(data);
flashReadGame(data, version); flashReadGame(data);
soundReadGame(data, version); soundReadGame(data);
rtcReadGame(data); rtcReadGame(data);
//// Copypasta stuff ... //// Copypasta stuff ...
@ -4260,14 +4255,15 @@ struct EmulatedSystem GBASystem = {
CPUReadState, CPUReadState,
// emuWriteState // emuWriteState
CPUWriteState, CPUWriteState,
// emuReadMemState
#ifdef __LIBRETRO__ #ifdef __LIBRETRO__
NULL, NULL, // emuReadMemState
NULL, // emuWriteMemState
#else #else
// emuReadMemState
CPUReadMemState, CPUReadMemState,
#endif
// emuWriteMemState // emuWriteMemState
CPUWriteMemState, CPUWriteMemState,
#endif
#ifdef __LIBRETRO__ #ifdef __LIBRETRO__
NULL, // emuWritePNG NULL, // emuWritePNG
NULL, // emuWriteBMP NULL, // emuWriteBMP

View File

@ -136,7 +136,7 @@ extern void CPUUpdateRenderBuffers(bool);
extern bool CPUReadMemState(char*, int); extern bool CPUReadMemState(char*, int);
extern bool CPUWriteMemState(char*, int); extern bool CPUWriteMemState(char*, int);
#ifdef __LIBRETRO__ #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); extern unsigned int CPUWriteState(uint8_t* data, unsigned int size);
#else #else
extern bool CPUReadState(const char*); extern bool CPUReadState(const char*);

View File

@ -799,7 +799,7 @@ static void soundReadGameOld(gzFile in, int version)
#include <stdio.h> #include <stdio.h>
#ifdef __LIBRETRO__ #ifdef __LIBRETRO__
void soundReadGame(const uint8_t*& in, int version) void soundReadGame(const uint8_t*& in)
#else #else
void soundReadGame(gzFile in, int version) void soundReadGame(gzFile in, int version)
#endif #endif

View File

@ -78,7 +78,7 @@ extern int soundTicks;
// Saves/loads emulator state // Saves/loads emulator state
#ifdef __LIBRETRO__ #ifdef __LIBRETRO__
void soundSaveGame(uint8_t*&); void soundSaveGame(uint8_t*&);
void soundReadGame(const uint8_t*& in, int version); void soundReadGame(const uint8_t*& in);
#else #else
void soundSaveGame(gzFile); void soundSaveGame(gzFile);
void soundReadGame(gzFile, int version); void soundReadGame(gzFile, int version);

View File

@ -1438,14 +1438,14 @@ size_t retro_serialize_size(void)
bool retro_serialize(void* data, size_t size) bool retro_serialize(void* data, size_t size)
{ {
if (size == serialize_size) if (size == serialize_size)
return core->emuWriteState((uint8_t*)data, size); return core->emuWriteState((uint8_t*)data);
return false; return false;
} }
bool retro_unserialize(const void* data, size_t size) bool retro_unserialize(const void* data, size_t size)
{ {
if (size == serialize_size) if (size == serialize_size)
return core->emuReadState((uint8_t*)data, size); return core->emuReadState((uint8_t*)data);
return false; 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_input_descriptors(); // Initialize input descriptors and info
update_variables(false); update_variables(false);
uint8_t* state_buf = (uint8_t*)malloc(2000000); uint8_t* state_buf = (uint8_t*)malloc(2000000);
serialize_size = core->emuWriteState(state_buf, 2000000); serialize_size = core->emuWriteState(state_buf);
free(state_buf); free(state_buf);
emulating = 1; emulating = 1;