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  [[nodiscard]] byte peekDataPort(EmuTime::param time) const;
24  byte readDataPort(EmuTime::param time);
25  [[nodiscard]] byte peekStatus() const;
26  byte readStatus(EmuTime::param time);
27  void writeControlReg0(byte data, EmuTime::param time);
28  void writeControlReg1(byte data, EmuTime::param time);
29  void writeDataPort(byte value, EmuTime::param time);
30  bool diskChanged(unsigned driveNum);
31  [[nodiscard]] bool peekDiskChanged(unsigned driveNum) const;
32 
33  template<typename Archive>
34  void serialize(Archive& ar, unsigned version);
35 
36  // public for serialization
37  enum Command {
54  };
55  enum Phase {
60  };
61  enum SeekState {
65  };
66 
67 private:
68  // Schedulable
69  void executeUntil(EmuTime::param time) override;
70 
71  [[nodiscard]] byte executionPhasePeek(EmuTime::param time) const;
72  byte executionPhaseRead(EmuTime::param time);
73  [[nodiscard]] byte resultsPhasePeek() const;
74  byte resultsPhaseRead(EmuTime::param time);
75  void idlePhaseWrite(byte value, EmuTime::param time);
76  void commandPhase1(byte value);
77  void commandPhaseWrite(byte value, EmuTime::param time);
78  void doSeek(int n);
79  void executionPhaseWrite(byte value, EmuTime::param time);
80  void resultPhase();
81  void endCommand(EmuTime::param time);
82 
83  [[nodiscard]] bool isHeadLoaded(EmuTime::param time) const;
84  [[nodiscard]] EmuDuration getHeadLoadDelay() const;
85  [[nodiscard]] EmuDuration getHeadUnloadDelay() const;
86  [[nodiscard]] EmuDuration getSeekDelay() const;
87 
88  [[nodiscard]] EmuTime locateSector(EmuTime::param time);
89  void startReadWriteSector(EmuTime::param time);
90  void writeSector();
91  void initTrackHeader(EmuTime::param time);
92  void formatSector();
93  void setDrqRate(unsigned trackLength);
94 
95 private:
96  CliComm& cliComm;
97  DiskDrive* drive[4];
98  DynamicClock delayTime;
99  EmuTime headUnloadTime; // Before this time head is loaded, after
100  // this time it's unloaded. Set to zero/infinity
101  // to force a (un)loaded head.
102 
103  Command command;
104  Phase phase;
105  int phaseStep;
106 
107  //bool interrupt;
108 
109  int dataAvailable;
110  int dataCurrent;
111  CRC16 crc;
112 
113  byte driveSelect;
114  byte mainStatus;
115  byte status0;
116  byte status1;
117  byte status2;
118  byte status3;
119  byte commandCode;
120 
121  byte cylinderNumber;
122  byte headNumber;
123  byte sectorNumber;
124  byte number;
125  byte endOfTrack;
126  byte sectorsPerCylinder;
127  byte fillerByte;
128  byte gapLength;
129  byte specifyData[2]; // filled in by SPECIFY command
130 
131  struct SeekInfo {
132  EmuTime time = EmuTime::zero();
133  byte currentTrack = 0;
134  byte seekValue = 0;
135  SeekState state = SEEK_IDLE;
136 
137  template<typename Archive>
138  void serialize(Archive& ar, unsigned version);
139  } seekInfo[4];
140 };
142 
143 } // namespace openmsx
144 
145 #endif
This class calculates CRC numbers for the polygon x^16 + x^12 + x^5 + 1.
Definition: CRC16.hh:17
This (abstract) class defines the DiskDrive interface.
Definition: DiskDrive.hh:13
Represents a clock with a variable frequency.
Definition: DynamicClock.hh:16
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:34
void writeDataPort(byte value, EmuTime::param time)
Definition: TC8566AF.cc:335
TC8566AF(Scheduler &scheduler, DiskDrive *drv[4], CliComm &cliComm, EmuTime::param time)
Definition: TC8566AF.cc:64
byte peekDataPort(EmuTime::param time) const
Definition: TC8566AF.cc:143
byte readDataPort(EmuTime::param time)
Definition: TC8566AF.cc:155
byte readStatus(EmuTime::param time)
Definition: TC8566AF.cc:130
void serialize(Archive &ar, unsigned version)
Definition: TC8566AF.cc:929
void reset(EmuTime::param time)
Definition: TC8566AF.cc:83
bool peekDiskChanged(unsigned driveNum) const
Definition: TC8566AF.cc:847
void writeControlReg0(byte data, EmuTime::param time)
Definition: TC8566AF.cc:315
byte peekStatus() const
Definition: TC8566AF.cc:123
bool diskChanged(unsigned driveNum)
Definition: TC8566AF.cc:841
@ CMD_SENSE_INTERRUPT_STATUS
Definition: TC8566AF.hh:51
void writeControlReg1(byte data, EmuTime::param time)
Definition: TC8566AF.cc:326
This file implemented 3 utility functions:
Definition: Autofire.cc:9
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)