From 82e5def7c4d6ae2ebe9e6db29e274eef6ca1ca41 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 20 Jan 2020 21:58:34 -0500 Subject: [PATCH] Implements get_scan_status, but for scale being incorrect. --- Outputs/CRT/CRT.cpp | 6 +++++- Outputs/CRT/Internals/Flywheel.hpp | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Outputs/CRT/CRT.cpp b/Outputs/CRT/CRT.cpp index 8d45b645d..0e2e6a6b2 100644 --- a/Outputs/CRT/CRT.cpp +++ b/Outputs/CRT/CRT.cpp @@ -469,5 +469,9 @@ Outputs::Display::Rect CRT::get_rect_for_area(int first_line_after_sync, int num } Outputs::Display::ScanStatus CRT::get_scan_status() const { - return Outputs::Display::ScanStatus(); + Outputs::Display::ScanStatus status; + status.field_duration = vertical_flywheel_->get_locked_period(); + status.field_duration_gradient = vertical_flywheel_->get_last_period_adjustment(); + status.current_position = float(vertical_flywheel_->get_current_output_position()) / float(vertical_flywheel_->get_locked_period()); + return status; } diff --git a/Outputs/CRT/Internals/Flywheel.hpp b/Outputs/CRT/Internals/Flywheel.hpp index 465785fce..eecde8b40 100644 --- a/Outputs/CRT/Internals/Flywheel.hpp +++ b/Outputs/CRT/Internals/Flywheel.hpp @@ -63,6 +63,7 @@ struct Flywheel { inline SyncEvent get_next_event_in_period(bool sync_is_requested, int cycles_to_run_for, int *cycles_advanced) { // If sync is signalled _now_, consider adjusting expected_next_sync_. if(sync_is_requested) { + const auto last_sync = expected_next_sync_; if(counter_ < sync_error_window_ || counter_ > expected_next_sync_ - sync_error_window_) { const int time_now = (counter_ < sync_error_window_) ? expected_next_sync_ + counter_ : counter_; expected_next_sync_ = (3*expected_next_sync_ + time_now) >> 2; @@ -75,6 +76,7 @@ struct Flywheel { expected_next_sync_ = (3*expected_next_sync_ + standard_period_ - sync_error_window_) >> 2; } } + last_adjustment_ = expected_next_sync_ - last_sync; } SyncEvent proposed_event = SyncEvent::None; @@ -165,6 +167,20 @@ struct Flywheel { return standard_period_; } + /*! + @returns the actual current period for a complete scan (including retrace). + */ + inline int get_locked_period() { + return expected_next_sync_; + } + + /*! + @returns the amount by which the @c locked_period was adjusted, the last time that an adjustment was applied. + */ + inline int get_last_period_adjustment() { + return last_adjustment_; + } + /*! @returns the number of synchronisation events that have seemed surprising since the last time this method was called; a low number indicates good synchronisation. @@ -195,6 +211,8 @@ struct Flywheel { int number_of_surprises_ = 0; // a count of the surprising syncs + int last_adjustment_ = 0; // The amount by which + /* Implementation notes: