input-rec: integrate with new SIO code

This commit is contained in:
Tyler Wilding 2022-11-18 21:17:47 -05:00 committed by refractionpcsx2
parent f66ea63b7e
commit 199db12565
4 changed files with 47 additions and 16 deletions

View File

@ -606,13 +606,43 @@ void InputRecording::stop()
// TODO: Refactor this
void InputRecording::ControllerInterrupt(u8 port, size_t fifoSize, u8 dataIn, u8 dataOut)
{
// TODO - Multi-Tap Support
m_pad_data_available = data == s_READ_DATA_AND_VIBRATE_QUERY_FIRST_BYTE;
}
void InputRecording::querySecondByte(const u8 data)
{
m_pad_data_available &= data == s_READ_DATA_AND_VIBRATE_QUERY_SECOND_BYTE;
}
void InputRecording::controllerInterrupt(u8 port, size_t fifoSize, u8& dataIn, u8& dataOut)
{
// TODO - Multi-Tap Support (Qt doesn't support it yet anyway!)
// Keep these safe-guard checks in here, they are input recording only concerns
if (fifoSize == 1)
fInterruptFrame = dataIn == READ_DATA_AND_VIBRATE_FIRST_BYTE;
{
queryFirstByte(dataOut);
return;
}
else if (fifoSize == 2)
{
if (dataOut != READ_DATA_AND_VIBRATE_SECOND_BYTE)
fInterruptFrame = false;
querySecondByte(dataOut);
return;
}
if (!m_pad_data_available)
{
// bad data / first and second byte checks failed
return;
}
if (m_controls.isReplaying())
{
if (!m_file.readKeyBuffer(dataOut, m_frame_counter, port, fifoSize))
{
InputRec::consoleLog(fmt::format("Failed to read input data at frame {}", m_frame_counter));
}
// Update controller data state for future VirtualPad / logging usage.
//pads[port].padData->UpdateControllerData(bufIndex, bufVal);
}
// If there is data to read (previous two bytes looked correct)
@ -622,7 +652,7 @@ void InputRecording::ControllerInterrupt(u8 port, size_t fifoSize, u8 dataIn, u8
const u16 bufIndex = fifoSize - 3;
if (state == InputRecordingMode::Replaying)
{
if (!m_file.writeKeyBuffer(m_frame_counter, port, bufIndex, bufVal))
if (!m_file.writeKeyBuffer(m_frame_counter, port, fifoSize, dataOut))
{
InputRec::consoleLog(fmt::format("Failed to write input data at frame {}", m_frame_counter));
}

View File

@ -168,7 +168,7 @@ public:
void queryFirstByte(const u8 data);
void querySecondByte(const u8 bufVal);
void controllerInterrupt(const u8 port, const u16 bufIndex, u8& bufVal);
void controllerInterrupt(const u8 port, const size_t fifoSize, u8& dataIn, u8& dataOut);
void incFrameCounter();
u64 getFrameCounter() const;
bool isActive() const;
@ -188,7 +188,7 @@ public:
private:
// - https://github.com/PCSX2/pcsx2/blob/7db9627ff6986c2d3faeecc58525a0e32da2f29f/pcsx2/PAD/Windows/PAD.cpp#L1141
static constexpr u8 s_READ_DATA_AND_VIBRATE_QUERY_FIRST_BYTE = 0x42;
static constexpr u8 s_READ_DATA_AND_VIBRATE_QUERY_FIRST_BYTE = 0x79;
// - https://github.com/PCSX2/pcsx2/blob/7db9627ff6986c2d3faeecc58525a0e32da2f29f/pcsx2/PAD/Windows/PAD.cpp#L1142
static constexpr u8 s_READ_DATA_AND_VIBRATE_QUERY_SECOND_BYTE = 0x5A;

View File

@ -421,14 +421,14 @@ u8 Sio0::Memcard(u8 value)
// SIO2
// ============================================================================
void Sio2::UpdateInputRecording(u8 dataIn, u8 dataOut)
void Sio2::UpdateInputRecording(u8& dataIn, u8& dataOut)
{
if (EmuConfig.EnableRecordingTools)
if (EmuConfig.EnableRecordingTools && g_InputRecording.isActive())
{
// Ignore multitapped slots, only allow physical ports
if (slot == 0)
{
g_InputRecording.ControllerInterrupt(port, fifoOut.size(), dataIn, dataOut);
g_InputRecording.controllerInterrupt(port, fifoOut.size(), dataIn, dataOut);
}
}
}
@ -540,9 +540,10 @@ void Sio2::SetRecv1(u32 value)
void Sio2::Pad()
{
// Send PAD our current port, and get back whatever it says the first response byte should be.
const u8 firstResponseByte = PADstartPoll(port, slot);
u8 commandByte = 0x01;
u8 firstResponseByte = PADstartPoll(port, slot);
UpdateInputRecording(commandByte, firstResponseByte);
fifoOut.push_back(firstResponseByte);
UpdateInputRecording(0x01, firstResponseByte);
// Some games will refuse to read ALL pads, if RECV1 is not set to the CONNECTED value when ANY pad is polled,
// REGARDLESS of whether that pad is truly connected or not.
SetRecv1(Recv1::CONNECTED);
@ -550,11 +551,11 @@ void Sio2::Pad()
// Then for every byte in fifoIn, pass to PAD and see what it kicks back to us.
while (!fifoIn.empty())
{
const u8 commandByte = fifoIn.front();
u8 commandByte = fifoIn.front();
fifoIn.pop_front();
const u8 responseByte = PADpoll(commandByte);
fifoOut.push_back(responseByte);
u8 responseByte = PADpoll(commandByte);
UpdateInputRecording(commandByte, responseByte);
fifoOut.push_back(responseByte);
}
}

View File

@ -162,7 +162,7 @@ public:
class Sio2
{
private:
void UpdateInputRecording(u8 dataIn, u8 dataOut);
void UpdateInputRecording(u8& dataIn, u8& dataOut);
public:
std::array<u32, 16> send3; // 0x1f808200 - 0x1f80823f