2016-09-17 22:01:00 +00:00
|
|
|
//
|
|
|
|
// 1770.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 17/09/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef _770_hpp
|
|
|
|
#define _770_hpp
|
|
|
|
|
2016-09-26 00:05:56 +00:00
|
|
|
#include "../../Storage/Disk/DiskController.hpp"
|
2016-12-26 21:46:26 +00:00
|
|
|
#include "../../NumberTheory/CRC.hpp"
|
2016-09-18 17:35:54 +00:00
|
|
|
|
|
|
|
namespace WD {
|
|
|
|
|
2016-09-26 00:05:56 +00:00
|
|
|
class WD1770: public Storage::Disk::Controller {
|
2016-09-18 17:35:54 +00:00
|
|
|
public:
|
2016-11-26 15:29:30 +00:00
|
|
|
enum Personality {
|
2016-11-28 04:39:08 +00:00
|
|
|
P1770, // implies automatic motor-on management with Type 2 commands offering a spin-up disable
|
|
|
|
P1772, // as per the 1770, with different stepping rates
|
|
|
|
P1773, // implements the side number-testing logic of the 1793; omits spin-up/loading logic
|
|
|
|
P1793 // implies Type 2 commands use side number testing logic; spin-up/loading is by HLD and HLT
|
2016-11-26 15:29:30 +00:00
|
|
|
};
|
|
|
|
WD1770(Personality p);
|
2016-09-20 19:56:31 +00:00
|
|
|
|
2016-09-18 17:35:54 +00:00
|
|
|
void set_is_double_density(bool is_double_density);
|
|
|
|
void set_register(int address, uint8_t value);
|
2016-09-20 02:06:56 +00:00
|
|
|
uint8_t get_register(int address);
|
|
|
|
|
|
|
|
void run_for_cycles(unsigned int number_of_cycles);
|
2016-09-20 19:56:31 +00:00
|
|
|
|
|
|
|
enum Flag: uint8_t {
|
2016-12-02 02:13:16 +00:00
|
|
|
NotReady = 0x80,
|
2016-09-20 19:56:31 +00:00
|
|
|
MotorOn = 0x80,
|
|
|
|
WriteProtect = 0x40,
|
|
|
|
RecordType = 0x20,
|
|
|
|
SpinUp = 0x20,
|
2016-12-02 02:13:16 +00:00
|
|
|
HeadLoaded = 0x20,
|
2016-09-20 19:56:31 +00:00
|
|
|
RecordNotFound = 0x10,
|
2016-09-25 02:04:54 +00:00
|
|
|
SeekError = 0x10,
|
2016-09-20 19:56:31 +00:00
|
|
|
CRCError = 0x08,
|
|
|
|
LostData = 0x04,
|
|
|
|
TrackZero = 0x04,
|
|
|
|
DataRequest = 0x02,
|
|
|
|
Index = 0x02,
|
|
|
|
Busy = 0x01
|
|
|
|
};
|
|
|
|
|
2016-12-07 02:16:29 +00:00
|
|
|
inline bool get_interrupt_request_line() { return status_.interrupt_request; }
|
|
|
|
inline bool get_data_request_line() { return status_.data_request; }
|
2016-11-21 05:21:49 +00:00
|
|
|
class Delegate {
|
|
|
|
public:
|
2016-12-01 12:41:52 +00:00
|
|
|
virtual void wd1770_did_change_output(WD1770 *wd1770) = 0;
|
2016-11-21 05:21:49 +00:00
|
|
|
};
|
|
|
|
inline void set_delegate(Delegate *delegate) { delegate_ = delegate; }
|
|
|
|
|
2016-12-02 01:12:22 +00:00
|
|
|
protected:
|
|
|
|
virtual void set_head_load_request(bool head_load);
|
|
|
|
void set_head_loaded(bool head_loaded);
|
|
|
|
|
2016-09-20 19:56:31 +00:00
|
|
|
private:
|
2016-11-26 15:29:30 +00:00
|
|
|
Personality personality_;
|
2016-12-01 12:41:52 +00:00
|
|
|
inline bool has_motor_on_line() { return (personality_ != P1793 ) && (personality_ != P1773); }
|
|
|
|
inline bool has_head_load_line() { return (personality_ == P1793 ); }
|
2016-11-26 15:29:30 +00:00
|
|
|
|
2016-12-01 03:26:02 +00:00
|
|
|
struct Status {
|
2016-12-01 03:39:55 +00:00
|
|
|
Status();
|
2016-12-01 03:26:02 +00:00
|
|
|
bool write_protect;
|
|
|
|
bool record_type;
|
|
|
|
bool spin_up;
|
|
|
|
bool record_not_found;
|
|
|
|
bool crc_error;
|
|
|
|
bool seek_error;
|
|
|
|
bool lost_data;
|
2016-12-01 12:41:52 +00:00
|
|
|
bool data_request;
|
2016-12-07 02:16:29 +00:00
|
|
|
bool interrupt_request;
|
2016-12-01 03:26:02 +00:00
|
|
|
bool busy;
|
|
|
|
enum {
|
|
|
|
One, Two, Three
|
|
|
|
} type;
|
|
|
|
} status_;
|
2016-09-25 00:12:45 +00:00
|
|
|
uint8_t track_;
|
|
|
|
uint8_t sector_;
|
|
|
|
uint8_t data_;
|
|
|
|
uint8_t command_;
|
|
|
|
|
|
|
|
int index_hole_count_;
|
2016-09-25 18:11:22 +00:00
|
|
|
int index_hole_count_target_;
|
2016-09-25 02:36:38 +00:00
|
|
|
int bits_since_token_;
|
|
|
|
int distance_into_section_;
|
2016-09-26 01:38:52 +00:00
|
|
|
bool is_awaiting_marker_value_;
|
2016-09-20 19:56:31 +00:00
|
|
|
|
2016-09-25 00:12:45 +00:00
|
|
|
int step_direction_;
|
2016-12-01 12:41:52 +00:00
|
|
|
void update_status(std::function<void(Status &)> updater);
|
2016-09-21 02:14:33 +00:00
|
|
|
|
2016-09-25 00:12:45 +00:00
|
|
|
// Tokeniser
|
2016-12-29 00:26:21 +00:00
|
|
|
enum DataMode {
|
|
|
|
Scanning,
|
|
|
|
Reading,
|
|
|
|
Writing
|
|
|
|
} data_mode_;
|
2016-09-25 00:12:45 +00:00
|
|
|
bool is_double_density_;
|
|
|
|
int shift_register_;
|
|
|
|
struct Token {
|
|
|
|
enum Type {
|
2017-01-02 01:39:19 +00:00
|
|
|
Index, ID, Data, DeletedData, Sync, Byte
|
2016-09-25 00:12:45 +00:00
|
|
|
} type;
|
|
|
|
uint8_t byte_value;
|
|
|
|
} latest_token_;
|
|
|
|
|
|
|
|
// Events
|
|
|
|
enum Event: int {
|
2016-09-25 18:11:22 +00:00
|
|
|
Command = (1 << 0), // Indicates receipt of a new command.
|
|
|
|
Token = (1 << 1), // Indicates recognition of a new token in the flux stream. Interrogate latest_token_ for details.
|
|
|
|
IndexHole = (1 << 2), // Indicates the passing of a physical index hole.
|
2016-12-02 02:13:16 +00:00
|
|
|
HeadLoad = (1 << 3), // Indicates the head has been loaded (1973 only).
|
2016-12-25 20:46:49 +00:00
|
|
|
DataWritten = (1 << 4), // Indicates that all queued bits have been written
|
2016-09-25 18:11:22 +00:00
|
|
|
|
2016-12-25 20:46:49 +00:00
|
|
|
Timer = (1 << 5), // Indicates that the delay_time_-powered timer has timed out.
|
|
|
|
IndexHoleTarget = (1 << 6) // Indicates that index_hole_count_ has reached index_hole_count_target_.
|
2016-09-25 00:12:45 +00:00
|
|
|
};
|
|
|
|
void posit_event(Event type);
|
|
|
|
int interesting_event_mask_;
|
|
|
|
int resume_point_;
|
2017-07-22 01:21:23 +00:00
|
|
|
unsigned int delay_time_;
|
2016-09-25 00:12:45 +00:00
|
|
|
|
2016-12-26 00:18:45 +00:00
|
|
|
// Output
|
|
|
|
int last_bit_;
|
|
|
|
void write_bit(int bit);
|
|
|
|
void write_byte(uint8_t byte);
|
2016-12-26 01:15:07 +00:00
|
|
|
void write_raw_short(uint16_t value);
|
2016-12-26 00:18:45 +00:00
|
|
|
|
2016-09-25 02:04:54 +00:00
|
|
|
// ID buffer
|
2016-11-21 05:21:49 +00:00
|
|
|
uint8_t header_[6];
|
|
|
|
|
2016-12-26 21:46:26 +00:00
|
|
|
// CRC generator
|
|
|
|
NumberTheory::CRC16 crc_generator_;
|
|
|
|
|
2016-12-02 01:12:22 +00:00
|
|
|
// 1793 head-loading logic
|
|
|
|
bool head_is_loaded_;
|
|
|
|
|
|
|
|
// delegate
|
2016-11-21 05:21:49 +00:00
|
|
|
Delegate *delegate_;
|
2016-09-25 02:04:54 +00:00
|
|
|
|
2016-11-21 05:21:49 +00:00
|
|
|
// Storage::Disk::Controller
|
2016-09-21 02:14:33 +00:00
|
|
|
virtual void process_input_bit(int value, unsigned int cycles_since_index_hole);
|
|
|
|
virtual void process_index_hole();
|
2016-12-25 20:46:49 +00:00
|
|
|
virtual void process_write_completed();
|
2016-09-18 17:35:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2016-09-17 22:01:00 +00:00
|
|
|
|
|
|
|
#endif /* _770_hpp */
|