diff --git a/Machines/Apple/Macintosh/DriveSpeedAccumulator.cpp b/Machines/Apple/Macintosh/DriveSpeedAccumulator.cpp index f51f0f5a7..b4277def4 100644 --- a/Machines/Apple/Macintosh/DriveSpeedAccumulator.cpp +++ b/Machines/Apple/Macintosh/DriveSpeedAccumulator.cpp @@ -11,7 +11,7 @@ using namespace Apple::Macintosh; void DriveSpeedAccumulator::post_sample(uint8_t sample) { - if(!number_of_drives_) return; + if(!delegate_) return; // An Euler-esque approximation is used here: just collect all // the samples until there is a certain small quantity of them, @@ -50,14 +50,7 @@ void DriveSpeedAccumulator::post_sample(uint8_t sample) { const float normalised_sum = float(sum) / float(samples_.size()); const float rotation_speed = (normalised_sum * 27.08f) - 259.0f; - for(int c = 0; c < number_of_drives_; ++c) { - drives_[c]->set_rotation_speed(rotation_speed); - } -// printf("RPM: %0.2f (%d sum)\n", rotation_speed, sum); + delegate_->drive_speed_accumulator_set_drive_speed(this, rotation_speed); } } -void DriveSpeedAccumulator::add_drive(Apple::Macintosh::DoubleDensityDrive *drive) { - drives_[number_of_drives_] = drive; - ++number_of_drives_; -} diff --git a/Machines/Apple/Macintosh/DriveSpeedAccumulator.hpp b/Machines/Apple/Macintosh/DriveSpeedAccumulator.hpp index 18a8d41b8..f626217d1 100644 --- a/Machines/Apple/Macintosh/DriveSpeedAccumulator.hpp +++ b/Machines/Apple/Macintosh/DriveSpeedAccumulator.hpp @@ -13,8 +13,6 @@ #include #include -#include "../../../Components/DiskII/MacintoshDoubleDensityDrive.hpp" - namespace Apple { namespace Macintosh { @@ -25,18 +23,20 @@ class DriveSpeedAccumulator { */ void post_sample(uint8_t sample); + struct Delegate { + virtual void drive_speed_accumulator_set_drive_speed(DriveSpeedAccumulator *, float speed) = 0; + }; /*! - Adds a connected drive. Up to two of these - can be supplied. Only Macintosh DoubleDensityDrives - are supported. + Sets the delegate to receive drive speed changes. */ - void add_drive(Apple::Macintosh::DoubleDensityDrive *drive); + void set_delegate(Delegate *delegate) { + delegate_ = delegate;; + } private: std::array samples_; std::size_t sample_pointer_ = 0; - Apple::Macintosh::DoubleDensityDrive *drives_[2] = {nullptr, nullptr}; - int number_of_drives_ = 0; + Delegate *delegate_ = nullptr; }; } diff --git a/Machines/Apple/Macintosh/Macintosh.cpp b/Machines/Apple/Macintosh/Macintosh.cpp index 89b303775..16d8c6bef 100644 --- a/Machines/Apple/Macintosh/Macintosh.cpp +++ b/Machines/Apple/Macintosh/Macintosh.cpp @@ -57,7 +57,8 @@ template class ConcreteMachin public CPU::MC68000::BusHandler, public KeyboardMachine::MappedMachine, public Zilog::SCC::z8530::Delegate, - public Activity::Source { + public Activity::Source, + public DriveSpeedAccumulator::Delegate { public: using Target = Analyser::Static::Macintosh::Target; @@ -119,8 +120,9 @@ template class ConcreteMachin iwm_->set_drive(1, &drives_[1]); // If they are 400kb drives, also attach them to the drive-speed accumulator. - if(!drives_[0].is_800k()) drive_speed_accumulator_.add_drive(&drives_[0]); - if(!drives_[1].is_800k()) drive_speed_accumulator_.add_drive(&drives_[1]); + if(!drives_[0].is_800k() || !drives_[1].is_800k()) { + drive_speed_accumulator_.set_delegate(this); + } // Make sure interrupt changes from the SCC are observed. scc_.set_delegate(this); @@ -444,6 +446,12 @@ template class ConcreteMachin } private: + void drive_speed_accumulator_set_drive_speed(DriveSpeedAccumulator *, float speed) override { + iwm_.flush(); + drives_[0].set_rotation_speed(speed); + drives_[1].set_rotation_speed(speed); + } + forceinline void adjust_phase() { ++phase_; }