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)
{
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

View File

@ -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;