From 50f9f9eba12586bad3c4d029ffb3363c48bed5ac Mon Sep 17 00:00:00 2001 From: BearOso Date: Mon, 20 Mar 2023 16:02:36 -0500 Subject: [PATCH] Move S9xSyncSpeed call. DMA can last multiple frames, and so can S9xMainLoop. If we throttle outside of S9xMainLoop or only as we're exiting the loop as is currently done, we zoom through multiple frames and overrun the audio. Moving S9xSyncSpeed just after EndScreenRefresh causes it to be called every frame. This seemingly wasn't a problem because throttling with vsync *did* happen every frame regardless. Oops. --- cpuexec.cpp | 13 ++++++------- gtk/src/gtk_s9x.cpp | 3 +-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/cpuexec.cpp b/cpuexec.cpp index 9f220219..b905f018 100644 --- a/cpuexec.cpp +++ b/cpuexec.cpp @@ -132,13 +132,6 @@ void S9xMainLoop (void) if (CPU.Flags & SCAN_KEYS_FLAG) { - #ifdef DEBUGGER - if (!(CPU.Flags & FRAME_ADVANCE_FLAG)) - #endif - { - S9xSyncSpeed(); - } - break; } @@ -326,6 +319,12 @@ void S9xDoHEventProcessing (void) if (CPU.V_Counter == PPU.ScreenHeight + FIRST_VISIBLE_LINE) // VBlank starts from V=225(240). { S9xEndScreenRefresh(); + #ifdef DEBUGGER + if (!(CPU.Flags & FRAME_ADVANCE_FLAG)) + #endif + { + S9xSyncSpeed(); + } CPU.Flags |= SCAN_KEYS_FLAG; diff --git a/gtk/src/gtk_s9x.cpp b/gtk/src/gtk_s9x.cpp index 5a7f1d74..4aa01a14 100644 --- a/gtk/src/gtk_s9x.cpp +++ b/gtk/src/gtk_s9x.cpp @@ -304,8 +304,6 @@ static bool S9xIdleFunc() S9xProcessEvents(true); - S9xThrottle(Settings.SkipFrames); - if (!S9xDisplayDriverIsReady()) { usleep(100); @@ -494,6 +492,7 @@ static void S9xThrottle(int method) void S9xSyncSpeed() { + S9xThrottle(Settings.SkipFrames); } static void S9xCheckPointerTimer()