2016-09-17 22:01:00 +00:00
|
|
|
//
|
|
|
|
// 1770.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 17/09/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-09-17 22:01:00 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef _770_hpp
|
|
|
|
#define _770_hpp
|
|
|
|
|
2017-09-23 02:39:23 +00:00
|
|
|
#include "../../Storage/Disk/Controller/MFMDiskController.hpp"
|
2016-09-18 17:35:54 +00:00
|
|
|
|
|
|
|
namespace WD {
|
|
|
|
|
2017-07-22 21:25:53 +00:00
|
|
|
/*!
|
|
|
|
Provides an emulation of various Western Digital drive controllers, including the
|
|
|
|
WD1770, WD1772, FDC1773 and FDC1793.
|
|
|
|
*/
|
2017-08-14 20:32:53 +00:00
|
|
|
class WD1770: public Storage::Disk::MFMController {
|
2016-09-18 17:35:54 +00:00
|
|
|
public:
|
2016-11-26 15:29:30 +00:00
|
|
|
enum Personality {
|
2017-07-22 21:25:53 +00:00
|
|
|
P1770, // implies automatic motor-on management, with Type 2 commands offering a spin-up disable
|
2016-11-28 04:39:08 +00:00
|
|
|
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
|
|
|
};
|
2017-07-22 21:25:53 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Constructs an instance of the drive controller that behaves according to personality @c p.
|
|
|
|
@param p The type of controller to emulate.
|
|
|
|
*/
|
2016-11-26 15:29:30 +00:00
|
|
|
WD1770(Personality p);
|
2016-09-20 19:56:31 +00:00
|
|
|
|
2017-07-22 21:25:53 +00:00
|
|
|
/// Sets the value of the double-density input; when @c is_double_density is @c true, reads and writes double-density format data.
|
2017-08-14 20:32:53 +00:00
|
|
|
using Storage::Disk::MFMController::set_is_double_density;
|
2017-07-22 21:25:53 +00:00
|
|
|
|
|
|
|
/// Writes @c value to the register at @c address. Only the low two bits of the address are decoded.
|
2016-09-18 17:35:54 +00:00
|
|
|
void set_register(int address, uint8_t value);
|
2017-07-22 21:25:53 +00:00
|
|
|
|
|
|
|
/// Fetches the value of the register @c address. Only the low two bits of the address are decoded.
|
2016-09-20 02:06:56 +00:00
|
|
|
uint8_t get_register(int address);
|
|
|
|
|
2017-07-22 21:25:53 +00:00
|
|
|
/// Runs the controller for @c number_of_cycles cycles.
|
2017-07-28 02:05:29 +00:00
|
|
|
void run_for(const Cycles 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
|
|
|
|
};
|
|
|
|
|
2017-07-22 21:25:53 +00:00
|
|
|
/// @returns The current value of the IRQ line output.
|
2016-12-07 02:16:29 +00:00
|
|
|
inline bool get_interrupt_request_line() { return status_.interrupt_request; }
|
2017-07-22 21:25:53 +00:00
|
|
|
|
|
|
|
/// @returns The current value of the DRQ line output.
|
2016-12-07 02:16:29 +00:00
|
|
|
inline bool get_data_request_line() { return status_.data_request; }
|
2017-07-22 21:25:53 +00:00
|
|
|
|
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);
|
2017-09-12 02:10:56 +00:00
|
|
|
virtual void set_motor_on(bool motor_on);
|
2016-12-02 01:12:22 +00:00
|
|
|
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 {
|
2017-11-11 03:20:44 +00:00
|
|
|
bool write_protect = false;
|
|
|
|
bool record_type = false;
|
|
|
|
bool spin_up = false;
|
|
|
|
bool record_not_found = false;
|
|
|
|
bool crc_error = false;
|
|
|
|
bool seek_error = false;
|
|
|
|
bool lost_data = false;
|
|
|
|
bool data_request = false;
|
|
|
|
bool interrupt_request = false;
|
|
|
|
bool busy = false;
|
2016-12-01 03:26:02 +00:00
|
|
|
enum {
|
|
|
|
One, Two, Three
|
2017-11-11 03:20:44 +00:00
|
|
|
} type = One;
|
2016-12-01 03:26:02 +00:00
|
|
|
} 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_;
|
2017-11-11 03:20:44 +00:00
|
|
|
int index_hole_count_target_ = -1;
|
2016-09-25 02:36:38 +00:00
|
|
|
int distance_into_section_;
|
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
|
|
|
// Events
|
2017-08-14 20:32:53 +00:00
|
|
|
enum Event1770: int {
|
|
|
|
Command = (1 << 3), // Indicates receipt of a new command.
|
|
|
|
HeadLoad = (1 << 4), // Indicates the head has been loaded (1973 only).
|
2016-12-25 20:46:49 +00:00
|
|
|
Timer = (1 << 5), // Indicates that the delay_time_-powered timer has timed out.
|
2018-01-08 00:42:38 +00:00
|
|
|
IndexHoleTarget = (1 << 6), // Indicates that index_hole_count_ has reached index_hole_count_target_.
|
|
|
|
ForceInterrupt = (1 << 7) // Indicates a forced interrupt.
|
2016-09-25 00:12:45 +00:00
|
|
|
};
|
2017-08-14 20:32:53 +00:00
|
|
|
void posit_event(int type);
|
2016-09-25 00:12:45 +00:00
|
|
|
int interesting_event_mask_;
|
2017-11-11 03:20:44 +00:00
|
|
|
int resume_point_ = 0;
|
2019-10-30 02:36:29 +00:00
|
|
|
Cycles::IntType delay_time_ = 0;
|
2016-09-25 00:12: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-02 01:12:22 +00:00
|
|
|
// 1793 head-loading logic
|
2017-11-11 03:20:44 +00:00
|
|
|
bool head_is_loaded_ = false;
|
2016-12-02 01:12:22 +00:00
|
|
|
|
|
|
|
// delegate
|
2017-11-11 03:20:44 +00:00
|
|
|
Delegate *delegate_ = nullptr;
|
2016-09-18 17:35:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2016-09-17 22:01:00 +00:00
|
|
|
|
|
|
|
#endif /* _770_hpp */
|