mirror of
https://github.com/TomHarte/CLK.git
synced 2026-04-20 10:17:05 +00:00
Fixes extra time accumulation during track running.
Introduces a bunch of further asserts, which aided me in determining the fix, i.e. that Drives being responsible for their own setup_track could double-pump the event loop.
This commit is contained in:
@@ -8,7 +8,9 @@
|
||||
|
||||
#include "TimedEventLoop.hpp"
|
||||
#include "../NumberTheory/Factors.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
using namespace Storage;
|
||||
|
||||
@@ -17,8 +19,14 @@ TimedEventLoop::TimedEventLoop(unsigned int input_clock_rate) :
|
||||
|
||||
void TimedEventLoop::run_for(const Cycles cycles) {
|
||||
int remaining_cycles = cycles.as_int();
|
||||
#ifndef NDEBUG
|
||||
int cycles_advanced = 0;
|
||||
#endif
|
||||
|
||||
while(cycles_until_event_ <= remaining_cycles) {
|
||||
#ifndef NDEBUG
|
||||
cycles_advanced += cycles_until_event_;
|
||||
#endif
|
||||
advance(cycles_until_event_);
|
||||
remaining_cycles -= cycles_until_event_;
|
||||
cycles_until_event_ = 0;
|
||||
@@ -27,8 +35,14 @@ void TimedEventLoop::run_for(const Cycles cycles) {
|
||||
|
||||
if(remaining_cycles) {
|
||||
cycles_until_event_ -= remaining_cycles;
|
||||
#ifndef NDEBUG
|
||||
cycles_advanced += remaining_cycles;
|
||||
#endif
|
||||
advance(remaining_cycles);
|
||||
}
|
||||
|
||||
assert(cycles_advanced == cycles.as_int());
|
||||
assert(cycles_until_event_ > 0);
|
||||
}
|
||||
|
||||
unsigned int TimedEventLoop::get_cycles_until_next_event() {
|
||||
@@ -65,7 +79,9 @@ 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
|
||||
assert(cycles_until_event_ == 0);
|
||||
cycles_until_event_ += (int)(numerator / denominator);
|
||||
assert(cycles_until_event_ >= 0);
|
||||
subcycles_until_event_.length = (unsigned int)(numerator % denominator);
|
||||
subcycles_until_event_.clock_rate = (unsigned int)denominator;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user