From b5932edff3db9fbfd914172a612b8cc7d6f9d7df Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 26 Aug 2024 21:13:49 -0400 Subject: [PATCH] Avoid missed interrupts on wraparound. --- Machines/Acorn/Electron/Video.cpp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/Machines/Acorn/Electron/Video.cpp b/Machines/Acorn/Electron/Video.cpp index b5e743764..71ba7dc2c 100644 --- a/Machines/Acorn/Electron/Video.cpp +++ b/Machines/Acorn/Electron/Video.cpp @@ -237,18 +237,27 @@ void VideoOutput::run_for(const Cycles cycles) { const auto start_position = output_position_; output_position_ = (output_position_ + number_of_cycles) % cycles_per_frame; - if( - (start_position < real_time_clock_interrupt_1 && output_position_ >= real_time_clock_interrupt_1) || - (start_position < real_time_clock_interrupt_2 && output_position_ >= real_time_clock_interrupt_2) - ) { - interrupts_ = Electron::Interrupt(interrupts_ | Electron::Interrupt::RealTimeClock); - } + const auto test_range = [&](int start, int end) { + if( + (start < real_time_clock_interrupt_1 && end >= real_time_clock_interrupt_1) || + (start < real_time_clock_interrupt_2 && end >= real_time_clock_interrupt_2) + ) { + interrupts_ = Electron::Interrupt(interrupts_ | Electron::Interrupt::RealTimeClock); + } - if( - (start_position < display_end_interrupt_1 && output_position_ >= display_end_interrupt_1) || - (start_position < display_end_interrupt_2 && output_position_ >= display_end_interrupt_2) - ) { - interrupts_ = Electron::Interrupt(interrupts_ | Electron::Interrupt::DisplayEnd); + if( + (start < display_end_interrupt_1 && end >= display_end_interrupt_1) || + (start < display_end_interrupt_2 && end >= display_end_interrupt_2) + ) { + interrupts_ = Electron::Interrupt(interrupts_ | Electron::Interrupt::DisplayEnd); + } + }; + + if(output_position_ >= start_position) { + test_range(start_position, output_position_); + } else { + test_range(start_position, cycles_per_frame); + test_range(0, output_position_); } while(number_of_cycles) {