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

Puts the disk controller back into the loop with knowledge about reading mode, and uses that knowledge to cut off the PLL.

This commit is contained in:
Thomas Harte 2017-09-14 22:30:40 -04:00
parent b62f3e726a
commit 4d4a0cf1d2
4 changed files with 37 additions and 13 deletions

View File

@ -541,7 +541,7 @@ void WD1770::posit_event(int new_event_type) {
});
WAIT_FOR_EVENT(Event::DataWritten);
if(status_.data_request) {
get_drive().end_writing();
end_writing();
update_status([] (Status &status) {
status.lost_data = true;
});
@ -554,7 +554,7 @@ void WD1770::posit_event(int new_event_type) {
write_crc();
write_byte(0xff);
WAIT_FOR_EVENT(Event::DataWritten);
get_drive().end_writing();
end_writing();
if(command_ & 0x10) {
sector_++;
@ -755,11 +755,11 @@ void WD1770::posit_event(int new_event_type) {
update_status([] (Status &status) {
status.lost_data = true;
});
get_drive().end_writing();
end_writing();
goto wait_for_command;
}
if(index_hole_count_) {
get_drive().end_writing();
end_writing();
goto wait_for_command;
}

View File

@ -525,7 +525,7 @@ void i8272::posit_event(int event_type) {
WAIT_FOR_EVENT(Event::DataWritten);
if(!has_input_) {
SetOverrun();
get_drive().end_writing();
end_writing();
goto abort;
}
write_byte(input_);
@ -540,7 +540,7 @@ void i8272::posit_event(int event_type) {
write_crc();
expects_input_ = false;
WAIT_FOR_EVENT(Event::DataWritten);
get_drive().end_writing();
end_writing();
if(sector_ != command_[6]) {
sector_++;
@ -646,7 +646,7 @@ void i8272::posit_event(int event_type) {
switch(event_type) {
case (int)Event::IndexHole:
SetOverrun();
get_drive().end_writing();
end_writing();
goto abort;
break;
case (int)Event::DataWritten:
@ -683,7 +683,7 @@ void i8272::posit_event(int event_type) {
WAIT_FOR_EVENT((int)Event::DataWritten | (int)Event::IndexHole);
if(event_type != (int)Event::IndexHole) goto format_track_pad;
get_drive().end_writing();
end_writing();
cylinder_ = header_[0];
head_ = header_[1];

View File

@ -48,7 +48,7 @@ void Controller::process_event(const Track::Event &event) {
}
void Controller::advance(const Cycles cycles) {
pll_->run_for(Cycles(cycles.as_int() * clock_rate_multiplier_));
if(is_reading_) pll_->run_for(Cycles(cycles.as_int() * clock_rate_multiplier_));
}
void Controller::process_write_completed() {
@ -72,7 +72,7 @@ void Controller::set_expected_bit_length(Time bit_length) {
}
void Controller::digital_phase_locked_loop_output_bit(int value) {
process_input_bit(value);
if(is_reading_) process_input_bit(value);
}
void Controller::set_drive(std::shared_ptr<Drive> drive) {
@ -99,5 +99,15 @@ void Controller::set_drive(std::shared_ptr<Drive> drive) {
}
void Controller::begin_writing(bool clamp_to_index_hole) {
is_reading_ = false;
get_drive().begin_writing(bit_length_, clamp_to_index_hole);
}
void Controller::end_writing() {
is_reading_ = true;
get_drive().end_writing();
}
bool Controller::is_reading() {
return is_reading_;
}

View File

@ -68,13 +68,25 @@ class Controller: public DigitalPhaseLockedLoop::Delegate, public Drive::EventDe
virtual void process_write_completed();
/*!
Puts the drive returned by get_drive() into write mode, supplying the current bit length.
Puts the drive returned by get_drive() into write mode, supplying the current bit length
and marks the controller as being in write mode.
@param clamp_to_index_hole If @c true then writing will automatically be truncated by
the index hole. Writing will continue over the index hole otherwise.
*/
void begin_writing(bool clamp_to_index_hole);
/*!
Puts the drive returned by get_drive() out of write mode, and marks the controller
as no longer being in write mode.
*/
void end_writing();
/*!
@returns @c true if the controller is in reading mode; @c false otherwise.
*/
bool is_reading();
/*!
Returns the connected drive or, if none is connected, an invented one. No guarantees are
made about the lifetime or the exclusivity of the invented drive.
@ -85,8 +97,10 @@ class Controller: public DigitalPhaseLockedLoop::Delegate, public Drive::EventDe
private:
Time bit_length_;
int clock_rate_multiplier_;
int clock_rate_;
int clock_rate_multiplier_ = 1;
int clock_rate_ = 1;
bool is_reading_ = true;
std::shared_ptr<DigitalPhaseLockedLoop> pll_;
std::shared_ptr<Drive> drive_;