From 58347cc79502d14cc595ec1c5659764ebed9bb22 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Tue, 25 Aug 2020 19:12:51 -0700 Subject: [PATCH] More work on multi-block reads; not fully functional --- Source/Core/Core/HW/EXI/EXI_DeviceSD.cpp | 37 +++++++++++++++++++----- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceSD.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceSD.cpp index 632f1e44f7..f2659b734b 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceSD.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceSD.cpp @@ -4,6 +4,7 @@ #include "Core/HW/EXI/EXI_DeviceSD.h" +#include #include #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(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; }