1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-26 09:29:45 +00:00

Ensured lengthy constant sync can't appear to be two sync pulses, regardless of other interruption.

This commit is contained in:
Thomas Harte 2017-07-29 18:25:04 -04:00
parent 3528a7f78b
commit ed8c73eb14
2 changed files with 19 additions and 16 deletions

View File

@ -70,7 +70,6 @@ void CRT::set_composite_function_type(CompositeSourceType type, float offset_of_
}
CRT::CRT(unsigned int common_output_divisor, unsigned int buffer_depth) :
sync_capacitor_charge_level_(0),
is_receiving_sync_(false),
common_output_divisor_(common_output_divisor),
is_writing_composite_run_(false),
@ -288,13 +287,15 @@ void CRT::output_scan(const Scan *const scan) {
if(this_is_sync) {
// if this is sync then either begin or continue a sync accumulation phase
is_accumulating_sync_ = true;
cycles_since_sync_ = 0;
} else {
// if this is not sync then check how long it has been since sync. If it's more than
// half a line then end sync accumulation and zero out the accumulating count
cycles_since_sync_ += scan->number_of_cycles;
if(cycles_since_sync_ > (cycles_per_line_ >> 1)) {
if(cycles_since_sync_ > (cycles_per_line_ >> 2)) {
cycles_of_sync_ = 0;
is_accumulating_sync_ = false;
is_refusing_sync_ = false;
}
}
@ -303,18 +304,21 @@ void CRT::output_scan(const Scan *const scan) {
// if sync is being accumulated then accumulate it; if it crosses the vertical sync threshold then
// divide this line at the crossing point and indicate vertical sync there
if(is_accumulating_sync_) {
if(is_accumulating_sync_ && !is_refusing_sync_) {
cycles_of_sync_ += scan->number_of_cycles;
if(this_is_sync && cycles_of_sync_ >= sync_capacitor_charge_threshold_) {
unsigned int overshoot = std::max(cycles_of_sync_ - sync_capacitor_charge_threshold_, number_of_cycles);
number_of_cycles -= overshoot;
advance_cycles(number_of_cycles, hsync_requested, false, scan->type);
is_refusing_sync_ = true;
unsigned int overshoot = std::min(cycles_of_sync_ - sync_capacitor_charge_threshold_, number_of_cycles);
if(overshoot) {
number_of_cycles -= overshoot;
advance_cycles(number_of_cycles, hsync_requested, false, scan->type);
hsync_requested = false;
number_of_cycles = overshoot;
}
cycles_of_sync_ = 0;
is_accumulating_sync_ = false;
number_of_cycles = overshoot;
hsync_requested = false;
vsync_requested = true;
}
}

View File

@ -40,11 +40,6 @@ class CRT {
std::unique_ptr<Flywheel> horizontal_flywheel_, vertical_flywheel_;
uint16_t vertical_flywheel_output_divider_;
// elements of sync separation
bool is_receiving_sync_; // true if the CRT is currently receiving sync (i.e. this is for edge triggering of horizontal sync)
int sync_capacitor_charge_level_; // this charges up during times of sync and depletes otherwise; needs to hit a required threshold to trigger a vertical sync
unsigned int sync_capacitor_charge_threshold_; // this charges up during times of sync and depletes otherwise; needs to hit a required threshold to trigger a vertical sync
struct Scan {
enum Type {
Sync, Level, Data, Blank, ColourBurst
@ -93,9 +88,13 @@ class CRT {
}
// sync counter, for determining vertical sync
bool is_accumulating_sync_;
unsigned int cycles_of_sync_;
unsigned int cycles_since_sync_;
bool is_receiving_sync_; // true if the CRT is currently receiving sync (i.e. this is for edge triggering of horizontal sync)
bool is_accumulating_sync_; // true if a sync level has triggered the suspicion that a vertical sync might be in progress
bool is_refusing_sync_; // true once a vertical sync has been detected, until a prolonged period of non-sync has ended suspicion of an ongoing vertical sync
unsigned int sync_capacitor_charge_threshold_; // this charges up during times of sync and depletes otherwise; needs to hit a required threshold to trigger a vertical sync
unsigned int cycles_of_sync_; // the number of cycles since the potential vertical sync began
unsigned int cycles_since_sync_; // the number of cycles since last in sync, for defeating the possibility of this being a vertical sync
unsigned int cycles_per_line_;
public: