1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-02-28 06:29:37 +00:00

Added ability to query how long since the new interval was set to the timed event loop. Discovered that LCM will returning the net effect of the common factors only. Otherwise continued iterating towards time preservation.

This commit is contained in:
Thomas Harte 2016-08-03 07:49:00 -04:00
parent a3a3486f54
commit e15241dc3c
5 changed files with 27 additions and 6 deletions

View File

@ -32,5 +32,5 @@ 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);
return (a / gcd) * (b / gcd) * gcd;
}

View File

@ -51,7 +51,7 @@ void DiskDrive::step(int direction)
_head_position = std::max(_head_position + direction, 0);
// TODO: add fractional part to _time_into_track
_time_into_track += get_time_into_next_event();
// TODO: probably a better implementation of the empty track?
// Time offset;
// if(_track)
@ -118,7 +118,7 @@ void DiskDrive::process_next_event()
{
case Track::Event::FluxTransition:
_pll->add_pulse();
_time_into_track = _time_into_track + _current_event.length;
_time_into_track += _current_event.length;
break;
case Track::Event::IndexHole:
_cycles_since_index_hole = 0;

View File

@ -40,12 +40,12 @@ struct Time {
return (float)length / (float)clock_rate;
}
inline bool operator<(Time &other)
inline bool operator<(Time other)
{
return other.clock_rate * length < clock_rate * other.length;
}
inline Time operator+(Time &other)
inline Time operator+(Time other)
{
Time result;
result.clock_rate = NumberTheory::least_common_multiple(clock_rate, other.clock_rate);
@ -53,7 +53,15 @@ struct Time {
return result;
}
inline Time operator-(Time &other)
inline Time &operator +=(Time other)
{
unsigned int combined_clock_rate = NumberTheory::least_common_multiple(clock_rate, other.clock_rate);
length = length * (combined_clock_rate / clock_rate) + other.length * (combined_clock_rate / other.clock_rate);
clock_rate = combined_clock_rate;
return *this;
}
inline Time operator-(Time other)
{
Time result;
result.clock_rate = NumberTheory::least_common_multiple(clock_rate, other.clock_rate);

View File

@ -70,3 +70,10 @@ void TimedEventLoop::set_next_event_time_interval(Time interval)
_stepper.reset(new SignalProcessing::Stepper(_event_interval.clock_rate, _input_clock_rate));
}
}
Time TimedEventLoop::get_time_into_next_event()
{
Time result = _event_interval;
result.length = _time_into_interval;
return result;
}

View File

@ -73,6 +73,12 @@ namespace Storage {
*/
void jump_to_next_event();
/*!
@returns the amount of time that has passed since the last call to @c set_next_time_interval,
which will always be less than or equal to the time that was supplied to @c set_next_time_interval.
*/
Time get_time_into_next_event();
private:
unsigned int _input_clock_rate;
Time _event_interval;