all repos — mgba @ 0501944b5abccaceb9046091bf21f39ec7696d22

mGBA Game Boy Advance Emulator

GBA: Savestates can store currently used cheats
Jeffrey Pfau jeffrey@endrift.com
Sun, 24 Jan 2016 17:59:45 -0800
commit

0501944b5abccaceb9046091bf21f39ec7696d22

parent

26e9e8d63ffab9b6d2cc3c83d8ed1c758eba6496

2 files changed, 34 insertions(+), 0 deletions(-)

jump to
M src/gba/serialize.csrc/gba/serialize.c

@@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "serialize.h" #include "gba/audio.h" +#include "gba/cheats.h" #include "gba/io.h" #include "gba/rr/rr.h" #include "gba/supervisor/thread.h"

@@ -426,6 +427,20 @@ free(sram);

} svf->close(svf); } + struct VFile* cheatVf = 0; + if (flags & SAVESTATE_CHEATS && gba->cpu->components && gba->cpu->components[GBA_COMPONENT_CHEAT_DEVICE]) { + struct GBACheatDevice* device = (struct GBACheatDevice*) gba->cpu->components[GBA_COMPONENT_CHEAT_DEVICE]; + cheatVf = VFileMemChunk(0, 0); + if (cheatVf) { + GBACheatSaveFile(device, cheatVf); + struct GBAExtdataItem item = { + .size = cheatVf->size(cheatVf), + .data = cheatVf->map(cheatVf, cheatVf->size(cheatVf), MAP_READ), + .clean = 0 + }; + GBAExtdataPut(&extdata, EXTDATA_CHEATS, &item); + } + }; #ifdef USE_PNG if (!(flags & SAVESTATE_SCREENSHOT)) { #else

@@ -435,6 +450,9 @@ vf->truncate(vf, sizeof(struct GBASerializedState));

struct GBASerializedState* state = vf->map(vf, sizeof(struct GBASerializedState), MAP_WRITE); if (!state) { GBAExtdataDeinit(&extdata); + if (cheatVf) { + cheatVf->close(cheatVf); + } return false; } GBASerialize(gba, state);

@@ -442,6 +460,9 @@ vf->unmap(vf, state, sizeof(struct GBASerializedState));

vf->seek(vf, sizeof(struct GBASerializedState), SEEK_SET); GBAExtdataSerialize(&extdata, vf); GBAExtdataDeinit(&extdata); + if (cheatVf) { + cheatVf->close(cheatVf); + } return true; #ifdef USE_PNG }

@@ -500,6 +521,17 @@ struct VFile* svf = VFileFromMemory(item.data, item.size);

if (svf) { GBASavedataLoad(&gba->memory.savedata, svf); svf->close(svf); + } + } + if (flags & SAVESTATE_CHEATS && gba->cpu->components && gba->cpu->components[GBA_COMPONENT_CHEAT_DEVICE] && GBAExtdataGet(&extdata, EXTDATA_CHEATS, &item)) { + if (item.size) { + struct GBACheatDevice* device = (struct GBACheatDevice*) gba->cpu->components[GBA_COMPONENT_CHEAT_DEVICE]; + struct VFile* svf = VFileFromMemory(item.data, item.size); + if (svf) { + GBACheatDeviceClear(device); + GBACheatParseFile(device, svf); + svf->close(svf); + } } } GBAExtdataDeinit(&extdata);
M src/gba/serialize.hsrc/gba/serialize.h

@@ -339,11 +339,13 @@ enum GBAExtdataTag {

EXTDATA_NONE = 0, EXTDATA_SCREENSHOT = 1, EXTDATA_SAVEDATA = 2, + EXTDATA_CHEATS = 3, EXTDATA_MAX }; #define SAVESTATE_SCREENSHOT 1 #define SAVESTATE_SAVEDATA 2 +#define SAVESTATE_CHEATS 4 struct GBAExtdataItem { int32_t size;