2016-09-26 01:24:16 +00:00
|
|
|
//
|
|
|
|
// Drive.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 25/09/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Drive_hpp
|
|
|
|
#define Drive_hpp
|
|
|
|
|
|
|
|
#include <memory>
|
2017-08-20 15:54:54 +00:00
|
|
|
|
2016-09-26 01:24:16 +00:00
|
|
|
#include "Disk.hpp"
|
2017-08-20 15:54:54 +00:00
|
|
|
#include "../../ClockReceiver/Sleeper.hpp"
|
2017-09-10 18:43:20 +00:00
|
|
|
#include "../TimedEventLoop.hpp"
|
2016-09-26 01:24:16 +00:00
|
|
|
|
|
|
|
namespace Storage {
|
|
|
|
namespace Disk {
|
|
|
|
|
2017-09-10 18:43:20 +00:00
|
|
|
class Drive: public Sleeper, public TimedEventLoop {
|
2016-09-26 01:24:16 +00:00
|
|
|
public:
|
2017-09-10 18:43:20 +00:00
|
|
|
Drive(unsigned int input_clock_rate, int revolutions_per_minute);
|
2016-09-26 01:24:16 +00:00
|
|
|
|
|
|
|
/*!
|
2016-12-26 19:24:33 +00:00
|
|
|
Replaces whatever is in the drive with @c disk.
|
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);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Replaces whatever is in the drive with a disk that contains endless copies of @c track.
|
|
|
|
*/
|
|
|
|
void set_disk_with_track(const std::shared_ptr<Track> &track);
|
2016-09-26 01:24:16 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
@returns @c true if a disk is currently inserted; @c false otherwise.
|
|
|
|
*/
|
|
|
|
bool has_disk();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@returns @c true if the drive head is currently at track zero; @c false otherwise.
|
|
|
|
*/
|
|
|
|
bool get_is_track_zero();
|
|
|
|
|
|
|
|
/*!
|
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
|
|
|
*/
|
|
|
|
void step(int direction);
|
|
|
|
|
|
|
|
/*!
|
2016-12-25 03:37:20 +00:00
|
|
|
Sets the current read head.
|
2016-09-26 01:24:16 +00:00
|
|
|
*/
|
|
|
|
void set_head(unsigned int head);
|
|
|
|
|
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
|
|
|
*/
|
2016-12-25 03:11:31 +00:00
|
|
|
bool get_is_read_only();
|
|
|
|
|
2016-12-25 03:37:20 +00:00
|
|
|
/*!
|
|
|
|
@returns the track underneath the current head at the location now stepped to.
|
|
|
|
*/
|
2016-09-26 01:24:16 +00:00
|
|
|
std::shared_ptr<Track> get_track();
|
2016-12-25 03:37:20 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Attempts to set @c track as the track underneath the current head at the location now stepped to.
|
|
|
|
*/
|
2016-12-25 03:11:31 +00:00
|
|
|
void set_track(const std::shared_ptr<Track> &track);
|
2016-09-26 01:24:16 +00:00
|
|
|
|
2017-08-09 01:15:56 +00:00
|
|
|
/*!
|
|
|
|
@returns @c true if the drive is ready; @c false otherwise.
|
|
|
|
*/
|
|
|
|
bool get_is_ready();
|
|
|
|
|
2017-09-10 18:43:20 +00:00
|
|
|
/*!
|
|
|
|
Sets whether the disk motor is on.
|
|
|
|
*/
|
|
|
|
void set_motor_on(bool);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Advances the drive by @c number_of_cycles cycles.
|
|
|
|
*/
|
|
|
|
void run_for(const Cycles cycles);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Provides a mechanism to receive track events as they occur.
|
|
|
|
*/
|
|
|
|
struct EventDelegate {
|
|
|
|
virtual void process_event(const Track::Event &event) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Sets the current event delegate.
|
|
|
|
void set_event_delegate(EventDelegate *);
|
|
|
|
|
2017-08-20 15:54:54 +00:00
|
|
|
// As per Sleeper.
|
|
|
|
bool is_sleeping();
|
|
|
|
|
2016-09-26 01:24:16 +00:00
|
|
|
private:
|
2016-12-26 19:24:33 +00:00
|
|
|
std::shared_ptr<Track> track_;
|
2016-12-03 16:59:28 +00:00
|
|
|
std::shared_ptr<Disk> disk_;
|
2017-09-10 18:43:20 +00:00
|
|
|
int cycles_since_index_hole_ = 0;
|
|
|
|
Time rotational_multiplier_;
|
|
|
|
|
|
|
|
bool has_disk_ = false;
|
|
|
|
|
|
|
|
int head_position_ = 0;
|
|
|
|
unsigned int head_ = 0;
|
|
|
|
|
|
|
|
void process_next_event();
|
|
|
|
void get_next_event(const Time &duration_already_passed);
|
|
|
|
Track::Event current_event_;
|
|
|
|
bool motor_is_on_ = false;
|
|
|
|
|
|
|
|
Time get_time_into_track();
|
|
|
|
EventDelegate *event_delegate_ = nullptr;
|
2016-09-26 01:24:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Drive_hpp */
|