3DS: Redo video sync to be more precise
Vicki Pfau vi@endrift.com
Fri, 07 Aug 2020 18:27:24 -0700
2 files changed,
12 insertions(+),
6 deletions(-)
M
CHANGES
→
CHANGES
@@ -25,6 +25,7 @@ - GBA Video: Latch scanline at end of Hblank (fixes mgba.io/i/1319)
- GBA Video: Fix Hblank timing - SM83: Emulate HALT bug Other fixes: + - 3DS: Redo video sync to be more precise - All: Improve export headers (fixes mgba.io/i/1738) - Core: Ensure ELF regions can be written before trying - Debugger: Don't skip undefined instructions when debugger attached
M
src/platform/3ds/main.c
→
src/platform/3ds/main.c
@@ -95,7 +95,7 @@ static int activeOutputTexture = 0;
static ndspWaveBuf dspBuffer[DSP_BUFFERS]; static int bufferId = 0; static bool frameLimiter = true; -static u64 tickCounter; +static u32 frameCounter; static C3D_RenderTarget* topScreen[2]; static C3D_RenderTarget* bottomScreen[2];@@ -213,11 +213,17 @@ if (frameStarted) {
return; } frameStarted = true; + + int screen = screenMode >= SM_PA_TOP ? GSP_SCREEN_TOP : GSP_SCREEN_BOTTOM; if (frameLimiter) { - if (tickCounter + 4481000 > svcGetSystemTick()) { - C3D_FrameSync(); + u32 oldFrame = frameCounter; + frameCounter = C3D_FrameCounter(screen); + while (oldFrame == frameCounter) { + gspWaitForAnyEvent(); + frameCounter = C3D_FrameCounter(screen); } - tickCounter = svcGetSystemTick(); + } else { + frameCounter = C3D_FrameCounter(screen); } C3D_FrameBegin(0); ctrStartFrame();@@ -350,7 +356,7 @@ break;
} osSetSpeedupEnable(true); - double ratio = GBAAudioCalculateRatio(1, 59.8260982880808, 1); + double ratio = GBAAudioCalculateRatio(1, 268111856.f / 4481136.f, 1); blip_set_rates(runner->core->getAudioChannel(runner->core, 0), runner->core->frequency(runner->core), 32768 * ratio); blip_set_rates(runner->core->getAudioChannel(runner->core, 1), runner->core->frequency(runner->core), 32768 * ratio); if (hasSound != NO_SOUND) {@@ -659,7 +665,6 @@ if (frameLimiter == limit) {
return; } frameLimiter = limit; - tickCounter = svcGetSystemTick(); } static bool _running(struct mGUIRunner* runner) {