From 60f7ffa2d01852458adf97944cf2030f61597214 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 29 Sep 2026 11:32:03 +1000 Subject: [PATCH] GPU: Fix scanline sync before vertical_display_start If the current line was before start, it wouldn't sync before end. --- src/core/gpu.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index 6fd1ab1fc..b301b3cb8 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -1510,14 +1510,16 @@ void GPU::UpdateCRTCTickEvent() lines_until_event = (s_locals.crtc_state.current_scanline >= s_locals.crtc_state.vertical_display_end) ? (s_locals.crtc_state.vertical_total - s_locals.crtc_state.current_scanline + s_locals.crtc_state.vertical_display_start) : - (s_locals.crtc_state.vertical_display_end - s_locals.crtc_state.current_scanline); + ((s_locals.crtc_state.current_scanline < s_locals.crtc_state.vertical_display_start) ? + (s_locals.crtc_state.vertical_display_start - s_locals.crtc_state.current_scanline) : + (s_locals.crtc_state.vertical_display_end - s_locals.crtc_state.current_scanline)); } else { - lines_until_event = (s_locals.crtc_state.current_scanline >= s_locals.crtc_state.vertical_display_end ? - (s_locals.crtc_state.vertical_total - s_locals.crtc_state.current_scanline + - s_locals.crtc_state.vertical_display_end) : - (s_locals.crtc_state.vertical_display_end - s_locals.crtc_state.current_scanline)); + lines_until_event = (s_locals.crtc_state.current_scanline >= s_locals.crtc_state.vertical_display_end) ? + (s_locals.crtc_state.vertical_total - s_locals.crtc_state.current_scanline + + s_locals.crtc_state.vertical_display_end) : + (s_locals.crtc_state.vertical_display_end - s_locals.crtc_state.current_scanline); } if (Timers::IsExternalIRQEnabled(HBLANK_TIMER_INDEX)) lines_until_event = std::min(lines_until_event, Timers::GetTicksUntilIRQ(HBLANK_TIMER_INDEX));