2014-11-12 16:13:08 -05:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 00:38:14 -05:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-11-12 16:13:08 -05:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2015-10-28 16:10:21 -04:00
|
|
|
#include <cstring>
|
2016-04-17 22:07:52 -04:00
|
|
|
#include "common/alignment.h"
|
2014-11-12 16:13:08 -05:00
|
|
|
#include "core/hle/hle.h"
|
2015-10-27 17:40:34 -04:00
|
|
|
#include "core/hle/kernel/mutex.h"
|
|
|
|
#include "core/hle/kernel/shared_memory.h"
|
2016-09-21 02:52:38 -04:00
|
|
|
#include "core/hle/service/csnd_snd.h"
|
2014-11-12 16:13:08 -05:00
|
|
|
|
2016-12-10 07:51:50 -05:00
|
|
|
namespace Service {
|
|
|
|
namespace CSND {
|
2014-11-12 16:13:08 -05:00
|
|
|
|
|
|
|
const Interface::FunctionInfo FunctionTable[] = {
|
2016-09-17 20:38:01 -04:00
|
|
|
{0x00010140, Initialize, "Initialize"},
|
|
|
|
{0x00020000, Shutdown, "Shutdown"},
|
|
|
|
{0x00030040, ExecuteType0Commands, "ExecuteType0Commands"},
|
|
|
|
{0x00040080, nullptr, "ExecuteType1Commands"},
|
|
|
|
{0x00050000, AcquireSoundChannels, "AcquireSoundChannels"},
|
|
|
|
{0x00060000, nullptr, "ReleaseSoundChannels"},
|
|
|
|
{0x00070000, nullptr, "AcquireCaptureDevice"},
|
|
|
|
{0x00080040, nullptr, "ReleaseCaptureDevice"},
|
|
|
|
{0x00090082, nullptr, "FlushDataCache"},
|
|
|
|
{0x000A0082, nullptr, "StoreDataCache"},
|
|
|
|
{0x000B0082, nullptr, "InvalidateDataCache"},
|
|
|
|
{0x000C0000, nullptr, "Reset"},
|
2014-11-12 16:13:08 -05:00
|
|
|
};
|
|
|
|
|
2016-12-10 07:51:50 -05:00
|
|
|
CSND_SND::CSND_SND() {
|
2015-01-30 13:56:49 -05:00
|
|
|
Register(FunctionTable);
|
2014-11-12 16:13:08 -05:00
|
|
|
}
|
|
|
|
|
2015-10-27 17:40:34 -04:00
|
|
|
static Kernel::SharedPtr<Kernel::SharedMemory> shared_memory = nullptr;
|
|
|
|
static Kernel::SharedPtr<Kernel::Mutex> mutex = nullptr;
|
|
|
|
|
2016-12-10 07:51:50 -05:00
|
|
|
void Initialize(Interface* self) {
|
2015-10-27 17:40:34 -04:00
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
2016-04-17 22:07:52 -04:00
|
|
|
u32 size = Common::AlignUp(cmd_buff[1], Memory::PAGE_SIZE);
|
|
|
|
using Kernel::MemoryPermission;
|
2016-09-17 20:38:01 -04:00
|
|
|
shared_memory = Kernel::SharedMemory::Create(nullptr, size, MemoryPermission::ReadWrite,
|
|
|
|
MemoryPermission::ReadWrite, 0,
|
|
|
|
Kernel::MemoryRegion::BASE, "CSND:SharedMemory");
|
2015-10-27 17:40:34 -04:00
|
|
|
|
|
|
|
mutex = Kernel::Mutex::Create(false);
|
|
|
|
|
2016-04-17 22:07:52 -04:00
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw;
|
2016-07-30 12:19:00 -04:00
|
|
|
cmd_buff[2] = IPC::CopyHandleDesc(2);
|
2015-10-27 17:40:34 -04:00
|
|
|
cmd_buff[3] = Kernel::g_handle_table.Create(mutex).MoveFrom();
|
|
|
|
cmd_buff[4] = Kernel::g_handle_table.Create(shared_memory).MoveFrom();
|
|
|
|
}
|
|
|
|
|
2016-12-10 07:51:50 -05:00
|
|
|
void ExecuteType0Commands(Interface* self) {
|
2015-10-28 16:10:21 -04:00
|
|
|
u32* const cmd_buff = Kernel::GetCommandBuffer();
|
2016-09-17 20:38:01 -04:00
|
|
|
u8* const ptr = shared_memory->GetPointer(cmd_buff[1]);
|
2015-10-28 16:10:21 -04:00
|
|
|
|
|
|
|
if (shared_memory != nullptr && ptr != nullptr) {
|
|
|
|
Type0Command command;
|
|
|
|
std::memcpy(&command, ptr, sizeof(Type0Command));
|
|
|
|
|
|
|
|
LOG_WARNING(Service, "(STUBBED) CSND_SND::ExecuteType0Commands");
|
|
|
|
command.finished |= 1;
|
|
|
|
cmd_buff[1] = 0;
|
2015-10-27 17:40:34 -04:00
|
|
|
|
2015-10-28 16:10:21 -04:00
|
|
|
std::memcpy(ptr, &command, sizeof(Type0Command));
|
|
|
|
} else {
|
2015-10-27 17:40:34 -04:00
|
|
|
cmd_buff[1] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-10 07:51:50 -05:00
|
|
|
void AcquireSoundChannels(Interface* self) {
|
2015-10-27 17:40:34 -04:00
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
cmd_buff[1] = 0;
|
|
|
|
cmd_buff[2] = 0xFFFFFF00;
|
|
|
|
}
|
|
|
|
|
2016-12-10 07:51:50 -05:00
|
|
|
void Shutdown(Interface* self) {
|
2015-10-27 17:40:34 -04:00
|
|
|
shared_memory = nullptr;
|
|
|
|
mutex = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-12-10 07:51:50 -05:00
|
|
|
} // namespace CSND
|
|
|
|
} // namespace Service
|