From dde9b73a22113569e02e8eb9577844be335c6996 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 9 Jun 2018 12:51:53 -0400 Subject: [PATCH] Creates the through-path that will be necessary for RWTS acceleration. --- Components/DiskII/DiskII.cpp | 4 ++++ Components/DiskII/DiskII.hpp | 4 ++++ Machines/AppleII/DiskIICard.cpp | 4 ++++ Machines/AppleII/DiskIICard.hpp | 1 + Storage/Disk/Drive.cpp | 12 ++++++++++++ Storage/Disk/Drive.hpp | 11 +++++++++++ Storage/Disk/Track/Track.hpp | 12 ++++++------ 7 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Components/DiskII/DiskII.cpp b/Components/DiskII/DiskII.cpp index 758ca4883..d02afdb37 100644 --- a/Components/DiskII/DiskII.cpp +++ b/Components/DiskII/DiskII.cpp @@ -260,3 +260,7 @@ void DiskII::set_activity_observer(Activity::Observer *observer) { drives_[0].set_activity_observer(observer, "Drive 1", true); drives_[1].set_activity_observer(observer, "Drive 2", true); } + +Storage::Disk::Drive &DiskII::get_drive(int index) { + return drives_[index]; +} diff --git a/Components/DiskII/DiskII.hpp b/Components/DiskII/DiskII.hpp index 31773b59e..ccb3ce491 100644 --- a/Components/DiskII/DiskII.hpp +++ b/Components/DiskII/DiskII.hpp @@ -81,6 +81,10 @@ class DiskII: // The Disk II functions as a potential target for @c Activity::Sources. void set_activity_observer(Activity::Observer *observer); + // Returns the Storage::Disk::Drive in use for drive @c index. + // *NOT FOR HARDWARE EMULATION USAGE*. + Storage::Disk::Drive &get_drive(int index); + private: enum class Control { P0, P1, P2, P3, diff --git a/Machines/AppleII/DiskIICard.cpp b/Machines/AppleII/DiskIICard.cpp index a914025db..8edc1ea6d 100644 --- a/Machines/AppleII/DiskIICard.cpp +++ b/Machines/AppleII/DiskIICard.cpp @@ -57,3 +57,7 @@ void DiskIICard::set_component_prefers_clocking(ClockingHint::Source *component, diskii_clocking_preference_ = preference; set_select_constraints((preference != ClockingHint::Preference::RealTime) ? (IO | Device) : 0); } + +Storage::Disk::Drive &DiskIICard::get_drive(int drive) { + return diskii_.get_drive(drive); +} diff --git a/Machines/AppleII/DiskIICard.hpp b/Machines/AppleII/DiskIICard.hpp index 2072241a1..703788f05 100644 --- a/Machines/AppleII/DiskIICard.hpp +++ b/Machines/AppleII/DiskIICard.hpp @@ -32,6 +32,7 @@ class DiskIICard: public Card, public ClockingHint::Observer { void set_activity_observer(Activity::Observer *observer) override; void set_disk(const std::shared_ptr &disk, int drive); + Storage::Disk::Drive &get_drive(int drive); private: void set_component_prefers_clocking(ClockingHint::Source *component, ClockingHint::Preference clocking) override; diff --git a/Storage/Disk/Drive.cpp b/Storage/Disk/Drive.cpp index 535f19624..350449447 100644 --- a/Storage/Disk/Drive.cpp +++ b/Storage/Disk/Drive.cpp @@ -77,6 +77,18 @@ void Drive::step(HeadPosition offset) { } } +std::shared_ptr Drive::step_to(HeadPosition offset) { + HeadPosition old_head_position = head_position_; + head_position_ = std::max(offset, HeadPosition(0)); + + if(head_position_ != old_head_position) { + track_ = nullptr; + setup_track(); + } + + return track_; +} + void Drive::set_head(int head) { head = std::min(head, available_heads_ - 1); if(head != head_) { diff --git a/Storage/Disk/Drive.hpp b/Storage/Disk/Drive.hpp index 8606534f8..a9c021528 100644 --- a/Storage/Disk/Drive.hpp +++ b/Storage/Disk/Drive.hpp @@ -127,6 +127,17 @@ class Drive: public ClockingHint::Source, public TimedEventLoop { /// The caller can specify whether to add an LED based on disk motor. void set_activity_observer(Activity::Observer *observer, const std::string &name, bool add_motor_led); + /*! + Attempts to step to the specified offset and returns the track there if one exists; an uninitialised + track otherwise. + + This is unambiguously **NOT A REALISTIC DRIVE FUNCTION**; real drives cannot step to a given offset. + So it is **NOT FOR HARDWARE EMULATION USAGE**. + + It's for the benefit of user-optional fast-loading mechanisms **ONLY**. + */ + std::shared_ptr step_to(HeadPosition offset); + private: // Drives contain an entire disk; from that a certain track // will be currently under the head. diff --git a/Storage/Disk/Track/Track.hpp b/Storage/Disk/Track/Track.hpp index bbc0fa96b..5075401fc 100644 --- a/Storage/Disk/Track/Track.hpp +++ b/Storage/Disk/Track/Track.hpp @@ -39,22 +39,22 @@ class HeadPosition { position_ += rhs.position_; return *this; } - bool operator ==(const HeadPosition &rhs) { + bool operator ==(const HeadPosition &rhs) const { return position_ == rhs.position_; } - bool operator !=(const HeadPosition &rhs) { + bool operator !=(const HeadPosition &rhs) const { return position_ != rhs.position_; } - bool operator <(const HeadPosition &rhs) { + bool operator <(const HeadPosition &rhs) const { return position_ < rhs.position_; } - bool operator <=(const HeadPosition &rhs) { + bool operator <=(const HeadPosition &rhs) const { return position_ <= rhs.position_; } - bool operator >(const HeadPosition &rhs) { + bool operator >(const HeadPosition &rhs) const { return position_ > rhs.position_; } - bool operator >=(const HeadPosition &rhs) { + bool operator >=(const HeadPosition &rhs) const { return position_ >= rhs.position_; }