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  byte peekReg(int reg, EmuTime::param time) const;
25  void writeReg(int reg, byte data, EmuTime::param time);
26  bool diskChanged(unsigned driveNum);
27  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  byte peekDataPort(EmuTime::param time) const;
63  byte readDataPort(EmuTime::param time);
64  byte peekStatus() const;
65  byte readStatus(EmuTime::param time);
66  byte executionPhasePeek(EmuTime::param time) const;
67  byte executionPhaseRead(EmuTime::param time);
68  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  bool isHeadLoaded(EmuTime::param time) const;
80  EmuDuration getHeadLoadDelay() const;
81  EmuDuration getHeadUnloadDelay() const;
82  EmuDuration getSeekDelay() const;
83 
84  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
byte peekReg(int reg, EmuTime::param time) const
Definition: TC8566AF.cc:116
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
TC8566AF(Scheduler &scheduler, DiskDrive *drv[4], CliComm &cliComm, EmuTime::param time)
Definition: TC8566AF.cc:62
byte readReg(int reg, EmuTime::param time)
Definition: TC8566AF.cc:127
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:33
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
This class calculates CRC numbers for the polygon x^16 + x^12 + x^5 + 1.
Definition: CRC16.hh:35
Represents a clock with a variable frequency.
Definition: DynamicClock.hh:15
void serialize(Archive &ar, unsigned version)
Definition: TC8566AF.cc:860
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void reset(EmuTime::param time)
Definition: TC8566AF.cc:81
bool peekDiskChanged(unsigned driveNum) const
Definition: TC8566AF.cc:796
bool diskChanged(unsigned driveNum)
Definition: TC8566AF.cc:790
This (abstract) class defines the DiskDrive interface.
Definition: DiskDrive.hh:12
void writeReg(int reg, byte data, EmuTime::param time)
Definition: TC8566AF.cc:318