all repos — mgba @ 96f33c114a682953aa0aeebe3b77732df58151dd

mGBA Game Boy Advance Emulator

GBA: Savestate debugging code
Jeffrey Pfau jeffrey@endrift.com
Fri, 16 Oct 2015 00:05:49 -0700
commit

96f33c114a682953aa0aeebe3b77732df58151dd

parent

28e2cc57c4c648378d3418a2c9e71490846cdc24

1 files changed, 29 insertions(+), 0 deletions(-)

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

@@ -265,10 +265,39 @@ }

bool success = GBASaveStateNamed(threadContext->gba, vf, screenshot); vf->close(vf); if (success) { +#if SAVESTATE_DEBUG + vf = GBAGetState(threadContext->gba, dir, slot, false); + if (vf) { + struct GBA* backup = anonymousMemoryMap(sizeof(*backup)); + memcpy(backup, threadContext->gba, sizeof(*backup)); + memset(threadContext->gba->memory.io, 0, sizeof(threadContext->gba->memory.io)); + memset(threadContext->gba->timers, 0, sizeof(threadContext->gba->timers)); + GBALoadStateNamed(threadContext->gba, vf); + if (memcmp(backup, threadContext->gba, sizeof(*backup))) { + char suffix[16] = { '\0' }; + struct VFile* vf2; + snprintf(suffix, sizeof(suffix), ".dump.0.%d", slot); + vf2 = VDirOptionalOpenFile(dir, threadContext->gba->activeFile, "savestate", suffix, write ? (O_CREAT | O_TRUNC | O_RDWR) : O_RDONLY); + if (vf2) { + vf2->write(vf2, backup, sizeof(*backup)); + vf2->close(vf2); + } + snprintf(suffix, sizeof(suffix), ".dump.1.%d", slot); + vf2 = VDirOptionalOpenFile(dir, threadContext->gba->activeFile, "savestate", suffix, write ? (O_CREAT | O_TRUNC | O_RDWR) : O_RDONLY); + if (vf2) { + vf2->write(vf2, threadContext->gba, sizeof(*threadContext->gba)); + vf2->close(vf2); + } + } + mappedMemoryFree(backup, sizeof(*backup)); + vf->close(vf); + } +#endif GBALog(threadContext->gba, GBA_LOG_STATUS, "State %i saved", slot); } else { GBALog(threadContext->gba, GBA_LOG_STATUS, "State %i failed to save", slot); } + return success; }