all repos — mgba @ c7f7d0f752cf6a58b9dacebc8b3dd5385b58833e

mGBA Game Boy Advance Emulator

Don't make empty savestate files when loading savestates
Jeffrey Pfau jeffrey@endrift.com
Wed, 23 Jul 2014 00:19:50 -0700
commit

c7f7d0f752cf6a58b9dacebc8b3dd5385b58833e

parent

94001b113311cad1cce263f14afa2334a5ba4249

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

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

@@ -68,11 +68,11 @@ GBAVideoDeserialize(&gba->video, state);

GBAAudioDeserialize(&gba->audio, state); } -static struct VFile* _getStateVf(struct GBA* gba, int slot) { +static struct VFile* _getStateVf(struct GBA* gba, int slot, bool write) { char path[PATH_MAX]; path[PATH_MAX - 1] = '\0'; snprintf(path, PATH_MAX - 1, "%s.ss%d", gba->activeFile, slot); - struct VFile* vf = VFileOpen(path, O_CREAT | O_RDWR); + struct VFile* vf = VFileOpen(path, write ? (O_CREAT | O_RDWR) : O_RDONLY); if (vf) { vf->truncate(vf, sizeof(struct GBASerializedState)); }

@@ -80,35 +80,27 @@ return vf;

} bool GBASaveState(struct GBA* gba, int slot) { - struct VFile* vf = _getStateVf(gba, slot); + struct VFile* vf = _getStateVf(gba, slot, true); if (!vf) { return false; } - struct GBASerializedState* state = GBAMapState(vf); + struct GBASerializedState* state = vf->map(vf, sizeof(struct GBASerializedState), MAP_WRITE); GBASerialize(gba, state); - GBAUnmapState(vf, state); + vf->unmap(vf, state, sizeof(struct GBASerializedState)); vf->close(vf); return true; } bool GBALoadState(struct GBA* gba, int slot) { - struct VFile* vf = _getStateVf(gba, slot); + struct VFile* vf = _getStateVf(gba, slot, false); if (!vf) { return false; } - struct GBASerializedState* state = GBAMapState(vf); + struct GBASerializedState* state = vf->map(vf, sizeof(struct GBASerializedState), MAP_READ); GBADeserialize(gba, state); - GBAUnmapState(vf, state); + vf->unmap(vf, state, sizeof(struct GBASerializedState)); vf->close(vf); return true; -} - -struct GBASerializedState* GBAMapState(struct VFile* vf) { - return vf->map(vf, sizeof(struct GBASerializedState), MAP_WRITE); -} - -void GBAUnmapState(struct VFile* vf, struct GBASerializedState* state) { - vf->unmap(vf, state, sizeof(struct GBASerializedState)); } struct GBASerializedState* GBAAllocateState(void) {
M src/gba/gba-serialize.hsrc/gba/gba-serialize.h

@@ -266,9 +266,6 @@

bool GBASaveState(struct GBA* gba, int slot); bool GBALoadState(struct GBA* gba, int slot); -struct GBASerializedState* GBAMapState(struct VFile* vf); -void GBAUnmapState(struct VFile* vf, struct GBASerializedState* state); - struct GBASerializedState* GBAAllocateState(void); void GBADeallocateState(struct GBASerializedState* state);