|
|
|
@ -2,15 +2,12 @@
|
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
|
#include "common/bit_field.h"
|
|
|
|
|
#include "core/core_timing.h"
|
|
|
|
|
#include "core/frontend/input.h"
|
|
|
|
|
#include "core/hle/ipc_helpers.h"
|
|
|
|
|
#include "core/hle/kernel/event.h"
|
|
|
|
|
#include "core/hle/kernel/shared_memory.h"
|
|
|
|
|
#include "core/hle/service/hid/hid.h"
|
|
|
|
|
#include "core/hle/service/ir/ir.h"
|
|
|
|
|
#include "core/hle/service/ir/ir_rst.h"
|
|
|
|
|
#include "core/settings.h"
|
|
|
|
|
|
|
|
|
@ -48,18 +45,7 @@ struct SharedMem {
|
|
|
|
|
|
|
|
|
|
static_assert(sizeof(SharedMem) == 0x98, "SharedMem has wrong size!");
|
|
|
|
|
|
|
|
|
|
static Kernel::SharedPtr<Kernel::Event> update_event;
|
|
|
|
|
static Kernel::SharedPtr<Kernel::SharedMemory> shared_memory;
|
|
|
|
|
static u32 next_pad_index;
|
|
|
|
|
static CoreTiming::EventType* update_callback_id;
|
|
|
|
|
static std::unique_ptr<Input::ButtonDevice> zl_button;
|
|
|
|
|
static std::unique_ptr<Input::ButtonDevice> zr_button;
|
|
|
|
|
static std::unique_ptr<Input::AnalogDevice> c_stick;
|
|
|
|
|
static std::atomic<bool> is_device_reload_pending;
|
|
|
|
|
static bool raw_c_stick;
|
|
|
|
|
static int update_period;
|
|
|
|
|
|
|
|
|
|
static void LoadInputDevices() {
|
|
|
|
|
void IR_RST::LoadInputDevices() {
|
|
|
|
|
zl_button = Input::CreateDevice<Input::ButtonDevice>(
|
|
|
|
|
Settings::values.buttons[Settings::NativeButton::ZL]);
|
|
|
|
|
zr_button = Input::CreateDevice<Input::ButtonDevice>(
|
|
|
|
@ -68,13 +54,13 @@ static void LoadInputDevices() {
|
|
|
|
|
Settings::values.analogs[Settings::NativeAnalog::CStick]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void UnloadInputDevices() {
|
|
|
|
|
void IR_RST::UnloadInputDevices() {
|
|
|
|
|
zl_button = nullptr;
|
|
|
|
|
zr_button = nullptr;
|
|
|
|
|
c_stick = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void UpdateCallback(u64 userdata, int cycles_late) {
|
|
|
|
|
void IR_RST::UpdateCallback(u64 userdata, int cycles_late) {
|
|
|
|
|
SharedMem* mem = reinterpret_cast<SharedMem*>(shared_memory->GetPointer());
|
|
|
|
|
|
|
|
|
|
if (is_device_reload_pending.exchange(false))
|
|
|
|
@ -133,30 +119,15 @@ static void UpdateCallback(u64 userdata, int cycles_late) {
|
|
|
|
|
CoreTiming::ScheduleEvent(msToCycles(update_period) - cycles_late, update_callback_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* IR::GetHandles service function
|
|
|
|
|
* Outputs:
|
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
|
* 2 : Translate header, used by the ARM11-kernel
|
|
|
|
|
* 3 : Shared memory handle
|
|
|
|
|
* 4 : Event handle
|
|
|
|
|
*/
|
|
|
|
|
static void GetHandles(Interface* self) {
|
|
|
|
|
IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x01, 0, 0);
|
|
|
|
|
void IR_RST::GetHandles(Kernel::HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp(ctx, 0x01, 0, 0);
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 3);
|
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
|
rb.PushMoveHandles(Kernel::g_handle_table.Create(Service::IR::shared_memory).Unwrap(),
|
|
|
|
|
Kernel::g_handle_table.Create(Service::IR::update_event).Unwrap());
|
|
|
|
|
rb.PushMoveObjects(shared_memory, update_event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* IR::Initialize service function
|
|
|
|
|
* Inputs:
|
|
|
|
|
* 1 : pad state update period in ms
|
|
|
|
|
* 2 : bool output raw c-stick data
|
|
|
|
|
*/
|
|
|
|
|
static void Initialize(Interface* self) {
|
|
|
|
|
IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x02, 2, 0);
|
|
|
|
|
void IR_RST::Initialize(Kernel::HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp(ctx, 0x02, 2, 0);
|
|
|
|
|
update_period = static_cast<int>(rp.Pop<u32>());
|
|
|
|
|
raw_c_stick = rp.Pop<bool>();
|
|
|
|
|
|
|
|
|
@ -173,8 +144,8 @@ static void Initialize(Interface* self) {
|
|
|
|
|
LOG_DEBUG(Service_IR, "called. update_period=%d, raw_c_stick=%d", update_period, raw_c_stick);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Shutdown(Interface* self) {
|
|
|
|
|
IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x03, 1, 0);
|
|
|
|
|
void IR_RST::Shutdown(Kernel::HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp(ctx, 0x03, 0, 0);
|
|
|
|
|
|
|
|
|
|
CoreTiming::UnscheduleEvent(update_callback_id, 0);
|
|
|
|
|
UnloadInputDevices();
|
|
|
|
@ -184,18 +155,7 @@ static void Shutdown(Interface* self) {
|
|
|
|
|
LOG_DEBUG(Service_IR, "called");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Interface::FunctionInfo FunctionTable[] = {
|
|
|
|
|
{0x00010000, GetHandles, "GetHandles"},
|
|
|
|
|
{0x00020080, Initialize, "Initialize"},
|
|
|
|
|
{0x00030000, Shutdown, "Shutdown"},
|
|
|
|
|
{0x00090000, nullptr, "WriteToTwoFields"},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
IR_RST_Interface::IR_RST_Interface() {
|
|
|
|
|
Register(FunctionTable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InitRST() {
|
|
|
|
|
IR_RST::IR_RST() : ServiceFramework("ir:rst", 1) {
|
|
|
|
|
using namespace Kernel;
|
|
|
|
|
// Note: these two kernel objects are even available before Initialize service function is
|
|
|
|
|
// called.
|
|
|
|
@ -204,16 +164,23 @@ void InitRST() {
|
|
|
|
|
0, MemoryRegion::BASE, "IRRST:SharedMemory");
|
|
|
|
|
update_event = Event::Create(ResetType::OneShot, "IRRST:UpdateEvent");
|
|
|
|
|
|
|
|
|
|
update_callback_id = CoreTiming::RegisterEvent("IRRST:UpdateCallBack", UpdateCallback);
|
|
|
|
|
update_callback_id =
|
|
|
|
|
CoreTiming::RegisterEvent("IRRST:UpdateCallBack", [this](u64 userdata, int cycles_late) {
|
|
|
|
|
UpdateCallback(userdata, cycles_late);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
|
{0x00010000, &IR_RST::GetHandles, "GetHandles"},
|
|
|
|
|
{0x00020080, &IR_RST::Initialize, "Initialize"},
|
|
|
|
|
{0x00030000, &IR_RST::Shutdown, "Shutdown"},
|
|
|
|
|
{0x00090000, nullptr, "WriteToTwoFields"},
|
|
|
|
|
};
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShutdownRST() {
|
|
|
|
|
shared_memory = nullptr;
|
|
|
|
|
update_event = nullptr;
|
|
|
|
|
UnloadInputDevices();
|
|
|
|
|
}
|
|
|
|
|
IR_RST::~IR_RST() = default;
|
|
|
|
|
|
|
|
|
|
void ReloadInputDevicesRST() {
|
|
|
|
|
void IR_RST::ReloadInputDevices() {
|
|
|
|
|
is_device_reload_pending.store(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|