From 329c19c8d9f0f838083e2923dfcdce4d01db6f59 Mon Sep 17 00:00:00 2001 From: Andrea Odetti Date: Sun, 16 May 2021 18:44:16 +0100 Subject: [PATCH] Handle MODE_DEBUG in main loop. Signed-off-by: Andrea Odetti --- source/frontends/common2/speed.cpp | 4 ++-- source/frontends/common2/speed.h | 2 +- source/frontends/libretro/game.cpp | 2 +- source/frontends/sdl/sdlframe.cpp | 20 ++++++++++++++++---- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/source/frontends/common2/speed.cpp b/source/frontends/common2/speed.cpp index 9ea5ab9c..7a5f1766 100644 --- a/source/frontends/common2/speed.cpp +++ b/source/frontends/common2/speed.cpp @@ -19,11 +19,11 @@ namespace common2 myStartCycles = g_nCumulativeCycles; } - size_t Speed::getCyclesTillNext(const size_t microseconds) const + uint64_t Speed::getCyclesTillNext(const size_t microseconds) const { if (myFixedSpeed) { - const size_t cycles = static_cast(microseconds * g_fCurrentCLK6502 * 1.0e-6); + const uint64_t cycles = static_cast(microseconds * g_fCurrentCLK6502 * 1.0e-6); return cycles; } else diff --git a/source/frontends/common2/speed.h b/source/frontends/common2/speed.h index 220dca69..d6ca8cf3 100644 --- a/source/frontends/common2/speed.h +++ b/source/frontends/common2/speed.h @@ -14,7 +14,7 @@ namespace common2 // calculate the number of cycles to execute in the current period // assuming the next call will happen in x microseconds - size_t getCyclesTillNext(const size_t microseconds) const; + uint64_t getCyclesTillNext(const size_t microseconds) const; private: diff --git a/source/frontends/libretro/game.cpp b/source/frontends/libretro/game.cpp index 63672a92..3f880525 100644 --- a/source/frontends/libretro/game.cpp +++ b/source/frontends/libretro/game.cpp @@ -92,12 +92,12 @@ namespace ra2 void Game::executeOneFrame() { - const size_t cyclesToExecute = mySpeed.getCyclesTillNext(ourFrameTime); if (g_nAppMode == MODE_RUNNING) { const bool bVideoUpdate = true; const UINT dwClksPerFrame = NTSC_GetCyclesPerFrame(); + const uint64_t cyclesToExecute = mySpeed.getCyclesTillNext(ourFrameTime); const DWORD executedCycles = CpuExecute(cyclesToExecute, bVideoUpdate); g_dwCyclesThisFrame = (g_dwCyclesThisFrame + executedCycles) % dwClksPerFrame; diff --git a/source/frontends/sdl/sdlframe.cpp b/source/frontends/sdl/sdlframe.cpp index 21f141ef..877bec5e 100644 --- a/source/frontends/sdl/sdlframe.cpp +++ b/source/frontends/sdl/sdlframe.cpp @@ -533,17 +533,24 @@ namespace sa2 { // when running in adaptive speed // the value msNextFrame is only a hint for when the next frame will arrive + const uint64_t cyclesToExecute = mySpeed.getCyclesTillNext(msNextFrame * 1000); switch (g_nAppMode) { case MODE_RUNNING: { - const size_t cyclesToExecute = mySpeed.getCyclesTillNext(msNextFrame * 1000); Execute(cyclesToExecute); break; } case MODE_STEPPING: { - DebugContinueStepping(); + // In AppleWin this is called without a timer for just one iteration + // because we run a "frame" at a time, we need a bit of ingenuity + const uint64_t target = g_nCumulativeCycles + cyclesToExecute; + + while (g_nAppMode == MODE_STEPPING && g_nCumulativeCycles < target) + { + DebugContinueStepping(); + } break; } }; @@ -553,14 +560,19 @@ namespace sa2 { if (mode != g_nAppMode) { - g_nAppMode = mode; - switch (g_nAppMode) + switch (mode) { case MODE_RUNNING: + DebugExitDebugger(); SoundCore_SetFade(FADE_IN); mySpeed.reset(); break; + case MODE_DEBUG: + DebugBegin(); + CmdWindowViewConsole(0); + break; default: + g_nAppMode = mode; SoundCore_SetFade(FADE_OUT); break; }