| e8555c89 Andy McCall |
1 |
#ifndef ABSTRACTIDEDEVICE_HH |
| 2 |
#define ABSTRACTIDEDEVICE_HH |
| 3 |
|
| 4 |
#include "IDEDevice.hh" |
| 5 |
|
| 6 |
#include "serialize_meta.hh" |
| 7 |
|
| 8 |
#include "AlignedBuffer.hh" |
| 9 |
|
| 10 |
namespace openmsx { |
| 11 |
|
| 12 |
class MSXMotherBoard; |
| 13 |
|
| 14 |
class AbstractIDEDevice : public IDEDevice |
| 15 |
{ |
| 16 |
public: |
| 17 |
void reset(EmuTime time) override; |
| 18 |
|
| 19 |
[[nodiscard]] uint16_t readData(EmuTime time) override; |
| 20 |
[[nodiscard]] uint8_t readReg(uint4_t reg, EmuTime time) override; |
| 21 |
|
| 22 |
void writeData(uint16_t value, EmuTime time) override; |
| 23 |
void writeReg(uint4_t reg, uint8_t value, EmuTime time) override; |
| 24 |
|
| 25 |
template<typename Archive> |
| 26 |
void serialize(Archive& ar, unsigned version); |
| 27 |
|
| 28 |
protected: |
| 29 |
|
| 30 |
static constexpr uint8_t DRDY = 0x40; |
| 31 |
static constexpr uint8_t DSC = 0x10; |
| 32 |
static constexpr uint8_t DRQ = 0x08; |
| 33 |
static constexpr uint8_t ERR = 0x01; |
| 34 |
|
| 35 |
|
| 36 |
static constexpr uint8_t UNC = 0x40; |
| 37 |
static constexpr uint8_t IDNF = 0x10; |
| 38 |
static constexpr uint8_t ABORT = 0x04; |
| 39 |
|
| 40 |
explicit AbstractIDEDevice(MSXMotherBoard& motherBoard); |
| 41 |
~AbstractIDEDevice() override = default; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
[[nodiscard]] virtual bool isPacketDevice() = 0; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
[[nodiscard]] virtual std::string_view getDeviceName() = 0; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
virtual void fillIdentifyBlock(AlignedBuffer& buffer) = 0; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
[[nodiscard]] virtual unsigned readBlockStart(AlignedBuffer& buffer, unsigned count) = 0; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
virtual void readEnd(); |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
virtual void writeBlockComplete(AlignedBuffer& buffer, unsigned count) = 0; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
virtual void executeCommand(uint8_t cmd); |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
void setError(uint8_t error); |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
[[nodiscard]] unsigned getSectorNumber() const; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
[[nodiscard]] unsigned getNumSectors() const; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
void setInterruptReason(uint8_t value); |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
[[nodiscard]] unsigned getByteCount() const; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
void setByteCount(unsigned count); |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
void setSectorNumber(unsigned lba); |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
void startLongReadTransfer(unsigned count); |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
[[nodiscard]] AlignedBuffer& startShortReadTransfer(unsigned count); |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
void abortReadTransfer(uint8_t error); |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
void startWriteTransfer(unsigned count); |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
void abortWriteTransfer(uint8_t error); |
| 154 |
|
| 155 |
[[nodiscard]] uint8_t getFeatureReg() const { return featureReg; } |
| 156 |
void setLBALow (uint8_t value) { sectorNumReg = value; } |
| 157 |
void setLBAMid (uint8_t value) { cylinderLowReg = value; } |
| 158 |
void setLBAHigh(uint8_t value) { cylinderHighReg = value; } |
| 159 |
|
| 160 |
[[nodiscard]] MSXMotherBoard& getMotherBoard() const { return motherBoard; } |
| 161 |
|
| 162 |
private: |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
[[nodiscard]] uint8_t diagnostic() const; |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
void createSignature(bool preserveDevice = false); |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
void createIdentifyBlock(AlignedBuffer& buffer); |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
void startReadTransfer(); |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
void readNextBlock(); |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
void setTransferRead(bool status); |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
void writeNextBlock(); |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
void setTransferWrite(bool status); |
| 202 |
|
| 203 |
private: |
| 204 |
MSXMotherBoard& motherBoard; |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
AlignedByteArray<512> buffer; |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
unsigned transferIdx = 0; |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
unsigned bufferLeft = 0; |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
unsigned transferCount = 0; |
| 225 |
|
| 226 |
|
| 227 |
uint8_t errorReg; |
| 228 |
uint8_t sectorCountReg; |
| 229 |
uint8_t sectorNumReg; |
| 230 |
uint8_t cylinderLowReg; |
| 231 |
uint8_t cylinderHighReg; |
| 232 |
uint8_t devHeadReg; |
| 233 |
uint8_t statusReg; |
| 234 |
uint8_t featureReg; |
| 235 |
|
| 236 |
bool transferRead = false; |
| 237 |
bool transferWrite = false; |
| 238 |
}; |
| 239 |
|
| 240 |
REGISTER_BASE_NAME_HELPER(AbstractIDEDevice, "IDEDevice"); |
| 241 |
|
| 242 |
} |
| 243 |
|
| 244 |
#endif |