openMSX
AbstractIDEDevice.hh
Go to the documentation of this file.
1 #ifndef ABSTRACTIDEDEVICE_HH
2 #define ABSTRACTIDEDEVICE_HH
3 
4 #include "IDEDevice.hh"
5 #include "serialize_meta.hh"
6 #include <string>
7 
8 namespace openmsx {
9 
10 class MSXMotherBoard;
11 
13 {
14 public:
15  virtual void reset(EmuTime::param time);
16 
17  virtual word readData(EmuTime::param time);
18  virtual byte readReg(nibble reg, EmuTime::param time);
19 
20  virtual void writeData(word value, EmuTime::param time);
21  virtual void writeReg(nibble reg, byte value, EmuTime::param time);
22 
23  template<typename Archive>
24  void serialize(Archive& ar, unsigned version);
25 
26 protected:
27  // Bit flags for the status register:
28  static const byte DRDY = 0x40;
29  static const byte DSC = 0x10;
30  static const byte DRQ = 0x08;
31  static const byte ERR = 0x01;
32 
33  // Bit flags for the error register:
34  static const byte UNC = 0x40;
35  static const byte IDNF = 0x10;
36  static const byte ABORT = 0x04;
37 
38  explicit AbstractIDEDevice(MSXMotherBoard& motherBoard);
39  virtual ~AbstractIDEDevice();
40 
44  virtual bool isPacketDevice() = 0;
45 
50  virtual const std::string& getDeviceName() = 0;
51 
57  virtual void fillIdentifyBlock(byte* buffer) = 0;
58 
68  virtual unsigned readBlockStart(byte* buffer, unsigned count) = 0;
69 
73  virtual void readEnd();
74 
80  virtual void writeBlockComplete(byte* buffer, unsigned count) = 0;
81 
86  virtual void executeCommand(byte cmd);
87 
91  void setError(byte error);
92 
96  unsigned getSectorNumber() const;
97 
100  unsigned getNumSectors() const;
101 
106  void setInterruptReason(byte value);
107 
111  unsigned getByteCount();
112 
116  void setByteCount(unsigned count);
117 
121  void setSectorNumber(unsigned lba);
122 
129  void startLongReadTransfer(unsigned count);
130 
138  byte* startShortReadTransfer(unsigned count);
139 
142  void abortReadTransfer(byte error);
143 
147  void startWriteTransfer(unsigned count);
148 
151  void abortWriteTransfer(byte error);
152 
153  byte getFeatureReg() const { return featureReg; }
154  void setLBALow (byte value) { sectorNumReg = value; }
155  void setLBAMid (byte value) { cylinderLowReg = value; }
156  void setLBAHigh(byte value) { cylinderHighReg = value; }
157 
158 private:
162  byte diagnostic();
163 
169  void createSignature(bool preserveDevice = false);
170 
175  void createIdentifyBlock(byte* buffer);
176 
179  void startReadTransfer();
180 
184  void readNextBlock();
185 
188  void setTransferRead(bool status);
189 
193  void writeNextBlock();
194 
197  void setTransferWrite(bool status);
198 
199  MSXMotherBoard& motherBoard;
200 
206  byte buffer[512];
207 
210  unsigned transferIdx;
211 
214  unsigned bufferLeft;
215 
219  unsigned transferCount;
220 
221  // ATA registers:
222  byte errorReg;
223  byte sectorCountReg;
224  byte sectorNumReg;
225  byte cylinderLowReg;
226  byte cylinderHighReg;
227  byte devHeadReg;
228  byte statusReg;
229  byte featureReg;
230 
231  bool transferRead;
232  bool transferWrite;
233 };
234 
236 
237 } // namespace openmsx
238 
239 #endif // ABSTRACTIDEDEVICE_HH