From b522d65c5049908f256a0bb80c4483dfb7e6422b Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 8 Jan 2023 17:04:19 -0500 Subject: [PATCH] Fix border lengths. --- Components/9918/Implementation/9918.cpp | 45 ++++++++++++++----------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/Components/9918/Implementation/9918.cpp b/Components/9918/Implementation/9918.cpp index b13dc2c31..1d988a353 100644 --- a/Components/9918/Implementation/9918.cpp +++ b/Components/9918/Implementation/9918.cpp @@ -470,35 +470,42 @@ void TMS9918::run_for(const HalfCycles cycles) { } template -void Base::output_border(int cycles, uint32_t cram_dot) { - cycles *= 4; +void Base::output_border(int cycles, [[maybe_unused]] uint32_t cram_dot) { + cycles = this->clock_converter_.to_crt_clock(cycles); const uint32_t border_colour = is_sega_vdp(personality) ? master_system_.colour_ram[16 + background_colour_] : palette[background_colour_]; - if(cram_dot) { - uint32_t *const pixel_target = reinterpret_cast(crt_.begin_data(1)); - if(pixel_target) { - *pixel_target = border_colour | cram_dot; - } - crt_.output_level(4); - cycles -= 4; - } - - if(cycles) { - // If the border colour is 0, that can be communicated - // more efficiently as an explicit blank. - if(border_colour) { + if constexpr (is_sega_vdp(personality)) { + if(cram_dot) { uint32_t *const pixel_target = reinterpret_cast(crt_.begin_data(1)); if(pixel_target) { - *pixel_target = border_colour; + *pixel_target = border_colour | cram_dot; } - crt_.output_level(cycles); - } else { - crt_.output_blank(cycles); + + // Four CRT cycles is one pixel width, so this doesn't need clock conversion. + // TODO: on the Mega Drive it may be only 3 colour cycles, depending on mode. + crt_.output_level(4); + cycles -= 4; } } + + if(!cycles) { + return; + } + + // If the border colour is 0, that can be communicated + // more efficiently as an explicit blank. + if(border_colour) { + uint32_t *const pixel_target = reinterpret_cast(crt_.begin_data(1)); + if(pixel_target) { + *pixel_target = border_colour; + } + crt_.output_level(cycles); + } else { + crt_.output_blank(cycles); + } } template