More work on multi-block reads; not fully functional

This commit is contained in:
Pokechu22 2020-08-25 19:12:51 -07:00
parent 1dd9ac2727
commit 58347cc795

View File

@ -4,6 +4,7 @@
#include "Core/HW/EXI/EXI_DeviceSD.h"
#include <cinttypes>
#include <string>
#include "Common/ChunkFile.h"
@ -461,12 +462,13 @@ u8 CEXISD::ReadForBlockRead()
}
else if (!m_card.ReadBytes(block_buffer.data(), BLOCK_SIZE))
{
ERROR_LOG_FMT(EXPANSIONINTERFACE, "SD read failed - error: {}, eof: {}",
ERROR_LOG_FMT(EXPANSIONINTERFACE, "SD read failed at {:#x} - error: {}, eof: {}", address,
ferror(m_card.GetHandle()), feof(m_card.GetHandle()));
block_state = BlockState::Token;
}
else
{
INFO_LOG_FMT(EXPANSIONINTERFACE, "SD read succeeded at {:#x}", address);
block_position = 0;
block_state = BlockState::Block;
block_crc = Common::HashCrc16(block_buffer);
@ -507,13 +509,13 @@ u8 CEXISD::ReadForBlockRead()
}
else if (!m_card.ReadBytes(block_buffer.data(), BLOCK_SIZE))
{
ERROR_LOG_FMT(EXPANSIONINTERFACE, "SD read failed - error: {}, eof: {}",
ERROR_LOG_FMT(EXPANSIONINTERFACE, "SD read failed at {:#x} - error: {}, eof: {}", address,
ferror(m_card.GetHandle()), feof(m_card.GetHandle()));
block_state = BlockState::Token;
}
else
{
INFO_LOG_FMT(EXPANSIONINTERFACE, "SD read succeeded");
INFO_LOG_FMT(EXPANSIONINTERFACE, "SD read succeeded at {:#x}", address);
block_position = 0;
block_state = BlockState::Block;
block_crc = Common::HashCrc16(block_buffer);
@ -538,14 +540,35 @@ void CEXISD::WriteForBlockRead(u8 byte)
{
if (byte != 0xff)
{
ERROR_LOG_FMT(EXPANSIONINTERFACE, "Data written during block read: {:02x}", byte);
WARN_LOG_FMT(EXPANSIONINTERFACE, "Data written during block read: {:02x}, {}, {}", byte,
u32(block_state), block_position);
}
// TODO: Read the whole command
if (((byte & 0b11000000) == 0b01000000) &&
static_cast<Command>(byte & 0x3f) == Command::StopTransmission)
{
// Finish transmitting the current block and then stop
state = State::SingleBlockRead;
if (state == State::MultipleBlockRead)
{
if (block_state == BlockState::ChecksumWritten ||
(block_state == BlockState::Block && block_position == 0))
{
// Done with the current block, finish everything up now.
INFO_LOG_FMT(EXPANSIONINTERFACE, "Assuming stop transmission; done with block read");
state = State::ReadyForCommand;
block_state = BlockState::Nothing;
address = 0;
block_position = 0;
}
else
{
INFO_LOG_FMT(EXPANSIONINTERFACE,
"Assuming stop transmission; changing to single block read to finish");
state = State::SingleBlockRead;
}
// JANK, but I think this will work right
response.push_back(0); // R1 - for later
}
}
}
@ -579,13 +602,13 @@ u8 CEXISD::ReadForBlockWrite()
}
else if (!m_card.WriteBytes(block_buffer.data(), BLOCK_SIZE))
{
ERROR_LOG_FMT(EXPANSIONINTERFACE, "SD write failed - error: {}, eof: {}",
ERROR_LOG_FMT(EXPANSIONINTERFACE, "SD write failed at {:#x} - error: {}, eof: {}", address,
ferror(m_card.GetHandle()), feof(m_card.GetHandle()));
result = DATA_RESPONSE_WRITE_ERROR;
}
else
{
INFO_LOG_FMT(EXPANSIONINTERFACE, "SD write succeeded");
INFO_LOG_FMT(EXPANSIONINTERFACE, "SD write succeeded at {:#x}", address);
result = DATA_RESPONSE_ACCEPTED;
}