diff --git a/NumberTheory/Factors.cpp b/NumberTheory/Factors.cpp index 4c44cfbfc..59f65709f 100644 --- a/NumberTheory/Factors.cpp +++ b/NumberTheory/Factors.cpp @@ -29,6 +29,8 @@ unsigned int NumberTheory::greatest_common_divisor(unsigned int a, unsigned int unsigned int NumberTheory::least_common_multiple(unsigned int a, unsigned int b) { + if(a == b) return a; + unsigned int gcd = greatest_common_divisor(a, b); return (a / gcd) * (b / gcd); } diff --git a/Storage/Disk/DiskDrive.cpp b/Storage/Disk/DiskDrive.cpp index 90a11a977..9c255b988 100644 --- a/Storage/Disk/DiskDrive.cpp +++ b/Storage/Disk/DiskDrive.cpp @@ -101,9 +101,11 @@ void DiskDrive::process_next_event() { case Track::Event::FluxTransition: _pll->add_pulse(); + _time_into_track = _time_into_track + _current_event.length; break; case Track::Event::IndexHole: _cycles_since_index_hole = 0; + _time_into_track.set_zero(); process_index_hole(); break; } diff --git a/Storage/Disk/DiskDrive.hpp b/Storage/Disk/DiskDrive.hpp index c207a2729..581b34998 100644 --- a/Storage/Disk/DiskDrive.hpp +++ b/Storage/Disk/DiskDrive.hpp @@ -103,6 +103,7 @@ class DiskDrive: public DigitalPhaseLockedLoop::Delegate, public TimedEventLoop inline void get_next_event(); Track::Event _current_event; + Time _time_into_track; }; } diff --git a/Storage/Storage.hpp b/Storage/Storage.hpp index 74852f5a1..34f952f8e 100644 --- a/Storage/Storage.hpp +++ b/Storage/Storage.hpp @@ -49,9 +49,21 @@ struct Time { { Time result; result.clock_rate = NumberTheory::least_common_multiple(clock_rate, other.clock_rate); - result.length = length * (clock_rate / result.clock_rate) + other.length * (other.clock_rate / result.clock_rate); + result.length = length * (result.clock_rate / clock_rate) + other.length * (result.clock_rate / other.clock_rate); return result; } + + inline void set_zero() + { + length = 0; + clock_rate = 1; + } + + inline void set_one() + { + length = 1; + clock_rate = 1; + } };