1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-03 23:06:18 +00:00

Clarify logic somewhat.

This commit is contained in:
Thomas Harte 2021-10-05 15:20:05 -07:00
parent 1180ad7662
commit 2cf5bcc5db

View File

@ -1036,23 +1036,23 @@ void Chipset::DiskController::set_mtr_sel_side_dir_step(uint8_t value) {
// Check for changes in the SEL line per drive. // Check for changes in the SEL line per drive.
const bool motor_on = !(value & 0x80); const bool motor_on = !(value & 0x80);
const int side = (value & 0x04) ? 0 : 1; const int side = (value & 0x04) ? 0 : 1;
const auto step = Storage::Disk::HeadPosition( const bool did_step = (difference & 0x1) && !(value & 0x1);
((difference & 0x1) && !(value & 0x1)) ? const auto direction = Storage::Disk::HeadPosition(
((value & 0x02) ? -1 : 1) : 0 (value & 0x02) ? -1 : 1
); );
for(int c = 0; c < 4; c++) { for(int c = 0; c < 4; c++) {
auto drive = get_drive(size_t(c)); auto drive = get_drive(size_t(c));
// If drive went from unselected to selected, latch
// the new motor value; if the motor goes active,
// reset the drive ID shift register.
const int select_mask = 0x08 << c; const int select_mask = 0x08 << c;
const bool is_selected = !(value & select_mask);
// Both the motor state and the ID shifter are affected upon
// changes in drive selection only.
if(difference & select_mask) { if(difference & select_mask) {
// If transitioning to inactive, shift the drive ID value; // If transitioning to inactive, shift the drive ID value;
// if transitioning to active, possibly reset the drive // if transitioning to active, possibly reset the drive
// ID and definitely latch the new motor state. // ID and definitely latch the new motor state.
if(value & select_mask) { if(!is_selected) {
drive_ids_[c] <<= 1; drive_ids_[c] <<= 1;
LOG("Shifted drive ID shift register for drive " << +c); LOG("Shifted drive ID shift register for drive " << +c);
} else { } else {
@ -1075,9 +1075,9 @@ void Chipset::DiskController::set_mtr_sel_side_dir_step(uint8_t value) {
drive.set_head(side); drive.set_head(side);
// Possibly step. // Possibly step.
if(step.as_int() && !(value & select_mask)) { if(did_step && is_selected) {
LOG("Stepped drive " << +c << " by " << step.as_int()); LOG("Stepped drive " << +c << " by " << direction.as_int());
drive.step(step); drive.step(direction);
} }
} }
} }