From ae41898206c5951c591f51791352f9a60257287f Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 12 Apr 2015 20:19:02 -0700 Subject: [PATCH] GBA: Fix rewind boundary conditions --- CHANGES | 1 + src/gba/serialize.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index f32c3a6bc..acf12ed08 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,7 @@ Bugfixes: - GBA Memory: Ensure changing the timing of a DMA reschedules it - Qt: Fix window not regaining focus after exiting savestate window - Qt: Fix regression where video would not record if the game had already started + - GBA: Fix rewind boundary conditions Misc: - Qt: Show multiplayer numbers in window title diff --git a/src/gba/serialize.c b/src/gba/serialize.c index 2395ee635..6fb920c30 100644 --- a/src/gba/serialize.c +++ b/src/gba/serialize.c @@ -291,14 +291,14 @@ void GBARewind(struct GBAThread* thread, int nStates) { } int offset = thread->rewindBufferWriteOffset - nStates; if (offset < 0) { - offset += thread->rewindBufferSize; + offset += thread->rewindBufferCapacity; } struct GBASerializedState* state = thread->rewindBuffer[offset]; if (!state) { return; } - thread->rewindBufferSize -= nStates - 1; - thread->rewindBufferWriteOffset = (offset + 1) % thread->rewindBufferCapacity; + thread->rewindBufferSize -= nStates; + thread->rewindBufferWriteOffset = offset; GBADeserialize(thread->gba, state); }