From 92e5c51adb2d973441ab303d9726f8474746a717 Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Thu, 6 Dec 2018 10:18:39 -0500 Subject: [PATCH] Service/DSP: implement semaphore event --- src/core/hle/kernel/wait_object.cpp | 7 +++++++ src/core/hle/kernel/wait_object.h | 7 +++++++ src/core/hle/service/dsp/dsp_dsp.cpp | 7 +++++-- src/core/hle/service/dsp/dsp_dsp.h | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/core/hle/kernel/wait_object.cpp b/src/core/hle/kernel/wait_object.cpp index d64b7def7..51d929d12 100644 --- a/src/core/hle/kernel/wait_object.cpp +++ b/src/core/hle/kernel/wait_object.cpp @@ -86,10 +86,17 @@ void WaitObject::WakeupAllWaitingThreads() { thread->ResumeFromWait(); } + + if (hle_notifier) + hle_notifier(); } const std::vector>& WaitObject::GetWaitingThreads() const { return waiting_threads; } +void WaitObject::SetHLENotifier(std::function callback) { + hle_notifier = callback; +} + } // namespace Kernel diff --git a/src/core/hle/kernel/wait_object.h b/src/core/hle/kernel/wait_object.h index 01fc40a0d..693ae2186 100644 --- a/src/core/hle/kernel/wait_object.h +++ b/src/core/hle/kernel/wait_object.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include "common/common_types.h" @@ -52,9 +53,15 @@ public: /// Get a const reference to the waiting threads list for debug use const std::vector>& GetWaitingThreads() const; + /// Sets a callback which is called when the object becomes available + void SetHLENotifier(std::function callback); + private: /// Threads waiting for this object to become available std::vector> waiting_threads; + + /// Function to call when this object becomes available + std::function hle_notifier; }; // Specialization of DynamicObjectCast for WaitObjects diff --git a/src/core/hle/service/dsp/dsp_dsp.cpp b/src/core/hle/service/dsp/dsp_dsp.cpp index c885b73fa..062ce8565 100644 --- a/src/core/hle/service/dsp/dsp_dsp.cpp +++ b/src/core/hle/service/dsp/dsp_dsp.cpp @@ -268,12 +268,12 @@ void DSP_DSP::GetSemaphoreEventHandle(Kernel::HLERequestContext& ctx) { void DSP_DSP::SetSemaphoreMask(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx, 0x17, 1, 0); - const u32 mask = rp.Pop(); + preset_semaphore = rp.Pop(); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(RESULT_SUCCESS); - LOG_WARNING(Service_DSP, "(STUBBED) called mask=0x{:08X}", mask); + LOG_WARNING(Service_DSP, "(STUBBED) called mask=0x{:04X}", preset_semaphore); } void DSP_DSP::GetHeadphoneStatus(Kernel::HLERequestContext& ctx) { @@ -380,6 +380,9 @@ DSP_DSP::DSP_DSP(Core::System& system) semaphore_event = system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "DSP_DSP::semaphore_event"); + + semaphore_event->SetHLENotifier( + [this]() { this->system.DSP().SetSemaphore(preset_semaphore); }); } DSP_DSP::~DSP_DSP() { diff --git a/src/core/hle/service/dsp/dsp_dsp.h b/src/core/hle/service/dsp/dsp_dsp.h index 2bc601511..5bf00334b 100644 --- a/src/core/hle/service/dsp/dsp_dsp.h +++ b/src/core/hle/service/dsp/dsp_dsp.h @@ -257,6 +257,7 @@ private: Core::System& system; Kernel::SharedPtr semaphore_event; + u16 preset_semaphore = 0; Kernel::SharedPtr interrupt_zero = nullptr; /// Currently unknown purpose Kernel::SharedPtr interrupt_one = nullptr; /// Currently unknown purpose