From 8d07bb1506a5c7bc8fdfad0b7e7199415e6bb0f5 Mon Sep 17 00:00:00 2001 From: Andrea Odetti Date: Thu, 3 Jun 2021 11:51:12 +0100 Subject: [PATCH] Fix for https://github.com/tomcw/mb-audit Update MB (and disk and speaker) in smaller batches. 1 ms like AppleWin. Signed-off-by: Andrea Odetti --- source/frontends/sdl/sdlframe.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/source/frontends/sdl/sdlframe.cpp b/source/frontends/sdl/sdlframe.cpp index f1530c32..739a6d22 100644 --- a/source/frontends/sdl/sdlframe.cpp +++ b/source/frontends/sdl/sdlframe.cpp @@ -502,12 +502,22 @@ namespace sa2 const bool bVideoUpdate = !g_bFullSpeed; const UINT dwClksPerFrame = NTSC_GetCyclesPerFrame(); - const DWORD executedCycles = CpuExecute(cyclesToExecute, bVideoUpdate); + // do it in the same batches as AppleWin (1 ms) + const DWORD fExecutionPeriodClks = g_fCurrentCLK6502 * (1.0 / 1000.0); // 1 ms - g_dwCyclesThisFrame = (g_dwCyclesThisFrame + executedCycles) % dwClksPerFrame; - GetCardMgr().GetDisk2CardMgr().UpdateDriveState(executedCycles); - MB_PeriodicUpdate(executedCycles); - SpkrUpdate(executedCycles); + DWORD totalCyclesExecuted = 0; + // check at the end because we want to always execute at least 1 cycle even for "0" + do + { + const DWORD thisCyclesToExecute = std::min(fExecutionPeriodClks, cyclesToExecute - totalCyclesExecuted); + const DWORD executedCycles = CpuExecute(thisCyclesToExecute, bVideoUpdate); + totalCyclesExecuted += executedCycles; + + g_dwCyclesThisFrame = (g_dwCyclesThisFrame + executedCycles) % dwClksPerFrame; + GetCardMgr().GetDisk2CardMgr().UpdateDriveState(executedCycles); + MB_PeriodicUpdate(executedCycles); + SpkrUpdate(executedCycles); + } while (totalCyclesExecuted < cyclesToExecute); } void SDLFrame::ExecuteInRunningMode(const size_t msNextFrame)