From f7a9ea9d7e82dfe609b17799599686c714d4d1b1 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Fri, 12 Jan 2024 07:02:40 +0100 Subject: [PATCH] Core/HW/GBACore: Avoid global System accessor. --- Source/Core/Core/HW/GBACore.cpp | 11 +++++------ Source/Core/Core/HW/GBACore.h | 12 +++++++++++- Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Source/Core/Core/HW/GBACore.cpp b/Source/Core/Core/HW/GBACore.cpp index 887982d03d..6bb39776a3 100644 --- a/Source/Core/Core/HW/GBACore.cpp +++ b/Source/Core/Core/HW/GBACore.cpp @@ -149,7 +149,8 @@ static std::array GetROMHash(VFile* rom) return digest; } -Core::Core(int device_number) : m_device_number(device_number) +Core::Core(::Core::System& system, int device_number) + : m_device_number(device_number), m_system(system) { mLogSetDefaultLogger(&s_stub_logger); } @@ -405,8 +406,7 @@ void Core::SetSampleRates() blip_set_rates(m_core->getAudioChannel(m_core, 0), m_core->frequency(m_core), SAMPLE_RATE); blip_set_rates(m_core->getAudioChannel(m_core, 1), m_core->frequency(m_core), SAMPLE_RATE); - auto& system = ::Core::System::GetInstance(); - SoundStream* sound_stream = system.GetSoundStream(); + SoundStream* sound_stream = m_system.GetSoundStream(); sound_stream->GetMixer()->SetGBAInputSampleRateDivisors( m_device_number, Mixer::FIXED_SAMPLE_RATE_DIVIDEND / SAMPLE_RATE); } @@ -441,8 +441,7 @@ void Core::SetAVStream() blip_read_samples(left, &buffer[0], SAMPLES, 1); blip_read_samples(right, &buffer[1], SAMPLES, 1); - auto& system = ::Core::System::GetInstance(); - SoundStream* sound_stream = system.GetSoundStream(); + SoundStream* sound_stream = core->m_system.GetSoundStream(); sound_stream->GetMixer()->PushGBASamples(core->m_device_number, &buffer[0], SAMPLES); }; m_core->setAVStream(m_core, &m_stream); @@ -568,7 +567,7 @@ void Core::RunUntil(u64 gc_ticks) if (static_cast(gc_ticks - m_last_gc_ticks) <= 0) return; - const u64 gc_frequency = ::Core::System::GetInstance().GetSystemTimers().GetTicksPerSecond(); + const u64 gc_frequency = m_system.GetSystemTimers().GetTicksPerSecond(); const u32 core_frequency = GetCoreFrequency(m_core); mTimingSchedule(m_core->timing, &m_event, diff --git a/Source/Core/Core/HW/GBACore.h b/Source/Core/Core/HW/GBACore.h index 79f522bd9d..3a149a54fd 100644 --- a/Source/Core/Core/HW/GBACore.h +++ b/Source/Core/Core/HW/GBACore.h @@ -23,6 +23,10 @@ class GBAHostInterface; class PointerWrap; +namespace Core +{ +class System; +} namespace HW::GBA { @@ -50,7 +54,11 @@ struct CoreInfo class Core final { public: - explicit Core(int device_number); + explicit Core(::Core::System& system, int device_number); + Core(const Core&) = delete; + Core(Core&&) = delete; + Core& operator=(const Core&) = delete; + Core& operator=(Core&&) = delete; ~Core(); bool Start(u64 gc_ticks); @@ -135,5 +143,7 @@ private: std::condition_variable m_response_cv; bool m_response_ready = false; std::vector m_response; + + ::Core::System& m_system; }; } // namespace HW::GBA diff --git a/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp b/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp index 791b587156..4bb0e69617 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp @@ -30,7 +30,7 @@ static s64 GetSyncInterval(const SystemTimers::SystemTimersManager& timers) CSIDevice_GBAEmu::CSIDevice_GBAEmu(Core::System& system, SIDevices device, int device_number) : ISIDevice(system, device, device_number) { - m_core = std::make_shared(m_device_number); + m_core = std::make_shared(system, m_device_number); m_core->Start(system.GetCoreTiming().GetTicks()); m_gbahost = Host_CreateGBAHost(m_core); m_core->SetHost(m_gbahost);