From 7398d0b6efccd7cfad28274951e3430738f399d3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 8 Jan 2024 10:56:39 -0500 Subject: [PATCH 1/2] SI_DeviceGBAEmu: Remove global system accessors We can pass the system timer instance in from the existing system instance instead of the global accessor. --- Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp b/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp index 15514dd860..667533eb13 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp @@ -22,9 +22,9 @@ namespace SerialInterface { -static s64 GetSyncInterval() +static s64 GetSyncInterval(const SystemTimers::SystemTimersManager& timers) { - return Core::System::GetInstance().GetSystemTimers().GetTicksPerSecond() / 1000; + return timers.GetTicksPerSecond() / 1000; } CSIDevice_GBAEmu::CSIDevice_GBAEmu(Core::System& system, SIDevices device, int device_number) @@ -34,7 +34,8 @@ CSIDevice_GBAEmu::CSIDevice_GBAEmu(Core::System& system, SIDevices device, int d m_core->Start(system.GetCoreTiming().GetTicks()); m_gbahost = Host_CreateGBAHost(m_core); m_core->SetHost(m_gbahost); - system.GetSerialInterface().ScheduleEvent(m_device_number, GetSyncInterval()); + system.GetSerialInterface().ScheduleEvent(m_device_number, + GetSyncInterval(system.GetSystemTimers())); } CSIDevice_GBAEmu::~CSIDevice_GBAEmu() @@ -61,7 +62,8 @@ int CSIDevice_GBAEmu::RunBuffer(u8* buffer, int request_length) auto& si = m_system.GetSerialInterface(); si.RemoveEvent(m_device_number); - si.ScheduleEvent(m_device_number, TransferInterval() + GetSyncInterval()); + si.ScheduleEvent(m_device_number, + TransferInterval() + GetSyncInterval(m_system.GetSystemTimers())); for (int i = 0; i < MAX_SI_CHANNELS; ++i) { if (i == m_device_number || si.GetDeviceType(i) != GetDeviceType()) @@ -165,6 +167,8 @@ void CSIDevice_GBAEmu::DoState(PointerWrap& p) void CSIDevice_GBAEmu::OnEvent(u64 userdata, s64 cycles_late) { m_core->SendJoybusCommand(m_system.GetCoreTiming().GetTicks() + userdata, 0, nullptr, m_keys); - m_system.GetSerialInterface().ScheduleEvent(m_device_number, userdata + GetSyncInterval()); + + const auto num_cycles = userdata + GetSyncInterval(m_system.GetSystemTimers()); + m_system.GetSerialInterface().ScheduleEvent(m_device_number, num_cycles); } } // namespace SerialInterface From 409d2ecad3639df2317cac69d5199948377959cc Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 8 Jan 2024 11:03:21 -0500 Subject: [PATCH 2/2] SI_Device: Remove global system accessors We can pass the system timer instance through to avoid needing the global accessor. --- Source/Core/Core/HW/SI/SI_Device.cpp | 5 +++-- Source/Core/Core/HW/SI/SI_Device.h | 7 ++++++- Source/Core/Core/HW/SI/SI_DeviceGBA.cpp | 4 ++-- Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Source/Core/Core/HW/SI/SI_Device.cpp b/Source/Core/Core/HW/SI/SI_Device.cpp index 388f252a3e..7504e5fbe7 100644 --- a/Source/Core/Core/HW/SI/SI_Device.cpp +++ b/Source/Core/Core/HW/SI/SI_Device.cpp @@ -112,7 +112,8 @@ void ISIDevice::OnEvent(u64 userdata, s64 cycles_late) { } -int SIDevice_GetGBATransferTime(EBufferCommands cmd) +int SIDevice_GetGBATransferTime(const SystemTimers::SystemTimersManager& timers, + EBufferCommands cmd) { u64 gc_bytes_transferred = 1; u64 gba_bytes_transferred = 1; @@ -143,7 +144,7 @@ int SIDevice_GetGBATransferTime(EBufferCommands cmd) } } - const u32 ticks_per_second = Core::System::GetInstance().GetSystemTimers().GetTicksPerSecond(); + const u32 ticks_per_second = timers.GetTicksPerSecond(); const u64 cycles = (gba_bytes_transferred * 8 * ticks_per_second / GBA_BITS_PER_SECOND) + (gc_bytes_transferred * 8 * ticks_per_second / GC_BITS_PER_SECOND) + (stop_bits_ns * ticks_per_second / 1000000000LL); diff --git a/Source/Core/Core/HW/SI/SI_Device.h b/Source/Core/Core/HW/SI/SI_Device.h index 463f51bb39..ee76b39525 100644 --- a/Source/Core/Core/HW/SI/SI_Device.h +++ b/Source/Core/Core/HW/SI/SI_Device.h @@ -12,6 +12,10 @@ namespace Core { class System; } +namespace SystemTimers +{ +class SystemTimersManager; +} namespace SerialInterface { @@ -138,7 +142,8 @@ protected: SIDevices m_device_type; }; -int SIDevice_GetGBATransferTime(EBufferCommands cmd); +int SIDevice_GetGBATransferTime(const SystemTimers::SystemTimersManager& timers, + EBufferCommands cmd); bool SIDevice_IsGCController(SIDevices type); std::unique_ptr SIDevice_Create(Core::System& system, SIDevices device, int port_number); diff --git a/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp b/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp index d7b8fb92ed..1b47887b28 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp @@ -298,7 +298,7 @@ int CSIDevice_GBA::RunBuffer(u8* buffer, int request_length) { int elapsed_time = static_cast(m_system.GetCoreTiming().GetTicks() - m_timestamp_sent); // Tell SI to ask again after TransferInterval() cycles - if (SIDevice_GetGBATransferTime(m_last_cmd) > elapsed_time) + if (SIDevice_GetGBATransferTime(m_system.GetSystemTimers(), m_last_cmd) > elapsed_time) return 0; m_next_action = NextAction::ReceiveResponse; [[fallthrough]]; @@ -345,7 +345,7 @@ int CSIDevice_GBA::RunBuffer(u8* buffer, int request_length) int CSIDevice_GBA::TransferInterval() { - return SIDevice_GetGBATransferTime(m_last_cmd); + return SIDevice_GetGBATransferTime(m_system.GetSystemTimers(), m_last_cmd); } bool CSIDevice_GBA::GetData(u32& hi, u32& low) diff --git a/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp b/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp index 667533eb13..791b587156 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp @@ -117,7 +117,7 @@ int CSIDevice_GBAEmu::RunBuffer(u8* buffer, int request_length) int CSIDevice_GBAEmu::TransferInterval() { - return SIDevice_GetGBATransferTime(m_last_cmd); + return SIDevice_GetGBATransferTime(m_system.GetSystemTimers(), m_last_cmd); } bool CSIDevice_GBAEmu::GetData(u32& hi, u32& low)