diff --git a/src/common/RewindManager.cxx b/src/common/RewindManager.cxx index 1a0194449..216e03943 100644 --- a/src/common/RewindManager.cxx +++ b/src/common/RewindManager.cxx @@ -138,7 +138,7 @@ bool RewindManager::addState(const string& message, bool timeMachine) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt32 RewindManager::rewindState(uInt32 numStates) +uInt32 RewindManager::rewindStates(uInt32 numStates) { uInt64 startCycles = myOSystem.console().tia().cycles(); uInt32 i; @@ -177,7 +177,7 @@ uInt32 RewindManager::rewindState(uInt32 numStates) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt32 RewindManager::unwindState(uInt32 numStates) +uInt32 RewindManager::unwindStates(uInt32 numStates) { uInt64 startCycles = myOSystem.console().tia().cycles(); uInt32 i; @@ -210,6 +210,16 @@ uInt32 RewindManager::unwindState(uInt32 numStates) return i; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt32 RewindManager::windStates(uInt32 numStates, bool unwind) +{ + if(unwind) + return unwindStates(numStates); + else + return rewindStates(numStates); +} + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void RewindManager::compressStates() { diff --git a/src/common/RewindManager.hxx b/src/common/RewindManager.hxx index 3c37aaf19..debe0cee8 100644 --- a/src/common/RewindManager.hxx +++ b/src/common/RewindManager.hxx @@ -106,22 +106,32 @@ class RewindManager bool addState(const string& message, bool timeMachine = false); /** - Rewind one level of the state list, and display the message associated + Rewind numStates levels of the state list, and display the message associated with that state. @param numStates Number of states to rewind @return Number of states to rewinded */ - uInt32 rewindState(uInt32 numStates = 1); + uInt32 rewindStates(uInt32 numStates = 1); /** - Unwind one level of the state list, and display the message associated + Unwind numStates levels of the state list, and display the message associated with that state. @param numStates Number of states to unwind @return Number of states to unwinded */ - uInt32 unwindState(uInt32 numStates = 1); + uInt32 unwindStates(uInt32 numStates = 1); + + /** + Rewind/unwind numStates levels of the state list, and display the message associated + with that state. + + @param numStates Number of states to wind + @param unwind unwind or rewind + @return Number of states to winded + */ + uInt32 windStates(uInt32 numStates, bool unwind); bool atFirst() const { return myStateList.atFirst(); } bool atLast() const { return myStateList.atLast(); } diff --git a/src/common/StateManager.cxx b/src/common/StateManager.cxx index 706f8f019..1b6b2ea7a 100644 --- a/src/common/StateManager.cxx +++ b/src/common/StateManager.cxx @@ -142,17 +142,31 @@ void StateManager::toggleTimeMachine() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool StateManager::rewindState(uInt32 numStates) +bool StateManager::addState(const string& message, bool timeMachine) { RewindManager& r = myOSystem.state().rewindManager(); - return r.rewindState(numStates); + return r.addState(message, timeMachine); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool StateManager::unwindState(uInt32 numStates) +bool StateManager::rewindStates(uInt32 numStates) { RewindManager& r = myOSystem.state().rewindManager(); - return r.unwindState(numStates); + return r.rewindStates(numStates); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool StateManager::unwindStates(uInt32 numStates) +{ + RewindManager& r = myOSystem.state().rewindManager(); + return r.unwindStates(numStates); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool StateManager::windStates(uInt32 numStates, bool unwind) +{ + RewindManager& r = myOSystem.state().rewindManager(); + return r.windStates(numStates, unwind); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/StateManager.hxx b/src/common/StateManager.hxx index 0e322f8dd..8206b61b3 100644 --- a/src/common/StateManager.hxx +++ b/src/common/StateManager.hxx @@ -72,14 +72,24 @@ class StateManager void setRewindMode(Mode mode) { myActiveMode = mode; } /** - Rewinds one state; this uses the RewindManager for its functionality. + Adds one state ; this uses the RewindManager for its functionality. */ - bool rewindState(uInt32 numStates = 1); + bool addState(const string& message, bool timeMachine = false); /** - Unwinds one state; this uses the RewindManager for its functionality. + Rewinds states; this uses the RewindManager for its functionality. */ - bool unwindState(uInt32 numStates = 1); + bool rewindStates(uInt32 numStates = 1); + + /** + Unwinds states; this uses the RewindManager for its functionality. + */ + bool unwindStates(uInt32 numStates = 1); + + /** + Rewinds/unwinds states; this uses the RewindManager for its functionality. + */ + bool windStates(uInt32 numStates, bool unwind); /** Updates the state of the system based on the currently active mode. diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index 95da6a018..ceb88aade 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -538,7 +538,7 @@ uInt16 Debugger::windStates(uInt16 numStates, bool unwind, string& message) unlockBankswitchState(); uInt64 startCycles = myOSystem.console().tia().cycles(); - uInt16 winds = unwind ? r.unwindState(numStates) : r.rewindState(numStates); + uInt16 winds = r.windStates(numStates, unwind); message = r.getUnitString(myOSystem.console().tia().cycles() - startCycles); lockBankswitchState(); diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 8b0038e1f..c3a018033 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -300,27 +300,19 @@ void EventHandler::handleKeyEvent(StellaKey key, StellaMod mod, bool state) switch(key) { case KBDK_LEFT: // Alt-left(-shift) rewinds 1(10) states - myOSystem.frameBuffer().setPauseDelay(); - setEventState(EventHandlerState::PAUSE); - myOSystem.state().rewindState((StellaModTest::isShift(mod) && state) ? 10 : 1); + enterTimeMachineMenuMode((StellaModTest::isShift(mod) && state) ? 10 : 1, false); break; case KBDK_RIGHT: // Alt-right(-shift) unwinds 1(10) states - myOSystem.frameBuffer().setPauseDelay(); - setEventState(EventHandlerState::PAUSE); - myOSystem.state().unwindState((StellaModTest::isShift(mod) && state) ? 10 : 1); + enterTimeMachineMenuMode((StellaModTest::isShift(mod) && state) ? 10 : 1, true); break; case KBDK_DOWN: // Alt-down rewinds to start of list - myOSystem.frameBuffer().setPauseDelay(); - setEventState(EventHandlerState::PAUSE); - myOSystem.state().rewindState(1000); + enterTimeMachineMenuMode(1000, false); break; case KBDK_UP: // Alt-up rewinds to end of list - myOSystem.frameBuffer().setPauseDelay(); - setEventState(EventHandlerState::PAUSE); - myOSystem.state().unwindState(1000); + enterTimeMachineMenuMode(1000, true); break; default: @@ -1223,14 +1215,14 @@ bool EventHandler::eventStateChange(Event::Type type) break; case Event::OptionsMenuMode: - if(myState == EventHandlerState::EMULATION) + if(myState == EventHandlerState::EMULATION || myState == EventHandlerState::PAUSE) enterMenuMode(EventHandlerState::OPTIONSMENU); else handled = false; break; case Event::CmdMenuMode: - if(myState == EventHandlerState::EMULATION) + if(myState == EventHandlerState::EMULATION || myState == EventHandlerState::PAUSE) enterMenuMode(EventHandlerState::CMDMENU); else if(myState == EventHandlerState::CMDMENU) leaveMenuMode(); @@ -1239,7 +1231,7 @@ bool EventHandler::eventStateChange(Event::Type type) break; case Event::TimeMachineMode: - if(myState == EventHandlerState::EMULATION) + if(myState == EventHandlerState::EMULATION || myState == EventHandlerState::PAUSE) enterMenuMode(EventHandlerState::TIMEMACHINE); else if(myState == EventHandlerState::TIMEMACHINE) leaveMenuMode(); @@ -1248,8 +1240,7 @@ bool EventHandler::eventStateChange(Event::Type type) break; case Event::DebuggerMode: - if(myState == EventHandlerState::EMULATION - || myState == EventHandlerState::PAUSE + if(myState == EventHandlerState::EMULATION || myState == EventHandlerState::PAUSE || myState == EventHandlerState::TIMEMACHINE) enterDebugMode(); else if(myState == EventHandlerState::DEBUGGER) @@ -2141,6 +2132,19 @@ void EventHandler::leaveDebugMode() #endif } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void EventHandler::enterTimeMachineMenuMode(uInt32 numWinds, bool unwind) +{ + // TODO: maybe remove this state if we leave the menu at the last state + myOSystem.state().addState("enter Time Machine menu", false); // force new state + myOSystem.state().windStates(numWinds, unwind); + + // TODO: probably this check is not necessary + if(myState != EventHandlerState::TIMEMACHINE) + // TODO: display last wind message in time machine dialog + enterMenuMode(EventHandlerState::TIMEMACHINE); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EventHandler::setEventState(EventHandlerState state) { diff --git a/src/emucore/EventHandler.hxx b/src/emucore/EventHandler.hxx index 0564c5d2e..c1539d38f 100644 --- a/src/emucore/EventHandler.hxx +++ b/src/emucore/EventHandler.hxx @@ -137,6 +137,7 @@ class EventHandler void leaveMenuMode(); bool enterDebugMode(); void leaveDebugMode(); + void enterTimeMachineMenuMode(uInt32 numWinds, bool unwind); void takeSnapshot(uInt32 number = 0); /** diff --git a/src/gui/TimeMachineDialog.cxx b/src/gui/TimeMachineDialog.cxx index d44a59ad5..ef1cb678d 100644 --- a/src/gui/TimeMachineDialog.cxx +++ b/src/gui/TimeMachineDialog.cxx @@ -383,10 +383,11 @@ void TimeMachineDialog::handleWinds(Int32 numWinds) if(numWinds) { uInt64 startCycles = instance().console().tia().cycles(); - if(numWinds < 0) r.rewindState(-numWinds); - else if(numWinds > 0) r.unwindState(numWinds); + if(numWinds < 0) r.rewindStates(-numWinds); + else if(numWinds > 0) r.unwindStates(numWinds); string message = r.getUnitString(instance().console().tia().cycles() - startCycles); + // TODO: add message text from addState() myMessageWidget->setLabel((numWinds < 0 ? "(-" : "(+") + message + ")"); } // Update time