From acb4a4be6448183eae9715d4608bb5afe723d193 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Tue, 15 Sep 2020 17:51:24 -0700 Subject: [PATCH] Eliminate hacky setup states There still probably needs to be another state for CMD0 or such, but that can be handled separately. --- Source/Core/Core/HW/EXI/EXI_DeviceSD.cpp | 48 ++++++------------------ Source/Core/Core/HW/EXI/EXI_DeviceSD.h | 6 +-- 2 files changed, 13 insertions(+), 41 deletions(-) diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceSD.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceSD.cpp index 03cb3d71d2..c43c0df76a 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceSD.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceSD.cpp @@ -59,49 +59,24 @@ CEXISD::CEXISD(Core::System& system, int channel_num) : IEXIDevice(system) void CEXISD::ImmWrite(u32 data, u32 size) { - if (state == State::Uninitialized || state == State::GetId) + while (size--) { - // Get ID command - INFO_LOG_FMT(EXPANSIONINTERFACE, "SD: EXI_GetID detected (size = {:x}, data = {:x})", size, - data); - state = State::GetId; - } - else - { - while (size--) - { - u8 byte = data >> 24; - WriteByte(byte); - data <<= 8; - } + u8 byte = data >> 24; + WriteByte(byte); + data <<= 8; } } u32 CEXISD::ImmRead(u32 size) { - if (state == State::Uninitialized) + u32 res = 0; + u32 position = 0; + while (size--) { - // ? - return 0; - } - else if (state == State::GetId) - { - INFO_LOG_FMT(EXPANSIONINTERFACE, "SD: EXI_GetID finished (size = {:x})", size); - state = State::ReadyForCommand; - // Same signed/unsigned mismatch in libogc; it wants -1 - return -1; - } - else - { - u32 res = 0; - u32 position = 0; - while (size--) - { - u8 byte = ReadByte(); - res |= byte << (24 - (position++ * 8)); - } - return res; + u8 byte = ReadByte(); + res |= byte << (24 - (position++ * 8)); } + return res; } void CEXISD::ImmReadWrite(u32& data, u32 size) @@ -490,7 +465,8 @@ u8 CEXISD::ReadByte() { if (response.empty()) { - // WARN_LOG_FMT(EXPANSIONINTERFACE, "Attempted to read from empty SD queue"); + // Note that SD cards are detected by trying to read a device ID, and getting 0xffffffff back; + // this behavior is required for correct handling. return 0xff; } else diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceSD.h b/Source/Core/Core/HW/EXI/EXI_DeviceSD.h index b7c8080004..4184150a8e 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceSD.h +++ b/Source/Core/Core/HW/EXI/EXI_DeviceSD.h @@ -173,10 +173,6 @@ private: enum class State { - // Hacky setup - Uninitialized, - GetId, - // Actual states for transmiting and receiving ReadyForCommand, ReadyForAppCommand, SingleBlockRead, @@ -232,7 +228,7 @@ private: File::IOFile m_card; // STATE_TO_SAVE - State state = State::Uninitialized; + State state = State::ReadyForCommand; BlockState block_state = BlockState::Nothing; u32 command_position = 0; u32 block_position = 0;