Controller: Always check for access byte

This commit is contained in:
Albert Liu 2021-02-21 15:20:31 -08:00
parent 30bcf280d4
commit 329e8317b4
12 changed files with 100 additions and 39 deletions

View file

@ -314,6 +314,22 @@ bool AnalogController::Transfer(const u8 data_in, u8* data_out)
switch (m_command)
{
case Command::Idle:
{
*data_out = 0xFF;
if (data_in == 0x01)
{
Log_DevPrintf("ACK controller access");
m_command = Command::Ready;
return true;
}
Log_DevPrintf("Unknown data_in = 0x%02X", data_in);
return false;
}
break;
case Command::Ready:
{
if (data_in == 0x42)
{
@ -378,15 +394,8 @@ bool AnalogController::Transfer(const u8 data_in, u8* data_out)
}
else
{
*data_out = 0xFF;
ack = (data_in == 0x01);
if (ack)
Log_DevPrintf("ACK controller access");
else
Log_DevPrintf("Unknown data_in = 0x%02X", data_in);
return ack;
Log_ErrorPrintf("Unimplemented analog controller command 0x%02X", data_in);
Panic("Unimplemented analog controller command");
}
}
break;

View file

@ -81,6 +81,7 @@ private:
enum class Command : u8
{
Idle,
Ready,
ReadPad, // 0x42
ConfigModeSetMode, // 0x43
SetAnalogMode, // 0x44

View file

@ -167,18 +167,27 @@ bool AnalogJoystick::Transfer(const u8 data_in, u8* data_out)
{
case TransferState::Idle:
{
// ack when sent 0x01, send ID for 0x42
*data_out = 0xFF;
if (data_in == 0x01)
{
m_transfer_state = TransferState::Ready;
return true;
}
return false;
}
case TransferState::Ready:
{
if (data_in == 0x42)
{
*data_out = Truncate8(GetID());
m_transfer_state = TransferState::IDMSB;
return true;
}
else
{
*data_out = 0xFF;
return (data_in == 0x01);
}
*data_out = 0xFF;
return false;
}
case TransferState::IDMSB:

View file

@ -71,6 +71,7 @@ private:
enum class TransferState : u8
{
Idle,
Ready,
IDMSB,
ButtonsLSB,
ButtonsMSB,

View file

@ -89,18 +89,27 @@ bool DigitalController::Transfer(const u8 data_in, u8* data_out)
{
case TransferState::Idle:
{
// ack when sent 0x01, send ID for 0x42
*data_out = 0xFF;
if (data_in == 0x01)
{
m_transfer_state = TransferState::Ready;
return true;
}
return false;
}
case TransferState::Ready:
{
if (data_in == 0x42)
{
*data_out = Truncate8(ID);
m_transfer_state = TransferState::IDMSB;
return true;
}
else
{
*data_out = 0xFF;
return (data_in == 0x01);
}
*data_out = 0xFF;
return false;
}
case TransferState::IDMSB:

View file

@ -61,6 +61,7 @@ private:
enum class TransferState : u8
{
Idle,
Ready,
IDMSB,
ButtonsLSB,
ButtonsMSB

View file

@ -95,18 +95,27 @@ bool NamcoGunCon::Transfer(const u8 data_in, u8* data_out)
{
case TransferState::Idle:
{
// ack when sent 0x01, send ID for 0x42
*data_out = 0xFF;
if (data_in == 0x01)
{
m_transfer_state = TransferState::Ready;
return true;
}
return false;
}
case TransferState::Ready:
{
if (data_in == 0x42)
{
*data_out = Truncate8(ID);
m_transfer_state = TransferState::IDMSB;
return true;
}
else
{
*data_out = 0xFF;
return (data_in == 0x01);
}
*data_out = 0xFF;
return false;
}
case TransferState::IDMSB:

View file

@ -50,6 +50,7 @@ private:
enum class TransferState : u8
{
Idle,
Ready,
IDMSB,
ButtonsLSB,
ButtonsMSB,

View file

@ -120,6 +120,18 @@ bool NeGcon::Transfer(const u8 data_in, u8* data_out)
switch (m_transfer_state)
{
case TransferState::Idle:
{
*data_out = 0xFF;
if (data_in == 0x01)
{
m_transfer_state = TransferState::Ready;
return true;
}
return false;
}
case TransferState::Ready:
{
if (data_in == 0x42)
{
@ -127,11 +139,9 @@ bool NeGcon::Transfer(const u8 data_in, u8* data_out)
m_transfer_state = TransferState::IDMSB;
return true;
}
else
{
*data_out = 0xFF;
return (data_in == 0x01);
}
*data_out = 0xFF;
return false;
}
case TransferState::IDMSB:

View file

@ -66,6 +66,7 @@ private:
enum class TransferState : u8
{
Idle,
Ready,
IDMSB,
ButtonsLSB,
ButtonsMSB,
@ -75,7 +76,7 @@ private:
AnalogL
};
std::array<u8, static_cast<u8>(Axis::Count)> m_axis_state {};
std::array<u8, static_cast<u8>(Axis::Count)> m_axis_state{};
// buttons are active low; bits 0-2, 8-10, 14-15 are not used and are always high
u16 m_button_state = UINT16_C(0xFFFF);

View file

@ -91,18 +91,27 @@ bool PlayStationMouse::Transfer(const u8 data_in, u8* data_out)
{
case TransferState::Idle:
{
// ack when sent 0x01, send ID for 0x42
*data_out = 0xFF;
if (data_in == 0x01)
{
m_transfer_state = TransferState::Ready;
return true;
}
return false;
}
case TransferState::Ready:
{
if (data_in == 0x42)
{
*data_out = Truncate8(ID);
m_transfer_state = TransferState::IDMSB;
return true;
}
else
{
*data_out = 0xFF;
return (data_in == 0x01);
}
*data_out = 0xFF;
return false;
}
case TransferState::IDMSB:

View file

@ -49,6 +49,7 @@ private:
enum class TransferState : u8
{
Idle,
Ready,
IDMSB,
ButtonsLSB,
ButtonsMSB,