From b3264af7327f5106064878d1458f3d6a31a8a19f Mon Sep 17 00:00:00 2001 From: booto Date: Fri, 2 Aug 2019 02:33:21 -0400 Subject: [PATCH] SI: Be more careful with polling controllers Return errors if no device is connected (e.g. unplugged controller from gcadapter). Only poll channels if polling is enabled for that channel. --- Source/Core/Core/HW/SI/SI.cpp | 35 ++++++++++++++----- Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp | 5 ++- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/Source/Core/Core/HW/SI/SI.cpp b/Source/Core/Core/HW/SI/SI.cpp index 3438a4c95079..aa61e7db8a8c 100644 --- a/Source/Core/Core/HW/SI/SI.cpp +++ b/Source/Core/Core/HW/SI/SI.cpp @@ -634,15 +634,34 @@ void UpdateDevices() g_controller_interface.UpdateInput(); // Update channels and set the status bit if there's new data - s_status_reg.RDST0 = - !!s_channel[0].device->GetData(s_channel[0].in_hi.hex, s_channel[0].in_lo.hex); - s_status_reg.RDST1 = - !!s_channel[1].device->GetData(s_channel[1].in_hi.hex, s_channel[1].in_lo.hex); - s_status_reg.RDST2 = - !!s_channel[2].device->GetData(s_channel[2].in_hi.hex, s_channel[2].in_lo.hex); - s_status_reg.RDST3 = - !!s_channel[3].device->GetData(s_channel[3].in_hi.hex, s_channel[3].in_lo.hex); + std::array port_enabled = { + s_poll.EN0, + s_poll.EN1, + s_poll.EN2, + s_poll.EN3, + }; + for (size_t i = 0; i < port_enabled.size(); ++i) + { + if (port_enabled[i] == 0) + continue; + u32 in_hi, in_lo; + bool result = s_channel[i].device->GetData(in_hi, in_lo); + if (result) + { + // set RDST, update INBUFH/INBUFL, retain ERRLATCH + u32 error_latch = s_channel[i].in_hi.hex & 0x40000000; + s_channel[i].in_hi.hex = in_hi || error_latch; + s_channel[i].in_lo.hex = in_lo; + s_status_reg.hex |= (0x20000000 >> (i * 8)); + } + else + { + // set NOREP, ERRSTAT, ERRLATCH + s_channel[i].in_hi.hex |= 0xc0000000; + s_status_reg.hex |= (0x08000000 >> (i * 8)); + } + } UpdateInterrupts(); // Polling finished diff --git a/Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp b/Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp index 3f3d70202c6f..4cdddcfa238f 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp @@ -72,7 +72,10 @@ int CSIDevice_GCAdapter::RunBuffer(u8* buffer, int length) bool CSIDevice_GCAdapter::GetData(u32& hi, u32& low) { CSIDevice_GCController::GetData(hi, low); - + if (!GCAdapter::DeviceConnected(m_device_number)) + { + return false; + } if (m_simulate_konga) { hi &= CSIDevice_TaruKonga::HI_BUTTON_MASK;