diff --git a/Components/1770/1770.cpp b/Components/1770/1770.cpp index d465c3578..a725a4770 100644 --- a/Components/1770/1770.cpp +++ b/Components/1770/1770.cpp @@ -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; } diff --git a/Storage/Disk/DiskController.cpp b/Storage/Disk/DiskController.cpp index 5c61311fe..47c971a22 100644 --- a/Storage/Disk/DiskController.cpp +++ b/Storage/Disk/DiskController.cpp @@ -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(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 diff --git a/Storage/Disk/DiskController.hpp b/Storage/Disk/DiskController.hpp index a39b74b48..19e9e8755 100644 --- a/Storage/Disk/DiskController.hpp +++ b/Storage/Disk/DiskController.hpp @@ -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(); }; } diff --git a/Storage/Disk/PCMPatchedTrack.cpp b/Storage/Disk/PCMPatchedTrack.cpp index 71ef0de86..a70ec9da9 100644 --- a/Storage/Disk/PCMPatchedTrack.cpp +++ b/Storage/Disk/PCMPatchedTrack.cpp @@ -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; diff --git a/Storage/Disk/PCMPatchedTrack.hpp b/Storage/Disk/PCMPatchedTrack.hpp index 83182b39b..2ea8ffd04 100644 --- a/Storage/Disk/PCMPatchedTrack.hpp +++ b/Storage/Disk/PCMPatchedTrack.hpp @@ -52,7 +52,7 @@ class PCMPatchedTrack: public Track { }; std::vector periods_; std::vector::iterator active_period_; - Time current_time_; + Time current_time_, insertion_error_; void insert_period(const Period &period); };