1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-25 03:32:01 +00:00

Adjusted stepper logic; some disks load now.

This commit is contained in:
Thomas Harte 2018-04-25 21:59:18 -04:00
parent c90e122eb2
commit d59db504a3
3 changed files with 15 additions and 16 deletions

View File

@ -24,8 +24,6 @@ DiskII::DiskII() :
} }
void DiskII::set_control(Control control, bool on) { void DiskII::set_control(Control control, bool on) {
printf("Set control %d %s\n", control, on ? "on" : "off");
int previous_stepper_mask = stepper_mask_; int previous_stepper_mask = stepper_mask_;
switch(control) { switch(control) {
case Control::P0: stepper_mask_ = (stepper_mask_ & 0xe) | (on ? 0x1 : 0x0); break; case Control::P0: stepper_mask_ = (stepper_mask_ & 0xe) | (on ? 0x1 : 0x0); break;
@ -40,41 +38,41 @@ void DiskII::set_control(Control control, bool on) {
break; break;
} }
// printf("%0x: Set control %d %s\n", stepper_mask_, control, on ? "on" : "off");
// If the stepper magnet selections have changed, and any is on, see how // If the stepper magnet selections have changed, and any is on, see how
// that moves the head. // that moves the head.
if(previous_stepper_mask ^ stepper_mask_ && stepper_mask_) { if(previous_stepper_mask ^ stepper_mask_ && stepper_mask_) {
// Convert from a representation of bits set to the centre of pull. // Convert from a representation of bits set to the centre of pull.
int position = 0; int direction = 0;
if(stepper_mask_&2) position += 2; if(stepper_mask_&1) direction += (((stepper_position_ - 0) + 4)&7) - 4;
if(stepper_mask_&4) position += 4; if(stepper_mask_&2) direction += (((stepper_position_ - 2) + 4)&7) - 4;
if(stepper_mask_&8) position += 6; if(stepper_mask_&4) direction += (((stepper_position_ - 4) + 4)&7) - 4;
// TODO: both 0 and 4 turned on should produce position 7 if(stepper_mask_&8) direction += (((stepper_position_ - 6) + 4)&7) - 4;
const int bits_set = (stepper_mask_&1) + ((stepper_mask_ >> 1)&1) + ((stepper_mask_ >> 2)&1) + ((stepper_mask_ >> 3)&1); const int bits_set = (stepper_mask_&1) + ((stepper_mask_ >> 1)&1) + ((stepper_mask_ >> 2)&1) + ((stepper_mask_ >> 3)&1);
position /= bits_set; direction /= bits_set;
// Compare to the stepper position to decide whether that pulls in the current cog notch, // Compare to the stepper position to decide whether that pulls in the current cog notch,
// or grabs a later one. // or grabs a later one.
int change = ((position - stepper_position_ + 4)&7) - 4; drives_[active_drive_].step(-direction);
drives_[active_drive_].step(change); stepper_position_ = (stepper_position_ - direction + 8) & 7;
stepper_position_ = position;
} }
} }
void DiskII::set_mode(Mode mode) { void DiskII::set_mode(Mode mode) {
printf("Set mode %d\n", mode); // printf("Set mode %d\n", mode);
inputs_ = (inputs_ & ~input_mode) | ((mode == Mode::Write) ? input_mode : 0); inputs_ = (inputs_ & ~input_mode) | ((mode == Mode::Write) ? input_mode : 0);
} }
void DiskII::select_drive(int drive) { void DiskII::select_drive(int drive) {
printf("Select drive %d\n", drive); // printf("Select drive %d\n", drive);
active_drive_ = drive & 1; active_drive_ = drive & 1;
drives_[active_drive_].set_event_delegate(this); drives_[active_drive_].set_event_delegate(this);
drives_[active_drive_^1].set_event_delegate(nullptr); drives_[active_drive_^1].set_event_delegate(nullptr);
} }
void DiskII::set_data_register(uint8_t value) { void DiskII::set_data_register(uint8_t value) {
printf("Set data register (?)\n"); // printf("Set data register (?)\n");
inputs_ |= input_command; inputs_ |= input_command;
data_register_ = value; data_register_ = value;
} }

View File

@ -48,9 +48,9 @@ bool Drive::get_is_track_zero() {
} }
void Drive::step(int direction) { void Drive::step(int direction) {
printf("Step %d\n", direction);
int old_head_position = head_position_; int old_head_position = head_position_;
head_position_ = std::max(head_position_ + direction, 0); head_position_ = std::max(head_position_ + direction, 0);
// printf("Step %d -> %d\n", direction, head_position_);
// If the head moved, flush the old track. // If the head moved, flush the old track.
if(head_position_ != old_head_position) { if(head_position_ != old_head_position) {

View File

@ -90,6 +90,7 @@ void TimedEventLoop::set_next_event_time_interval(Time interval) {
// If even that doesn't work then reduce precision. // If even that doesn't work then reduce precision.
if(numerator < 0 || denominator < 0 || denominator > std::numeric_limits<int>::max()) { if(numerator < 0 || denominator < 0 || denominator > std::numeric_limits<int>::max()) {
// printf(".");
const double double_interval = interval.get<double>(); const double double_interval = interval.get<double>();
const double double_subcycles_remaining = subcycles_until_event_.get<double>(); const double double_subcycles_remaining = subcycles_until_event_.get<double>();
const double output = double_interval * static_cast<double>(input_clock_rate_) + double_subcycles_remaining; const double output = double_interval * static_cast<double>(input_clock_rate_) + double_subcycles_remaining;