Eliminate hacky setup states

There still probably needs to be another state for CMD0 or such, but that can be handled separately.
This commit is contained in:
Pokechu22 2020-09-15 17:51:24 -07:00
parent bb432b6a9e
commit acb4a4be64
2 changed files with 13 additions and 41 deletions

View File

@ -59,49 +59,24 @@ CEXISD::CEXISD(Core::System& system, int channel_num) : IEXIDevice(system)
void CEXISD::ImmWrite(u32 data, u32 size) void CEXISD::ImmWrite(u32 data, u32 size)
{ {
if (state == State::Uninitialized || state == State::GetId) while (size--)
{ {
// Get ID command u8 byte = data >> 24;
INFO_LOG_FMT(EXPANSIONINTERFACE, "SD: EXI_GetID detected (size = {:x}, data = {:x})", size, WriteByte(byte);
data); data <<= 8;
state = State::GetId;
}
else
{
while (size--)
{
u8 byte = data >> 24;
WriteByte(byte);
data <<= 8;
}
} }
} }
u32 CEXISD::ImmRead(u32 size) u32 CEXISD::ImmRead(u32 size)
{ {
if (state == State::Uninitialized) u32 res = 0;
u32 position = 0;
while (size--)
{ {
// ? u8 byte = ReadByte();
return 0; res |= byte << (24 - (position++ * 8));
}
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;
} }
return res;
} }
void CEXISD::ImmReadWrite(u32& data, u32 size) void CEXISD::ImmReadWrite(u32& data, u32 size)
@ -490,7 +465,8 @@ u8 CEXISD::ReadByte()
{ {
if (response.empty()) 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; return 0xff;
} }
else else

View File

@ -173,10 +173,6 @@ private:
enum class State enum class State
{ {
// Hacky setup
Uninitialized,
GetId,
// Actual states for transmiting and receiving
ReadyForCommand, ReadyForCommand,
ReadyForAppCommand, ReadyForAppCommand,
SingleBlockRead, SingleBlockRead,
@ -232,7 +228,7 @@ private:
File::IOFile m_card; File::IOFile m_card;
// STATE_TO_SAVE // STATE_TO_SAVE
State state = State::Uninitialized; State state = State::ReadyForCommand;
BlockState block_state = BlockState::Nothing; BlockState block_state = BlockState::Nothing;
u32 command_position = 0; u32 command_position = 0;
u32 block_position = 0; u32 block_position = 0;