diff --git a/Outputs/CRT/CRT.cpp b/Outputs/CRT/CRT.cpp index 55157b83c..7e1199b7a 100644 --- a/Outputs/CRT/CRT.cpp +++ b/Outputs/CRT/CRT.cpp @@ -281,8 +281,11 @@ void CRT::output_scan(const Scan *const scan) const bool is_leading_edge = (!_is_receiving_sync && this_is_sync); _is_receiving_sync = this_is_sync; - const bool hsync_requested = is_leading_edge; -// const bool hsync_requested = is_trailing_edge && (_sync_period < (_horizontal_flywheel->get_scan_period() >> 2)); + // This introduces a blackout period close to the expected vertical sync point in which horizontal syncs are not + // recognised, effectively causing the horizontal flywheel to freewheel during that period. This attempts to seek + // the problem that vertical sync otherwise often starts halfway through a scanline, which confuses the horizontal + // flywheel. I'm currently unclear whether this is an accurate solution to this problem. + const bool hsync_requested = is_leading_edge && !_vertical_flywheel->is_near_expected_sync(); const bool vsync_requested = is_trailing_edge && (_sync_capacitor_charge_level >= _sync_capacitor_charge_threshold); // simplified colour burst logic: if it's within the back porch we'll take it diff --git a/Outputs/CRT/Internals/Flywheel.hpp b/Outputs/CRT/Internals/Flywheel.hpp index e10d621fd..c3a00a3aa 100644 --- a/Outputs/CRT/Internals/Flywheel.hpp +++ b/Outputs/CRT/Internals/Flywheel.hpp @@ -9,6 +9,8 @@ #ifndef Flywheel_hpp #define Flywheel_hpp +#include + namespace Outputs { namespace CRT { @@ -187,6 +189,14 @@ struct Flywheel return result; } + /*! + @returns `true` if a sync is expected soon or the time at which it was expected was recent. + */ + inline bool is_near_expected_sync() + { + return abs((int)_counter - (int)_expected_next_sync) < (int)_standard_period / 50; + } + private: unsigned int _standard_period; // the normal length of time between syncs const unsigned int _retrace_time; // a constant indicating the amount of time it takes to perform a retrace