diff --git a/Storage/Disk/Drive.cpp b/Storage/Disk/Drive.cpp index 42ad569c9..931877bd1 100644 --- a/Storage/Disk/Drive.cpp +++ b/Storage/Disk/Drive.cpp @@ -33,7 +33,7 @@ Drive::Drive( // Get at least 64 bits of random information; rounding is likey to give this a slight bias. random_source_ = 0; - auto half_range = (randomiser.max() - randomiser.min()) / 2; + const auto half_range = (randomiser.max() - randomiser.min()) / 2; for(int bit = 0; bit < 64; ++bit) { random_source_ <<= 1; random_source_ |= ((randomiser() - randomiser.min()) >= half_range) ? 1 : 0; @@ -233,11 +233,11 @@ void Drive::run_for(const Cycles cycles) { if(disk_is_rotating_) { if(has_disk_) { - Time zero(0); + static constexpr Time zero(0); auto number_of_cycles = cycles.get(); while(number_of_cycles) { - auto cycles_until_next_event = get_cycles_until_next_event(); + const auto cycles_until_next_event = get_cycles_until_next_event(); auto cycles_to_run_for = std::min(cycles_until_next_event, number_of_cycles); if(!is_reading_ && cycles_until_bits_written_ > zero) { auto write_cycles_target = cycles_until_bits_written_.get(); @@ -248,7 +248,7 @@ void Drive::run_for(const Cycles cycles) { number_of_cycles -= cycles_to_run_for; if(!is_reading_) { if(cycles_until_bits_written_ > zero) { - Storage::Time cycles_to_run_for_time(static_cast(cycles_to_run_for)); + const Storage::Time cycles_to_run_for_time(static_cast(cycles_to_run_for)); if(cycles_until_bits_written_ <= cycles_to_run_for_time) { cycles_until_bits_written_.set_zero(); if(event_delegate_) { @@ -347,7 +347,10 @@ void Drive::get_next_event(const float duration_already_passed) { void Drive::process_next_event() { if(current_event_.type == Track::Event::IndexHole) { ++ready_index_count_; - if(ready_index_count_ == 2 && (ready_type_ == ReadyType::ShugartRDY || ready_type_ == ReadyType::ShugartModifiedRDY)) { + if( + ready_index_count_ == 2 && + (ready_type_ == ReadyType::ShugartRDY || ready_type_ == ReadyType::ShugartModifiedRDY) + ) { is_ready_ = true; } cycles_since_index_hole_ = 0; diff --git a/Storage/TimedEventLoop.cpp b/Storage/TimedEventLoop.cpp index 89a3fb15e..782e91c4b 100644 --- a/Storage/TimedEventLoop.cpp +++ b/Storage/TimedEventLoop.cpp @@ -14,7 +14,7 @@ using namespace Storage; -TimedEventLoop::TimedEventLoop(Cycles::IntType input_clock_rate) : +TimedEventLoop::TimedEventLoop(const Cycles::IntType input_clock_rate) : input_clock_rate_(input_clock_rate) {} void TimedEventLoop::add_delay(const Cycles cycles) { @@ -73,24 +73,36 @@ void TimedEventLoop::jump_to_next_event() { process_next_event(); } -void TimedEventLoop::set_next_event_time_interval(Time interval) { +void TimedEventLoop::set_next_event_time_interval(const Time interval) { set_next_event_time_interval(interval.get()); } -void TimedEventLoop::set_next_event_time_interval(float interval) { +void TimedEventLoop::set_next_event_time_interval(const float interval) { // Calculate [interval]*[input clock rate] + [subcycles until this event] - const float float_interval = interval * float(input_clock_rate_) + subcycles_until_event_; + const float cycles = interval * float(input_clock_rate_) + subcycles_until_event_; // This event will fire in the integral number of cycles from now, putting us at the remainder // number of subcycles. - const Cycles::IntType addition = Cycles::IntType(float_interval); + const Cycles::IntType addition = Cycles::IntType(cycles); cycles_until_event_ += addition; - subcycles_until_event_ = fmodf(float_interval, 1.0f); + subcycles_until_event_ = std::fmod(cycles, 1.0f); + +#ifndef NDEBUG + cycles_total_ += addition; +#endif assert(cycles_until_event_ >= 0); assert(subcycles_until_event_ >= 0.0f); } +#ifndef NDEBUG +float TimedEventLoop::get_reset_cycles_total() { + const auto result = cycles_total_; + cycles_total_ = 0; + return result; +} +#endif + Time TimedEventLoop::get_time_into_next_event() { // TODO: calculate, presumably as [length of interval] - ([cycles left] + [subcycles left]) Time zero; diff --git a/Storage/TimedEventLoop.hpp b/Storage/TimedEventLoop.hpp index f7e280aea..fa42a68ed 100644 --- a/Storage/TimedEventLoop.hpp +++ b/Storage/TimedEventLoop.hpp @@ -111,12 +111,17 @@ protected: */ Time get_time_into_next_event(); +#ifndef NDEBUG + float get_reset_cycles_total(); +#endif + private: Cycles::IntType input_clock_rate_ = 0; Cycles::IntType cycles_until_event_ = 0; float subcycles_until_event_ = 0.0f; #ifndef NDEBUG int event_count_ = 0; + float cycles_total_ = 0.0f; #endif };