1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-26 09:29:45 +00:00

Merge pull request #643 from TomHarte/Mac512

Simplifies just-in-time usage of the IWM, and the disk-speed accumulator
This commit is contained in:
Thomas Harte 2019-08-07 21:51:07 -04:00 committed by GitHub
commit 4859d3781b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 45 deletions

View File

@ -21,7 +21,7 @@
Machines that accumulate HalfCycle time but supply to a Cycle-counted device may supply a
separate @c TargetTimeScale at template declaration.
*/
template <class T, class LocalTimeScale, class TargetTimeScale = LocalTimeScale> class JustInTimeActor {
template <class T, class LocalTimeScale = HalfCycles, class TargetTimeScale = LocalTimeScale> class JustInTimeActor {
public:
/// Constructs a new JustInTimeActor using the same construction arguments as the included object.
template<typename... Args> JustInTimeActor(Args&&... args) : object_(std::forward<Args>(args)...) {}
@ -60,7 +60,7 @@ template <class T, class LocalTimeScale, class TargetTimeScale = LocalTimeScale>
Any time the amount of accumulated time crosses a threshold provided at construction time,
the object will be updated on the AsyncTaskQueue.
*/
template <class T, class LocalTimeScale, class TargetTimeScale = LocalTimeScale> class AsyncJustInTimeActor {
template <class T, class LocalTimeScale = HalfCycles, class TargetTimeScale = LocalTimeScale> class AsyncJustInTimeActor {
public:
/// Constructs a new AsyncJustInTimeActor using the same construction arguments as the included object.
template<typename... Args> AsyncJustInTimeActor(TargetTimeScale threshold, Args&&... args) :

View File

@ -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_;
}

View File

@ -13,8 +13,6 @@
#include <cstddef>
#include <cstdint>
#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<uint8_t, 20> samples_;
std::size_t sample_pointer_ = 0;
Apple::Macintosh::DoubleDensityDrive *drives_[2] = {nullptr, nullptr};
int number_of_drives_ = 0;
Delegate *delegate_ = nullptr;
};
}

View File

@ -57,7 +57,8 @@ template <Analyser::Static::Macintosh::Target::Model model> 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;
@ -115,12 +116,13 @@ template <Analyser::Static::Macintosh::Target::Model model> class ConcreteMachin
Memory::Fuzz(ram_, sizeof(ram_) / sizeof(*ram_));
// Attach the drives to the IWM.
iwm_.iwm.set_drive(0, &drives_[0]);
iwm_.iwm.set_drive(1, &drives_[1]);
iwm_->set_drive(0, &drives_[0]);
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);
@ -218,11 +220,10 @@ template <Analyser::Static::Macintosh::Target::Model model> class ConcreteMachin
const int register_address = word_address >> 8;
// The IWM; this is a purely polled device, so can be run on demand.
iwm_.flush();
if(cycle.operation & Microcycle::Read) {
cycle.value->halves.low = iwm_.iwm.read(register_address);
cycle.value->halves.low = iwm_->read(register_address);
} else {
iwm_.iwm.write(register_address, cycle.value->halves.low);
iwm_->write(register_address, cycle.value->halves.low);
}
if(cycle.operation & Microcycle::SelectWord) cycle.value->halves.high = 0xff;
@ -441,10 +442,16 @@ template <Analyser::Static::Macintosh::Target::Model model> class ConcreteMachin
// MARK: - Activity Source
void set_activity_observer(Activity::Observer *observer) override {
iwm_.iwm.set_activity_observer(observer);
iwm_->set_activity_observer(observer);
}
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_;
}
@ -461,7 +468,7 @@ template <Analyser::Static::Macintosh::Target::Model model> class ConcreteMachin
/// Advances all non-CPU components by @c duration half cycles.
forceinline void advance_time(HalfCycles duration) {
time_since_video_update_ += duration;
iwm_.time_since_update += duration;
iwm_ += duration;
ram_subcycle_ = (ram_subcycle_ + duration.as_int()) & 15;
// The VIA runs at one-tenth of the 68000's clock speed, in sync with the E clock.
@ -537,20 +544,9 @@ template <Analyser::Static::Macintosh::Target::Model model> class ConcreteMachin
return mouse_;
}
struct IWM {
IWM(int clock_rate) : iwm(clock_rate) {}
HalfCycles time_since_update;
Apple::IWM iwm;
void flush() {
iwm.run_for(time_since_update.flush<Cycles>());
}
};
class VIAPortHandler: public MOS::MOS6522::PortHandler {
public:
VIAPortHandler(ConcreteMachine &machine, RealTimeClock &clock, Keyboard &keyboard, Video &video, DeferredAudio &audio, IWM &iwm, Inputs::QuadratureMouse &mouse) :
VIAPortHandler(ConcreteMachine &machine, RealTimeClock &clock, Keyboard &keyboard, Video &video, DeferredAudio &audio, JustInTimeActor<IWM, HalfCycles, Cycles> &iwm, Inputs::QuadratureMouse &mouse) :
machine_(machine), clock_(clock), keyboard_(keyboard), video_(video), audio_(audio), iwm_(iwm), mouse_(mouse) {}
using Port = MOS::MOS6522::Port;
@ -572,8 +568,7 @@ template <Analyser::Static::Macintosh::Target::Model model> class ConcreteMachin
b3: 0 = use alternate sound buffer, 1 = use ordinary sound buffer
b2b0: audio output volume
*/
iwm_.flush();
iwm_.iwm.set_select(!!(value & 0x20));
iwm_->set_select(!!(value & 0x20));
machine_.set_use_alternate_buffers(!(value & 0x40), !(value&0x08));
machine_.set_rom_is_overlay(!!(value & 0x10));
@ -658,14 +653,14 @@ template <Analyser::Static::Macintosh::Target::Model model> class ConcreteMachin
Keyboard &keyboard_;
Video &video_;
DeferredAudio &audio_;
IWM &iwm_;
JustInTimeActor<IWM, HalfCycles, Cycles> &iwm_;
Inputs::QuadratureMouse &mouse_;
};
CPU::MC68000::Processor<ConcreteMachine, true> mc68000_;
DriveSpeedAccumulator drive_speed_accumulator_;
IWM iwm_;
JustInTimeActor<IWM, HalfCycles, Cycles> iwm_;
DeferredAudio audio_;
Video video_;