mirror of https://github.com/mgba-emu/mgba.git
Libretro: Include extdata in savestates
This commit is contained in:
parent
91eb813e56
commit
8be2e10c87
|
@ -11,6 +11,7 @@
|
||||||
#include <mgba/core/cheats.h>
|
#include <mgba/core/cheats.h>
|
||||||
#include <mgba/core/core.h>
|
#include <mgba/core/core.h>
|
||||||
#include <mgba/core/log.h>
|
#include <mgba/core/log.h>
|
||||||
|
#include <mgba/core/serialize.h>
|
||||||
#include <mgba/core/version.h>
|
#include <mgba/core/version.h>
|
||||||
#ifdef M_CORE_GB
|
#ifdef M_CORE_GB
|
||||||
#include <mgba/gb/core.h>
|
#include <mgba/gb/core.h>
|
||||||
|
@ -558,23 +559,33 @@ void retro_unload_game(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t retro_serialize_size(void) {
|
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) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
core->saveState(core, data);
|
vfm->seek(vfm, 0, SEEK_SET);
|
||||||
|
vfm->read(vfm, data, size);
|
||||||
|
vfm->close(vfm);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool retro_unserialize(const void* data, size_t size) {
|
bool retro_unserialize(const void* data, size_t size) {
|
||||||
if (size != retro_serialize_size()) {
|
struct VFile* vfm = VFileFromConstMemory(data, size);
|
||||||
return false;
|
bool success = mCoreLoadStateNamed(core, vfm, SAVESTATE_RTC);
|
||||||
}
|
vfm->close(vfm);
|
||||||
core->loadState(core, data);
|
return success;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void retro_cheat_reset(void) {
|
void retro_cheat_reset(void) {
|
||||||
|
|
Loading…
Reference in New Issue