diff --git a/src/common/StateManager.cxx b/src/common/StateManager.cxx index 5533017b6..3e669678b 100644 --- a/src/common/StateManager.cxx +++ b/src/common/StateManager.cxx @@ -134,6 +134,22 @@ void StateManager::toggleRewindMode() myOSystem.frameBuffer().showMessage("Continuous rewind disabled"); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool StateManager::rewindState() +{ + RewindManager& r = myOSystem.state().rewindManager(); + // TODO: add parameter to indicate rewinding from within emulation + return r.rewindState(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool StateManager::unwindState() +{ + RewindManager& r = myOSystem.state().rewindManager(); + // TODO: add parameter to indicate unwinding from within emulation + return r.unwindState(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void StateManager::update() { diff --git a/src/common/StateManager.hxx b/src/common/StateManager.hxx index a5c9c2b8a..a88a16d60 100644 --- a/src/common/StateManager.hxx +++ b/src/common/StateManager.hxx @@ -64,6 +64,16 @@ class StateManager */ void toggleRewindMode(); + /** + Rewinds one state; this uses the RewindManager for its functionality. + */ + bool rewindState(); + + /** + Unwinds one state; this uses the RewindManager for its functionality. + */ + bool unwindState(); + /** Updates the state of the system based on the currently active mode. */ diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index d4274cf64..3913e19c6 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -273,9 +273,30 @@ void EventHandler::handleKeyEvent(StellaKey key, StellaMod mod, bool state) { myOSystem.frameBuffer().toggleFullscreen(); } - // These only work when in emulation mode - else if(myState == S_EMULATE) + // state rewinding must work in pause mode too + else if(myState == S_EMULATE || myState == S_PAUSE) { + switch(key) + { + case KBDK_LEFT: // Alt-left rewinds states + if(myOSystem.state().rewindState() && myState != S_PAUSE) + setEventState(S_PAUSE); + break; + + case KBDK_RIGHT: // Alt-right unwinds states + if(myOSystem.state().unwindState() && myState != S_PAUSE) + setEventState(S_PAUSE); + break; + + default: + handled = false; + break; + } + } + // These only work when in emulation mode + if(!handled && myState == S_EMULATE) + { + handled = true; switch(key) { case KBDK_EQUALS: @@ -566,10 +587,19 @@ void EventHandler::handleKeyEvent(StellaKey key, StellaMod mod, bool state) case S_EMULATE: handleEvent(myKeyTable[key][kEmulationMode], state); break; + case S_PAUSE: - if(myKeyTable[key][kEmulationMode] == Event::TakeSnapshot) - handleEvent(myKeyTable[key][kEmulationMode], state); + switch(myKeyTable[key][kEmulationMode]) + { + case Event::TakeSnapshot: + case Event::DebuggerMode: + handleEvent(myKeyTable[key][kEmulationMode], state); + + default: + break; + } break; + default: if(myOverlay) myOverlay->handleKeyEvent(key, mod, state); @@ -1174,7 +1204,7 @@ bool EventHandler::eventStateChange(Event::Type type) break; case Event::DebuggerMode: - if(myState == S_EMULATE) + if(myState == S_EMULATE || myState == S_PAUSE) enterDebugMode(); else if(myState == S_DEBUGGER) leaveDebugMode(); diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx index eeca3ab9d..470ca7d0a 100644 --- a/src/emucore/FrameBuffer.cxx +++ b/src/emucore/FrameBuffer.cxx @@ -285,6 +285,7 @@ void FrameBuffer::update() myStatsMsg.surface->setDstPos(myImageRect.x() + 1, myImageRect.y() + 1); myStatsMsg.surface->render(); } + myPausedCount = 0; break; // S_EMULATE } @@ -292,10 +293,10 @@ void FrameBuffer::update() { myTIASurface->render(); - // Show a pause message every 5 seconds - if(myPausedCount++ >= 7*myOSystem.frameRate()) + // Show a pause message immediately and then every 7 seconds + if (myPausedCount-- <= 0) { - myPausedCount = 0; + myPausedCount = uInt32(7 * myOSystem.frameRate()); showMessage("Paused", kMiddleCenter); } break; // S_PAUSE diff --git a/src/emucore/FrameBuffer.hxx b/src/emucore/FrameBuffer.hxx index 76f484cd8..d13642012 100644 --- a/src/emucore/FrameBuffer.hxx +++ b/src/emucore/FrameBuffer.hxx @@ -475,7 +475,7 @@ class FrameBuffer uInt32 myInitializedCount; // Used to set intervals between messages while in pause mode - uInt32 myPausedCount; + Int32 myPausedCount; // Dimensions of the actual image, after zooming, and taking into account // any image 'centering'