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 "EmuTime.hh"
7#include "Schedulable.hh"
8#include "serialize_meta.hh"
9#include <array>
10#include <cstdint>
11#include <span>
12
13namespace openmsx {
14
15class Scheduler;
16class DiskDrive;
17class MSXCliComm;
18
19class TC8566AF final : public Schedulable
20{
21public:
22 TC8566AF(Scheduler& scheduler, std::span<std::unique_ptr<DiskDrive>, 4>, MSXCliComm& cliComm,
23 EmuTime::param time);
24
25 void reset(EmuTime::param time);
26 [[nodiscard]] uint8_t peekDataPort(EmuTime::param time) const;
27 uint8_t readDataPort(EmuTime::param time);
28 [[nodiscard]] uint8_t peekStatus() const;
29 uint8_t readStatus(EmuTime::param time);
30 void writeControlReg0(uint8_t value, EmuTime::param time);
31 void writeControlReg1(uint8_t value, EmuTime::param time);
32 void writeDataPort(uint8_t value, EmuTime::param time);
33 bool diskChanged(unsigned driveNum);
34 [[nodiscard]] bool peekDiskChanged(unsigned driveNum) const;
35
36 template<typename Archive>
37 void serialize(Archive& ar, unsigned version);
38
39 // public for serialization
58 enum class Phase {
59 IDLE,
60 COMMAND,
62 RESULT,
63 };
64 enum class Seek {
65 IDLE,
66 SEEK,
68 };
69
70private:
71 // Schedulable
72 void executeUntil(EmuTime::param time) override;
73
74 [[nodiscard]] uint8_t executionPhasePeek(EmuTime::param time) const;
75 uint8_t executionPhaseRead(EmuTime::param time);
76 [[nodiscard]] uint8_t resultsPhasePeek() const;
77 uint8_t resultsPhaseRead(EmuTime::param time);
78 void idlePhaseWrite(uint8_t value, EmuTime::param time);
79 void commandPhase1(uint8_t value);
80 void commandPhaseWrite(uint8_t value, EmuTime::param time);
81 void doSeek(int n);
82 void executionPhaseWrite(uint8_t value, EmuTime::param time);
83 void resultPhase(bool readId = false);
84 void endCommand(EmuTime::param time);
85
86 [[nodiscard]] bool isHeadLoaded(EmuTime::param time) const;
87 [[nodiscard]] EmuDuration getHeadLoadDelay() const;
88 [[nodiscard]] EmuDuration getHeadUnloadDelay() const;
89 [[nodiscard]] EmuDuration getSeekDelay() const;
90
91 [[nodiscard]] EmuTime locateSector(EmuTime::param time, bool readId);
92 void startReadWriteSector(EmuTime::param time);
93 void writeSector();
94 void initTrackHeader(EmuTime::param time);
95 void formatSector();
96 void setDrqRate(unsigned trackLength);
97
98private:
99 MSXCliComm& cliComm;
100 std::array<DiskDrive*, 4> drive;
101 DynamicClock delayTime{EmuTime::zero()};
102
103 // Before this time head is loaded, after this time it's unloaded. Set
104 // to zero/infinity to force a (un)loaded head.
105 EmuTime headUnloadTime = EmuTime::zero(); // head not loaded
106
107 Command command;
108 Phase phase;
109 int phaseStep;
110
111 //bool interrupt;
112
113 unsigned dataAvailable = 0; // avoid UMR (on savestate)
114 int dataCurrent = 0;
115 CRC16 crc;
116
117 uint8_t driveSelect;
118 uint8_t mainStatus;
119 uint8_t status0;
120 uint8_t status1;
121 uint8_t status2;
122 uint8_t status3;
123 uint8_t commandCode;
124
125 uint8_t cylinderNumber;
126 uint8_t headNumber;
127 uint8_t sectorNumber;
128 uint8_t number;
129 uint8_t endOfTrack;
130 uint8_t sectorsPerCylinder;
131 uint8_t fillerByte;
132 uint8_t gapLength;
133 std::array<uint8_t, 2> specifyData; // filled in by SPECIFY command
134
135 struct SeekInfo {
136 EmuTime time = EmuTime::zero();
137 uint8_t currentTrack = 0;
138 uint8_t seekValue = 0;
139 Seek state = Seek::IDLE;
140
141 template<typename Archive>
142 void serialize(Archive& ar, unsigned version);
143 };
144 std::array<SeekInfo, 4> seekInfo;
145};
147
148} // namespace openmsx
149
150#endif
Represents a clock with a variable frequency.
Every class that wants to get scheduled at some point must inherit from this class.
uint8_t peekStatus() const
Definition TC8566AF.cc:116
void writeControlReg0(uint8_t value, EmuTime::param time)
Definition TC8566AF.cc:318
void writeDataPort(uint8_t value, EmuTime::param time)
Definition TC8566AF.cc:338
void serialize(Archive &ar, unsigned version)
Definition TC8566AF.cc:971
void writeControlReg1(uint8_t value, EmuTime::param time)
Definition TC8566AF.cc:329
uint8_t peekDataPort(EmuTime::param time) const
Definition TC8566AF.cc:139
void reset(EmuTime::param time)
Definition TC8566AF.cc:77
uint8_t readDataPort(EmuTime::param time)
Definition TC8566AF.cc:151
bool peekDiskChanged(unsigned driveNum) const
Definition TC8566AF.cc:889
uint8_t readStatus(EmuTime::param time)
Definition TC8566AF.cc:123
bool diskChanged(unsigned driveNum)
Definition TC8566AF.cc:883
This file implemented 3 utility functions:
Definition Autofire.cc:11
#define SERIALIZE_CLASS_VERSION(CLASS, VERSION)