1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 08:49:37 +00:00

Switches the drive-speed accumulator to the delegate pattern.

This allows the Macintosh to ensure that the IWM is kept up just-in-time with drive speed changes.
This commit is contained in:
Thomas Harte 2019-08-07 21:39:23 -04:00
parent f26a200d78
commit bac0461f7f
3 changed files with 21 additions and 20 deletions

View File

@ -11,7 +11,7 @@
using namespace Apple::Macintosh; using namespace Apple::Macintosh;
void DriveSpeedAccumulator::post_sample(uint8_t sample) { 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 // An Euler-esque approximation is used here: just collect all
// the samples until there is a certain small quantity of them, // 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 normalised_sum = float(sum) / float(samples_.size());
const float rotation_speed = (normalised_sum * 27.08f) - 259.0f; const float rotation_speed = (normalised_sum * 27.08f) - 259.0f;
for(int c = 0; c < number_of_drives_; ++c) { delegate_->drive_speed_accumulator_set_drive_speed(this, rotation_speed);
drives_[c]->set_rotation_speed(rotation_speed);
}
// printf("RPM: %0.2f (%d sum)\n", rotation_speed, sum);
} }
} }
void DriveSpeedAccumulator::add_drive(Apple::Macintosh::DoubleDensityDrive *drive) {
drives_[number_of_drives_] = drive;
++number_of_drives_;
}

View File

@ -13,8 +13,6 @@
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include "../../../Components/DiskII/MacintoshDoubleDensityDrive.hpp"
namespace Apple { namespace Apple {
namespace Macintosh { namespace Macintosh {
@ -25,18 +23,20 @@ class DriveSpeedAccumulator {
*/ */
void post_sample(uint8_t sample); 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 Sets the delegate to receive drive speed changes.
can be supplied. Only Macintosh DoubleDensityDrives
are supported.
*/ */
void add_drive(Apple::Macintosh::DoubleDensityDrive *drive); void set_delegate(Delegate *delegate) {
delegate_ = delegate;;
}
private: private:
std::array<uint8_t, 20> samples_; std::array<uint8_t, 20> samples_;
std::size_t sample_pointer_ = 0; std::size_t sample_pointer_ = 0;
Apple::Macintosh::DoubleDensityDrive *drives_[2] = {nullptr, nullptr}; Delegate *delegate_ = nullptr;
int number_of_drives_ = 0;
}; };
} }

View File

@ -57,7 +57,8 @@ template <Analyser::Static::Macintosh::Target::Model model> class ConcreteMachin
public CPU::MC68000::BusHandler, public CPU::MC68000::BusHandler,
public KeyboardMachine::MappedMachine, public KeyboardMachine::MappedMachine,
public Zilog::SCC::z8530::Delegate, public Zilog::SCC::z8530::Delegate,
public Activity::Source { public Activity::Source,
public DriveSpeedAccumulator::Delegate {
public: public:
using Target = Analyser::Static::Macintosh::Target; using Target = Analyser::Static::Macintosh::Target;
@ -119,8 +120,9 @@ template <Analyser::Static::Macintosh::Target::Model model> class ConcreteMachin
iwm_->set_drive(1, &drives_[1]); iwm_->set_drive(1, &drives_[1]);
// If they are 400kb drives, also attach them to the drive-speed accumulator. // 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_[0].is_800k() || !drives_[1].is_800k()) {
if(!drives_[1].is_800k()) drive_speed_accumulator_.add_drive(&drives_[1]); drive_speed_accumulator_.set_delegate(this);
}
// Make sure interrupt changes from the SCC are observed. // Make sure interrupt changes from the SCC are observed.
scc_.set_delegate(this); scc_.set_delegate(this);
@ -444,6 +446,12 @@ template <Analyser::Static::Macintosh::Target::Model model> class ConcreteMachin
} }
private: 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() { forceinline void adjust_phase() {
++phase_; ++phase_;
} }