38 : hd(config.getXML() ? std::make_unique<
HD>(config) : nullptr)
40 , transferDelayCounter(0)
43 , currentByteInSector(0)
50 byte SdCard::readCurrentByteFromCurrentSector()
53 if (currentByteInSector == -1) {
55 hd->readSector(currentSector, sectorBuf);
57 }
catch (MSXException&) {
62 return sectorBuf.
raw[currentByteInSector];
65 currentByteInSector++;
66 if (currentByteInSector ==
sizeof(sectorBuf)) {
83 if (transferDelayCounter > 0) {
84 --transferDelayCounter;
86 if (responseQueue.
empty()) {
89 retval = readCurrentByteFromCurrentSector();
90 if (currentByteInSector ==
sizeof(sectorBuf)) {
99 if (currentSector >= hd->getNbSectors()) {
103 retval = readCurrentByteFromCurrentSector();
104 if (currentByteInSector ==
sizeof(sectorBuf)) {
106 currentByteInSector = -1;
126 if (currentByteInSector == -1) {
128 currentByteInSector++;
132 if (currentByteInSector <
int(
sizeof(sectorBuf))) {
133 sectorBuf.
raw[currentByteInSector] = value;
135 currentByteInSector++;
136 if (currentByteInSector == (
sizeof(sectorBuf) + 2)) {
140 hd->writeSector(currentSector, sectorBuf);
145 transferDelayCounter = 1;
151 if (currentByteInSector == -1) {
156 currentByteInSector++;
160 if (currentByteInSector <
int(
sizeof(sectorBuf))) {
161 sectorBuf.
raw[currentByteInSector] = value;
163 currentByteInSector++;
164 if (currentByteInSector == (
sizeof(sectorBuf) + 2)) {
167 if (currentSector >= hd->getNbSectors()) {
176 hd->writeSector(currentSector, sectorBuf);
177 currentByteInSector = -1;
189 transferDelayCounter = 1;
195 if ((cmdIdx == 0 && (value >> 6) == 1)
197 cmdBuf[cmdIdx] = value;
210 void SdCard::executeCommand()
214 transferDelayCounter = 2;
215 byte command = cmdBuf[0] & 0x3F;
218 responseQueue.
clear();
244 auto c_size = unsigned((hd->getNbSectors() *
sizeof(sectorBuf)) / (512 * 1024) - 1);
246 byte((c_size >> 16) & 0x3F),
247 byte((c_size >> 8) & 0xFF),
248 byte((c_size >> 0) & 0xFF),
290 if (currentSector >= hd->getNbSectors()) {
295 case 17: mode =
READ;
break;
297 case 24: mode =
WRITE;
break;
301 currentByteInSector = -1;
327 static constexpr std::initializer_list<enum_string<SdCard::Mode>> modeInfo = {
336 template<
typename Archive>
339 ar.serialize(
"mode", mode,
341 ar.serialize_blob(
"sectorBuf", sectorBuf.
raw,
sizeof(sectorBuf));
342 if (hd) ar.serialize(
"hd", *hd);
343 ar.serialize(
"cmdIdx", cmdIdx,
344 "transferDelayCounter", transferDelayCounter,
345 "responseQueue", responseQueue,
346 "currentSector", currentSector,
347 "currentByteInSector", currentByteInSector);
SdCard(const DeviceConfig &config)
void serialize(Archive &ar, unsigned version)
byte transfer(byte value, bool cs)
uint32_t readB32(const void *p)
This file implemented 3 utility functions:
constexpr byte R1_PARAMETER_ERROR
uint8_t byte
8 bit unsigned integer
constexpr byte R1_ILLEGAL_COMMAND
constexpr byte DRT_ACCEPTED
SERIALIZE_ENUM(CassettePlayer::State, stateInfo)
constexpr byte STOP_TRAN_TOKEN
constexpr byte DATA_ERROR_TOKEN_ERROR
constexpr byte DATA_ERROR_TOKEN_OUT_OF_RANGE
constexpr byte DRT_WRITE_ERROR
constexpr byte START_BLOCK_TOKEN
constexpr byte START_BLOCK_TOKEN_MBW
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)