From 31d33d0efde8a517c4754dc6a3efb14f12cd85a0 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sun, 12 Mar 2023 18:13:43 +0100 Subject: [PATCH] HW/ProcessorInterface: Store reference to System in class. --- Source/Core/Core/HW/ProcessorInterface.cpp | 26 +++++++++++++--------- Source/Core/Core/HW/ProcessorInterface.h | 11 ++++++++- Source/Core/Core/System.cpp | 3 ++- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Source/Core/Core/HW/ProcessorInterface.cpp b/Source/Core/Core/HW/ProcessorInterface.cpp index 2c45e56416..70b34ccc81 100644 --- a/Source/Core/Core/HW/ProcessorInterface.cpp +++ b/Source/Core/Core/HW/ProcessorInterface.cpp @@ -18,6 +18,7 @@ #include "Core/IOS/IOS.h" #include "Core/IOS/STM/STM.h" #include "Core/PowerPC/PowerPC.h" +#include "Core/System.h" #include "VideoCommon/AsyncRequests.h" #include "VideoCommon/Fifo.h" @@ -27,6 +28,12 @@ constexpr u32 FLIPPER_REV_A = 0x046500B0; constexpr u32 FLIPPER_REV_B = 0x146500B1; constexpr u32 FLIPPER_REV_C = 0x246500B1; +ProcessorInterfaceManager::ProcessorInterfaceManager(Core::System& system) : m_system(system) +{ +} + +ProcessorInterfaceManager::~ProcessorInterfaceManager() = default; + void ProcessorInterfaceManager::DoState(PointerWrap& p) { p.Do(m_interrupt_mask); @@ -49,8 +56,7 @@ void ProcessorInterfaceManager::Init() m_reset_code = 0; // Cold reset m_interrupt_cause = INT_CAUSE_RST_BUTTON | INT_CAUSE_VI; - auto& system = Core::System::GetInstance(); - auto& core_timing = system.GetCoreTiming(); + auto& core_timing = m_system.GetCoreTiming(); m_event_type_toggle_reset_button = core_timing.RegisterEvent("ToggleResetButton", ToggleResetButtonCallback); m_event_type_ios_notify_reset_button = @@ -65,14 +71,14 @@ void ProcessorInterfaceManager::RegisterMMIO(MMIO::Mapping* mmio, u32 base) MMIO::ComplexWrite([](Core::System& system, u32, u32 val) { auto& processor_interface = system.GetProcessorInterface(); processor_interface.m_interrupt_cause &= ~val; - processor_interface.UpdateException(system); + processor_interface.UpdateException(); })); mmio->Register(base | PI_INTERRUPT_MASK, MMIO::DirectRead(&m_interrupt_mask), MMIO::ComplexWrite([](Core::System& system, u32, u32 val) { auto& processor_interface = system.GetProcessorInterface(); processor_interface.m_interrupt_mask = val; - processor_interface.UpdateException(system); + processor_interface.UpdateException(); })); mmio->Register(base | PI_FIFO_BASE, MMIO::DirectRead(&m_fifo_cpu_base), @@ -137,9 +143,9 @@ void ProcessorInterfaceManager::RegisterMMIO(MMIO::Mapping* mmio, u32 base) } } -void ProcessorInterfaceManager::UpdateException(Core::System& system) +void ProcessorInterfaceManager::UpdateException() { - auto& ppc_state = system.GetPPCState(); + auto& ppc_state = m_system.GetPPCState(); if ((m_interrupt_cause & m_interrupt_mask) != 0) ppc_state.Exceptions |= EXCEPTION_EXTERNAL_INT; else @@ -209,7 +215,7 @@ void ProcessorInterfaceManager::SetInterrupt(u32 cause_mask, bool set) m_interrupt_cause &= ~cause_mask; // is there any reason to have this possibility? // F|RES: i think the hw devices reset the interrupt in the PI to 0 // if the interrupt cause is eliminated. that isn't done by software (afaik) - UpdateException(Core::System::GetInstance()); + UpdateException(); } void ProcessorInterfaceManager::SetResetButton(bool set) @@ -252,8 +258,7 @@ void ProcessorInterfaceManager::ResetButton_Tap() if (!Core::IsRunning()) return; - auto& system = Core::System::GetInstance(); - auto& core_timing = system.GetCoreTiming(); + auto& core_timing = m_system.GetCoreTiming(); core_timing.ScheduleEvent(0, m_event_type_toggle_reset_button, true, CoreTiming::FromThread::ANY); core_timing.ScheduleEvent(0, m_event_type_ios_notify_reset_button, 0, CoreTiming::FromThread::ANY); @@ -266,8 +271,7 @@ void ProcessorInterfaceManager::PowerButton_Tap() if (!Core::IsRunning()) return; - auto& system = Core::System::GetInstance(); - auto& core_timing = system.GetCoreTiming(); + auto& core_timing = m_system.GetCoreTiming(); core_timing.ScheduleEvent(0, m_event_type_ios_notify_power_button, 0, CoreTiming::FromThread::ANY); } diff --git a/Source/Core/Core/HW/ProcessorInterface.h b/Source/Core/Core/HW/ProcessorInterface.h index 5247c03b2f..6387634843 100644 --- a/Source/Core/Core/HW/ProcessorInterface.h +++ b/Source/Core/Core/HW/ProcessorInterface.h @@ -63,6 +63,13 @@ enum class ProcessorInterfaceManager { public: + explicit ProcessorInterfaceManager(Core::System& system); + ProcessorInterfaceManager(const ProcessorInterfaceManager& other) = delete; + ProcessorInterfaceManager(ProcessorInterfaceManager&& other) = delete; + ProcessorInterfaceManager& operator=(const ProcessorInterfaceManager& other) = delete; + ProcessorInterfaceManager& operator=(ProcessorInterfaceManager&& other) = delete; + ~ProcessorInterfaceManager(); + void Init(); void DoState(PointerWrap& p); @@ -87,7 +94,7 @@ public: private: // Let the PPC know that an external exception is set/cleared - void UpdateException(Core::System& system); + void UpdateException(); void SetResetButton(bool set); @@ -101,5 +108,7 @@ private: CoreTiming::EventType* m_event_type_ios_notify_power_button = nullptr; u32 m_reset_code = 0; + + Core::System& m_system; }; } // namespace ProcessorInterface diff --git a/Source/Core/Core/System.cpp b/Source/Core/Core/System.cpp index b282687cfa..788a4834b9 100644 --- a/Source/Core/Core/System.cpp +++ b/Source/Core/Core/System.cpp @@ -38,7 +38,8 @@ struct System::Impl explicit Impl(System& system) : m_audio_interface(system), m_core_timing(system), m_dsp(system), m_dvd_interface(system), m_dvd_thread(system), m_expansion_interface(system), m_gp_fifo(system), m_memory(system), - m_ppc_state(PowerPC::ppcState), m_serial_interface(system), m_video_interface(system) + m_ppc_state(PowerPC::ppcState), m_processor_interface(system), m_serial_interface(system), + m_video_interface(system) { }