openMSX
TC8566AF.hh
Go to the documentation of this file.
1 #ifndef TC8566AF_HH
2 #define TC8566AF_HH
3 
4 #include "DynamicClock.hh"
5 #include "CRC16.hh"
6 #include "Schedulable.hh"
7 #include "serialize_meta.hh"
8 #include "openmsx.hh"
9 
10 namespace openmsx {
11 
12 class Scheduler;
13 class DiskDrive;
14 class CliComm;
15 
16 class TC8566AF final : public Schedulable
17 {
18 public:
19  TC8566AF(Scheduler& scheduler, DiskDrive* drv[4], CliComm& cliComm,
20  EmuTime::param time);
21 
22  void reset(EmuTime::param time);
23  byte readReg(int reg, EmuTime::param time);
24  [[nodiscard]] byte peekReg(int reg, EmuTime::param time) const;
25  void writeReg(int reg, byte data, EmuTime::param time);
26  bool diskChanged(unsigned driveNum);
27  [[nodiscard]] bool peekDiskChanged(unsigned driveNum) const;
28 
29  template<typename Archive>
30  void serialize(Archive& ar, unsigned version);
31 
32  // public for serialization
33  enum Command {
50  };
51  enum Phase {
56  };
57 
58 private:
59  // Schedulable
60  void executeUntil(EmuTime::param time) override;
61 
62  [[nodiscard]] byte peekDataPort(EmuTime::param time) const;
63  byte readDataPort(EmuTime::param time);
64  [[nodiscard]] byte peekStatus() const;
65  byte readStatus(EmuTime::param time);
66  [[nodiscard]] byte executionPhasePeek(EmuTime::param time) const;
67  byte executionPhaseRead(EmuTime::param time);
68  [[nodiscard]] byte resultsPhasePeek() const;
69  byte resultsPhaseRead(EmuTime::param time);
70  void writeDataPort(byte value, EmuTime::param time);
71  void idlePhaseWrite(byte value, EmuTime::param time);
72  void commandPhase1(byte value);
73  void commandPhaseWrite(byte value, EmuTime::param time);
74  void doSeek(EmuTime::param time);
75  void executionPhaseWrite(byte value, EmuTime::param time);
76  void resultPhase();
77  void endCommand(EmuTime::param time);
78 
79  [[nodiscard]] bool isHeadLoaded(EmuTime::param time) const;
80  [[nodiscard]] EmuDuration getHeadLoadDelay() const;
81  [[nodiscard]] EmuDuration getHeadUnloadDelay() const;
82  [[nodiscard]] EmuDuration getSeekDelay() const;
83 
84  [[nodiscard]] EmuTime locateSector(EmuTime::param time);
85  void writeSector();
86  void initTrackHeader(EmuTime::param time);
87  void formatSector();
88  void setDrqRate(unsigned trackLength);
89 
90 private:
91  CliComm& cliComm;
92  DiskDrive* drive[4];
93  DynamicClock delayTime;
94  EmuTime headUnloadTime; // Before this time head is loaded, after
95  // this time it's unloaded. Set to zero/infinity
96  // to force a (un)loaded head.
97 
98  Command command;
99  Phase phase;
100  int phaseStep;
101 
102  //bool interrupt;
103 
104  int dataAvailable;
105  int dataCurrent;
106  CRC16 crc;
107 
108  byte driveSelect;
109  byte mainStatus;
110  byte status0;
111  byte status1;
112  byte status2;
113  byte status3;
114  byte commandCode;
115 
116  byte cylinderNumber;
117  byte headNumber;
118  byte sectorNumber;
119  byte number;
120  byte currentTrack;
121  byte sectorsPerCylinder;
122  byte fillerByte;
123  byte gapLength;
124  byte specifyData[2]; // filled in by SPECIFY command
125  byte seekValue;
126 };
128 
129 } // namespace openmsx
130 
131 #endif
openmsx::TC8566AF::readReg
byte readReg(int reg, EmuTime::param time)
Definition: TC8566AF.cc:128
openmsx::TC8566AF::Phase
Phase
Definition: TC8566AF.hh:51
openmsx.hh
openmsx::TC8566AF
Definition: TC8566AF.hh:17
openmsx::Scheduler
Definition: Scheduler.hh:34
openmsx::TC8566AF::CMD_READ_DELETED_DATA
@ CMD_READ_DELETED_DATA
Definition: TC8566AF.hh:38
openmsx::TC8566AF::PHASE_DATATRANSFER
@ PHASE_DATATRANSFER
Definition: TC8566AF.hh:54
openmsx::TC8566AF::reset
void reset(EmuTime::param time)
Definition: TC8566AF.cc:82
openmsx::TC8566AF::PHASE_COMMAND
@ PHASE_COMMAND
Definition: TC8566AF.hh:53
CRC16.hh
openmsx::DiskDrive
This (abstract) class defines the DiskDrive interface.
Definition: DiskDrive.hh:13
openmsx::EmuDuration
Definition: EmuDuration.hh:19
openmsx::TC8566AF::CMD_SENSE_INTERRUPT_STATUS
@ CMD_SENSE_INTERRUPT_STATUS
Definition: TC8566AF.hh:47
serialize_meta.hh
openmsx::TC8566AF::CMD_READ_ID
@ CMD_READ_ID
Definition: TC8566AF.hh:40
openmsx::TC8566AF::CMD_SPECIFY
@ CMD_SPECIFY
Definition: TC8566AF.hh:48
openmsx::TC8566AF::peekDiskChanged
bool peekDiskChanged(unsigned driveNum) const
Definition: TC8566AF.cc:797
openmsx::Schedulable
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:34
Schedulable.hh
openmsx::TC8566AF::TC8566AF
TC8566AF(Scheduler &scheduler, DiskDrive *drv[4], CliComm &cliComm, EmuTime::param time)
Definition: TC8566AF.cc:63
openmsx::TC8566AF::CMD_READ_DIAGNOSTIC
@ CMD_READ_DIAGNOSTIC
Definition: TC8566AF.hh:39
openmsx::SERIALIZE_CLASS_VERSION
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
openmsx::DynamicClock
Represents a clock with a variable frequency.
Definition: DynamicClock.hh:17
openmsx::CRC16
This class calculates CRC numbers for the polygon x^16 + x^12 + x^5 + 1.
Definition: CRC16.hh:16
openmsx::TC8566AF::CMD_SCAN_HIGH_OR_EQUAL
@ CMD_SCAN_HIGH_OR_EQUAL
Definition: TC8566AF.hh:44
openmsx::TC8566AF::CMD_WRITE_DATA
@ CMD_WRITE_DATA
Definition: TC8566AF.hh:36
openmsx::TC8566AF::CMD_UNKNOWN
@ CMD_UNKNOWN
Definition: TC8566AF.hh:34
openmsx::TC8566AF::CMD_SENSE_DEVICE_STATUS
@ CMD_SENSE_DEVICE_STATUS
Definition: TC8566AF.hh:49
openmsx::TC8566AF::peekReg
byte peekReg(int reg, EmuTime::param time) const
Definition: TC8566AF.cc:117
openmsx::TC8566AF::CMD_SCAN_EQUAL
@ CMD_SCAN_EQUAL
Definition: TC8566AF.hh:42
openmsx::TC8566AF::CMD_RECALIBRATE
@ CMD_RECALIBRATE
Definition: TC8566AF.hh:46
openmsx::TC8566AF::CMD_SCAN_LOW_OR_EQUAL
@ CMD_SCAN_LOW_OR_EQUAL
Definition: TC8566AF.hh:43
openmsx::TC8566AF::PHASE_IDLE
@ PHASE_IDLE
Definition: TC8566AF.hh:52
openmsx::TC8566AF::diskChanged
bool diskChanged(unsigned driveNum)
Definition: TC8566AF.cc:791
openmsx::TC8566AF::PHASE_RESULT
@ PHASE_RESULT
Definition: TC8566AF.hh:55
openmsx::TC8566AF::CMD_SEEK
@ CMD_SEEK
Definition: TC8566AF.hh:45
openmsx::TC8566AF::CMD_READ_DATA
@ CMD_READ_DATA
Definition: TC8566AF.hh:35
openmsx::TC8566AF::writeReg
void writeReg(int reg, byte data, EmuTime::param time)
Definition: TC8566AF.cc:319
openmsx::Command
Definition: Command.hh:41
openmsx::CliComm
Definition: CliComm.hh:11
openmsx::Scheduler
Scheduler
Definition: Scheduler.cc:132
openmsx::TC8566AF::serialize
void serialize(Archive &ar, unsigned version)
Definition: TC8566AF.cc:861
DynamicClock.hh
openmsx::TC8566AF::CMD_WRITE_DELETED_DATA
@ CMD_WRITE_DELETED_DATA
Definition: TC8566AF.hh:37
openmsx::TC8566AF::Command
Command
Definition: TC8566AF.hh:33
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::TC8566AF::CMD_FORMAT
@ CMD_FORMAT
Definition: TC8566AF.hh:41