From 1a0b1a31499db62a5bd95933e410ded51e72d3bd Mon Sep 17 00:00:00 2001 From: Albert Liu <45282415+ggrtk@users.noreply.github.com> Date: Sun, 27 Sep 2020 07:35:55 -0700 Subject: [PATCH] GPU: Use accurate VRAM display width rounding Modified version of Nocash algorithm, confirmed with hardware test. Relies on proper horizontal display range rounding for correct results. --- src/core/gpu.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index 259fd07c7..c893f58e2 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -598,11 +598,16 @@ void GPU::UpdateCRTCDisplayParameters() cs.display_width = (cs.horizontal_active_end - cs.horizontal_active_start) / cs.dot_clock_divider; cs.display_height = (cs.vertical_active_end - cs.vertical_active_start) << height_shift; - // Determine number of pixels outputted from VRAM (align to 4-pixel boundary). - // TODO: Verify behavior if start > end and also if values are outside of the active video portion of scanline. - const u16 horizontal_display_ticks = horizontal_display_end - horizontal_display_start; - cs.display_vram_width = - (static_cast(std::round(horizontal_display_ticks / static_cast(cs.dot_clock_divider))) + 2u) & ~3u; + // Determine number of pixels outputted from VRAM (in general, round to 4-pixel multiple). + // TODO: Verify behavior if values are outside of the active video portion of scanline. + const u16 horizontal_display_ticks = + (horizontal_display_end < horizontal_display_start) ? 0 : (horizontal_display_end - horizontal_display_start); + + const u16 horizontal_display_pixels = horizontal_display_ticks / cs.dot_clock_divider; + if (horizontal_display_pixels == 1u) + cs.display_vram_width = 4u; + else + cs.display_vram_width = (horizontal_display_pixels + 2u) & ~3u; // Determine if we need to adjust the VRAM rectangle (because the display is starting outside the visible area) or add // padding.