1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-02-16 18:30:32 +00:00

Extended to permit subclasses that are interested to get sub-run_for information about event times.

This commit is contained in:
Thomas Harte 2017-09-10 14:44:38 -04:00
parent 90c7056d12
commit 90d2347c90
2 changed files with 21 additions and 3 deletions

View File

@ -16,10 +16,19 @@ TimedEventLoop::TimedEventLoop(unsigned int input_clock_rate) :
input_clock_rate_(input_clock_rate) {}
void TimedEventLoop::run_for(const Cycles cycles) {
cycles_until_event_ -= cycles.as_int();
while(cycles_until_event_ <= 0) {
int remaining_cycles = cycles.as_int();
while(cycles_until_event_ <= remaining_cycles) {
advance(cycles_until_event_);
remaining_cycles -= cycles_until_event_;
cycles_until_event_ = 0;
process_next_event();
}
if(remaining_cycles) {
cycles_until_event_ -= remaining_cycles;
advance(remaining_cycles);
}
}
unsigned int TimedEventLoop::get_cycles_until_next_event() {
@ -52,7 +61,7 @@ void TimedEventLoop::set_next_event_time_interval(Time interval) {
// So this event will fire in the integral number of cycles from now, putting us at the remainder
// number of subcycles
cycles_until_event_ = (int)(numerator / denominator);
cycles_until_event_ += (int)(numerator / denominator);
subcycles_until_event_.length = (unsigned int)(numerator % denominator);
subcycles_until_event_.clock_rate = (unsigned int)denominator;
}

View File

@ -66,6 +66,15 @@ namespace Storage {
*/
virtual void process_next_event() = 0;
/*!
Optionally allows a subclass to track time within run_for periods; if a subclass implements
advnace then it will receive advance increments that add up to the number of cycles supplied
to run_for, but calls to process_next_event will be precisely interspersed. No time will carry
forward between calls into run_for; a subclass can receive arbitrarily many instructions to
advance before receiving a process_next_event.
*/
virtual void advance(const Cycles cycles) {};
/*!
Resets timing, throwing away any current internal state. So clears any fractional ticks
that the event loop is currently tracking.