From 8118c94c8128a4aaf5cef83d87dab1e4b09bd646 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 11 Jan 2015 06:24:24 -0800 Subject: [PATCH] GBA: Move numbered savestate loading to GBAThread, clear rewind buffer when loading (fixes #174) --- src/gba/gba-cli.c | 4 ++-- src/gba/gba-serialize.c | 13 +++++++------ src/gba/gba-serialize.h | 6 +++--- src/platform/qt/GameController.cpp | 4 ++-- src/platform/sdl/sdl-events.c | 4 ++-- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/gba/gba-cli.c b/src/gba/gba-cli.c index f9f16ed1e..59e6ff53a 100644 --- a/src/gba/gba-cli.c +++ b/src/gba/gba-cli.c @@ -112,7 +112,7 @@ static void _load(struct CLIDebugger* debugger, struct CLIDebugVector* dv) { struct GBACLIDebugger* gbaDebugger = (struct GBACLIDebugger*) debugger->system; - GBALoadState(gbaDebugger->context->gba, gbaDebugger->context->stateDir, dv->intValue); + GBALoadState(gbaDebugger->context, gbaDebugger->context->stateDir, dv->intValue); } static void _rewind(struct CLIDebugger* debugger, struct CLIDebugVector* dv) { @@ -139,6 +139,6 @@ static void _save(struct CLIDebugger* debugger, struct CLIDebugVector* dv) { struct GBACLIDebugger* gbaDebugger = (struct GBACLIDebugger*) debugger->system; - GBASaveState(gbaDebugger->context->gba, gbaDebugger->context->stateDir, dv->intValue, true); + GBASaveState(gbaDebugger->context, gbaDebugger->context->stateDir, dv->intValue, true); } #endif diff --git a/src/gba/gba-serialize.c b/src/gba/gba-serialize.c index c59a9d938..19f418fa2 100644 --- a/src/gba/gba-serialize.c +++ b/src/gba/gba-serialize.c @@ -175,22 +175,23 @@ static bool _loadPNGState(struct GBA* gba, struct VFile* vf) { } #endif -bool GBASaveState(struct GBA* gba, struct VDir* dir, int slot, bool screenshot) { - struct VFile* vf = GBAGetState(gba, dir, slot, true); +bool GBASaveState(struct GBAThread* threadContext, struct VDir* dir, int slot, bool screenshot) { + struct VFile* vf = GBAGetState(threadContext->gba, dir, slot, true); if (!vf) { return false; } - bool success = GBASaveStateNamed(gba, vf, screenshot); + bool success = GBASaveStateNamed(threadContext->gba, vf, screenshot); vf->close(vf); return success; } -bool GBALoadState(struct GBA* gba, struct VDir* dir, int slot) { - struct VFile* vf = GBAGetState(gba, dir, slot, false); +bool GBALoadState(struct GBAThread* threadContext, struct VDir* dir, int slot) { + struct VFile* vf = GBAGetState(threadContext->gba, dir, slot, false); if (!vf) { return false; } - bool success = GBALoadStateNamed(gba, vf); + threadContext->rewindBufferSize = 0; + bool success = GBALoadStateNamed(threadContext->gba, vf); vf->close(vf); return success; } diff --git a/src/gba/gba-serialize.h b/src/gba/gba-serialize.h index def9c98dc..ddf905458 100644 --- a/src/gba/gba-serialize.h +++ b/src/gba/gba-serialize.h @@ -282,12 +282,13 @@ struct GBASerializedState { }; struct VDir; +struct GBAThread; void GBASerialize(struct GBA* gba, struct GBASerializedState* state); void GBADeserialize(struct GBA* gba, struct GBASerializedState* state); -bool GBASaveState(struct GBA* gba, struct VDir* dir, int slot, bool screenshot); -bool GBALoadState(struct GBA* gba, struct VDir* dir, int slot); +bool GBASaveState(struct GBAThread* thread, struct VDir* dir, int slot, bool screenshot); +bool GBALoadState(struct GBAThread* thread, struct VDir* dir, int slot); struct VFile* GBAGetState(struct GBA* gba, struct VDir* dir, int slot, bool write); bool GBASaveStateNamed(struct GBA* gba, struct VFile* vf, bool screenshot); @@ -296,7 +297,6 @@ bool GBALoadStateNamed(struct GBA* gba, struct VFile* vf); struct GBASerializedState* GBAAllocateState(void); void GBADeallocateState(struct GBASerializedState* state); -struct GBAThread; void GBARecordFrame(struct GBAThread* thread); void GBARewindSettingsChanged(struct GBAThread* thread, int newCapacity, int newInterval); void GBARewind(struct GBAThread* thread, int nStates); diff --git a/src/platform/qt/GameController.cpp b/src/platform/qt/GameController.cpp index 65e1a2d9b..13da6e093 100644 --- a/src/platform/qt/GameController.cpp +++ b/src/platform/qt/GameController.cpp @@ -361,7 +361,7 @@ void GameController::setSkipBIOS(bool set) { void GameController::loadState(int slot) { threadInterrupt(); - GBALoadState(m_threadContext.gba, m_threadContext.stateDir, slot); + GBALoadState(&m_threadContext, m_threadContext.stateDir, slot); threadContinue(); emit stateLoaded(&m_threadContext); emit frameAvailable(m_drawContext); @@ -369,7 +369,7 @@ void GameController::loadState(int slot) { void GameController::saveState(int slot) { threadInterrupt(); - GBASaveState(m_threadContext.gba, m_threadContext.stateDir, slot, true); + GBASaveState(&m_threadContext, m_threadContext.stateDir, slot, true); threadContinue(); } diff --git a/src/platform/sdl/sdl-events.c b/src/platform/sdl/sdl-events.c index 7f3eb8bff..240e34b2a 100644 --- a/src/platform/sdl/sdl-events.c +++ b/src/platform/sdl/sdl-events.c @@ -213,7 +213,7 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, struct GBASDLEvents case SDLK_F8: case SDLK_F9: GBAThreadInterrupt(context); - GBASaveState(context->gba, context->stateDir, event->keysym.sym - SDLK_F1 + 1, true); + GBASaveState(context, context->stateDir, event->keysym.sym - SDLK_F1 + 1, true); GBAThreadContinue(context); break; default: @@ -231,7 +231,7 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, struct GBASDLEvents case SDLK_F8: case SDLK_F9: GBAThreadInterrupt(context); - GBALoadState(context->gba, context->stateDir, event->keysym.sym - SDLK_F1 + 1); + GBALoadState(context, context->stateDir, event->keysym.sym - SDLK_F1 + 1); GBAThreadContinue(context); break; default: