From 9be9cbda2f8876695ea18f44257dd032e63ef02f Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sat, 6 Jan 2024 04:56:36 +0100 Subject: [PATCH] Core/DSPHLE: Store reference to System in DSPHLE instances. --- Source/Core/Core/DSPEmulator.cpp | 4 ++-- Source/Core/Core/DSPEmulator.h | 6 +++++- Source/Core/Core/HW/DSP.cpp | 2 +- Source/Core/Core/HW/DSPHLE/DSPHLE.cpp | 14 +++++++------- Source/Core/Core/HW/DSPHLE/DSPHLE.h | 14 +++++++++++++- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Source/Core/Core/DSPEmulator.cpp b/Source/Core/Core/DSPEmulator.cpp index 61562317b9..0b5dd461e1 100644 --- a/Source/Core/Core/DSPEmulator.cpp +++ b/Source/Core/Core/DSPEmulator.cpp @@ -10,10 +10,10 @@ DSPEmulator::~DSPEmulator() = default; -std::unique_ptr CreateDSPEmulator(bool hle) +std::unique_ptr CreateDSPEmulator(Core::System& system, bool hle) { if (hle) - return std::make_unique(); + return std::make_unique(system); return std::make_unique(); } diff --git a/Source/Core/Core/DSPEmulator.h b/Source/Core/Core/DSPEmulator.h index b3b733817b..edd64cabad 100644 --- a/Source/Core/Core/DSPEmulator.h +++ b/Source/Core/Core/DSPEmulator.h @@ -6,6 +6,10 @@ #include #include "Common/CommonTypes.h" +namespace Core +{ +class System; +} class PointerWrap; class DSPEmulator @@ -34,4 +38,4 @@ protected: bool m_wii = false; }; -std::unique_ptr CreateDSPEmulator(bool hle); +std::unique_ptr CreateDSPEmulator(Core::System& system, bool hle); diff --git a/Source/Core/Core/HW/DSP.cpp b/Source/Core/Core/HW/DSP.cpp index c00da2a520..6099cec8be 100644 --- a/Source/Core/Core/HW/DSP.cpp +++ b/Source/Core/Core/HW/DSP.cpp @@ -119,7 +119,7 @@ void DSPManager::Init(bool hle) void DSPManager::Reinit(bool hle) { - m_dsp_emulator = CreateDSPEmulator(hle); + m_dsp_emulator = CreateDSPEmulator(m_system, hle); m_is_lle = m_dsp_emulator->IsLLE(); if (SConfig::GetInstance().bWii) diff --git a/Source/Core/Core/HW/DSPHLE/DSPHLE.cpp b/Source/Core/Core/HW/DSPHLE/DSPHLE.cpp index 2429ce9577..22f6f70e86 100644 --- a/Source/Core/Core/HW/DSPHLE/DSPHLE.cpp +++ b/Source/Core/Core/HW/DSPHLE/DSPHLE.cpp @@ -14,7 +14,9 @@ namespace DSP::HLE { -DSPHLE::DSPHLE() = default; +DSPHLE::DSPHLE(Core::System& system) : m_system(system) +{ +} DSPHLE::~DSPHLE() = default; @@ -55,7 +57,7 @@ u32 DSPHLE::DSP_UpdateRate() { // AX HLE uses 3ms (Wii) or 5ms (GC) timing period // But to be sure, just update the HLE every ms. - return Core::System::GetInstance().GetSystemTimers().GetTicksPerSecond() / 1000; + return m_system.GetSystemTimers().GetTicksPerSecond() / 1000; } void DSPHLE::SendMailToDSP(u32 mail) @@ -221,8 +223,7 @@ u16 DSPHLE::DSP_WriteControlRegister(u16 value) SetUCode(UCODE_INIT_AUDIO_SYSTEM); temp.DSPInitCode = 1; // Number obtained from real hardware on a Wii, but it's not perfectly consistent - m_control_reg_init_code_clear_time = - Core::System::GetInstance().GetSystemTimers().GetFakeTimeBase() + 130; + m_control_reg_init_code_clear_time = m_system.GetSystemTimers().GetFakeTimeBase() + 130; } m_dsp_control.Hex = temp.Hex; @@ -233,11 +234,10 @@ u16 DSPHLE::DSP_ReadControlRegister() { if (m_dsp_control.DSPInitCode != 0) { - auto& system = Core::System::GetInstance(); - if (system.GetSystemTimers().GetFakeTimeBase() >= m_control_reg_init_code_clear_time) + if (m_system.GetSystemTimers().GetFakeTimeBase() >= m_control_reg_init_code_clear_time) m_dsp_control.DSPInitCode = 0; else - system.GetCoreTiming().ForceExceptionCheck(50); // Keep checking + m_system.GetCoreTiming().ForceExceptionCheck(50); // Keep checking } return m_dsp_control.Hex; } diff --git a/Source/Core/Core/HW/DSPHLE/DSPHLE.h b/Source/Core/Core/HW/DSPHLE/DSPHLE.h index d03c5be5cc..a88c66052c 100644 --- a/Source/Core/Core/HW/DSPHLE/DSPHLE.h +++ b/Source/Core/Core/HW/DSPHLE/DSPHLE.h @@ -10,6 +10,10 @@ #include "Core/HW/DSP.h" #include "Core/HW/DSPHLE/MailHandler.h" +namespace Core +{ +class System; +} class PointerWrap; namespace DSP::HLE @@ -19,7 +23,11 @@ class UCodeInterface; class DSPHLE : public DSPEmulator { public: - DSPHLE(); + explicit DSPHLE(Core::System& system); + DSPHLE(const DSPHLE& other) = delete; + DSPHLE(DSPHLE&& other) = delete; + DSPHLE& operator=(const DSPHLE& other) = delete; + DSPHLE& operator=(DSPHLE&& other) = delete; ~DSPHLE(); bool Initialize(bool wii, bool dsp_thread) override; @@ -42,6 +50,8 @@ public: void SetUCode(u32 crc); void SwapUCode(u32 crc); + Core::System& GetSystem() const { return m_system; } + private: void SendMailToDSP(u32 mail); @@ -67,5 +77,7 @@ private: DSP::UDSPControl m_dsp_control; u64 m_control_reg_init_code_clear_time = 0; CMailHandler m_mail_handler; + + Core::System& m_system; }; } // namespace DSP::HLE