all repos — mgba @ 8be2e10c877b45fad6bb6751a42e9b3d9fcf9050

mGBA Game Boy Advance Emulator

Libretro: Include extdata in savestates
Vicki Pfau vi@endrift.com
Mon, 17 Sep 2018 13:05:00 -0700
commit

8be2e10c877b45fad6bb6751a42e9b3d9fcf9050

parent

91eb813e564f9ddd1b60dfc371b2a6c793e46e14

1 files changed, 19 insertions(+), 8 deletions(-)

jump to
M src/platform/libretro/libretro.csrc/platform/libretro/libretro.c

@@ -11,6 +11,7 @@ #include <mgba/core/blip_buf.h>

#include <mgba/core/cheats.h> #include <mgba/core/core.h> #include <mgba/core/log.h> +#include <mgba/core/serialize.h> #include <mgba/core/version.h> #ifdef M_CORE_GB #include <mgba/gb/core.h>

@@ -558,23 +559,33 @@ CircleBufferDeinit(&rumbleHistory);

} size_t retro_serialize_size(void) { - return core->stateSize(core); + struct VFile* vfm = VFileMemChunk(NULL, 0); + mCoreSaveStateNamed(core, vfm, SAVESTATE_SAVEDATA | SAVESTATE_RTC); + size_t size = vfm->size(vfm); + vfm->close(vfm); + return size; } bool retro_serialize(void* data, size_t size) { - if (size != retro_serialize_size()) { + struct VFile* vfm = VFileMemChunk(NULL, 0); + mCoreSaveStateNamed(core, vfm, SAVESTATE_SAVEDATA | SAVESTATE_RTC); + if ((ssize_t) size > vfm->size(vfm)) { + size = vfm->size(vfm); + } else if ((ssize_t) size < vfm->size(vfm)) { + vfm->close(vfm); return false; } - core->saveState(core, data); + vfm->seek(vfm, 0, SEEK_SET); + vfm->read(vfm, data, size); + vfm->close(vfm); return true; } bool retro_unserialize(const void* data, size_t size) { - if (size != retro_serialize_size()) { - return false; - } - core->loadState(core, data); - return true; + struct VFile* vfm = VFileFromConstMemory(data, size); + bool success = mCoreLoadStateNamed(core, vfm, SAVESTATE_RTC); + vfm->close(vfm); + return success; } void retro_cheat_reset(void) {