From 1effb97b74869f88c4a2aeee73cc483e6271a0e4 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 4 Nov 2018 21:57:46 -0500 Subject: [PATCH] Reintroduces colour phase acquisition from the colour burst. --- Outputs/CRT/CRT.cpp | 16 ++++++++++------ Outputs/CRT/CRT.hpp | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Outputs/CRT/CRT.cpp b/Outputs/CRT/CRT.cpp index 8a3f81f96..52f677e99 100644 --- a/Outputs/CRT/CRT.cpp +++ b/Outputs/CRT/CRT.cpp @@ -185,7 +185,6 @@ void CRT::advance_cycles(int number_of_cycles, bool hsync_requested, bool vsync_ scan_target_->announce(Outputs::Display::ScanTarget::Event::HorizontalRetrace); is_alernate_line_ ^= phase_alternates_; colour_burst_amplitude_ = 0; - phase_numerator_ = 0; } // Also announce if this is vertical retrace. @@ -216,12 +215,16 @@ void CRT::output_scan(const Scan *const scan) { // simplified colour burst logic: if it's within the back porch we'll take it if(scan->type == Scan::Type::ColourBurst) { if(!colour_burst_amplitude_ && horizontal_flywheel_->get_current_time() < (horizontal_flywheel_->get_standard_period() * 12) >> 6) { -// int position_phase = (horizontal_flywheel_->get_current_time() * colour_cycle_numerator_ * 256) / phase_denominator_; -// colour_burst_phase_ = (position_phase + scan->phase) & 255; - colour_burst_amplitude_ = scan->amplitude; + // Load phase_numerator_ as a fixed-point quantity in the range [0, 255]. + phase_numerator_ = scan->phase; + if(colour_burst_phase_adjustment_ != 0xff) + phase_numerator_ = (phase_numerator_ & ~63) + colour_burst_phase_adjustment_; -// if(colour_burst_phase_adjustment_ != 0xff) -// colour_burst_phase_ = (colour_burst_phase_ & ~63) + colour_burst_phase_adjustment_; + // Multiply the phase_numerator_ up to be to the proper scale. + phase_numerator_ = (phase_numerator_ * phase_denominator_) >> 8; + + // Crib the colour burst amplitude. + colour_burst_amplitude_ = scan->amplitude; } } // TODO: inspect raw data for potential colour burst if required; the DPLL and some zero crossing logic @@ -313,6 +316,7 @@ void CRT::output_colour_burst(int number_of_cycles, uint8_t phase, uint8_t ampli } void CRT::output_default_colour_burst(int number_of_cycles) { + // TODO: avoid applying a rounding error here? output_colour_burst(number_of_cycles, static_cast((phase_numerator_ * 256) / phase_denominator_)); } diff --git a/Outputs/CRT/CRT.hpp b/Outputs/CRT/CRT.hpp index 803006fe5..0dccfc5b3 100644 --- a/Outputs/CRT/CRT.hpp +++ b/Outputs/CRT/CRT.hpp @@ -50,7 +50,7 @@ class CRT { int16_t colour_burst_angle_ = 0; uint8_t colour_burst_amplitude_ = 30; - int colour_burst_phase_adjustment_ = 0; + int colour_burst_phase_adjustment_ = 0xff; bool is_writing_composite_run_ = false; int64_t phase_denominator_ = 1;