Merge pull request #12491 from lioncash/si

HW/SI: Remove remaining global system accessors
This commit is contained in:
Tilka 2024-01-08 21:30:47 +00:00 committed by GitHub
commit e7ecc6fc9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 11 deletions

View File

@ -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);

View File

@ -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<ISIDevice> SIDevice_Create(Core::System& system, SIDevices device, int port_number);

View File

@ -298,7 +298,7 @@ int CSIDevice_GBA::RunBuffer(u8* buffer, int request_length)
{
int elapsed_time = static_cast<int>(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)

View File

@ -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())
@ -115,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)
@ -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