diff --git a/Source/Core/Core/HW/SI/SI.cpp b/Source/Core/Core/HW/SI/SI.cpp index ff349c64bf..7b17a213c1 100644 --- a/Source/Core/Core/HW/SI/SI.cpp +++ b/Source/Core/Core/HW/SI/SI.cpp @@ -240,7 +240,6 @@ static void SetNoResponse(u32 channel) s_status_reg.NOREP3 = 1; break; } - s_com_csr.COMERR = 1; } static void ChangeDeviceCallback(u64 user_data, s64 cycles_late) @@ -286,7 +285,7 @@ static void GenerateSIInterrupt(SIInterruptType type) constexpr u32 SI_XFER_LENGTH_MASK = 0x7f; // Translate [0,1,2,...,126,127] to [128,1,2,...,126,127] -constexpr u32 ConvertSILengthField(u32 field) +constexpr s32 ConvertSILengthField(u32 field) { return ((field - 1) & SI_XFER_LENGTH_MASK) + 1; } @@ -295,19 +294,19 @@ static void RunSIBuffer(u64 user_data, s64 cycles_late) { if (s_com_csr.TSTART) { - const u32 request_length = ConvertSILengthField(s_com_csr.OUTLNGTH); - const u32 expected_response_length = ConvertSILengthField(s_com_csr.INLNGTH); + const s32 request_length = ConvertSILengthField(s_com_csr.OUTLNGTH); + const s32 expected_response_length = ConvertSILengthField(s_com_csr.INLNGTH); const std::vector request_copy(s_si_buffer.data(), s_si_buffer.data() + request_length); const std::unique_ptr& device = s_channel[s_com_csr.CHANNEL].device; - const u32 actual_response_length = device->RunBuffer(s_si_buffer.data(), request_length); + const s32 actual_response_length = device->RunBuffer(s_si_buffer.data(), request_length); DEBUG_LOG_FMT(SERIALINTERFACE, "RunSIBuffer chan: {} request_length: {} expected_response_length: {} " "actual_response_length: {}", s_com_csr.CHANNEL, request_length, expected_response_length, actual_response_length); - if (expected_response_length != actual_response_length) + if (actual_response_length > 0 && expected_response_length != actual_response_length) { std::ostringstream ss; for (u8 b : request_copy) @@ -331,6 +330,9 @@ static void RunSIBuffer(u64 user_data, s64 cycles_late) if (actual_response_length != 0) { s_com_csr.TSTART = 0; + s_com_csr.COMERR = actual_response_length < 0; + if (actual_response_length < 0) + SetNoResponse(s_com_csr.CHANNEL); GenerateSIInterrupt(INT_TCINT); } else @@ -501,8 +503,6 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base) s_com_csr.RDSTINTMSK = tmp_com_csr.RDSTINTMSK; s_com_csr.TCINTMSK = tmp_com_csr.TCINTMSK; - s_com_csr.COMERR = 0; - if (tmp_com_csr.RDSTINT) s_com_csr.RDSTINT = 0; if (tmp_com_csr.TCINT) diff --git a/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp b/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp index 9268ca9127..36561a6ffb 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp @@ -332,10 +332,9 @@ int CSIDevice_GBA::RunBuffer(u8* buffer, int request_length) } else { - u32 reply = Common::swap32(SI_ERROR_NO_RESPONSE); - std::memcpy(buffer, &reply, sizeof(reply)); - return sizeof(reply); + return -1; } + m_last_cmd = buffer[0]; m_timestamp_sent = CoreTiming::GetTicks(); m_next_action = NextAction::WaitTransferTime; @@ -371,11 +370,7 @@ int CSIDevice_GBA::RunBuffer(u8* buffer, int request_length) m_next_action = NextAction::SendCommand; if (num_data_received == 0) - { - u32 reply = Common::swap32(SI_ERROR_NO_RESPONSE); - std::memcpy(buffer, &reply, sizeof(reply)); - return sizeof(reply); - } + return -1; #ifdef _DEBUG const Common::Log::LOG_LEVELS log_level = (m_last_cmd == CMD_STATUS || m_last_cmd == CMD_RESET) ? Common::Log::LERROR : diff --git a/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp b/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp index 4cf332347b..3393a996c4 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp @@ -43,11 +43,7 @@ int CSIDevice_GCController::RunBuffer(u8* buffer, int request_length) GCPadStatus pad_status = GetPadStatus(); if (!pad_status.isConnected) - { - u32 reply = Common::swap32(SI_ERROR_NO_RESPONSE); - std::memcpy(buffer, &reply, sizeof(reply)); - return sizeof(reply); - } + return -1; // Read the command EBufferCommands command = static_cast(buffer[0]); diff --git a/Source/Core/Core/HW/SI/SI_DeviceNull.cpp b/Source/Core/Core/HW/SI/SI_DeviceNull.cpp index f4ed00e7ae..6a2b16f2a0 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceNull.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceNull.cpp @@ -16,9 +16,7 @@ CSIDevice_Null::CSIDevice_Null(SIDevices device, int device_number) int CSIDevice_Null::RunBuffer(u8* buffer, int request_length) { - u32 reply = Common::swap32(SI_ERROR_NO_RESPONSE); - std::memcpy(buffer, &reply, sizeof(reply)); - return sizeof(reply); + return -1; } bool CSIDevice_Null::GetData(u32& hi, u32& low)