From bbaebfd4c9955bdf2a36fb6c7fe0423c342077b2 Mon Sep 17 00:00:00 2001 From: Albert Liu <45282415+ggrtk@users.noreply.github.com> Date: Sun, 27 Sep 2020 07:33:51 -0700 Subject: [PATCH] GPU: Round horizontal display range values down to clockdiv multiple GP1(06h) X1 and X2 are persistent across clockdiv changes, but the GPU actively uses rounded values for display output. This behavior is modeled by storing the rounded values in horizontal_display_start and horizontal_display_end. Verified with hardware test. --- src/core/gpu.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index ebfd0559d..259fd07c7 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -481,8 +481,10 @@ void GPU::UpdateCRTCConfig() const u8 horizontal_resolution_index = m_GPUSTAT.horizontal_resolution_1 | (m_GPUSTAT.horizontal_resolution_2 << 2); cs.dot_clock_divider = dot_clock_dividers[horizontal_resolution_index]; - cs.horizontal_display_start = std::min(cs.regs.X1, cs.horizontal_total); - cs.horizontal_display_end = std::min(cs.regs.X2, cs.horizontal_total); + cs.horizontal_display_start = + (std::min(cs.regs.X1, cs.horizontal_total) / cs.dot_clock_divider) * cs.dot_clock_divider; + cs.horizontal_display_end = + (std::min(cs.regs.X2, cs.horizontal_total) / cs.dot_clock_divider) * cs.dot_clock_divider; cs.vertical_display_start = std::min(cs.regs.Y1, cs.vertical_total); cs.vertical_display_end = std::min(cs.regs.Y2, cs.vertical_total); @@ -524,8 +526,10 @@ void GPU::UpdateCRTCDisplayParameters() const u16 horizontal_total = m_GPUSTAT.pal_mode ? PAL_TICKS_PER_LINE : NTSC_TICKS_PER_LINE; const u16 vertical_total = m_GPUSTAT.pal_mode ? PAL_TOTAL_LINES : NTSC_TOTAL_LINES; - const u16 horizontal_display_start = std::min(cs.regs.X1, horizontal_total); - const u16 horizontal_display_end = std::min(cs.regs.X2, horizontal_total); + const u16 horizontal_display_start = + (std::min(cs.regs.X1, horizontal_total) / cs.dot_clock_divider) * cs.dot_clock_divider; + const u16 horizontal_display_end = + (std::min(cs.regs.X2, horizontal_total) / cs.dot_clock_divider) * cs.dot_clock_divider; const u16 vertical_display_start = std::min(cs.regs.Y1, vertical_total); const u16 vertical_display_end = std::min(cs.regs.Y2, vertical_total);