Handle MODE_DEBUG in main loop.

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2021-05-16 18:44:16 +01:00
parent 9d4f293a3c
commit 329c19c8d9
4 changed files with 20 additions and 8 deletions

View file

@ -19,11 +19,11 @@ namespace common2
myStartCycles = g_nCumulativeCycles; myStartCycles = g_nCumulativeCycles;
} }
size_t Speed::getCyclesTillNext(const size_t microseconds) const uint64_t Speed::getCyclesTillNext(const size_t microseconds) const
{ {
if (myFixedSpeed) if (myFixedSpeed)
{ {
const size_t cycles = static_cast<uint64_t>(microseconds * g_fCurrentCLK6502 * 1.0e-6); const uint64_t cycles = static_cast<uint64_t>(microseconds * g_fCurrentCLK6502 * 1.0e-6);
return cycles; return cycles;
} }
else else

View file

@ -14,7 +14,7 @@ namespace common2
// calculate the number of cycles to execute in the current period // calculate the number of cycles to execute in the current period
// assuming the next call will happen in x microseconds // 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: private:

View file

@ -92,12 +92,12 @@ namespace ra2
void Game::executeOneFrame() void Game::executeOneFrame()
{ {
const size_t cyclesToExecute = mySpeed.getCyclesTillNext(ourFrameTime);
if (g_nAppMode == MODE_RUNNING) if (g_nAppMode == MODE_RUNNING)
{ {
const bool bVideoUpdate = true; const bool bVideoUpdate = true;
const UINT dwClksPerFrame = NTSC_GetCyclesPerFrame(); const UINT dwClksPerFrame = NTSC_GetCyclesPerFrame();
const uint64_t cyclesToExecute = mySpeed.getCyclesTillNext(ourFrameTime);
const DWORD executedCycles = CpuExecute(cyclesToExecute, bVideoUpdate); const DWORD executedCycles = CpuExecute(cyclesToExecute, bVideoUpdate);
g_dwCyclesThisFrame = (g_dwCyclesThisFrame + executedCycles) % dwClksPerFrame; g_dwCyclesThisFrame = (g_dwCyclesThisFrame + executedCycles) % dwClksPerFrame;

View file

@ -533,17 +533,24 @@ namespace sa2
{ {
// when running in adaptive speed // when running in adaptive speed
// the value msNextFrame is only a hint for when the next frame will arrive // 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) switch (g_nAppMode)
{ {
case MODE_RUNNING: case MODE_RUNNING:
{ {
const size_t cyclesToExecute = mySpeed.getCyclesTillNext(msNextFrame * 1000);
Execute(cyclesToExecute); Execute(cyclesToExecute);
break; break;
} }
case MODE_STEPPING: case MODE_STEPPING:
{
// 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(); DebugContinueStepping();
}
break; break;
} }
}; };
@ -553,14 +560,19 @@ namespace sa2
{ {
if (mode != g_nAppMode) if (mode != g_nAppMode)
{ {
g_nAppMode = mode; switch (mode)
switch (g_nAppMode)
{ {
case MODE_RUNNING: case MODE_RUNNING:
DebugExitDebugger();
SoundCore_SetFade(FADE_IN); SoundCore_SetFade(FADE_IN);
mySpeed.reset(); mySpeed.reset();
break; break;
case MODE_DEBUG:
DebugBegin();
CmdWindowViewConsole(0);
break;
default: default:
g_nAppMode = mode;
SoundCore_SetFade(FADE_OUT); SoundCore_SetFade(FADE_OUT);
break; break;
} }