2016-09-26 01:24:16 +00:00
|
|
|
//
|
|
|
|
// Drive.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 25/09/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-09-26 01:24:16 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Drive_hpp
|
|
|
|
#define Drive_hpp
|
|
|
|
|
|
|
|
#include "Disk.hpp"
|
2017-09-23 02:39:23 +00:00
|
|
|
#include "Track/PCMSegment.hpp"
|
2018-07-02 02:49:57 +00:00
|
|
|
#include "Track/PCMTrack.hpp"
|
2017-09-10 20:23:31 +00:00
|
|
|
|
2017-09-10 18:43:20 +00:00
|
|
|
#include "../TimedEventLoop.hpp"
|
2018-05-11 01:54:10 +00:00
|
|
|
#include "../../Activity/Observer.hpp"
|
2018-05-28 03:17:06 +00:00
|
|
|
#include "../../ClockReceiver/ClockingHintSource.hpp"
|
2017-09-10 20:23:31 +00:00
|
|
|
|
|
|
|
#include <memory>
|
2016-09-26 01:24:16 +00:00
|
|
|
|
|
|
|
namespace Storage {
|
|
|
|
namespace Disk {
|
|
|
|
|
2018-05-28 03:17:06 +00:00
|
|
|
class Drive: public ClockingHint::Source, public TimedEventLoop {
|
2016-09-26 01:24:16 +00:00
|
|
|
public:
|
2020-01-17 02:34:48 +00:00
|
|
|
enum class ReadyType {
|
|
|
|
/// Indicates that RDY will go active when the motor is on and two index holes have passed; it will go inactive when the motor is off.
|
|
|
|
ShugartRDY,
|
|
|
|
/// Indicates that RDY will go active when the motor is on and two index holes have passed; it will go inactive when the disk is ejected.
|
|
|
|
ShugartModifiedRDY,
|
|
|
|
/// Indicates that RDY will go active when the head steps; it will go inactive when the disk is ejected.
|
|
|
|
IBMRDY,
|
|
|
|
};
|
|
|
|
|
|
|
|
Drive(int input_clock_rate, int revolutions_per_minute, int number_of_heads, ReadyType rdy_type = ReadyType::ShugartRDY);
|
|
|
|
Drive(int input_clock_rate, int number_of_heads, ReadyType rdy_type = ReadyType::ShugartRDY);
|
2020-05-30 04:37:06 +00:00
|
|
|
virtual ~Drive();
|
2016-09-26 01:24:16 +00:00
|
|
|
|
|
|
|
/*!
|
2020-01-17 02:34:48 +00:00
|
|
|
Replaces whatever is in the drive with @c disk. Supply @c nullptr to eject any current disk and leave none inserted.
|
2016-09-26 01:24:16 +00:00
|
|
|
*/
|
2016-12-26 19:24:33 +00:00
|
|
|
void set_disk(const std::shared_ptr<Disk> &disk);
|
|
|
|
|
2016-09-26 01:24:16 +00:00
|
|
|
/*!
|
|
|
|
@returns @c true if a disk is currently inserted; @c false otherwise.
|
|
|
|
*/
|
2019-12-25 01:53:37 +00:00
|
|
|
bool has_disk() const;
|
2016-09-26 01:24:16 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
@returns @c true if the drive head is currently at track zero; @c false otherwise.
|
|
|
|
*/
|
2019-12-25 01:53:37 +00:00
|
|
|
bool get_is_track_zero() const;
|
2016-09-26 01:24:16 +00:00
|
|
|
|
|
|
|
/*!
|
2016-12-25 03:37:20 +00:00
|
|
|
Steps the disk head the specified number of tracks. Positive numbers step inwards (i.e. away from track 0),
|
|
|
|
negative numbers step outwards (i.e. towards track 0).
|
2016-09-26 01:24:16 +00:00
|
|
|
*/
|
2018-05-07 03:17:36 +00:00
|
|
|
void step(HeadPosition offset);
|
2016-09-26 01:24:16 +00:00
|
|
|
|
|
|
|
/*!
|
2016-12-25 03:37:20 +00:00
|
|
|
Sets the current read head.
|
2016-09-26 01:24:16 +00:00
|
|
|
*/
|
2017-10-07 01:45:12 +00:00
|
|
|
void set_head(int head);
|
2016-09-26 01:24:16 +00:00
|
|
|
|
2019-06-05 01:41:54 +00:00
|
|
|
/*!
|
|
|
|
Gets the head count for this disk.
|
|
|
|
*/
|
2019-12-25 01:53:37 +00:00
|
|
|
int get_head_count() const;
|
2019-06-05 01:41:54 +00:00
|
|
|
|
2016-12-25 03:37:20 +00:00
|
|
|
/*!
|
2017-08-13 15:50:49 +00:00
|
|
|
@returns @c true if the inserted disk is read-only or no disk is inserted; @c false otherwise.
|
2016-12-25 03:37:20 +00:00
|
|
|
*/
|
2019-12-25 01:53:37 +00:00
|
|
|
bool get_is_read_only() const;
|
2016-12-25 03:11:31 +00:00
|
|
|
|
2017-08-09 01:15:56 +00:00
|
|
|
/*!
|
|
|
|
@returns @c true if the drive is ready; @c false otherwise.
|
|
|
|
*/
|
2019-12-25 01:53:37 +00:00
|
|
|
bool get_is_ready() const;
|
2017-08-09 01:15:56 +00:00
|
|
|
|
2017-09-10 18:43:20 +00:00
|
|
|
/*!
|
|
|
|
Sets whether the disk motor is on.
|
|
|
|
*/
|
|
|
|
void set_motor_on(bool);
|
|
|
|
|
2017-09-10 20:23:31 +00:00
|
|
|
/*!
|
2020-01-16 04:16:25 +00:00
|
|
|
@returns @c true if the motor on input is active; @c false otherwise. This does not necessarily indicate whether the drive is spinning, due to momentum.
|
2017-09-10 20:23:31 +00:00
|
|
|
*/
|
2019-12-25 01:53:37 +00:00
|
|
|
bool get_motor_on() const;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@returns @c true if the index pulse output is active; @c false otherwise.
|
|
|
|
*/
|
|
|
|
bool get_index_pulse() const;
|
2017-09-10 20:23:31 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Begins write mode, initiating a PCM sampled region of data. Bits should be written via
|
|
|
|
@c write_bit. They will be written with the length set via @c set_expected_bit_length.
|
|
|
|
It is acceptable to supply a backlog of bits. Flux transition events will not be reported
|
|
|
|
while writing.
|
|
|
|
|
|
|
|
@param clamp_to_index_hole If @c true then writing will automatically be truncated by
|
|
|
|
the index hole. Writing will continue over the index hole otherwise.
|
|
|
|
*/
|
2017-09-10 21:33:01 +00:00
|
|
|
void begin_writing(Time bit_length, bool clamp_to_index_hole);
|
2017-09-10 20:23:31 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Writes the bit @c value as the next in the PCM stream initiated by @c begin_writing.
|
|
|
|
*/
|
|
|
|
void write_bit(bool value);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Ends write mode, switching back to read mode. The drive will stop overwriting events.
|
|
|
|
*/
|
|
|
|
void end_writing();
|
|
|
|
|
2019-07-12 22:53:41 +00:00
|
|
|
/*!
|
|
|
|
@returns @c true if the drive has received a call to begin_writing but not yet a call to
|
|
|
|
end_writing; @c false otherwise.
|
|
|
|
*/
|
2019-12-25 01:53:37 +00:00
|
|
|
bool is_writing() const;
|
2019-07-12 22:53:41 +00:00
|
|
|
|
2017-09-10 18:43:20 +00:00
|
|
|
/*!
|
|
|
|
Advances the drive by @c number_of_cycles cycles.
|
|
|
|
*/
|
|
|
|
void run_for(const Cycles cycles);
|
|
|
|
|
2019-07-02 19:43:03 +00:00
|
|
|
struct Event {
|
|
|
|
Track::Event::Type type;
|
|
|
|
float length = 0.0f;
|
|
|
|
} current_event_;
|
|
|
|
|
2017-09-10 18:43:20 +00:00
|
|
|
/*!
|
2017-09-10 20:23:31 +00:00
|
|
|
Provides a mechanism to receive track events as they occur, including the synthetic
|
|
|
|
event of "you told me to output the following data, and I've done that now".
|
2017-09-10 18:43:20 +00:00
|
|
|
*/
|
|
|
|
struct EventDelegate {
|
2017-09-10 20:23:31 +00:00
|
|
|
/// Informs the delegate that @c event has been reached.
|
2019-07-02 19:43:03 +00:00
|
|
|
virtual void process_event(const Event &event) = 0;
|
2017-09-10 20:23:31 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
If the drive is in write mode, announces that all queued bits have now been written.
|
|
|
|
If the controller provides further bits now then there will be no gap in written data.
|
|
|
|
*/
|
2018-04-25 02:44:45 +00:00
|
|
|
virtual void process_write_completed() {}
|
2017-09-10 21:33:01 +00:00
|
|
|
|
|
|
|
/// Informs the delegate of the passing of @c cycles.
|
2020-05-30 04:37:06 +00:00
|
|
|
virtual void advance([[maybe_unused]] Cycles cycles) {}
|
2017-09-10 18:43:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Sets the current event delegate.
|
|
|
|
void set_event_delegate(EventDelegate *);
|
|
|
|
|
2017-08-20 15:54:54 +00:00
|
|
|
// As per Sleeper.
|
2020-05-10 01:22:51 +00:00
|
|
|
ClockingHint::Preference preferred_clocking() const final;
|
2017-08-20 15:54:54 +00:00
|
|
|
|
2018-05-11 01:54:10 +00:00
|
|
|
/// Adds an activity observer; it'll be notified of disk activity.
|
|
|
|
/// 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);
|
|
|
|
|
2018-06-09 16:51:53 +00:00
|
|
|
/*!
|
|
|
|
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<Track> step_to(HeadPosition offset);
|
|
|
|
|
2019-06-05 01:41:54 +00:00
|
|
|
/*!
|
|
|
|
Alters the rotational velocity of this drive.
|
|
|
|
*/
|
|
|
|
void set_rotation_speed(float revolutions_per_minute);
|
|
|
|
|
2019-06-06 22:32:11 +00:00
|
|
|
/*!
|
|
|
|
@returns the current value of the tachometer pulse offered by some drives.
|
|
|
|
*/
|
2019-12-25 01:53:37 +00:00
|
|
|
bool get_tachometer() const;
|
2019-06-06 22:32:11 +00:00
|
|
|
|
2019-06-05 01:41:54 +00:00
|
|
|
protected:
|
2019-06-06 22:32:11 +00:00
|
|
|
/*!
|
|
|
|
Announces the result of a step.
|
|
|
|
*/
|
2020-05-30 04:37:06 +00:00
|
|
|
virtual void did_step([[maybe_unused]] HeadPosition to_position) {}
|
2019-06-02 17:39:25 +00:00
|
|
|
|
2019-07-12 17:17:24 +00:00
|
|
|
/*!
|
|
|
|
Announces new media installation.
|
|
|
|
*/
|
|
|
|
virtual void did_set_disk() {}
|
|
|
|
|
2019-06-06 22:32:11 +00:00
|
|
|
/*!
|
|
|
|
@returns the current rotation of the disk, a float in the half-open range
|
|
|
|
0.0 (the index hole) to 1.0 (back to the index hole, a whole rotation later).
|
|
|
|
*/
|
2019-12-25 01:53:37 +00:00
|
|
|
float get_rotation() const;
|
2019-06-06 22:32:11 +00:00
|
|
|
|
2016-09-26 01:24:16 +00:00
|
|
|
private:
|
2017-09-10 21:33:01 +00:00
|
|
|
// Drives contain an entire disk; from that a certain track
|
2017-09-10 20:23:31 +00:00
|
|
|
// will be currently under the head.
|
2016-12-03 16:59:28 +00:00
|
|
|
std::shared_ptr<Disk> disk_;
|
2017-09-10 20:23:31 +00:00
|
|
|
std::shared_ptr<Track> track_;
|
|
|
|
bool has_disk_ = false;
|
|
|
|
|
|
|
|
// Contains the multiplier that converts between track-relative lengths
|
2018-05-13 19:34:31 +00:00
|
|
|
// to real-time lengths. So it's the reciprocal of rotation speed.
|
2020-02-19 03:58:37 +00:00
|
|
|
float rotational_multiplier_ = 1.0f;
|
2017-09-10 18:43:20 +00:00
|
|
|
|
2017-09-10 20:23:31 +00:00
|
|
|
// A count of time since the index hole was last seen. Which is used to
|
|
|
|
// determine how far the drive is into a full rotation when switching to
|
|
|
|
// a new track.
|
2019-10-30 02:36:29 +00:00
|
|
|
Cycles::IntType cycles_since_index_hole_ = 0;
|
2017-09-10 18:43:20 +00:00
|
|
|
|
2019-07-26 21:20:32 +00:00
|
|
|
// The number of cycles that should fall within one revolution at the
|
|
|
|
// current rotation speed.
|
|
|
|
int cycles_per_revolution_ = 1;
|
|
|
|
|
2017-09-10 20:23:31 +00:00
|
|
|
// A record of head position and active head.
|
2018-05-07 03:17:36 +00:00
|
|
|
HeadPosition head_position_;
|
2017-10-07 01:45:12 +00:00
|
|
|
int head_ = 0;
|
|
|
|
int available_heads_ = 0;
|
2017-09-10 18:43:20 +00:00
|
|
|
|
2017-09-10 20:23:31 +00:00
|
|
|
// Motor control state.
|
2020-01-16 04:16:25 +00:00
|
|
|
bool motor_input_is_on_ = false;
|
2020-01-16 04:29:52 +00:00
|
|
|
bool disk_is_rotating_ = false;
|
|
|
|
Cycles time_until_motor_transition;
|
|
|
|
void set_disk_is_rotating(bool);
|
2017-09-10 20:23:31 +00:00
|
|
|
|
2019-12-25 01:53:37 +00:00
|
|
|
// Current state of the index pulse output.
|
|
|
|
Cycles index_pulse_remaining_;
|
|
|
|
|
2017-09-10 20:23:31 +00:00
|
|
|
// If the drive is not currently reading then it is writing. While writing
|
|
|
|
// it can optionally be told to clamp to the index hole.
|
2017-09-11 00:51:05 +00:00
|
|
|
bool is_reading_ = true;
|
2017-09-10 21:33:01 +00:00
|
|
|
bool clamp_writing_to_index_hole_ = false;
|
2017-09-10 20:23:31 +00:00
|
|
|
|
|
|
|
// If writing is occurring then the drive will be accumulating a write segment,
|
2018-07-02 02:49:57 +00:00
|
|
|
// for addition to a (high-resolution) PCM track.
|
|
|
|
std::shared_ptr<PCMTrack> patched_track_;
|
2017-09-10 20:23:31 +00:00
|
|
|
PCMSegment write_segment_;
|
|
|
|
Time write_start_time_;
|
|
|
|
|
2020-01-17 02:34:48 +00:00
|
|
|
// Indicates progress towards Shugart-style drive ready states.
|
2017-09-12 02:27:50 +00:00
|
|
|
int ready_index_count_ = 0;
|
2020-01-17 02:34:48 +00:00
|
|
|
ReadyType ready_type_;
|
|
|
|
bool is_ready_ = false;
|
2017-09-10 21:33:01 +00:00
|
|
|
|
2017-09-10 20:23:31 +00:00
|
|
|
// Maintains appropriate counting to know when to indicate that writing
|
|
|
|
// is complete.
|
|
|
|
Time cycles_until_bits_written_;
|
|
|
|
Time cycles_per_bit_;
|
|
|
|
|
|
|
|
// TimedEventLoop call-ins and state.
|
2018-05-28 03:17:06 +00:00
|
|
|
void process_next_event() override;
|
2019-07-02 19:43:03 +00:00
|
|
|
void get_next_event(float duration_already_passed);
|
2018-05-28 03:17:06 +00:00
|
|
|
void advance(const Cycles cycles) override;
|
2017-09-10 18:43:20 +00:00
|
|
|
|
2017-09-10 20:23:31 +00:00
|
|
|
// Helper for track changes.
|
2019-12-25 01:53:37 +00:00
|
|
|
float get_time_into_track() const;
|
2017-09-10 20:23:31 +00:00
|
|
|
|
|
|
|
// The target (if any) for track events.
|
2017-09-10 18:43:20 +00:00
|
|
|
EventDelegate *event_delegate_ = nullptr;
|
2017-09-10 21:33:01 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
@returns the track underneath the current head at the location now stepped to.
|
|
|
|
*/
|
|
|
|
std::shared_ptr<Track> get_track();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Attempts to set @c track as the track underneath the current head at the location now stepped to.
|
|
|
|
*/
|
|
|
|
void set_track(const std::shared_ptr<Track> &track);
|
|
|
|
|
|
|
|
void setup_track();
|
|
|
|
void invalidate_track();
|
2018-05-11 01:54:10 +00:00
|
|
|
|
|
|
|
// Activity observer description.
|
|
|
|
Activity::Observer *observer_ = nullptr;
|
|
|
|
std::string drive_name_;
|
|
|
|
bool announce_motor_led_ = false;
|
2018-05-14 23:17:34 +00:00
|
|
|
|
|
|
|
// A rotating random data source.
|
|
|
|
uint64_t random_source_;
|
2019-07-02 19:43:03 +00:00
|
|
|
float random_interval_;
|
2016-09-26 01:24:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Drive_hpp */
|