DigitalController: Fix broken input due to 0x01 handling
Fixes THPS among others.
This commit is contained in:
parent
3b32053065
commit
b0c492fd43
|
@ -16,68 +16,59 @@ void DigitalController::SetButtonState(Button button, bool pressed)
|
||||||
|
|
||||||
void DigitalController::ResetTransferState()
|
void DigitalController::ResetTransferState()
|
||||||
{
|
{
|
||||||
m_transfer_fifo.Clear();
|
m_transfer_state = TransferState::Idle;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DigitalController::Transfer(const u8 data_in, u8* data_out)
|
bool DigitalController::Transfer(const u8 data_in, u8* data_out)
|
||||||
{
|
{
|
||||||
bool ack;
|
static constexpr u16 ID = 0x5A41;
|
||||||
|
|
||||||
switch (data_in)
|
switch (m_transfer_state)
|
||||||
{
|
{
|
||||||
case 0x01: // tests if the controller is present
|
case TransferState::Idle:
|
||||||
{
|
{
|
||||||
Log_DebugPrintf("Access");
|
// ack when sent 0x01, send ID for 0x42
|
||||||
|
if (data_in == 0x42)
|
||||||
// response is hi-z
|
|
||||||
*data_out = 0xFF;
|
|
||||||
ack = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 0x42: // query state
|
|
||||||
{
|
{
|
||||||
Log_DebugPrintf("Query state");
|
*data_out = Truncate8(ID);
|
||||||
QueryState();
|
m_transfer_state = TransferState::IDMSB;
|
||||||
[[fallthrough]];
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
default: // sending response
|
|
||||||
{
|
|
||||||
if (m_transfer_fifo.IsEmpty())
|
|
||||||
{
|
|
||||||
Log_WarningPrint("FIFO empty on read");
|
|
||||||
*data_out = 0xFF;
|
|
||||||
ack = false;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*data_out = m_transfer_fifo.Pop();
|
*data_out = 0xFF;
|
||||||
ack = !m_transfer_fifo.IsEmpty();
|
return (data_in == 0x01);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log_DebugPrintf("Transfer, data_in=0x%02X, data_out=0x%02X, ack=%s", data_in, *data_out, ack ? "true" : "false");
|
case TransferState::IDMSB:
|
||||||
return ack;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DigitalController::QueryState()
|
|
||||||
{
|
{
|
||||||
constexpr u16 ID = 0x5A41;
|
*data_out = Truncate8(ID >> 8);
|
||||||
|
m_transfer_state = TransferState::ButtonsLSB;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
m_transfer_fifo.Clear();
|
case TransferState::ButtonsLSB:
|
||||||
|
{
|
||||||
|
*data_out = Truncate8(m_button_state);
|
||||||
|
m_transfer_state = TransferState::ButtonsMSB;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
m_transfer_fifo.Push(Truncate8(ID));
|
case TransferState::ButtonsMSB:
|
||||||
m_transfer_fifo.Push(Truncate8(ID >> 8));
|
*data_out = Truncate8(m_button_state >> 8);
|
||||||
|
m_transfer_state = TransferState::Idle;
|
||||||
|
return false;
|
||||||
|
|
||||||
m_transfer_fifo.Push(Truncate8(m_button_state)); // Digital switches low
|
default:
|
||||||
m_transfer_fifo.Push(Truncate8(m_button_state >> 8)); // Digital switches high
|
{
|
||||||
|
UnreachableCode();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<DigitalController> DigitalController::Create()
|
std::shared_ptr<DigitalController> DigitalController::Create()
|
||||||
{
|
{
|
||||||
return std::make_shared<DigitalController>();
|
return std::make_shared<DigitalController>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "common/fifo_queue.h"
|
|
||||||
#include "pad_device.h"
|
#include "pad_device.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
@ -37,10 +36,16 @@ public:
|
||||||
bool Transfer(const u8 data_in, u8* data_out) override;
|
bool Transfer(const u8 data_in, u8* data_out) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void QueryState();
|
enum class TransferState : u8
|
||||||
|
{
|
||||||
|
Idle,
|
||||||
|
IDMSB,
|
||||||
|
ButtonsLSB,
|
||||||
|
ButtonsMSB
|
||||||
|
};
|
||||||
|
|
||||||
// buttons are active low
|
// buttons are active low
|
||||||
u16 m_button_state = UINT16_C(0xFFFF);
|
u16 m_button_state = UINT16_C(0xFFFF);
|
||||||
|
|
||||||
InlineFIFOQueue<u8, 8> m_transfer_fifo;
|
TransferState m_transfer_state = TransferState::Idle;
|
||||||
};
|
};
|
||||||
|
|
|
@ -278,12 +278,14 @@ void Pad::DoTransfer()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// memory card responded, make it the active device until non-ack
|
// memory card responded, make it the active device until non-ack
|
||||||
|
Log_DebugPrintf("Transfer to memory card, data_out=0x%02X, data_in=0x%02X", data_in, data_out);
|
||||||
m_active_device = ActiveDevice::MemoryCard;
|
m_active_device = ActiveDevice::MemoryCard;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// controller responded, make it the active device until non-ack
|
// controller responded, make it the active device until non-ack
|
||||||
|
Log_DebugPrintf("Transfer to controller, data_out=0x%02X, data_in=0x%02X", data_in, data_out);
|
||||||
m_active_device = ActiveDevice::Controller;
|
m_active_device = ActiveDevice::Controller;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue