2016-07-15 10:51:11 +00:00
|
|
|
//
|
2016-09-26 00:05:56 +00:00
|
|
|
// DiskController.hpp
|
2016-07-15 10:51:11 +00:00
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 14/07/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-07-15 10:51:11 +00:00
|
|
|
//
|
|
|
|
|
2016-09-26 00:05:56 +00:00
|
|
|
#ifndef Storage_Disk_Controller_hpp
|
|
|
|
#define Storage_Disk_Controller_hpp
|
2016-07-15 10:51:11 +00:00
|
|
|
|
2017-09-23 02:39:23 +00:00
|
|
|
#include "../Drive.hpp"
|
|
|
|
#include "../DPLL/DigitalPhaseLockedLoop.hpp"
|
|
|
|
#include "../Track/PCMSegment.hpp"
|
2017-08-20 15:54:54 +00:00
|
|
|
|
2017-09-23 02:39:23 +00:00
|
|
|
#include "../../../ClockReceiver/ClockReceiver.hpp"
|
2018-05-28 03:17:06 +00:00
|
|
|
#include "../../../ClockReceiver/ClockingHintSource.hpp"
|
2016-07-15 10:51:11 +00:00
|
|
|
|
|
|
|
namespace Storage {
|
2016-08-27 21:15:09 +00:00
|
|
|
namespace Disk {
|
2016-07-15 10:51:11 +00:00
|
|
|
|
2016-08-01 10:04:55 +00:00
|
|
|
/*!
|
2018-05-13 19:34:31 +00:00
|
|
|
Provides the shell for emulating a disk controller: something that is connected to a disk drive and uses a
|
2016-09-26 01:24:16 +00:00
|
|
|
phase locked loop ('PLL') to decode a bit stream from the surface of the disk.
|
2016-08-01 10:04:55 +00:00
|
|
|
|
|
|
|
Partly abstract; it is expected that subclasses will provide methods to deal with receiving a newly-recognised
|
|
|
|
bit from the PLL and with crossing the index hole.
|
|
|
|
|
2016-09-26 01:24:16 +00:00
|
|
|
TODO: communication of head size and permissible stepping extents, appropriate simulation of gain.
|
2016-08-01 10:04:55 +00:00
|
|
|
*/
|
2018-05-28 03:17:06 +00:00
|
|
|
class Controller:
|
|
|
|
public Drive::EventDelegate,
|
|
|
|
public ClockingHint::Source,
|
|
|
|
public ClockingHint::Observer {
|
2016-09-26 01:24:16 +00:00
|
|
|
protected:
|
2016-08-01 10:04:55 +00:00
|
|
|
/*!
|
2017-09-11 02:56:05 +00:00
|
|
|
Constructs a @c Controller that will be run at @c clock_rate.
|
2016-08-01 10:04:55 +00:00
|
|
|
*/
|
2017-09-11 02:56:05 +00:00
|
|
|
Controller(Cycles clock_rate);
|
2016-07-15 12:28:34 +00:00
|
|
|
|
2016-08-01 10:04:55 +00:00
|
|
|
/*!
|
2016-09-19 02:03:06 +00:00
|
|
|
Communicates to the PLL the expected length of a bit as a fraction of a second.
|
2016-08-01 10:04:55 +00:00
|
|
|
*/
|
2016-07-15 12:28:34 +00:00
|
|
|
void set_expected_bit_length(Time bit_length);
|
2016-07-15 10:51:11 +00:00
|
|
|
|
2016-08-01 10:04:55 +00:00
|
|
|
/*!
|
|
|
|
Advances the drive by @c number_of_cycles cycles.
|
|
|
|
*/
|
2017-07-28 02:05:29 +00:00
|
|
|
void run_for(const Cycles cycles);
|
2016-07-15 10:51:11 +00:00
|
|
|
|
2016-08-01 10:04:55 +00:00
|
|
|
/*!
|
2020-02-12 02:59:13 +00:00
|
|
|
Sets the current drive(s). Normally this will be exactly one, but some machines allow
|
|
|
|
zero or multiple drives to be attached, with useless results.
|
2016-08-01 10:04:55 +00:00
|
|
|
*/
|
2020-02-12 02:59:13 +00:00
|
|
|
void set_drive(int index_mask);
|
|
|
|
|
|
|
|
/*!
|
2020-02-13 03:28:42 +00:00
|
|
|
Adds a new drive to the drive list, returning its index.
|
2020-02-12 02:59:13 +00:00
|
|
|
*/
|
|
|
|
template<typename... Args> size_t emplace_drive(Args&&... args) {
|
|
|
|
drives_.emplace_back(std::forward<Args>(args)...);
|
2020-02-13 03:28:42 +00:00
|
|
|
drives_.back().set_clocking_hint_observer(this);
|
2020-02-12 02:59:13 +00:00
|
|
|
return drives_.size() - 1;
|
|
|
|
}
|
|
|
|
|
2020-02-13 03:28:42 +00:00
|
|
|
/*!
|
|
|
|
Adds @c count new drives to the drive list, returning the index of the final one added.
|
|
|
|
*/
|
2020-02-12 02:59:13 +00:00
|
|
|
template<typename... Args> size_t emplace_drives(size_t count, Args&&... args) {
|
|
|
|
while(count--) {
|
|
|
|
drives_.emplace_back(std::forward<Args>(args)...);
|
2020-02-13 03:28:42 +00:00
|
|
|
drives_.back().set_clocking_hint_observer(this);
|
2020-02-12 02:59:13 +00:00
|
|
|
}
|
|
|
|
return drives_.size() - 1;
|
|
|
|
}
|
2016-12-26 02:06:58 +00:00
|
|
|
|
|
|
|
/*!
|
2017-09-10 23:23:23 +00:00
|
|
|
Should be implemented by subclasses; communicates each bit that the PLL recognises.
|
2016-12-26 02:06:58 +00:00
|
|
|
*/
|
2017-09-10 23:23:23 +00:00
|
|
|
virtual void process_input_bit(int value) = 0;
|
2016-08-01 10:04:55 +00:00
|
|
|
|
|
|
|
/*!
|
2017-09-10 23:23:23 +00:00
|
|
|
Should be implemented by subclasses; communicates that the index hole has been reached.
|
2016-08-01 10:04:55 +00:00
|
|
|
*/
|
2017-09-10 23:23:23 +00:00
|
|
|
virtual void process_index_hole() = 0;
|
2016-07-15 10:51:11 +00:00
|
|
|
|
2016-12-01 03:26:02 +00:00
|
|
|
/*!
|
2017-09-10 23:23:23 +00:00
|
|
|
Should be implemented by subclasses if they implement writing; communicates that
|
|
|
|
all bits supplied to write_bit have now been written.
|
2016-12-01 03:26:02 +00:00
|
|
|
*/
|
2018-05-28 03:17:06 +00:00
|
|
|
virtual void process_write_completed() override;
|
2016-12-01 03:26:02 +00:00
|
|
|
|
2016-12-08 03:19:20 +00:00
|
|
|
/*!
|
2017-09-15 23:14:36 +00:00
|
|
|
Puts the controller and the drive returned by get_drive() into write mode, supplying to
|
|
|
|
the drive the current bit length.
|
|
|
|
|
|
|
|
While the controller is in write mode it disconnects the PLL. So subclasses will not
|
|
|
|
receive any calls to @c process_input_bit.
|
2017-08-15 20:05:10 +00:00
|
|
|
|
|
|
|
@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.
|
2016-12-08 03:19:20 +00:00
|
|
|
*/
|
2017-08-15 20:05:10 +00:00
|
|
|
void begin_writing(bool clamp_to_index_hole);
|
2016-12-08 03:19:20 +00:00
|
|
|
|
2017-09-15 02:30:40 +00:00
|
|
|
/*!
|
|
|
|
Puts the drive returned by get_drive() out of write mode, and marks the controller
|
|
|
|
as no longer being in write mode.
|
|
|
|
*/
|
|
|
|
void end_writing();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@returns @c true if the controller is in reading mode; @c false otherwise.
|
|
|
|
*/
|
|
|
|
bool is_reading();
|
|
|
|
|
2016-12-08 03:19:20 +00:00
|
|
|
/*!
|
2017-09-10 23:23:23 +00:00
|
|
|
Returns the connected drive or, if none is connected, an invented one. No guarantees are
|
|
|
|
made about the lifetime or the exclusivity of the invented drive.
|
2016-12-25 17:31:38 +00:00
|
|
|
*/
|
2017-09-10 23:23:23 +00:00
|
|
|
Drive &get_drive();
|
2016-09-26 01:24:16 +00:00
|
|
|
|
2020-02-12 02:59:13 +00:00
|
|
|
Drive &get_drive(size_t index) {
|
|
|
|
return drives_[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
void for_all_drives(const std::function<void(Drive &, size_t)> &func) {
|
|
|
|
size_t index = 0;
|
|
|
|
for(auto &drive: drives_) {
|
|
|
|
func(drive, index);
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-15 23:14:36 +00:00
|
|
|
/*!
|
2018-05-28 03:17:06 +00:00
|
|
|
As per ClockingHint::Source.
|
2017-09-15 23:14:36 +00:00
|
|
|
*/
|
2020-05-10 01:22:51 +00:00
|
|
|
ClockingHint::Preference preferred_clocking() const override;
|
2017-08-20 15:54:54 +00:00
|
|
|
|
2016-07-15 12:28:34 +00:00
|
|
|
private:
|
2016-12-03 16:59:28 +00:00
|
|
|
Time bit_length_;
|
2019-10-30 02:36:29 +00:00
|
|
|
Cycles::IntType clock_rate_multiplier_ = 1;
|
|
|
|
Cycles::IntType clock_rate_ = 1;
|
2017-09-15 02:30:40 +00:00
|
|
|
|
|
|
|
bool is_reading_ = true;
|
2016-07-29 09:19:01 +00:00
|
|
|
|
2020-01-12 22:25:21 +00:00
|
|
|
DigitalPhaseLockedLoop<Controller> pll_;
|
|
|
|
friend DigitalPhaseLockedLoop<Controller>;
|
|
|
|
|
2020-02-12 02:59:13 +00:00
|
|
|
Drive empty_drive_;
|
|
|
|
std::vector<Drive> drives_;
|
|
|
|
Drive *drive_;
|
|
|
|
int drive_selection_mask_ = 0xff;
|
2016-12-24 18:07:23 +00:00
|
|
|
|
2018-05-28 03:17:06 +00:00
|
|
|
// ClockingHint::Observer.
|
2020-01-24 03:57:51 +00:00
|
|
|
void set_component_prefers_clocking(ClockingHint::Source *component, ClockingHint::Preference clocking) final;
|
2016-12-25 17:31:38 +00:00
|
|
|
|
2017-09-10 23:23:23 +00:00
|
|
|
// for Drive::EventDelegate
|
2020-01-24 03:57:51 +00:00
|
|
|
void process_event(const Drive::Event &event) final;
|
|
|
|
void advance(const Cycles cycles) final;
|
2017-08-20 15:54:54 +00:00
|
|
|
|
2017-09-10 23:23:23 +00:00
|
|
|
// to satisfy DigitalPhaseLockedLoop::Delegate
|
2020-01-12 22:25:21 +00:00
|
|
|
void digital_phase_locked_loop_output_bit(int value);
|
2016-07-15 10:51:11 +00:00
|
|
|
};
|
|
|
|
|
2016-08-27 21:15:09 +00:00
|
|
|
}
|
2016-07-15 10:51:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* DiskDrive_hpp */
|