summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2025-11-22 04:38:12 -0500
committerGitHub <noreply@github.com>2025-11-22 04:38:12 -0500
commitccc19aafe00f4ae4c78393d0e22b01e55aace675 (patch)
tree4861114c56a18bd81e0259881f8f496a1e8887a4 /Source
parentf38a2bbb0ea0bb3e53992a492da5254f35fe0be2 (diff)
parenta3b1445e04931eea2fcf9f5cf7e78e0f92084591 (diff)
Merge pull request #14119 from jordan-woyak/si-status-response-length
HW/SI: Fix CMD_STATUS response lengths.
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/Core/HW/SI/SI.cpp30
-rw-r--r--Source/Core/Core/HW/SI/SI_Device.cpp10
-rw-r--r--Source/Core/Core/HW/SI/SI_Device.h8
-rw-r--r--Source/Core/Core/HW/SI/SI_DeviceDanceMat.cpp8
-rw-r--r--Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp1
-rw-r--r--Source/Core/Core/HW/SI/SI_DeviceGCController.cpp4
-rw-r--r--Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.cpp4
-rw-r--r--Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp5
8 files changed, 41 insertions, 29 deletions
diff --git a/Source/Core/Core/HW/SI/SI.cpp b/Source/Core/Core/HW/SI/SI.cpp
index c869ed0e3d..f451be328d 100644
--- a/Source/Core/Core/HW/SI/SI.cpp
+++ b/Source/Core/Core/HW/SI/SI.cpp
@@ -3,13 +3,15 @@
#include "Core/HW/SI/SI.h"
-#include <algorithm>
#include <array>
-#include <atomic>
#include <cstring>
-#include <iomanip>
#include <memory>
-#include <sstream>
+
+#if defined(_DEBUG)
+#include <vector>
+
+#include "Common/StringUtil.h"
+#endif
#include "Common/BitField.h"
#include "Common/ChunkFile.h"
@@ -147,9 +149,12 @@ void SerialInterfaceManager::RunSIBuffer(u64 user_data, s64 cycles_late)
{
const s32 request_length = ConvertSILengthField(m_com_csr.OUTLNGTH);
const s32 expected_response_length = ConvertSILengthField(m_com_csr.INLNGTH);
+
+#if defined(_DEBUG)
const std::vector<u8> request_copy(m_si_buffer.data(), m_si_buffer.data() + request_length);
+#endif
- const std::unique_ptr<ISIDevice>& device = m_channel[m_com_csr.CHANNEL].device;
+ auto* const device = m_channel[m_com_csr.CHANNEL].device.get();
const s32 actual_response_length = device->RunBuffer(m_si_buffer.data(), request_length);
DEBUG_LOG_FMT(SERIALINTERFACE,
@@ -159,15 +164,16 @@ void SerialInterfaceManager::RunSIBuffer(u64 user_data, s64 cycles_late)
actual_response_length);
if (actual_response_length > 0 && expected_response_length != actual_response_length)
{
- std::ostringstream ss;
- for (const u8 b : request_copy)
- {
- ss << std::hex << std::setw(2) << std::setfill('0') << (int)b << ' ';
- }
- DEBUG_LOG_FMT(
+#if defined(_DEBUG)
+ WARN_LOG_FMT(
SERIALINTERFACE,
"RunSIBuffer: expected_response_length({}) != actual_response_length({}): request: {}",
- expected_response_length, actual_response_length, ss.str());
+ expected_response_length, actual_response_length, Common::BytesToHexString(request_copy));
+#else
+ WARN_LOG_FMT(SERIALINTERFACE,
+ "RunSIBuffer: expected_response_length({}) != actual_response_length({})",
+ expected_response_length, actual_response_length);
+#endif
}
// TODO:
diff --git a/Source/Core/Core/HW/SI/SI_Device.cpp b/Source/Core/Core/HW/SI/SI_Device.cpp
index 8ea3e75d02..451523624b 100644
--- a/Source/Core/Core/HW/SI/SI_Device.cpp
+++ b/Source/Core/Core/HW/SI/SI_Device.cpp
@@ -11,6 +11,7 @@
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"
+#include "Common/Swap.h"
#include "Core/HW/SI/SI_DeviceDanceMat.h"
#include "Core/HW/SI/SI_DeviceGBA.h"
#ifdef HAS_LIBMGBA
@@ -87,6 +88,15 @@ void ISIDevice::OnEvent(u64 userdata, s64 cycles_late)
{
}
+int ISIDevice::CreateStatusResponse(u32 si_device_id, u8* buffer)
+{
+ constexpr int RESPONSE_LENGTH = 3;
+
+ Common::BigEndianValue<u32> id(si_device_id);
+ std::memcpy(buffer, &id, RESPONSE_LENGTH);
+ return RESPONSE_LENGTH;
+}
+
int SIDevice_GetGBATransferTime(const SystemTimers::SystemTimersManager& timers,
EBufferCommands cmd)
{
diff --git a/Source/Core/Core/HW/SI/SI_Device.h b/Source/Core/Core/HW/SI/SI_Device.h
index ebab7e3235..234c475e5f 100644
--- a/Source/Core/Core/HW/SI/SI_Device.h
+++ b/Source/Core/Core/HW/SI/SI_Device.h
@@ -123,7 +123,12 @@ public:
SIDevices GetDeviceType() const;
// Run the SI Buffer
+ // Return value:
+ // positive: The response length.
+ // 0: Response not ready, we will try again `TransferInterval()` cycles later.
+ // -1: No response.
virtual int RunBuffer(u8* buffer, int request_length);
+
virtual int TransferInterval();
virtual DataResponse GetData(u32& hi, u32& low) = 0;
@@ -138,6 +143,9 @@ public:
virtual void OnEvent(u64 userdata, s64 cycles_late);
protected:
+ // Only the three high bytes of `si_device_id` are used.
+ static int CreateStatusResponse(u32 si_device_id, u8* buffer);
+
Core::System& m_system;
int m_device_number;
diff --git a/Source/Core/Core/HW/SI/SI_DeviceDanceMat.cpp b/Source/Core/Core/HW/SI/SI_DeviceDanceMat.cpp
index d7ca1c8a3a..10cf79c0ec 100644
--- a/Source/Core/Core/HW/SI/SI_DeviceDanceMat.cpp
+++ b/Source/Core/Core/HW/SI/SI_DeviceDanceMat.cpp
@@ -3,10 +3,7 @@
#include "Core/HW/SI/SI_DeviceDanceMat.h"
-#include <cstring>
-
#include "Common/CommonTypes.h"
-#include "Common/Swap.h"
#include "InputCommon/GCPadStatus.h"
namespace SerialInterface
@@ -22,11 +19,10 @@ int CSIDevice_DanceMat::RunBuffer(u8* buffer, int request_length)
const auto command = static_cast<EBufferCommands>(buffer[0]);
if (command == EBufferCommands::CMD_STATUS)
{
+ // Only used for logging.
ISIDevice::RunBuffer(buffer, request_length);
- const u32 id = Common::swap32(SI_DANCEMAT);
- std::memcpy(buffer, &id, sizeof(id));
- return sizeof(id);
+ return CreateStatusResponse(SI_DANCEMAT, buffer);
}
return CSIDevice_GCController::RunBuffer(buffer, request_length);
}
diff --git a/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp b/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp
index b9c22f1d58..eb7c06343d 100644
--- a/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp
+++ b/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp
@@ -10,7 +10,6 @@
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
-#include "Common/Swap.h"
#include "Core/Core.h"
#include "Core/CoreTiming.h"
#include "Core/HW/GBACore.h"
diff --git a/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp b/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp
index beb633f499..270e75f56a 100644
--- a/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp
+++ b/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp
@@ -57,9 +57,7 @@ int CSIDevice_GCController::RunBuffer(u8* buffer, int request_length)
case EBufferCommands::CMD_STATUS:
case EBufferCommands::CMD_RESET:
{
- const u32 id = Common::swap32(SI_GC_CONTROLLER);
- std::memcpy(buffer, &id, sizeof(id));
- return sizeof(id);
+ return CreateStatusResponse(SI_GC_CONTROLLER, buffer);
}
case EBufferCommands::CMD_DIRECT:
diff --git a/Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.cpp b/Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.cpp
index cb639f415e..a3ca7e9ebe 100644
--- a/Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.cpp
+++ b/Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.cpp
@@ -34,9 +34,7 @@ int CSIDevice_GCSteeringWheel::RunBuffer(u8* buffer, int request_length)
case EBufferCommands::CMD_STATUS:
case EBufferCommands::CMD_RESET:
{
- const u32 id = Common::swap32(SI_GC_STEERING);
- std::memcpy(buffer, &id, sizeof(id));
- return sizeof(id);
+ return CreateStatusResponse(SI_GC_STEERING, buffer);
}
default:
return CSIDevice_GCController::RunBuffer(buffer, request_length);
diff --git a/Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp b/Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp
index 28ffc13f61..e3655bc904 100644
--- a/Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp
+++ b/Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp
@@ -9,7 +9,6 @@
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
-#include "Common/Swap.h"
#include "Core/HW/GCKeyboard.h"
#include "InputCommon/KeyboardStatus.h"
@@ -35,9 +34,7 @@ int CSIDevice_Keyboard::RunBuffer(u8* buffer, int request_length)
case EBufferCommands::CMD_STATUS:
case EBufferCommands::CMD_RESET:
{
- const u32 id = Common::swap32(SI_GC_KEYBOARD);
- std::memcpy(buffer, &id, sizeof(id));
- return sizeof(id);
+ return CreateStatusResponse(SI_GC_KEYBOARD, buffer);
}
case EBufferCommands::CMD_DIRECT_KB: