From 8cc20844a98cf3afc3b5ea97e9ad361327f94375 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 8 Jan 2023 17:31:08 -0500 Subject: [PATCH] Clock convert for draw_ calls. --- Components/9918/Implementation/9918.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Components/9918/Implementation/9918.cpp b/Components/9918/Implementation/9918.cpp index 1d988a353..3c47a6878 100644 --- a/Components/9918/Implementation/9918.cpp +++ b/Components/9918/Implementation/9918.cpp @@ -405,6 +405,12 @@ void TMS9918::run_for(const HalfCycles cycles) { // Left border. border(Timing::StartOfLeftBorder, line_buffer.first_pixel_output_column); +#define draw(function, converter) { \ + const int relative_start = this->clock_converter_.converter(start - line_buffer.first_pixel_output_column); \ + const int relative_end = this->clock_converter_.converter(end - line_buffer.first_pixel_output_column); \ + if(relative_start == relative_end) break; \ + this->function; } + // Pixel region. intersect( line_buffer.first_pixel_output_column, @@ -417,12 +423,10 @@ void TMS9918::run_for(const HalfCycles cycles) { } if(this->pixel_target_) { - const int relative_start = start - line_buffer.first_pixel_output_column; - const int relative_end = end - line_buffer.first_pixel_output_column; switch(line_buffer.line_mode) { - case LineMode::SMS: this->draw_sms(relative_start, relative_end, cram_value); break; - case LineMode::Character: this->draw_tms_character(relative_start, relative_end); break; - case LineMode::Text: this->draw_tms_text(relative_start, relative_end); break; + case LineMode::SMS: draw(draw_sms(relative_start, relative_end, cram_value), to_tms_access_clock); break; + case LineMode::Character: draw(draw_tms_character(relative_start, relative_end), to_tms_access_clock); break; + case LineMode::Text: draw(draw_tms_text(relative_start, relative_end), to_tms_access_clock); break; case LineMode::Refresh: break; /* Dealt with elsewhere. */ } @@ -436,6 +440,8 @@ void TMS9918::run_for(const HalfCycles cycles) { } ); +#undef draw + // Additional right border, if called for. if(line_buffer.next_border_column != Timing::CyclesPerLine) { border(line_buffer.next_border_column, Timing::CyclesPerLine);