From d67bcd654c11d49a9e0e2a88c471da049d96be29 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 20 Mar 2020 01:12:41 +1000 Subject: [PATCH] GPU: Prevent emulator locking up when switching between PAL/NTSC mode --- src/core/gpu.cpp | 12 ++++++++---- src/core/gpu.h | 6 +++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index 28529a0a3..80523ed07 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -321,13 +321,17 @@ void GPU::UpdateCRTCConfig() if (m_GPUSTAT.pal_mode) { - cs.vertical_total = 314; - cs.horizontal_total = 3406; + cs.vertical_total = PAL_TOTAL_LINES; + cs.current_scanline %= PAL_TOTAL_LINES; + cs.horizontal_total = PAL_TICKS_PER_LINE; + cs.current_tick_in_scanline %= PAL_TICKS_PER_LINE; } else { - cs.vertical_total = 263; - cs.horizontal_total = 3413; + cs.vertical_total = NTSC_TOTAL_LINES; + cs.current_scanline %= NTSC_TOTAL_LINES; + cs.horizontal_total = NTSC_TICKS_PER_LINE; + cs.current_tick_in_scanline %= NTSC_TICKS_PER_LINE; } const TickCount ticks_per_frame = cs.horizontal_total * cs.vertical_total; diff --git a/src/core/gpu.h b/src/core/gpu.h index 0d97806c9..713cfe219 100644 --- a/src/core/gpu.h +++ b/src/core/gpu.h @@ -94,7 +94,11 @@ public: MAX_PRIMITIVE_HEIGHT = 512, DOT_TIMER_INDEX = 0, HBLANK_TIMER_INDEX = 1, - MAX_RESOLUTION_SCALE = 16 + MAX_RESOLUTION_SCALE = 16, + NTSC_TICKS_PER_LINE = 3413, + NTSC_TOTAL_LINES = 263, + PAL_TICKS_PER_LINE = 3406, + PAL_TOTAL_LINES = 314, }; // 4x4 dither matrix.