1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-07 08:28:57 +00:00

With lots of logging arising temporarily, fixed bug whereby conversion to a patched track would lead to holding a track with a distinct measure of time, leading to improperly-placed patches.

This commit is contained in:
Thomas Harte 2016-12-25 22:00:39 -05:00
parent b538ee5bd8
commit 742c5df367
5 changed files with 19 additions and 11 deletions

View File

@ -535,7 +535,7 @@ void WD1770::posit_event(Event new_event_type)
}
if(distance_into_section_ == 7)
{
printf("Considering %d/%d\n", header_[0], header_[2]);
printf("Considering %d/%d at %0.4f\n", header_[0], header_[2], get_time_into_track().get_float());
is_reading_data_ = false;
if(header_[0] == track_ && header_[2] == sector_ &&
(has_motor_on_line() || !(command_&0x02) || ((command_&0x08) >> 3) == header_[1]))
@ -563,6 +563,7 @@ void WD1770::posit_event(Event new_event_type)
});
distance_into_section_ = 0;
is_reading_data_ = true;
printf("\n");
goto type2_read_byte;
}
goto type2_read_data;
@ -570,7 +571,7 @@ void WD1770::posit_event(Event new_event_type)
type2_read_byte:
WAIT_FOR_EVENT(Event::Token);
if(latest_token_.type != Token::Byte) goto type2_read_byte;
data_ = latest_token_.byte_value;
data_ = latest_token_.byte_value; printf("%02x", data_);
update_status([] (Status &status) {
status.lost_data |= status.data_request;
status.data_request = true;
@ -579,6 +580,7 @@ void WD1770::posit_event(Event new_event_type)
if(distance_into_section_ == 128 << header_[3])
{
distance_into_section_ = 0;
printf("\n");
goto type2_check_crc;
}
goto type2_read_byte;
@ -640,9 +642,10 @@ void WD1770::posit_event(Event new_event_type)
WAIT_FOR_EVENT(Event::DataWritten);
distance_into_section_ = 0;
printf("\n");
type2_write_loop:
write_byte(data_);
write_byte(data_); printf("%02x", data_);
update_status([] (Status &status) {
status.data_request = true;
});
@ -650,6 +653,7 @@ void WD1770::posit_event(Event new_event_type)
distance_into_section_++;
if(distance_into_section_ == 128 << header_[3])
{
printf("\n");
goto type2_write_crc;
}

View File

@ -166,11 +166,15 @@ void Controller::end_writing()
if(!patched_track_)
{
// TODO: is the track already actually a patched track?
// see dynamic_pointer_cast
patched_track_.reset(new PCMPatchedTrack(track_));
// Avoid creating a new patched track if this one is already patched
patched_track_ = std::dynamic_pointer_cast<PCMPatchedTrack>(track_);
if(!patched_track_)
{
patched_track_.reset(new PCMPatchedTrack(track_));
}
}
patched_track_->add_segment(write_start_time_, write_segment_);
invalidate_track(); // TEMPORARY: to force a seek
}
#pragma mark - PLL control and delegate

View File

@ -110,6 +110,7 @@ class Controller: public DigitalPhaseLockedLoop::Delegate, public TimedEventLoop
void step(int direction);
virtual bool get_drive_is_ready();
bool get_drive_is_read_only();
Time get_time_into_track();
private:
Time bit_length_;
@ -135,7 +136,6 @@ class Controller: public DigitalPhaseLockedLoop::Delegate, public TimedEventLoop
Time cycles_per_bit_;
void setup_track();
Time get_time_into_track();
};
}

View File

@ -43,8 +43,7 @@ void PCMPatchedTrack::add_segment(const Time &start_time, const PCMSegment &segm
// the vector may have been resized, potentially invalidating active_period_ even if
// the thing it pointed to is still the same thing. So work it out afresh.
active_period_ = periods_.begin();
while(active_period_->start_time > current_time_) active_period_++;
insertion_error_ = current_time_ - seek_to(current_time_);
}
void PCMPatchedTrack::insert_period(const Period &period)
@ -155,7 +154,8 @@ Track::Event PCMPatchedTrack::get_next_event()
else event = underlying_track_->get_next_event();
// see what time that gets us to. If it's still within the current period, return the found event
Time event_time = current_time_ + event.length - period_error;
Time event_time = current_time_ + event.length - period_error - insertion_error_;
insertion_error_.set_zero();
if(event_time < active_period_->end_time)
{
current_time_ = event_time;

View File

@ -52,7 +52,7 @@ class PCMPatchedTrack: public Track {
};
std::vector<Period> periods_;
std::vector<Period>::iterator active_period_;
Time current_time_;
Time current_time_, insertion_error_;
void insert_period(const Period &period);
};