From 5a4ed10982da69f0fdb594617fdcb38735aa3537 Mon Sep 17 00:00:00 2001 From: NarcolepticK Date: Fri, 27 Jul 2018 04:25:20 -0400 Subject: [PATCH] service/csnd: Moved into csnd folder and stubbed a few functions (#4006) * service/csnd: Moved into csnd folder and stubbed a few functions * service/csnd: Addresed comment about missing rb.Skip --- src/core/CMakeLists.txt | 4 +- src/core/hle/service/{ => csnd}/csnd_snd.cpp | 103 +++++++++++++------ src/core/hle/service/{ => csnd}/csnd_snd.h | 54 ++++++++++ src/core/hle/service/service.cpp | 2 +- 4 files changed, 127 insertions(+), 36 deletions(-) rename src/core/hle/service/{ => csnd}/csnd_snd.cpp (64%) rename src/core/hle/service/{ => csnd}/csnd_snd.h (70%) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 11cb01e23a..64703f6062 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -218,8 +218,8 @@ add_library(core STATIC hle/service/cfg/cfg_s.h hle/service/cfg/cfg_u.cpp hle/service/cfg/cfg_u.h - hle/service/csnd_snd.cpp - hle/service/csnd_snd.h + hle/service/csnd/csnd_snd.cpp + hle/service/csnd/csnd_snd.h hle/service/dlp/dlp.cpp hle/service/dlp/dlp.h hle/service/dlp/dlp_clnt.cpp diff --git a/src/core/hle/service/csnd_snd.cpp b/src/core/hle/service/csnd/csnd_snd.cpp similarity index 64% rename from src/core/hle/service/csnd_snd.cpp rename to src/core/hle/service/csnd/csnd_snd.cpp index 19a7952133..c1d9374739 100644 --- a/src/core/hle/service/csnd_snd.cpp +++ b/src/core/hle/service/csnd/csnd_snd.cpp @@ -4,27 +4,19 @@ #include "common/alignment.h" #include "core/hle/ipc_helpers.h" -#include "core/hle/service/csnd_snd.h" +#include "core/hle/result.h" +#include "core/hle/service/csnd/csnd_snd.h" namespace Service { namespace CSND { -struct Type0Command { - // command id and next command offset - u32 command_id; - u32 finished; - u32 flags; - u8 parameters[20]; -}; -static_assert(sizeof(Type0Command) == 0x20, "Type0Command structure size is wrong"); - void CSND_SND::Initialize(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx, 0x01, 5, 0); - u32 size = Common::AlignUp(rp.Pop(), Memory::PAGE_SIZE); - u32 offset0 = rp.Pop(); - u32 offset1 = rp.Pop(); - u32 offset2 = rp.Pop(); - u32 offset3 = rp.Pop(); + const u32 size = Common::AlignUp(rp.Pop(), Memory::PAGE_SIZE); + const u32 offset0 = rp.Pop(); + const u32 offset1 = rp.Pop(); + const u32 offset2 = rp.Pop(); + const u32 offset3 = rp.Pop(); using Kernel::MemoryPermission; mutex = Kernel::Mutex::Create(false, "CSND:mutex"); @@ -58,7 +50,7 @@ void CSND_SND::Shutdown(Kernel::HLERequestContext& ctx) { void CSND_SND::ExecuteCommands(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx, 0x03, 1, 0); - u32 addr = rp.Pop(); + const u32 addr = rp.Pop(); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); if (!shared_memory) { @@ -97,45 +89,90 @@ void CSND_SND::ReleaseSoundChannels(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service_CSND, "(STUBBED) called"); } -void CSND_SND::FlushDataCache(Kernel::HLERequestContext& ctx) { - IPC::RequestParser rp(ctx, 0x9, 2, 2); - VAddr address = rp.Pop(); - u32 size = rp.Pop(); - auto process = rp.PopObject(); +void CSND_SND::AcquireCapUnit(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp(ctx, 0x7, 0, 0); + + IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); + if (capture_units[0] && capture_units[1]) { + LOG_WARNING(Service_CSND, "No more capture units available"); + rb.Push(ResultCode(ErrorDescription::InvalidResultValue, ErrorModule::CSND, + ErrorSummary::OutOfResource, ErrorLevel::Status)); + rb.Skip(1, false); + return; + } + rb.Push(RESULT_SUCCESS); + + if (capture_units[0]) { + capture_units[1] = true; + rb.Push(1); + } else { + capture_units[0] = true; + rb.Push(0); + } + + LOG_WARNING(Service_CSND, "(STUBBED) called"); +} + +void CSND_SND::ReleaseCapUnit(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp(ctx, 0x8, 1, 0); + const u32 index = rp.Pop(); + + capture_units[index] = false; IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(RESULT_SUCCESS); - LOG_DEBUG(Service_CSND, "(STUBBED) called address=0x{:08X}, size=0x{:08X}, process={}", address, + LOG_WARNING(Service_CSND, "(STUBBED) called, capture_unit_index={}", index); +} + +void CSND_SND::FlushDataCache(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp(ctx, 0x9, 2, 2); + const VAddr address = rp.Pop(); + const u32 size = rp.Pop(); + const auto process = rp.PopObject(); + + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + rb.Push(RESULT_SUCCESS); + + LOG_TRACE(Service_CSND, "(STUBBED) called address=0x{:08X}, size=0x{:08X}, process={}", address, size, process->process_id); } void CSND_SND::StoreDataCache(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx, 0xA, 2, 2); - VAddr address = rp.Pop(); - u32 size = rp.Pop(); - auto process = rp.PopObject(); + const VAddr address = rp.Pop(); + const u32 size = rp.Pop(); + const auto process = rp.PopObject(); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(RESULT_SUCCESS); - LOG_DEBUG(Service_CSND, "(STUBBED) called address=0x{:08X}, size=0x{:08X}, process={}", address, + LOG_TRACE(Service_CSND, "(STUBBED) called address=0x{:08X}, size=0x{:08X}, process={}", address, size, process->process_id); } void CSND_SND::InvalidateDataCache(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx, 0xB, 2, 2); - VAddr address = rp.Pop(); - u32 size = rp.Pop(); - auto process = rp.PopObject(); + const VAddr address = rp.Pop(); + const u32 size = rp.Pop(); + const auto process = rp.PopObject(); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(RESULT_SUCCESS); - LOG_DEBUG(Service_CSND, "(STUBBED) called address=0x{:08X}, size=0x{:08X}, process={}", address, + LOG_TRACE(Service_CSND, "(STUBBED) called address=0x{:08X}, size=0x{:08X}, process={}", address, size, process->process_id); } +void CSND_SND::Reset(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp(ctx, 0xC, 0, 0); + + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + rb.Push(RESULT_SUCCESS); + + LOG_WARNING(Service_CSND, "(STUBBED) called"); +} + CSND_SND::CSND_SND() : ServiceFramework("csnd:SND", 4) { static const FunctionInfo functions[] = { // clang-format off @@ -145,12 +182,12 @@ CSND_SND::CSND_SND() : ServiceFramework("csnd:SND", 4) { {0x00040080, nullptr, "ExecuteType1Commands"}, {0x00050000, &CSND_SND::AcquireSoundChannels, "AcquireSoundChannels"}, {0x00060000, &CSND_SND::ReleaseSoundChannels, "ReleaseSoundChannels"}, - {0x00070000, nullptr, "AcquireCaptureDevice"}, - {0x00080040, nullptr, "ReleaseCaptureDevice"}, + {0x00070000, &CSND_SND::AcquireCapUnit, "AcquireCapUnit"}, + {0x00080040, &CSND_SND::ReleaseCapUnit, "ReleaseCapUnit"}, {0x00090082, &CSND_SND::FlushDataCache, "FlushDataCache"}, {0x000A0082, &CSND_SND::StoreDataCache, "StoreDataCache"}, {0x000B0082, &CSND_SND::InvalidateDataCache, "InvalidateDataCache"}, - {0x000C0000, nullptr, "Reset"}, + {0x000C0000, &CSND_SND::Reset, "Reset"}, // clang-format on }; diff --git a/src/core/hle/service/csnd_snd.h b/src/core/hle/service/csnd/csnd_snd.h similarity index 70% rename from src/core/hle/service/csnd_snd.h rename to src/core/hle/service/csnd/csnd_snd.h index 34722874de..baa4086e3d 100644 --- a/src/core/hle/service/csnd_snd.h +++ b/src/core/hle/service/csnd/csnd_snd.h @@ -53,6 +53,17 @@ private: */ void ExecuteCommands(Kernel::HLERequestContext& ctx); + /** + * CSND_SND::ExecuteType1Commands service function + * Inputs: + * 0 : Header Code[0x00040080] + * 1 : unknown + * 2 : unknown + * Outputs: + * 1 : Result of function, 0 on success, otherwise error code + */ + void ExecuteType1Commands(Kernel::HLERequestContext& ctx); + /** * CSND_SND::AcquireSoundChannels service function * Inputs: @@ -72,6 +83,28 @@ private: */ void ReleaseSoundChannels(Kernel::HLERequestContext& ctx); + /** + * CSND_SND::AcquireCapUnit service function + * This function tries to acquire one capture device (max: 2). + * Returns index of which capture device was acquired. + * Inputs: + * 0 : Header Code[0x00070000] + * Outputs: + * 1 : Result of function, 0 on success, otherwise error code + * 2 : Capture Unit + */ + void AcquireCapUnit(Kernel::HLERequestContext& ctx); + + /** + * CSND_SND::ReleaseCapUnit service function + * Inputs: + * 0 : Header Code[0x00080040] + * 1 : Capture Unit + * Outputs: + * 1 : Result of function, 0 on success, otherwise error code + */ + void ReleaseCapUnit(Kernel::HLERequestContext& ctx); + /** * CSND_SND::FlushDataCache service function * @@ -120,8 +153,29 @@ private: */ void InvalidateDataCache(Kernel::HLERequestContext& ctx); + /** + * CSND_SND::Reset service function + * Inputs: + * 0 : Header Code[0x000C0000] + * Outputs: + * 1 : Result of function, 0 on success, otherwise error code + */ + void Reset(Kernel::HLERequestContext& ctx); + + struct Type0Command { + // command id and next command offset + u32 command_id; + u32 finished; + u32 flags; + u8 parameters[20]; + }; + static_assert(sizeof(Type0Command) == 0x20, "Type0Command structure size is wrong"); + Kernel::SharedPtr mutex = nullptr; Kernel::SharedPtr shared_memory = nullptr; + + static constexpr u32 MaxCaptureUnits = 2; + std::array capture_units = {false, false}; }; /// Initializes the CSND_SND Service diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index a65249a3ec..efa258e089 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -22,7 +22,7 @@ #include "core/hle/service/cam/cam.h" #include "core/hle/service/cecd/cecd.h" #include "core/hle/service/cfg/cfg.h" -#include "core/hle/service/csnd_snd.h" +#include "core/hle/service/csnd/csnd_snd.h" #include "core/hle/service/dlp/dlp.h" #include "core/hle/service/dsp/dsp_dsp.h" #include "core/hle/service/err_f.h"