2016-07-15 10:51:11 +00:00
|
|
|
//
|
|
|
|
// DiskDrive.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 14/07/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef DiskDrive_hpp
|
|
|
|
#define DiskDrive_hpp
|
|
|
|
|
|
|
|
#include "Disk.hpp"
|
2016-07-15 12:28:34 +00:00
|
|
|
#include "DigitalPhaseLockedLoop.hpp"
|
2016-07-29 11:31:02 +00:00
|
|
|
#include "../TimedEventLoop.hpp"
|
2016-07-15 10:51:11 +00:00
|
|
|
|
|
|
|
namespace Storage {
|
|
|
|
|
2016-08-01 10:04:55 +00:00
|
|
|
/*!
|
|
|
|
Provides the shell for emulating a disk drive — something that takes a disk and has a drive head
|
|
|
|
that steps between tracks, using a phase locked loop ('PLL') to decode a bit stream from the surface of
|
|
|
|
the disk.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
TODO: double sided disks, communication of head size and permissible stepping extents, appropriate
|
|
|
|
simulation of gain.
|
|
|
|
*/
|
2016-07-29 11:31:02 +00:00
|
|
|
class DiskDrive: public DigitalPhaseLockedLoop::Delegate, public TimedEventLoop {
|
2016-07-15 10:51:11 +00:00
|
|
|
public:
|
2016-08-01 10:04:55 +00:00
|
|
|
/*!
|
|
|
|
Constructs a @c DiskDrive that will be run at @c clock_rate and runs its PLL at @c clock_rate*clock_rate_multiplier,
|
|
|
|
spinning inserted disks at @c revolutions_per_minute.
|
|
|
|
*/
|
2016-07-31 17:32:30 +00:00
|
|
|
DiskDrive(unsigned int clock_rate, unsigned int clock_rate_multiplier, unsigned int revolutions_per_minute);
|
2016-07-15 12:28:34 +00:00
|
|
|
|
2016-08-01 10:04:55 +00:00
|
|
|
/*!
|
|
|
|
Communicates to the PLL the expected length of a bit.
|
|
|
|
*/
|
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
|
|
|
/*!
|
|
|
|
Inserts @c disk into the drive.
|
|
|
|
*/
|
2016-07-15 10:51:11 +00:00
|
|
|
void set_disk(std::shared_ptr<Disk> disk);
|
2016-08-01 10:04:55 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
@returns @c true if a disk is currently inserted; @c false otherwise.
|
|
|
|
*/
|
2016-07-15 10:51:11 +00:00
|
|
|
bool has_disk();
|
|
|
|
|
2016-08-01 10:04:55 +00:00
|
|
|
/*!
|
|
|
|
Advances the drive by @c number_of_cycles cycles.
|
|
|
|
*/
|
2016-07-29 15:03:09 +00:00
|
|
|
void run_for_cycles(int number_of_cycles);
|
2016-07-15 10:51:11 +00:00
|
|
|
|
2016-08-01 10:04:55 +00:00
|
|
|
/*!
|
|
|
|
@returns @c true if the drive head is currently at track zero; @c false otherwise.
|
|
|
|
*/
|
2016-07-15 10:51:11 +00:00
|
|
|
bool get_is_track_zero();
|
2016-08-01 10:04:55 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Steps the disk head the specified number of tracks. Positive numbers step inwards, negative numbers
|
|
|
|
step outwards.
|
|
|
|
*/
|
2016-07-15 10:51:11 +00:00
|
|
|
void step(int direction);
|
2016-08-01 10:04:55 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Enables or disables the disk motor.
|
|
|
|
*/
|
2016-07-15 10:51:11 +00:00
|
|
|
void set_motor_on(bool motor_on);
|
|
|
|
|
2016-07-15 12:28:34 +00:00
|
|
|
// to satisfy DigitalPhaseLockedLoop::Delegate
|
|
|
|
void digital_phase_locked_loop_output_bit(int value);
|
|
|
|
|
2016-07-15 10:51:11 +00:00
|
|
|
protected:
|
2016-08-01 10:04:55 +00:00
|
|
|
/*!
|
|
|
|
Should be implemented by subclasses; communicates each bit that the PLL recognises, also specifying
|
|
|
|
the amount of time since the index hole was last seen.
|
|
|
|
*/
|
2016-07-15 12:28:34 +00:00
|
|
|
virtual void process_input_bit(int value, unsigned int cycles_since_index_hole) = 0;
|
2016-08-01 10:04:55 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Should be implemented by subcalsses; communicates that the index hole has been reached.
|
|
|
|
*/
|
2016-07-15 12:28:34 +00:00
|
|
|
virtual void process_index_hole() = 0;
|
|
|
|
|
2016-07-29 11:31:02 +00:00
|
|
|
// for TimedEventLoop
|
|
|
|
virtual void process_next_event();
|
|
|
|
|
2016-07-15 12:28:34 +00:00
|
|
|
private:
|
|
|
|
Time _bit_length;
|
|
|
|
unsigned int _clock_rate;
|
2016-07-31 17:32:30 +00:00
|
|
|
unsigned int _clock_rate_multiplier;
|
2016-08-05 01:36:39 +00:00
|
|
|
Time _rotational_multiplier;
|
2016-07-29 09:19:01 +00:00
|
|
|
|
|
|
|
std::shared_ptr<DigitalPhaseLockedLoop> _pll;
|
|
|
|
std::shared_ptr<Disk> _disk;
|
|
|
|
std::shared_ptr<Track> _track;
|
|
|
|
int _head_position;
|
|
|
|
unsigned int _cycles_since_index_hole;
|
2016-08-03 12:16:23 +00:00
|
|
|
void set_track(Time initial_offset);
|
2016-07-29 09:19:01 +00:00
|
|
|
|
2016-07-29 11:31:02 +00:00
|
|
|
inline void get_next_event();
|
|
|
|
Track::Event _current_event;
|
2016-08-03 11:26:05 +00:00
|
|
|
Time _time_into_track;
|
2016-07-15 10:51:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* DiskDrive_hpp */
|