From 96e79301f344c6a9d7b3c1011d55e3fe6b699bbe Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 15 Nov 2020 19:14:57 -0500 Subject: [PATCH] Clamps 16-bit positioning values. --- Outputs/CRT/CRT.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Outputs/CRT/CRT.cpp b/Outputs/CRT/CRT.cpp index c2af216c2..c72d98a39 100644 --- a/Outputs/CRT/CRT.cpp +++ b/Outputs/CRT/CRT.cpp @@ -190,8 +190,10 @@ Flywheel::SyncEvent CRT::get_next_horizontal_sync_event(bool hsync_is_requested, Outputs::Display::ScanTarget::Scan::EndPoint CRT::end_point(uint16_t data_offset) { Display::ScanTarget::Scan::EndPoint end_point; - end_point.x = uint16_t(horizontal_flywheel_->get_current_output_position()); - end_point.y = uint16_t(vertical_flywheel_->get_current_output_position() / vertical_flywheel_output_divider_); + // Clamp the available range on endpoints. These will almost always be within range, but may go + // out during times of resync. + end_point.x = uint16_t(std::min(horizontal_flywheel_->get_current_output_position(), 65535)); + end_point.y = uint16_t(std::min(vertical_flywheel_->get_current_output_position() / vertical_flywheel_output_divider_, 65535)); end_point.data_offset = data_offset; // Ensure .composite_angle is sampled at the location indicated by .cycles_since_end_of_horizontal_retrace.