Core/DSPHLE: Store reference to System in DSPHLE instances.

This commit is contained in:
Admiral H. Curtiss 2024-01-06 04:56:36 +01:00
parent 00fb709c74
commit 9be9cbda2f
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
5 changed files with 28 additions and 12 deletions

View File

@ -10,10 +10,10 @@
DSPEmulator::~DSPEmulator() = default; DSPEmulator::~DSPEmulator() = default;
std::unique_ptr<DSPEmulator> CreateDSPEmulator(bool hle) std::unique_ptr<DSPEmulator> CreateDSPEmulator(Core::System& system, bool hle)
{ {
if (hle) if (hle)
return std::make_unique<DSP::HLE::DSPHLE>(); return std::make_unique<DSP::HLE::DSPHLE>(system);
return std::make_unique<DSP::LLE::DSPLLE>(); return std::make_unique<DSP::LLE::DSPLLE>();
} }

View File

@ -6,6 +6,10 @@
#include <memory> #include <memory>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
namespace Core
{
class System;
}
class PointerWrap; class PointerWrap;
class DSPEmulator class DSPEmulator
@ -34,4 +38,4 @@ protected:
bool m_wii = false; bool m_wii = false;
}; };
std::unique_ptr<DSPEmulator> CreateDSPEmulator(bool hle); std::unique_ptr<DSPEmulator> CreateDSPEmulator(Core::System& system, bool hle);

View File

@ -119,7 +119,7 @@ void DSPManager::Init(bool hle)
void DSPManager::Reinit(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(); m_is_lle = m_dsp_emulator->IsLLE();
if (SConfig::GetInstance().bWii) if (SConfig::GetInstance().bWii)

View File

@ -14,7 +14,9 @@
namespace DSP::HLE namespace DSP::HLE
{ {
DSPHLE::DSPHLE() = default; DSPHLE::DSPHLE(Core::System& system) : m_system(system)
{
}
DSPHLE::~DSPHLE() = default; DSPHLE::~DSPHLE() = default;
@ -55,7 +57,7 @@ u32 DSPHLE::DSP_UpdateRate()
{ {
// AX HLE uses 3ms (Wii) or 5ms (GC) timing period // AX HLE uses 3ms (Wii) or 5ms (GC) timing period
// But to be sure, just update the HLE every ms. // 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) void DSPHLE::SendMailToDSP(u32 mail)
@ -221,8 +223,7 @@ u16 DSPHLE::DSP_WriteControlRegister(u16 value)
SetUCode(UCODE_INIT_AUDIO_SYSTEM); SetUCode(UCODE_INIT_AUDIO_SYSTEM);
temp.DSPInitCode = 1; temp.DSPInitCode = 1;
// Number obtained from real hardware on a Wii, but it's not perfectly consistent // Number obtained from real hardware on a Wii, but it's not perfectly consistent
m_control_reg_init_code_clear_time = m_control_reg_init_code_clear_time = m_system.GetSystemTimers().GetFakeTimeBase() + 130;
Core::System::GetInstance().GetSystemTimers().GetFakeTimeBase() + 130;
} }
m_dsp_control.Hex = temp.Hex; m_dsp_control.Hex = temp.Hex;
@ -233,11 +234,10 @@ u16 DSPHLE::DSP_ReadControlRegister()
{ {
if (m_dsp_control.DSPInitCode != 0) if (m_dsp_control.DSPInitCode != 0)
{ {
auto& system = Core::System::GetInstance(); if (m_system.GetSystemTimers().GetFakeTimeBase() >= m_control_reg_init_code_clear_time)
if (system.GetSystemTimers().GetFakeTimeBase() >= m_control_reg_init_code_clear_time)
m_dsp_control.DSPInitCode = 0; m_dsp_control.DSPInitCode = 0;
else else
system.GetCoreTiming().ForceExceptionCheck(50); // Keep checking m_system.GetCoreTiming().ForceExceptionCheck(50); // Keep checking
} }
return m_dsp_control.Hex; return m_dsp_control.Hex;
} }

View File

@ -10,6 +10,10 @@
#include "Core/HW/DSP.h" #include "Core/HW/DSP.h"
#include "Core/HW/DSPHLE/MailHandler.h" #include "Core/HW/DSPHLE/MailHandler.h"
namespace Core
{
class System;
}
class PointerWrap; class PointerWrap;
namespace DSP::HLE namespace DSP::HLE
@ -19,7 +23,11 @@ class UCodeInterface;
class DSPHLE : public DSPEmulator class DSPHLE : public DSPEmulator
{ {
public: 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(); ~DSPHLE();
bool Initialize(bool wii, bool dsp_thread) override; bool Initialize(bool wii, bool dsp_thread) override;
@ -42,6 +50,8 @@ public:
void SetUCode(u32 crc); void SetUCode(u32 crc);
void SwapUCode(u32 crc); void SwapUCode(u32 crc);
Core::System& GetSystem() const { return m_system; }
private: private:
void SendMailToDSP(u32 mail); void SendMailToDSP(u32 mail);
@ -67,5 +77,7 @@ private:
DSP::UDSPControl m_dsp_control; DSP::UDSPControl m_dsp_control;
u64 m_control_reg_init_code_clear_time = 0; u64 m_control_reg_init_code_clear_time = 0;
CMailHandler m_mail_handler; CMailHandler m_mail_handler;
Core::System& m_system;
}; };
} // namespace DSP::HLE } // namespace DSP::HLE