1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-11 08:30:55 +00:00

At the cost of extra storage, attempts to simplify away potential rounding issues around the index hole.

This commit is contained in:
Thomas Harte 2019-07-26 17:20:32 -04:00
parent 9b634472c6
commit 572e8b52e1
2 changed files with 12 additions and 3 deletions

View File

@ -38,10 +38,15 @@ Drive::Drive(int input_clock_rate, int revolutions_per_minute, int number_of_hea
Drive::Drive(int input_clock_rate, int number_of_heads) : Drive(input_clock_rate, 300, number_of_heads) {}
void Drive::set_rotation_speed(float revolutions_per_minute) {
const float new_rotational_multiplier = 60.0f / revolutions_per_minute;
// Rationalise the supplied speed so that cycles_per_revolution_ is exact.
cycles_per_revolution_ = int(0.5f + float(get_input_clock_rate()) * 60.0f / revolutions_per_minute);
// From there derive the appropriate rotational multiplier and possibly update the
// count of cycles since the index hole proportionally.
const float new_rotational_multiplier = float(cycles_per_revolution_) / float(get_input_clock_rate());
cycles_since_index_hole_ *= new_rotational_multiplier / rotational_multiplier_;
rotational_multiplier_ = new_rotational_multiplier;
cycles_since_index_hole_ %= int(get_input_clock_rate() * rotational_multiplier_);
cycles_since_index_hole_ %= cycles_per_revolution_;
}
Drive::~Drive() {
@ -358,7 +363,7 @@ void Drive::end_writing() {
}
}
patched_track_->add_segment(write_start_time_, write_segment_, clamp_writing_to_index_hole_);
cycles_since_index_hole_ %= int(get_input_clock_rate() * rotational_multiplier_);
cycles_since_index_hole_ %= cycles_per_revolution_;
invalidate_track();
}
}

View File

@ -198,6 +198,10 @@ class Drive: public ClockingHint::Source, public TimedEventLoop {
// a new track.
int cycles_since_index_hole_ = 0;
// The number of cycles that should fall within one revolution at the
// current rotation speed.
int cycles_per_revolution_ = 1;
// A record of head position and active head.
HeadPosition head_position_;
int head_ = 0;