diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java index a7c47a03ad..a2b380e989 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java @@ -228,7 +228,6 @@ public enum BooleanSetting implements AbstractBooleanSetting MAIN_CPU_THREAD, MAIN_ENABLE_CHEATS, MAIN_OVERRIDE_REGION_SETTINGS, - MAIN_WII_SD_CARD, // Can actually be changed, but specialized code is required MAIN_MMU, MAIN_DSP_JIT, }; diff --git a/Source/Core/Core/IOS/IOS.cpp b/Source/Core/Core/IOS/IOS.cpp index 9465cbe918..364e647839 100644 --- a/Source/Core/Core/IOS/IOS.cpp +++ b/Source/Core/Core/IOS/IOS.cpp @@ -63,7 +63,6 @@ static std::unique_ptr s_ios; constexpr u64 ENQUEUE_REQUEST_FLAG = 0x100000000ULL; static CoreTiming::EventType* s_event_enqueue; -static CoreTiming::EventType* s_event_sdio_notify; static CoreTiming::EventType* s_event_finish_ppc_bootstrap; static CoreTiming::EventType* s_event_finish_ios_boot; @@ -789,14 +788,6 @@ void Kernel::UpdateWantDeterminism(const bool new_want_determinism) device.second->UpdateWantDeterminism(new_want_determinism); } -void Kernel::SDIO_EventNotify() -{ - // TODO: Potential race condition: If IsRunning() becomes false after - // it's checked, an event may be scheduled after CoreTiming shuts down. - if (SConfig::GetInstance().bWii && Core::IsRunning()) - CoreTiming::ScheduleEvent(0, s_event_sdio_notify, 0, CoreTiming::FromThread::NON_CPU); -} - void Kernel::DoState(PointerWrap& p) { p.Do(m_request_queue); @@ -886,16 +877,6 @@ void Init() s_ios->HandleIPCEvent(userdata); }); - s_event_sdio_notify = CoreTiming::RegisterEvent("SDIO_EventNotify", [](u64, s64) { - if (!s_ios) - return; - - auto sdio_slot0 = s_ios->GetDeviceByName("/dev/sdio/slot0"); - auto device = static_cast(sdio_slot0.get()); - if (device) - device->EventNotify(); - }); - ESDevice::InitializeEmulationState(); s_event_finish_ppc_bootstrap = diff --git a/Source/Core/Core/IOS/IOS.h b/Source/Core/Core/IOS/IOS.h index 14254fa9cf..773a5d4d64 100644 --- a/Source/Core/Core/IOS/IOS.h +++ b/Source/Core/Core/IOS/IOS.h @@ -125,8 +125,6 @@ public: std::shared_ptr GetFSDevice(); std::shared_ptr GetES(); - void SDIO_EventNotify(); - void EnqueueIPCRequest(u32 address); void EnqueueIPCReply(const Request& request, s32 return_value, s64 cycles_in_future = 0, CoreTiming::FromThread from = CoreTiming::FromThread::CPU); diff --git a/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp b/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp index 4ea206e6ce..8cb17f3267 100644 --- a/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp +++ b/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp @@ -14,8 +14,10 @@ #include "Common/IOFile.h" #include "Common/Logging/Log.h" #include "Common/SDCardUtil.h" + #include "Core/Config/MainSettings.h" #include "Core/Config/SessionSettings.h" +#include "Core/Core.h" #include "Core/HW/Memmap.h" #include "Core/IOS/IOS.h" #include "Core/IOS/VersionInfo.h" @@ -27,6 +29,29 @@ SDIOSlot0Device::SDIOSlot0Device(Kernel& ios, const std::string& device_name) { if (!Config::Get(Config::MAIN_ALLOW_SD_WRITES)) INFO_LOG_FMT(IOS_SD, "Writes to SD card disabled by user"); + + m_config_callback_id = Config::AddConfigChangedCallback([this] { RefreshConfig(); }); + m_sd_card_inserted = Config::Get(Config::MAIN_WII_SD_CARD); +} + +SDIOSlot0Device::~SDIOSlot0Device() +{ + Config::RemoveConfigChangedCallback(m_config_callback_id); +} + +void SDIOSlot0Device::RefreshConfig() +{ + if (m_sd_card_inserted != Config::Get(Config::MAIN_WII_SD_CARD)) + { + Core::RunAsCPUThread([this] { + const bool sd_card_inserted = Config::Get(Config::MAIN_WII_SD_CARD); + if (m_sd_card_inserted != sd_card_inserted) + { + m_sd_card_inserted = sd_card_inserted; + EventNotify(); + } + }); + } } void SDIOSlot0Device::DoState(PointerWrap& p) @@ -49,10 +74,14 @@ void SDIOSlot0Device::EventNotify() if (!m_event) return; - const bool sd_card_inserted = Config::Get(Config::MAIN_WII_SD_CARD); - if ((sd_card_inserted && m_event->type == EVENT_INSERT) || - (!sd_card_inserted && m_event->type == EVENT_REMOVE)) + if ((m_sd_card_inserted && m_event->type == EVENT_INSERT) || + (!m_sd_card_inserted && m_event->type == EVENT_REMOVE)) { + if (m_sd_card_inserted) + INFO_LOG_FMT(IOS_SD, "Notifying PPC of SD card insertion"); + else + INFO_LOG_FMT(IOS_SD, "Notifying PPC of SD card removal"); + m_ios.EnqueueIPCReply(m_event->request, m_event->type); m_event.reset(); } diff --git a/Source/Core/Core/IOS/SDIO/SDIOSlot0.h b/Source/Core/Core/IOS/SDIO/SDIOSlot0.h index efa6595c78..fcdabd372e 100644 --- a/Source/Core/Core/IOS/SDIO/SDIOSlot0.h +++ b/Source/Core/Core/IOS/SDIO/SDIOSlot0.h @@ -22,6 +22,7 @@ class SDIOSlot0Device : public Device { public: SDIOSlot0Device(Kernel& ios, const std::string& device_name); + ~SDIOSlot0Device() override; void DoState(PointerWrap& p) override; @@ -30,8 +31,6 @@ public: std::optional IOCtl(const IOCtlRequest& request) override; std::optional IOCtlV(const IOCtlVRequest& request) override; - void EventNotify(); - private: // SD Host Controller Registers enum @@ -124,6 +123,10 @@ private: Request request; }; + void RefreshConfig(); + + void EventNotify(); + IPCReply WriteHCRegister(const IOCtlRequest& request); IPCReply ReadHCRegister(const IOCtlRequest& request); IPCReply ResetCard(const IOCtlRequest& request); @@ -162,5 +165,8 @@ private: std::array m_registers{}; File::IOFile m_card; + + size_t m_config_callback_id; + bool m_sd_card_inserted = false; }; } // namespace IOS::HLE diff --git a/Source/Core/DolphinQt/Settings.cpp b/Source/Core/DolphinQt/Settings.cpp index d22dcc6e25..61e378f736 100644 --- a/Source/Core/DolphinQt/Settings.cpp +++ b/Source/Core/DolphinQt/Settings.cpp @@ -705,10 +705,6 @@ void Settings::SetSDCardInserted(bool inserted) { Config::SetBaseOrCurrent(Config::MAIN_WII_SD_CARD, inserted); emit SDCardInsertionChanged(inserted); - - auto* ios = IOS::HLE::GetIOS(); - if (ios) - ios->SDIO_EventNotify(); } }