From 865abfc37c5b3e8945d833bd44db428ad720bd58 Mon Sep 17 00:00:00 2001 From: Narr the Reg Date: Sun, 31 Dec 2023 00:42:23 -0600 Subject: service: hid: Use applet resource to get latest shared memory handle --- src/core/CMakeLists.txt | 16 +- .../service/hid/controllers/applet_resource.cpp | 18 +- .../hle/service/hid/controllers/applet_resource.h | 94 +++++--- .../hle/service/hid/controllers/capture_button.cpp | 38 ++++ .../hle/service/hid/controllers/capture_button.h | 27 +++ .../service/hid/controllers/console_six_axis.cpp | 15 +- .../hle/service/hid/controllers/console_six_axis.h | 6 +- .../service/hid/controllers/controller_base.cpp | 5 + .../hle/service/hid/controllers/controller_base.h | 8 +- .../hle/service/hid/controllers/debug_mouse.cpp | 63 ++++++ src/core/hle/service/hid/controllers/debug_mouse.h | 34 +++ src/core/hle/service/hid/controllers/debug_pad.cpp | 16 +- src/core/hle/service/hid/controllers/debug_pad.h | 6 +- src/core/hle/service/hid/controllers/digitizer.cpp | 38 ++++ src/core/hle/service/hid/controllers/digitizer.h | 27 +++ src/core/hle/service/hid/controllers/gesture.cpp | 41 ++-- src/core/hle/service/hid/controllers/gesture.h | 5 +- .../hle/service/hid/controllers/home_button.cpp | 38 ++++ src/core/hle/service/hid/controllers/home_button.h | 27 +++ src/core/hle/service/hid/controllers/keyboard.cpp | 16 +- src/core/hle/service/hid/controllers/keyboard.h | 6 +- src/core/hle/service/hid/controllers/mouse.cpp | 15 +- src/core/hle/service/hid/controllers/mouse.h | 5 +- src/core/hle/service/hid/controllers/npad.cpp | 51 ++--- src/core/hle/service/hid/controllers/npad.h | 11 +- .../service/hid/controllers/shared_memory_format.h | 240 --------------------- .../hid/controllers/shared_memory_holder.cpp | 3 +- src/core/hle/service/hid/controllers/six_axis.cpp | 24 ++- .../hle/service/hid/controllers/sleep_button.cpp | 38 ++++ .../hle/service/hid/controllers/sleep_button.h | 27 +++ src/core/hle/service/hid/controllers/stubbed.cpp | 31 --- src/core/hle/service/hid/controllers/stubbed.h | 29 --- .../hle/service/hid/controllers/touchscreen.cpp | 17 +- src/core/hle/service/hid/controllers/touchscreen.h | 4 +- .../hid/controllers/types/shared_memory_format.h | 240 +++++++++++++++++++++ .../hle/service/hid/controllers/unique_pad.cpp | 38 ++++ src/core/hle/service/hid/controllers/unique_pad.h | 27 +++ src/core/hle/service/hid/resource_manager.cpp | 107 +++++---- src/core/hle/service/hid/resource_manager.h | 18 +- 39 files changed, 975 insertions(+), 494 deletions(-) create mode 100644 src/core/hle/service/hid/controllers/capture_button.cpp create mode 100644 src/core/hle/service/hid/controllers/capture_button.h create mode 100644 src/core/hle/service/hid/controllers/debug_mouse.cpp create mode 100644 src/core/hle/service/hid/controllers/debug_mouse.h create mode 100644 src/core/hle/service/hid/controllers/digitizer.cpp create mode 100644 src/core/hle/service/hid/controllers/digitizer.h create mode 100644 src/core/hle/service/hid/controllers/home_button.cpp create mode 100644 src/core/hle/service/hid/controllers/home_button.h delete mode 100644 src/core/hle/service/hid/controllers/shared_memory_format.h create mode 100644 src/core/hle/service/hid/controllers/sleep_button.cpp create mode 100644 src/core/hle/service/hid/controllers/sleep_button.h delete mode 100644 src/core/hle/service/hid/controllers/stubbed.cpp delete mode 100644 src/core/hle/service/hid/controllers/stubbed.h create mode 100644 src/core/hle/service/hid/controllers/types/shared_memory_format.h create mode 100644 src/core/hle/service/hid/controllers/unique_pad.cpp create mode 100644 src/core/hle/service/hid/controllers/unique_pad.h (limited to 'src/core') diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 96ab39cb8..560330b47 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -553,17 +553,26 @@ add_library(core STATIC hle/service/hid/controllers/types/keyboard_types.h hle/service/hid/controllers/types/mouse_types.h hle/service/hid/controllers/types/npad_types.h + hle/service/hid/controllers/types/shared_memory_format.h hle/service/hid/controllers/types/touch_types.h hle/service/hid/controllers/applet_resource.cpp hle/service/hid/controllers/applet_resource.h + hle/service/hid/controllers/capture_button.cpp + hle/service/hid/controllers/capture_button.h hle/service/hid/controllers/console_six_axis.cpp hle/service/hid/controllers/console_six_axis.h hle/service/hid/controllers/controller_base.cpp hle/service/hid/controllers/controller_base.h + hle/service/hid/controllers/debug_mouse.cpp + hle/service/hid/controllers/debug_mouse.h hle/service/hid/controllers/debug_pad.cpp hle/service/hid/controllers/debug_pad.h + hle/service/hid/controllers/digitizer.cpp + hle/service/hid/controllers/digitizer.h hle/service/hid/controllers/gesture.cpp hle/service/hid/controllers/gesture.h + hle/service/hid/controllers/home_button.cpp + hle/service/hid/controllers/home_button.h hle/service/hid/controllers/keyboard.cpp hle/service/hid/controllers/keyboard.h hle/service/hid/controllers/mouse.cpp @@ -574,15 +583,16 @@ add_library(core STATIC hle/service/hid/controllers/palma.h hle/service/hid/controllers/seven_six_axis.cpp hle/service/hid/controllers/seven_six_axis.h - hle/service/hid/controllers/shared_memory_format.h hle/service/hid/controllers/shared_memory_holder.cpp hle/service/hid/controllers/shared_memory_holder.h hle/service/hid/controllers/six_axis.cpp hle/service/hid/controllers/six_axis.h - hle/service/hid/controllers/stubbed.cpp - hle/service/hid/controllers/stubbed.h + hle/service/hid/controllers/sleep_button.cpp + hle/service/hid/controllers/sleep_button.h hle/service/hid/controllers/touchscreen.cpp hle/service/hid/controllers/touchscreen.h + hle/service/hid/controllers/unique_pad.cpp + hle/service/hid/controllers/unique_pad.h hle/service/hid/hidbus/hidbus_base.cpp hle/service/hid/hidbus/hidbus_base.h hle/service/hid/hidbus/ringcon.cpp diff --git a/src/core/hle/service/hid/controllers/applet_resource.cpp b/src/core/hle/service/hid/controllers/applet_resource.cpp index c8e74c764..b4ff663c2 100644 --- a/src/core/hle/service/hid/controllers/applet_resource.cpp +++ b/src/core/hle/service/hid/controllers/applet_resource.cpp @@ -4,7 +4,7 @@ #include "core/core.h" #include "core/hle/kernel/k_shared_memory.h" #include "core/hle/service/hid/controllers/applet_resource.h" -#include "core/hle/service/hid/controllers/shared_memory_format.h" +#include "core/hle/service/hid/controllers/types/shared_memory_format.h" #include "core/hle/service/hid/errors.h" namespace Service::HID { @@ -164,6 +164,22 @@ Result AppletResource::GetSharedMemoryFormat(SharedMemoryFormat** out_shared_mem return ResultSuccess; } +AruidData* AppletResource::GetAruidData(u64 aruid) { + const u64 aruid_index = GetIndexFromAruid(aruid); + if (aruid_index == AruidIndexMax) { + return nullptr; + } + return &data[aruid_index]; +} + +AruidData* AppletResource::GetAruidDataByIndex(std::size_t aruid_index) { + return &data[aruid_index]; +} + +bool AppletResource::IsVibrationAruidActive(u64 aruid) const { + return aruid == 0 || aruid == active_vibration_aruid; +} + u64 AppletResource::GetIndexFromAruid(u64 aruid) { for (std::size_t i = 0; i < AruidIndexMax; i++) { if (registration_list.flag[i] == RegistrationStatus::Initialized && diff --git a/src/core/hle/service/hid/controllers/applet_resource.h b/src/core/hle/service/hid/controllers/applet_resource.h index e7991f93a..52cc4cf42 100644 --- a/src/core/hle/service/hid/controllers/applet_resource.h +++ b/src/core/hle/service/hid/controllers/applet_resource.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include "common/bit_field.h" #include "common/common_types.h" @@ -20,6 +21,59 @@ class KSharedMemory; namespace Service::HID { struct SharedMemoryFormat; +class AppletResource; +class NPadResource; + +static constexpr std::size_t AruidIndexMax = 0x20; + +enum class RegistrationStatus : u32 { + None, + Initialized, + PendingDelete, +}; + +struct DataStatusFlag { + union { + u32 raw{}; + + BitField<0, 1, u32> is_initialized; + BitField<1, 1, u32> is_assigned; + BitField<16, 1, u32> enable_pad_input; + BitField<17, 1, u32> enable_six_axis_sensor; + BitField<18, 1, u32> bit_18; + BitField<19, 1, u32> is_palma_connectable; + BitField<20, 1, u32> enable_palma_boost_mode; + BitField<21, 1, u32> enable_touchscreen; + }; +}; + +struct AruidRegisterList { + std::array flag{}; + std::array aruid{}; +}; +static_assert(sizeof(AruidRegisterList) == 0x180, "AruidRegisterList is an invalid size"); + +struct AruidData { + DataStatusFlag flag{}; + u64 aruid{}; + SharedMemoryFormat* shared_memory_format{nullptr}; +}; + +struct HandheldConfig { + bool is_handheld_hid_enabled; + bool is_force_handheld; + bool is_joycon_rail_enabled; + bool is_force_handheld_style_vibration; +}; +static_assert(sizeof(HandheldConfig) == 0x4, "HandheldConfig is an invalid size"); + +struct AppletResourceHolder { + std::shared_ptr applet_resource{nullptr}; + std::recursive_mutex* shared_mutex{nullptr}; + NPadResource* shared_npad_resource{nullptr}; + std::shared_ptr handheld_config{nullptr}; + long* handle_1; +}; class AppletResource { public: @@ -36,6 +90,10 @@ public: u64 GetActiveAruid(); Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid); Result GetSharedMemoryFormat(SharedMemoryFormat** out_shared_memory_format, u64 aruid); + AruidData* GetAruidData(u64 aruid); + AruidData* GetAruidDataByIndex(std::size_t aruid_index); + + bool IsVibrationAruidActive(u64 aruid) const; u64 GetIndexFromAruid(u64 aruid); @@ -52,46 +110,12 @@ public: Result UnregisterCoreAppletResource(); private: - static constexpr std::size_t AruidIndexMax = 0x20; - - enum RegistrationStatus : u32 { - None, - Initialized, - PendingDelete, - }; - - struct DataStatusFlag { - union { - u32 raw{}; - - BitField<0, 1, u32> is_initialized; - BitField<1, 1, u32> is_assigned; - BitField<16, 1, u32> enable_pad_input; - BitField<17, 1, u32> enable_six_axis_sensor; - BitField<18, 1, u32> bit_18; - BitField<19, 1, u32> is_palma_connectable; - BitField<20, 1, u32> enable_palma_boost_mode; - BitField<21, 1, u32> enable_touchscreen; - }; - }; - - struct AruidRegisterList { - std::array flag{}; - std::array aruid{}; - }; - static_assert(sizeof(AruidRegisterList) == 0x180, "AruidRegisterList is an invalid size"); - - struct AruidData { - DataStatusFlag flag{}; - u64 aruid{}; - SharedMemoryFormat* shared_memory_format{nullptr}; - }; - u64 active_aruid{}; AruidRegisterList registration_list{}; std::array data{}; std::array shared_memory_holder{}; s32 ref_counter{}; + u64 active_vibration_aruid; Core::System& system; }; diff --git a/src/core/hle/service/hid/controllers/capture_button.cpp b/src/core/hle/service/hid/controllers/capture_button.cpp new file mode 100644 index 000000000..8b486fcb5 --- /dev/null +++ b/src/core/hle/service/hid/controllers/capture_button.cpp @@ -0,0 +1,38 @@ +// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/core_timing.h" +#include "core/hle/service/hid/controllers/applet_resource.h" +#include "core/hle/service/hid/controllers/capture_button.h" +#include "core/hle/service/hid/controllers/types/shared_memory_format.h" + +namespace Service::HID { + +CaptureButton::CaptureButton(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {} + +CaptureButton::~CaptureButton() = default; + +void CaptureButton::OnInit() {} + +void CaptureButton::OnRelease() {} + +void CaptureButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + if (!smart_update) { + return; + } + + const u64 aruid = applet_resource->GetActiveAruid(); + auto* data = applet_resource->GetAruidData(aruid); + + if (data == nullptr) { + return; + } + + auto& header = data->shared_memory_format->capture_button.header; + header.timestamp = core_timing.GetGlobalTimeNs().count(); + header.total_entry_count = 17; + header.entry_count = 0; + header.last_entry_index = 0; +} + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/capture_button.h b/src/core/hle/service/hid/controllers/capture_button.h new file mode 100644 index 000000000..dcc4715c5 --- /dev/null +++ b/src/core/hle/service/hid/controllers/capture_button.h @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/hle/service/hid/controllers/controller_base.h" + +namespace Service::HID { + +class CaptureButton final : public ControllerBase { +public: + explicit CaptureButton(Core::HID::HIDCore& hid_core_); + ~CaptureButton() override; + + // Called when the controller is initialized + void OnInit() override; + + // When the controller is released + void OnRelease() override; + + // When the controller is requesting an update for the shared memory + void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; + +private: + bool smart_update{}; +}; +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/console_six_axis.cpp b/src/core/hle/service/hid/controllers/console_six_axis.cpp index 3961d2b5f..8eba2c292 100644 --- a/src/core/hle/service/hid/controllers/console_six_axis.cpp +++ b/src/core/hle/service/hid/controllers/console_six_axis.cpp @@ -5,13 +5,11 @@ #include "core/hid/emulated_console.h" #include "core/hid/hid_core.h" #include "core/hle/service/hid/controllers/console_six_axis.h" -#include "core/hle/service/hid/controllers/shared_memory_format.h" +#include "core/hle/service/hid/controllers/types/shared_memory_format.h" namespace Service::HID { -ConsoleSixAxis::ConsoleSixAxis(Core::HID::HIDCore& hid_core_, - ConsoleSixAxisSensorSharedMemoryFormat& console_shared_memory) - : ControllerBase{hid_core_}, shared_memory{console_shared_memory} { +ConsoleSixAxis::ConsoleSixAxis(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} { console = hid_core.GetEmulatedConsole(); } @@ -22,6 +20,15 @@ void ConsoleSixAxis::OnInit() {} void ConsoleSixAxis::OnRelease() {} void ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + const u64 aruid = applet_resource->GetActiveAruid(); + auto* data = applet_resource->GetAruidData(aruid); + + if (data == nullptr) { + return; + } + + ConsoleSixAxisSensorSharedMemoryFormat& shared_memory = data->shared_memory_format->console; + if (!IsControllerActivated()) { return; } diff --git a/src/core/hle/service/hid/controllers/console_six_axis.h b/src/core/hle/service/hid/controllers/console_six_axis.h index 3d1c9ce23..e3351f83c 100644 --- a/src/core/hle/service/hid/controllers/console_six_axis.h +++ b/src/core/hle/service/hid/controllers/console_six_axis.h @@ -10,12 +10,9 @@ class EmulatedConsole; } // namespace Core::HID namespace Service::HID { -struct ConsoleSixAxisSensorSharedMemoryFormat; - class ConsoleSixAxis final : public ControllerBase { public: - explicit ConsoleSixAxis(Core::HID::HIDCore& hid_core_, - ConsoleSixAxisSensorSharedMemoryFormat& console_shared_memory); + explicit ConsoleSixAxis(Core::HID::HIDCore& hid_core_); ~ConsoleSixAxis() override; // Called when the controller is initialized @@ -28,7 +25,6 @@ public: void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; private: - ConsoleSixAxisSensorSharedMemoryFormat& shared_memory; Core::HID::EmulatedConsole* console = nullptr; }; } // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/controller_base.cpp b/src/core/hle/service/hid/controllers/controller_base.cpp index 0bcd87062..2083ccfad 100644 --- a/src/core/hle/service/hid/controllers/controller_base.cpp +++ b/src/core/hle/service/hid/controllers/controller_base.cpp @@ -31,4 +31,9 @@ void ControllerBase::DeactivateController() { bool ControllerBase::IsControllerActivated() const { return is_activated; } + +void ControllerBase::SetAppletResource(std::shared_ptr resource) { + applet_resource = resource; +} + } // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/controller_base.h b/src/core/hle/service/hid/controllers/controller_base.h index 4326c7821..759ae0053 100644 --- a/src/core/hle/service/hid/controllers/controller_base.h +++ b/src/core/hle/service/hid/controllers/controller_base.h @@ -3,8 +3,11 @@ #pragma once +#include + #include "common/common_types.h" #include "core/hle/result.h" +#include "core/hle/service/hid/controllers/applet_resource.h" namespace Core::Timing { class CoreTiming; @@ -12,7 +15,7 @@ class CoreTiming; namespace Core::HID { class HIDCore; -} +} // namespace Core::HID namespace Service::HID { class ControllerBase { @@ -39,8 +42,11 @@ public: bool IsControllerActivated() const; + void SetAppletResource(std::shared_ptr resource); + protected: bool is_activated{false}; + std::shared_ptr applet_resource{nullptr}; Core::HID::HIDCore& hid_core; }; diff --git a/src/core/hle/service/hid/controllers/debug_mouse.cpp b/src/core/hle/service/hid/controllers/debug_mouse.cpp new file mode 100644 index 000000000..f2f1a27f8 --- /dev/null +++ b/src/core/hle/service/hid/controllers/debug_mouse.cpp @@ -0,0 +1,63 @@ +// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/core_timing.h" +#include "core/frontend/emu_window.h" +#include "core/hid/emulated_devices.h" +#include "core/hid/hid_core.h" +#include "core/hle/service/hid/controllers/applet_resource.h" +#include "core/hle/service/hid/controllers/debug_mouse.h" +#include "core/hle/service/hid/controllers/types/shared_memory_format.h" + +namespace Service::HID { + +DebugMouse::DebugMouse(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} { + emulated_devices = hid_core.GetEmulatedDevices(); +} + +DebugMouse::~DebugMouse() = default; + +void DebugMouse::OnInit() {} +void DebugMouse::OnRelease() {} + +void DebugMouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + const u64 aruid = applet_resource->GetActiveAruid(); + auto* data = applet_resource->GetAruidData(aruid); + + if (data == nullptr) { + return; + } + + MouseSharedMemoryFormat& shared_memory = data->shared_memory_format->debug_mouse; + + if (!IsControllerActivated()) { + shared_memory.mouse_lifo.buffer_count = 0; + shared_memory.mouse_lifo.buffer_tail = 0; + return; + } + + next_state = {}; + + const auto& last_entry = shared_memory.mouse_lifo.ReadCurrentEntry().state; + next_state.sampling_number = last_entry.sampling_number + 1; + + if (Settings::values.mouse_enabled) { + const auto& mouse_button_state = emulated_devices->GetMouseButtons(); + const auto& mouse_position_state = emulated_devices->GetMousePosition(); + const auto& mouse_wheel_state = emulated_devices->GetMouseWheel(); + next_state.attribute.is_connected.Assign(1); + next_state.x = static_cast(mouse_position_state.x * Layout::ScreenUndocked::Width); + next_state.y = static_cast(mouse_position_state.y * Layout::ScreenUndocked::Height); + next_state.delta_x = next_state.x - last_entry.x; + next_state.delta_y = next_state.y - last_entry.y; + next_state.delta_wheel_x = mouse_wheel_state.x - last_mouse_wheel_state.x; + next_state.delta_wheel_y = mouse_wheel_state.y - last_mouse_wheel_state.y; + + last_mouse_wheel_state = mouse_wheel_state; + next_state.button = mouse_button_state; + } + + shared_memory.mouse_lifo.WriteNextEntry(next_state); +} + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/debug_mouse.h b/src/core/hle/service/hid/controllers/debug_mouse.h new file mode 100644 index 000000000..ec939fa9f --- /dev/null +++ b/src/core/hle/service/hid/controllers/debug_mouse.h @@ -0,0 +1,34 @@ +// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/hle/service/hid/controllers/controller_base.h" + +namespace Core::HID { +class EmulatedDevices; +struct MouseState; +struct AnalogStickState; +} // namespace Core::HID + +namespace Service::HID { +class DebugMouse final : public ControllerBase { +public: + explicit DebugMouse(Core::HID::HIDCore& hid_core_); + ~DebugMouse() override; + + // Called when the controller is initialized + void OnInit() override; + + // When the controller is released + void OnRelease() override; + + // When the controller is requesting an update for the shared memory + void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; + +private: + Core::HID::MouseState next_state{}; + Core::HID::AnalogStickState last_mouse_wheel_state{}; + Core::HID::EmulatedDevices* emulated_devices = nullptr; +}; +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/debug_pad.cpp b/src/core/hle/service/hid/controllers/debug_pad.cpp index 7d2370b4f..1811cf620 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.cpp +++ b/src/core/hle/service/hid/controllers/debug_pad.cpp @@ -6,14 +6,13 @@ #include "core/hid/emulated_controller.h" #include "core/hid/hid_core.h" #include "core/hid/hid_types.h" +#include "core/hle/service/hid/controllers/applet_resource.h" #include "core/hle/service/hid/controllers/debug_pad.h" -#include "core/hle/service/hid/controllers/shared_memory_format.h" +#include "core/hle/service/hid/controllers/types/shared_memory_format.h" namespace Service::HID { -DebugPad::DebugPad(Core::HID::HIDCore& hid_core_, - DebugPadSharedMemoryFormat& debug_pad_shared_memory) - : ControllerBase{hid_core_}, shared_memory{debug_pad_shared_memory} { +DebugPad::DebugPad(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} { controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Other); } @@ -24,6 +23,15 @@ void DebugPad::OnInit() {} void DebugPad::OnRelease() {} void DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + const u64 aruid = applet_resource->GetActiveAruid(); + auto* data = applet_resource->GetAruidData(aruid); + + if (data == nullptr) { + return; + } + + DebugPadSharedMemoryFormat& shared_memory = data->shared_memory_format->debug_pad; + if (!IsControllerActivated()) { shared_memory.debug_pad_lifo.buffer_count = 0; shared_memory.debug_pad_lifo.buffer_tail = 0; diff --git a/src/core/hle/service/hid/controllers/debug_pad.h b/src/core/hle/service/hid/controllers/debug_pad.h index 8ab29eca8..dd00b2402 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.h +++ b/src/core/hle/service/hid/controllers/debug_pad.h @@ -15,12 +15,9 @@ class CoreTiming; } namespace Service::HID { -struct DebugPadSharedMemoryFormat; - class DebugPad final : public ControllerBase { public: - explicit DebugPad(Core::HID::HIDCore& hid_core_, - DebugPadSharedMemoryFormat& debug_pad_shared_memory); + explicit DebugPad(Core::HID::HIDCore& hid_core_); ~DebugPad() override; // Called when the controller is initialized @@ -34,7 +31,6 @@ public: private: DebugPadState next_state{}; - DebugPadSharedMemoryFormat& shared_memory; Core::HID::EmulatedController* controller = nullptr; }; } // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/digitizer.cpp b/src/core/hle/service/hid/controllers/digitizer.cpp new file mode 100644 index 000000000..c01580fd6 --- /dev/null +++ b/src/core/hle/service/hid/controllers/digitizer.cpp @@ -0,0 +1,38 @@ +// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/core_timing.h" +#include "core/hle/service/hid/controllers/applet_resource.h" +#include "core/hle/service/hid/controllers/digitizer.h" +#include "core/hle/service/hid/controllers/types/shared_memory_format.h" + +namespace Service::HID { + +Digitizer::Digitizer(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {} + +Digitizer::~Digitizer() = default; + +void Digitizer::OnInit() {} + +void Digitizer::OnRelease() {} + +void Digitizer::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + if (!smart_update) { + return; + } + + const u64 aruid = applet_resource->GetActiveAruid(); + auto* data = applet_resource->GetAruidData(aruid); + + if (data == nullptr) { + return; + } + + auto& header = data->shared_memory_format->digitizer.header; + header.timestamp = core_timing.GetGlobalTimeNs().count(); + header.total_entry_count = 17; + header.entry_count = 0; + header.last_entry_index = 0; +} + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/digitizer.h b/src/core/hle/service/hid/controllers/digitizer.h new file mode 100644 index 000000000..d81f814c3 --- /dev/null +++ b/src/core/hle/service/hid/controllers/digitizer.h @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/hle/service/hid/controllers/controller_base.h" + +namespace Service::HID { + +class Digitizer final : public ControllerBase { +public: + explicit Digitizer(Core::HID::HIDCore& hid_core_); + ~Digitizer() override; + + // Called when the controller is initialized + void OnInit() override; + + // When the controller is released + void OnRelease() override; + + // When the controller is requesting an update for the shared memory + void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; + +private: + bool smart_update{}; +}; +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/gesture.cpp b/src/core/hle/service/hid/controllers/gesture.cpp index f658005f6..6e686fe65 100644 --- a/src/core/hle/service/hid/controllers/gesture.cpp +++ b/src/core/hle/service/hid/controllers/gesture.cpp @@ -6,8 +6,9 @@ #include "core/frontend/emu_window.h" #include "core/hid/emulated_console.h" #include "core/hid/hid_core.h" +#include "core/hle/service/hid/controllers/applet_resource.h" #include "core/hle/service/hid/controllers/gesture.h" -#include "core/hle/service/hid/controllers/shared_memory_format.h" +#include "core/hle/service/hid/controllers/types/shared_memory_format.h" namespace Service::HID { // HW is around 700, value is set to 400 to make it easier to trigger with mouse @@ -21,24 +22,40 @@ constexpr f32 Square(s32 num) { return static_cast(num * num); } -Gesture::Gesture(Core::HID::HIDCore& hid_core_, GestureSharedMemoryFormat& gesture_shared_memory) - : ControllerBase(hid_core_), shared_memory{gesture_shared_memory} { +Gesture::Gesture(Core::HID::HIDCore& hid_core_) : ControllerBase(hid_core_) { console = hid_core.GetEmulatedConsole(); } Gesture::~Gesture() = default; void Gesture::OnInit() { - shared_memory.gesture_lifo.buffer_count = 0; - shared_memory.gesture_lifo.buffer_tail = 0; + const u64 aruid = applet_resource->GetActiveAruid(); + auto* data = applet_resource->GetAruidData(aruid); + + if (data == nullptr) { + return; + } + + shared_memory = &data->shared_memory_format->gesture; + shared_memory->gesture_lifo.buffer_count = 0; + shared_memory->gesture_lifo.buffer_tail = 0; force_update = true; } void Gesture::OnRelease() {} void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + const u64 aruid = applet_resource->GetActiveAruid(); + auto* data = applet_resource->GetAruidData(aruid); + + if (data == nullptr) { + return; + } + + shared_memory = &data->shared_memory_format->gesture; + if (!IsControllerActivated()) { - shared_memory.gesture_lifo.buffer_count = 0; - shared_memory.gesture_lifo.buffer_tail = 0; + shared_memory->gesture_lifo.buffer_count = 0; + shared_memory->gesture_lifo.buffer_tail = 0; return; } @@ -46,7 +63,7 @@ void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) { GestureProperties gesture = GetGestureProperties(); f32 time_difference = - static_cast(shared_memory.gesture_lifo.timestamp - last_update_timestamp) / + static_cast(shared_memory->gesture_lifo.timestamp - last_update_timestamp) / (1000 * 1000 * 1000); // Only update if necessary @@ -54,7 +71,7 @@ void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) { return; } - last_update_timestamp = shared_memory.gesture_lifo.timestamp; + last_update_timestamp = shared_memory->gesture_lifo.timestamp; UpdateGestureSharedMemory(gesture, time_difference); } @@ -97,7 +114,7 @@ void Gesture::UpdateGestureSharedMemory(GestureProperties& gesture, f32 time_dif GestureType type = GestureType::Idle; GestureAttribute attributes{}; - const auto& last_entry = shared_memory.gesture_lifo.ReadCurrentEntry().state; + const auto& last_entry = shared_memory->gesture_lifo.ReadCurrentEntry().state; // Reset next state to default next_state.sampling_number = last_entry.sampling_number + 1; @@ -127,7 +144,7 @@ void Gesture::UpdateGestureSharedMemory(GestureProperties& gesture, f32 time_dif next_state.points = gesture.points; last_gesture = gesture; - shared_memory.gesture_lifo.WriteNextEntry(next_state); + shared_memory->gesture_lifo.WriteNextEntry(next_state); } void Gesture::NewGesture(GestureProperties& gesture, GestureType& type, @@ -300,7 +317,7 @@ void Gesture::SetSwipeEvent(GestureProperties& gesture, GestureProperties& last_ } const GestureState& Gesture::GetLastGestureEntry() const { - return shared_memory.gesture_lifo.ReadCurrentEntry().state; + return shared_memory->gesture_lifo.ReadCurrentEntry().state; } GestureProperties Gesture::GetGestureProperties() { diff --git a/src/core/hle/service/hid/controllers/gesture.h b/src/core/hle/service/hid/controllers/gesture.h index 41fdfcd03..78da1552a 100644 --- a/src/core/hle/service/hid/controllers/gesture.h +++ b/src/core/hle/service/hid/controllers/gesture.h @@ -18,8 +18,7 @@ struct GestureSharedMemoryFormat; class Gesture final : public ControllerBase { public: - explicit Gesture(Core::HID::HIDCore& hid_core_, - GestureSharedMemoryFormat& gesture_shared_memory); + explicit Gesture(Core::HID::HIDCore& hid_core_); ~Gesture() override; // Called when the controller is initialized @@ -74,7 +73,7 @@ private: GestureProperties GetGestureProperties(); GestureState next_state{}; - GestureSharedMemoryFormat& shared_memory; + GestureSharedMemoryFormat* shared_memory; Core::HID::EmulatedConsole* console = nullptr; std::array fingers{}; diff --git a/src/core/hle/service/hid/controllers/home_button.cpp b/src/core/hle/service/hid/controllers/home_button.cpp new file mode 100644 index 000000000..71dd9bc08 --- /dev/null +++ b/src/core/hle/service/hid/controllers/home_button.cpp @@ -0,0 +1,38 @@ +// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/core_timing.h" +#include "core/hle/service/hid/controllers/applet_resource.h" +#include "core/hle/service/hid/controllers/home_button.h" +#include "core/hle/service/hid/controllers/types/shared_memory_format.h" + +namespace Service::HID { + +HomeButton::HomeButton(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {} + +HomeButton::~HomeButton() = default; + +void HomeButton::OnInit() {} + +void HomeButton::OnRelease() {} + +void HomeButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + if (!smart_update) { + return; + } + + const u64 aruid = applet_resource->GetActiveAruid(); + auto* data = applet_resource->GetAruidData(aruid); + + if (data == nullptr) { + return; + } + + auto& header = data->shared_memory_format->home_button.header; + header.timestamp = core_timing.GetGlobalTimeNs().count(); + header.total_entry_count = 17; + header.entry_count = 0; + header.last_entry_index = 0; +} + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/home_button.h b/src/core/hle/service/hid/controllers/home_button.h new file mode 100644 index 000000000..e91c2aa5d --- /dev/null +++ b/src/core/hle/service/hid/controllers/home_button.h @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/hle/service/hid/controllers/controller_base.h" + +namespace Service::HID { + +class HomeButton final : public ControllerBase { +public: + explicit HomeButton(Core::HID::HIDCore& hid_core_); + ~HomeButton() override; + + // Called when the controller is initialized + void OnInit() override; + + // When the controller is released + void OnRelease() override; + + // When the controller is requesting an update for the shared memory + void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; + +private: + bool smart_update{}; +}; +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/keyboard.cpp b/src/core/hle/service/hid/controllers/keyboard.cpp index 871e5036a..c72b3e5ce 100644 --- a/src/core/hle/service/hid/controllers/keyboard.cpp +++ b/src/core/hle/service/hid/controllers/keyboard.cpp @@ -5,14 +5,13 @@ #include "core/core_timing.h" #include "core/hid/emulated_devices.h" #include "core/hid/hid_core.h" +#include "core/hle/service/hid/controllers/applet_resource.h" #include "core/hle/service/hid/controllers/keyboard.h" -#include "core/hle/service/hid/controllers/shared_memory_format.h" +#include "core/hle/service/hid/controllers/types/shared_memory_format.h" namespace Service::HID { -Keyboard::Keyboard(Core::HID::HIDCore& hid_core_, - KeyboardSharedMemoryFormat& keyboard_shared_memory) - : ControllerBase{hid_core_}, shared_memory{keyboard_shared_memory} { +Keyboard::Keyboard(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} { emulated_devices = hid_core.GetEmulatedDevices(); } @@ -23,6 +22,15 @@ void Keyboard::OnInit() {} void Keyboard::OnRelease() {} void Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + const u64 aruid = applet_resource->GetActiveAruid(); + auto* data = applet_resource->GetAruidData(aruid); + + if (data == nullptr) { + return; + } + + KeyboardSharedMemoryFormat& shared_memory = data->shared_memory_format->keyboard; + if (!IsControllerActivated()) { shared_memory.keyboard_lifo.buffer_count = 0; shared_memory.keyboard_lifo.buffer_tail = 0; diff --git a/src/core/hle/service/hid/controllers/keyboard.h b/src/core/hle/service/hid/controllers/keyboard.h index 4d72171b9..e8ca326c6 100644 --- a/src/core/hle/service/hid/controllers/keyboard.h +++ b/src/core/hle/service/hid/controllers/keyboard.h @@ -7,12 +7,9 @@ #include "core/hle/service/hid/controllers/types/keyboard_types.h" namespace Service::HID { -struct KeyboardSharedMemoryFormat; - class Keyboard final : public ControllerBase { public: - explicit Keyboard(Core::HID::HIDCore& hid_core_, - KeyboardSharedMemoryFormat& keyboard_shared_memory); + explicit Keyboard(Core::HID::HIDCore& hid_core_); ~Keyboard() override; // Called when the controller is initialized @@ -26,7 +23,6 @@ public: private: KeyboardState next_state{}; - KeyboardSharedMemoryFormat& shared_memory; Core::HID::EmulatedDevices* emulated_devices = nullptr; }; } // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/mouse.cpp b/src/core/hle/service/hid/controllers/mouse.cpp index de5b2c804..58deafbc5 100644 --- a/src/core/hle/service/hid/controllers/mouse.cpp +++ b/src/core/hle/service/hid/controllers/mouse.cpp @@ -5,13 +5,13 @@ #include "core/frontend/emu_window.h" #include "core/hid/emulated_devices.h" #include "core/hid/hid_core.h" +#include "core/hle/service/hid/controllers/applet_resource.h" #include "core/hle/service/hid/controllers/mouse.h" -#include "core/hle/service/hid/controllers/shared_memory_format.h" +#include "core/hle/service/hid/controllers/types/shared_memory_format.h" namespace Service::HID { -Mouse::Mouse(Core::HID::HIDCore& hid_core_, MouseSharedMemoryFormat& mouse_shared_memory) - : ControllerBase{hid_core_}, shared_memory{mouse_shared_memory} { +Mouse::Mouse(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} { emulated_devices = hid_core.GetEmulatedDevices(); } @@ -21,6 +21,15 @@ void Mouse::OnInit() {} void Mouse::OnRelease() {} void Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + const u64 aruid = applet_resource->GetActiveAruid(); + auto* data = applet_resource->GetAruidData(aruid); + + if (data == nullptr) { + return; + } + + MouseSharedMemoryFormat& shared_memory = data->shared_memory_format->mouse; + if (!IsControllerActivated()) { shared_memory.mouse_lifo.buffer_count = 0; shared_memory.mouse_lifo.buffer_tail = 0; diff --git a/src/core/hle/service/hid/controllers/mouse.h b/src/core/hle/service/hid/controllers/mouse.h index 363f316a5..cefad956c 100644 --- a/src/core/hle/service/hid/controllers/mouse.h +++ b/src/core/hle/service/hid/controllers/mouse.h @@ -12,11 +12,9 @@ struct AnalogStickState; } // namespace Core::HID namespace Service::HID { -struct MouseSharedMemoryFormat; - class Mouse final : public ControllerBase { public: - explicit Mouse(Core::HID::HIDCore& hid_core_, MouseSharedMemoryFormat& mouse_shared_memory); + explicit Mouse(Core::HID::HIDCore& hid_core_); ~Mouse() override; // Called when the controller is initialized @@ -31,7 +29,6 @@ public: private: Core::HID::MouseState next_state{}; Core::HID::AnalogStickState last_mouse_wheel_state{}; - MouseSharedMemoryFormat& shared_memory; Core::HID::EmulatedDevices* emulated_devices = nullptr; }; } // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 53a737cf5..c7aa606bc 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -16,8 +16,9 @@ #include "core/hid/hid_core.h" #include "core/hle/kernel/k_event.h" #include "core/hle/kernel/k_readable_event.h" +#include "core/hle/service/hid/controllers/applet_resource.h" #include "core/hle/service/hid/controllers/npad.h" -#include "core/hle/service/hid/controllers/shared_memory_format.h" +#include "core/hle/service/hid/controllers/types/shared_memory_format.h" #include "core/hle/service/hid/errors.h" #include "core/hle/service/hid/hid_util.h" #include "core/hle/service/kernel_helpers.h" @@ -30,12 +31,10 @@ constexpr std::array npad_id_list{ Core::HID::NpadIdType::Handheld, }; -NPad::NPad(Core::HID::HIDCore& hid_core_, NpadSharedMemoryFormat& npad_shared_memory_format, - KernelHelpers::ServiceContext& service_context_) +NPad::NPad(Core::HID::HIDCore& hid_core_, KernelHelpers::ServiceContext& service_context_) : ControllerBase{hid_core_}, service_context{service_context_} { for (std::size_t i = 0; i < controller_data.size(); ++i) { auto& controller = controller_data[i]; - controller.shared_memory = &npad_shared_memory_format.npad_entry[i].internal_state; controller.device = hid_core.GetEmulatedControllerByIndex(i); controller.vibration[Core::HID::EmulatedDeviceIndex::LeftIndex].latest_vibration_value = Core::HID::DEFAULT_VIBRATION_VALUE; @@ -297,12 +296,20 @@ void NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) { } void NPad::OnInit() { + const u64 aruid = applet_resource->GetActiveAruid(); + auto* data = applet_resource->GetAruidData(aruid); + + if (data == nullptr) { + return; + } + if (!IsControllerActivated()) { return; } for (std::size_t i = 0; i < controller_data.size(); ++i) { auto& controller = controller_data[i]; + controller.shared_memory = &data->shared_memory_format->npad.npad_entry[i].internal_state; controller.styleset_changed_event = service_context.CreateEvent(fmt::format("npad:NpadStyleSetChanged_{}", i)); } @@ -355,7 +362,9 @@ void NPad::OnRelease() { is_controller_initialized = false; for (std::size_t i = 0; i < controller_data.size(); ++i) { auto& controller = controller_data[i]; - service_context.CloseEvent(controller.styleset_changed_event); + if (controller.styleset_changed_event) { + service_context.CloseEvent(controller.styleset_changed_event); + } for (std::size_t device_idx = 0; device_idx < controller.vibration.size(); ++device_idx) { VibrateControllerAtIndex(controller.device->GetNpadIdType(), device_idx, {}); } @@ -432,12 +441,20 @@ void NPad::RequestPadStateUpdate(Core::HID::NpadIdType npad_id) { } void NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + const u64 aruid = applet_resource->GetActiveAruid(); + auto* data = applet_resource->GetAruidData(aruid); + + if (data == nullptr) { + return; + } + if (!IsControllerActivated()) { return; } for (std::size_t i = 0; i < controller_data.size(); ++i) { auto& controller = controller_data[i]; + controller.shared_memory = &data->shared_memory_format->npad.npad_entry[i].internal_state; auto* npad = controller.shared_memory; const auto& controller_type = controller.device->GetNpadStyleIndex(); @@ -976,30 +993,6 @@ Result NPad::ResetIsSixAxisSensorDeviceNewlyAssigned( return ResultSuccess; } -NpadSixAxisSensorLifo& NPad::GetSixAxisFullkeyLifo(Core::HID::NpadIdType npad_id) { - return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_fullkey_lifo; -} - -NpadSixAxisSensorLifo& NPad::GetSixAxisHandheldLifo(Core::HID::NpadIdType npad_id) { - return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_handheld_lifo; -} - -NpadSixAxisSensorLifo& NPad::GetSixAxisDualLeftLifo(Core::HID::NpadIdType npad_id) { - return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_dual_left_lifo; -} - -NpadSixAxisSensorLifo& NPad::GetSixAxisDualRightLifo(Core::HID::NpadIdType npad_id) { - return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_dual_right_lifo; -} - -NpadSixAxisSensorLifo& NPad::GetSixAxisLeftLifo(Core::HID::NpadIdType npad_id) { - return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_left_lifo; -} - -NpadSixAxisSensorLifo& NPad::GetSixAxisRightLifo(Core::HID::NpadIdType npad_id) { - return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_right_lifo; -} - Result NPad::MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1, Core::HID::NpadIdType npad_id_2) { if (!IsNpadIdValid(npad_id_1) || !IsNpadIdValid(npad_id_2)) { diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index 4e2412356..80cfcb2bb 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h @@ -30,14 +30,14 @@ class ServiceContext; union Result; namespace Service::HID { +class AppletResource; struct NpadInternalState; struct NpadSixAxisSensorLifo; struct NpadSharedMemoryFormat; class NPad final : public ControllerBase { public: - explicit NPad(Core::HID::HIDCore& hid_core_, NpadSharedMemoryFormat& npad_shared_memory_format, - KernelHelpers::ServiceContext& service_context_); + explicit NPad(Core::HID::HIDCore& hid_core_, KernelHelpers::ServiceContext& service_context_); ~NPad() override; // Called when the controller is initialized @@ -106,13 +106,6 @@ public: Result ResetIsSixAxisSensorDeviceNewlyAssigned( const Core::HID::SixAxisSensorHandle& sixaxis_handle); - NpadSixAxisSensorLifo& GetSixAxisFullkeyLifo(Core::HID::NpadIdType npad_id); - NpadSixAxisSensorLifo& GetSixAxisHandheldLifo(Core::HID::NpadIdType npad_id); - NpadSixAxisSensorLifo& GetSixAxisDualLeftLifo(Core::HID::NpadIdType npad_id); - NpadSixAxisSensorLifo& GetSixAxisDualRightLifo(Core::HID::NpadIdType npad_id); - NpadSixAxisSensorLifo& GetSixAxisLeftLifo(Core::HID::NpadIdType npad_id); - NpadSixAxisSensorLifo& GetSixAxisRightLifo(Core::HID::NpadIdType npad_id); - Result GetLedPattern(Core::HID::NpadIdType npad_id, Core::HID::LedPattern& pattern) const; Result IsUnintendedHomeButtonInputProtectionEnabled(Core::HID::NpadIdType npad_id, bool& is_enabled) const; diff --git a/src/core/hle/service/hid/controllers/shared_memory_format.h b/src/core/hle/service/hid/controllers/shared_memory_format.h deleted file mode 100644 index 2986c113e..000000000 --- a/src/core/hle/service/hid/controllers/shared_memory_format.h +++ /dev/null @@ -1,240 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -#pragma once - -#include "common/common_funcs.h" -#include "common/common_types.h" -#include "common/vector_math.h" -#include "core/hid/hid_types.h" -#include "core/hle/service/hid//controllers/types/debug_pad_types.h" -#include "core/hle/service/hid//controllers/types/keyboard_types.h" -#include "core/hle/service/hid//controllers/types/mouse_types.h" -#include "core/hle/service/hid//controllers/types/npad_types.h" -#include "core/hle/service/hid//controllers/types/touch_types.h" -#include "core/hle/service/hid/ring_lifo.h" - -namespace Service::HID { -static const std::size_t HidEntryCount = 17; - -struct CommonHeader { - s64 timestamp{}; - s64 total_entry_count{}; - s64 last_entry_index{}; - s64 entry_count{}; -}; -static_assert(sizeof(CommonHeader) == 0x20, "CommonHeader is an invalid size"); - -// This is nn::hid::detail::DebugPadSharedMemoryFormat -struct DebugPadSharedMemoryFormat { - // This is nn::hid::detail::DebugPadLifo - Lifo debug_pad_lifo{}; - static_assert(sizeof(debug_pad_lifo) == 0x2C8, "debug_pad_lifo is an invalid size"); - INSERT_PADDING_WORDS(0x4E); -}; -static_assert(sizeof(DebugPadSharedMemoryFormat) == 0x400, - "DebugPadSharedMemoryFormat is an invalid size"); - -// This is nn::hid::detail::TouchScreenSharedMemoryFormat -struct TouchScreenSharedMemoryFormat { - // This is nn::hid::detail::TouchScreenLifo - Lifo touch_screen_lifo{}; - static_assert(sizeof(touch_screen_lifo) == 0x2C38, "touch_screen_lifo is an invalid size"); - INSERT_PADDING_WORDS(0xF2); -}; -static_assert(sizeof(TouchScreenSharedMemoryFormat) == 0x3000, - "TouchScreenSharedMemoryFormat is an invalid size"); - -// This is nn::hid::detail::MouseSharedMemoryFormat -struct MouseSharedMemoryFormat { - // This is nn::hid::detail::MouseLifo - Lifo mouse_lifo{}; - static_assert(sizeof(mouse_lifo) == 0x350, "mouse_lifo is an invalid size"); - INSERT_PADDING_WORDS(0x2C); -}; -static_assert(sizeof(MouseSharedMemoryFormat) == 0x400, - "MouseSharedMemoryFormat is an invalid size"); - -// This is nn::hid::detail::KeyboardSharedMemoryFormat -struct KeyboardSharedMemoryFormat { - // This is nn::hid::detail::KeyboardLifo - Lifo keyboard_lifo{}; - static_assert(sizeof(keyboard_lifo) == 0x3D8, "keyboard_lifo is an invalid size"); - INSERT_PADDING_WORDS(0xA); -}; -static_assert(sizeof(KeyboardSharedMemoryFormat) == 0x400, - "KeyboardSharedMemoryFormat is an invalid size"); - -// This is nn::hid::detail::DigitizerSharedMemoryFormat -struct DigitizerSharedMemoryFormat { - CommonHeader header; - INSERT_PADDING_BYTES(0xFE0); -}; -static_assert(sizeof(DigitizerSharedMemoryFormat) == 0x1000, - "DigitizerSharedMemoryFormat is an invalid size"); - -// This is nn::hid::detail::HomeButtonSharedMemoryFormat -struct HomeButtonSharedMemoryFormat { - CommonHeader header; - INSERT_PADDING_BYTES(0x1E0); -}; -static_assert(sizeof(HomeButtonSharedMemoryFormat) == 0x200, - "HomeButtonSharedMemoryFormat is an invalid size"); - -// This is nn::hid::detail::SleepButtonSharedMemoryFormat -struct SleepButtonSharedMemoryFormat { - CommonHeader header; - INSERT_PADDING_BYTES(0x1E0); -}; -static_assert(sizeof(SleepButtonSharedMemoryFormat) == 0x200, - "SleepButtonSharedMemoryFormat is an invalid size"); - -// This is nn::hid::detail::CaptureButtonSharedMemoryFormat -struct CaptureButtonSharedMemoryFormat { - CommonHeader header; - INSERT_PADDING_BYTES(0x1E0); -}; -static_assert(sizeof(CaptureButtonSharedMemoryFormat) == 0x200, - "CaptureButtonSharedMemoryFormat is an invalid size"); - -// This is nn::hid::detail::InputDetectorSharedMemoryFormat -struct InputDetectorSharedMemoryFormat { - CommonHeader header; - INSERT_PADDING_BYTES(0x7E0); -}; -static_assert(sizeof(InputDetectorSharedMemoryFormat) == 0x800, - "InputDetectorSharedMemoryFormat is an invalid size"); - -// This is nn::hid::detail::UniquePadSharedMemoryFormat -struct UniquePadSharedMemoryFormat { - CommonHeader header; - INSERT_PADDING_BYTES(0x3FE0); -}; -static_assert(sizeof(UniquePadSharedMemoryFormat) == 0x4000, - "UniquePadSharedMemoryFormat is an invalid size"); - -// This is nn::hid::detail::NpadSixAxisSensorLifo -struct NpadSixAxisSensorLifo { - Lifo lifo; -}; - -// This is nn::hid::detail::NpadInternalState -struct NpadInternalState { - Core::HID::NpadStyleTag style_tag{Core::HID::NpadStyleSet::None}; - NpadJoyAssignmentMode assignment_mode{NpadJoyAssignmentMode::Dual}; - NpadFullKeyColorState fullkey_color{}; - NpadJoyColorState joycon_color{}; - Lifo fullkey_lifo{}; - Lifo handheld_lifo{}; - Lifo joy_dual_lifo{}; - Lifo joy_left_lifo{}; - Lifo joy_right_lifo{}; - Lifo palma_lifo{}; - Lifo system_ext_lifo{}; - NpadSixAxisSensorLifo sixaxis_fullkey_lifo{}; - NpadSixAxisSensorLifo sixaxis_handheld_lifo{}; - NpadSixAxisSensorLifo sixaxis_dual_left_lifo{}; - NpadSixAxisSensorLifo sixaxis_dual_right_lifo{}; - NpadSixAxisSensorLifo sixaxis_left_lifo{}; - NpadSixAxisSensorLifo sixaxis_right_lifo{}; - DeviceType device_type{}; - INSERT_PADDING_BYTES(0x4); // Reserved - NPadSystemProperties system_properties{}; - NpadSystemButtonProperties button_properties{}; - Core::HID::NpadBatteryLevel battery_level_dual{}; - Core::HID::NpadBatteryLevel battery_level_left{}; - Core::HID::NpadBatteryLevel battery_level_right{}; - AppletFooterUiAttributes applet_footer_attributes{}; - AppletFooterUiType applet_footer_type{AppletFooterUiType::None}; - INSERT_PADDING_BYTES(0x5B); // Reserved - INSERT_PADDING_BYTES(0x20); // Unknown - Lifo gc_trigger_lifo{}; - NpadLarkType lark_type_l_and_main{}; - NpadLarkType lark_type_r{}; - NpadLuciaType lucia_type{}; - NpadLagerType lager_type{}; - Core::HID::SixAxisSensorProperties sixaxis_fullkey_properties; - Core::HID::SixAxisSensorProperties sixaxis_handheld_properties; - Core::HID::SixAxisSensorProperties sixaxis_dual_left_properties; - Core::HID::SixAxisSensorProperties sixaxis_dual_right_properties; - Core::HID::SixAxisSensorProperties sixaxis_left_properties; - Core::HID::SixAxisSensorProperties sixaxis_right_properties; -}; -static_assert(sizeof(NpadInternalState) == 0x43F8, "NpadInternalState is an invalid size"); - -// This is nn::hid::detail::NpadSharedMemoryEntry -struct NpadSharedMemoryEntry { - NpadInternalState internal_state; - INSERT_PADDING_BYTES(0xC08); -}; -static_assert(sizeof(NpadSharedMemoryEntry) == 0x5000, "NpadSharedMemoryEntry is an invalid size"); - -// This is nn::hid::detail::NpadSharedMemoryFormat -struct NpadSharedMemoryFormat { - std::array npad_entry; -}; -static_assert(sizeof(NpadSharedMemoryFormat) == 0x32000, - "NpadSharedMemoryFormat is an invalid size"); - -// This is nn::hid::detail::GestureSharedMemoryFormat -struct GestureSharedMemoryFormat { - // This is nn::hid::detail::GestureLifo - Lifo gesture_lifo{}; - static_assert(sizeof(gesture_lifo) == 0x708, "gesture_lifo is an invalid size"); - INSERT_PADDING_WORDS(0x3E); -}; -static_assert(sizeof(GestureSharedMemoryFormat) == 0x800, - "GestureSharedMemoryFormat is an invalid size"); - -// This is nn::hid::detail::ConsoleSixAxisSensorSharedMemoryFormat -struct ConsoleSixAxisSensorSharedMemoryFormat { - u64 sampling_number{}; - bool is_seven_six_axis_sensor_at_rest{}; - INSERT_PADDING_BYTES(3); // padding - f32 verticalization_error{}; - Common::Vec3f gyro_bias{}; - INSERT_PADDING_BYTES(4); // padding -}; -static_assert(sizeof(ConsoleSixAxisSensorSharedMemoryFormat) == 0x20, - "ConsoleSixAxisSensorSharedMemoryFormat is an invalid size"); - -// This is nn::hid::detail::SharedMemoryFormat -struct SharedMemoryFormat { - void Initialize() {} - - DebugPadSharedMemoryFormat debug_pad; - TouchScreenSharedMemoryFormat touch_screen; - MouseSharedMemoryFormat mouse; - KeyboardSharedMemoryFormat keyboard; - DigitizerSharedMemoryFormat digitizer; - HomeButtonSharedMemoryFormat home_button; - SleepButtonSharedMemoryFormat sleep_button; - CaptureButtonSharedMemoryFormat capture_button; - InputDetectorSharedMemoryFormat input_detector; - UniquePadSharedMemoryFormat unique_pad; - NpadSharedMemoryFormat npad; - GestureSharedMemoryFormat gesture; - ConsoleSixAxisSensorSharedMemoryFormat console; - INSERT_PADDING_BYTES(0x19E0); - MouseSharedMemoryFormat debug_mouse; - INSERT_PADDING_BYTES(0x2000); -}; -static_assert(offsetof(SharedMemoryFormat, debug_pad) == 0x0, "debug_pad has wrong offset"); -static_assert(offsetof(SharedMemoryFormat, touch_screen) == 0x400, "touch_screen has wrong offset"); -static_assert(offsetof(SharedMemoryFormat, mouse) == 0x3400, "mouse has wrong offset"); -static_assert(offsetof(SharedMemoryFormat, keyboard) == 0x3800, "keyboard has wrong offset"); -static_assert(offsetof(SharedMemoryFormat, digitizer) == 0x3C00, "digitizer has wrong offset"); -static_assert(offsetof(SharedMemoryFormat, home_button) == 0x4C00, "home_button has wrong offset"); -static_assert(offsetof(SharedMemoryFormat, sleep_button) == 0x4E00, - "sleep_button has wrong offset"); -static_assert(offsetof(SharedMemoryFormat, capture_button) == 0x5000, - "capture_button has wrong offset"); -static_assert(offsetof(SharedMemoryFormat, input_detector) == 0x5200, - "input_detector has wrong offset"); -static_assert(offsetof(SharedMemoryFormat, npad) == 0x9A00, "npad has wrong offset"); -static_assert(offsetof(SharedMemoryFormat, gesture) == 0x3BA00, "gesture has wrong offset"); -static_assert(offsetof(SharedMemoryFormat, console) == 0x3C200, "console has wrong offset"); -static_assert(offsetof(SharedMemoryFormat, debug_mouse) == 0x3DC00, "debug_mouse has wrong offset"); -static_assert(sizeof(SharedMemoryFormat) == 0x40000, "SharedMemoryFormat is an invalid size"); - -} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/shared_memory_holder.cpp b/src/core/hle/service/hid/controllers/shared_memory_holder.cpp index 51581188e..0bc5169c6 100644 --- a/src/core/hle/service/hid/controllers/shared_memory_holder.cpp +++ b/src/core/hle/service/hid/controllers/shared_memory_holder.cpp @@ -3,8 +3,9 @@ #include "core/core.h" #include "core/hle/kernel/k_shared_memory.h" -#include "core/hle/service/hid/controllers/shared_memory_format.h" +#include "core/hle/service/hid/controllers/applet_resource.h" #include "core/hle/service/hid/controllers/shared_memory_holder.h" +#include "core/hle/service/hid/controllers/types/shared_memory_format.h" #include "core/hle/service/hid/errors.h" namespace Service::HID { diff --git a/src/core/hle/service/hid/controllers/six_axis.cpp b/src/core/hle/service/hid/controllers/six_axis.cpp index 36b72f9ea..a5a67dea6 100644 --- a/src/core/hle/service/hid/controllers/six_axis.cpp +++ b/src/core/hle/service/hid/controllers/six_axis.cpp @@ -6,8 +6,8 @@ #include "core/hid/emulated_controller.h" #include "core/hid/hid_core.h" #include "core/hle/service/hid/controllers/npad.h" -#include "core/hle/service/hid/controllers/shared_memory_format.h" #include "core/hle/service/hid/controllers/six_axis.h" +#include "core/hle/service/hid/controllers/types/shared_memory_format.h" #include "core/hle/service/hid/errors.h" #include "core/hle/service/hid/hid_util.h" @@ -27,14 +27,20 @@ void SixAxis::OnInit() {} void SixAxis::OnRelease() {} void SixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + const u64 aruid = applet_resource->GetActiveAruid(); + auto* data = applet_resource->GetAruidData(aruid); + + if (data == nullptr) { + return; + } + if (!IsControllerActivated()) { return; } for (std::size_t i = 0; i < controller_data.size(); ++i) { + NpadSharedMemoryEntry& shared_memory = data->shared_memory_format->npad.npad_entry[i]; auto& controller = controller_data[i]; - - const auto npad_id = IndexToNpadIdType(i); const auto& controller_type = controller.device->GetNpadStyleIndex(); if (controller_type == Core::HID::NpadStyleIndex::None || @@ -50,12 +56,12 @@ void SixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { auto& sixaxis_left_lifo_state = controller.sixaxis_left_lifo_state; auto& sixaxis_right_lifo_state = controller.sixaxis_right_lifo_state; - auto& sixaxis_fullkey_lifo = npad->GetSixAxisFullkeyLifo(npad_id); - auto& sixaxis_handheld_lifo = npad->GetSixAxisHandheldLifo(npad_id); - auto& sixaxis_dual_left_lifo = npad->GetSixAxisDualLeftLifo(npad_id); - auto& sixaxis_dual_right_lifo = npad->GetSixAxisDualRightLifo(npad_id); - auto& sixaxis_left_lifo = npad->GetSixAxisLeftLifo(npad_id); - auto& sixaxis_right_lifo = npad->GetSixAxisRightLifo(npad_id); + auto& sixaxis_fullkey_lifo = shared_memory.internal_state.sixaxis_fullkey_lifo; + auto& sixaxis_handheld_lifo = shared_memory.internal_state.sixaxis_handheld_lifo; + auto& sixaxis_dual_left_lifo = shared_memory.internal_state.sixaxis_dual_left_lifo; + auto& sixaxis_dual_right_lifo = shared_memory.internal_state.sixaxis_dual_right_lifo; + auto& sixaxis_left_lifo = shared_memory.internal_state.sixaxis_left_lifo; + auto& sixaxis_right_lifo = shared_memory.internal_state.sixaxis_right_lifo; // Clear previous state sixaxis_fullkey_state = {}; diff --git a/src/core/hle/service/hid/controllers/sleep_button.cpp b/src/core/hle/service/hid/controllers/sleep_button.cpp new file mode 100644 index 000000000..978dc4c1f --- /dev/null +++ b/src/core/hle/service/hid/controllers/sleep_button.cpp @@ -0,0 +1,38 @@ +// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/core_timing.h" +#include "core/hle/service/hid/controllers/applet_resource.h" +#include "core/hle/service/hid/controllers/sleep_button.h" +#include "core/hle/service/hid/controllers/types/shared_memory_format.h" + +namespace Service::HID { + +SleepButton::SleepButton(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {} + +SleepButton::~SleepButton() = default; + +void SleepButton::OnInit() {} + +void SleepButton::OnRelease() {} + +void SleepButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + if (!smart_update) { + return; + } + + const u64 aruid = applet_resource->GetActiveAruid(); + auto* data = applet_resource->GetAruidData(aruid); + + if (data == nullptr) { + return; + } + + auto& header = data->shared_memory_format->capture_button.header; + header.timestamp = core_timing.GetGlobalTimeNs().count(); + header.total_entry_count = 17; + header.entry_count = 0; + header.last_entry_index = 0; +} + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/sleep_button.h b/src/core/hle/service/hid/controllers/sleep_button.h new file mode 100644 index 000000000..59964bf63 --- /dev/null +++ b/src/core/hle/service/hid/controllers/sleep_button.h @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/hle/service/hid/controllers/controller_base.h" + +namespace Service::HID { + +class SleepButton final : public ControllerBase { +public: + explicit SleepButton(Core::HID::HIDCore& hid_core_); + ~SleepButton() override; + + // Called when the controller is initialized + void OnInit() override; + + // When the controller is released + void OnRelease() override; + + // When the controller is requesting an update for the shared memory + void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; + +private: + bool smart_update{}; +}; +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/stubbed.cpp b/src/core/hle/service/hid/controllers/stubbed.cpp deleted file mode 100644 index e2a5f5d79..000000000 --- a/src/core/hle/service/hid/controllers/stubbed.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "core/core_timing.h" -#include "core/hle/service/hid/controllers/shared_memory_format.h" -#include "core/hle/service/hid/controllers/stubbed.h" - -namespace Service::HID { - -Controller_Stubbed::Controller_Stubbed(Core::HID::HIDCore& hid_core_, - CommonHeader& ring_lifo_header) - : ControllerBase{hid_core_}, header{ring_lifo_header} {} - -Controller_Stubbed::~Controller_Stubbed() = default; - -void Controller_Stubbed::OnInit() {} - -void Controller_Stubbed::OnRelease() {} - -void Controller_Stubbed::OnUpdate(const Core::Timing::CoreTiming& core_timing) { - if (!smart_update) { - return; - } - - header.timestamp = core_timing.GetGlobalTimeNs().count(); - header.total_entry_count = 17; - header.entry_count = 0; - header.last_entry_index = 0; -} - -} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/stubbed.h b/src/core/hle/service/hid/controllers/stubbed.h deleted file mode 100644 index d2052fb17..000000000 --- a/src/core/hle/service/hid/controllers/stubbed.h +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include "core/hle/service/hid/controllers/controller_base.h" - -namespace Service::HID { -struct CommonHeader; - -class Controller_Stubbed final : public ControllerBase { -public: - explicit Controller_Stubbed(Core::HID::HIDCore& hid_core_, CommonHeader& ring_lifo_header); - ~Controller_Stubbed() override; - - // Called when the controller is initialized - void OnInit() override; - - // When the controller is released - void OnRelease() override; - - // When the controller is requesting an update for the shared memory - void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; - -private: - CommonHeader& header; - bool smart_update{}; -}; -} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/core/hle/service/hid/controllers/touchscreen.cpp index 469750006..291dc707e 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.cpp +++ b/src/core/hle/service/hid/controllers/touchscreen.cpp @@ -8,15 +8,14 @@ #include "core/frontend/emu_window.h" #include "core/hid/emulated_console.h" #include "core/hid/hid_core.h" -#include "core/hle/service/hid/controllers/shared_memory_format.h" +#include "core/hle/service/hid/controllers/applet_resource.h" #include "core/hle/service/hid/controllers/touchscreen.h" +#include "core/hle/service/hid/controllers/types/shared_memory_format.h" namespace Service::HID { -TouchScreen::TouchScreen(Core::HID::HIDCore& hid_core_, - TouchScreenSharedMemoryFormat& touch_shared_memory) - : ControllerBase{hid_core_}, shared_memory{touch_shared_memory}, - touchscreen_width(Layout::ScreenUndocked::Width), +TouchScreen::TouchScreen(Core::HID::HIDCore& hid_core_) + : ControllerBase{hid_core_}, touchscreen_width(Layout::ScreenUndocked::Width), touchscreen_height(Layout::ScreenUndocked::Height) { console = hid_core.GetEmulatedConsole(); } @@ -28,6 +27,14 @@ void TouchScreen::OnInit() {} void TouchScreen::OnRelease() {} void TouchScreen::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + const u64 aruid = applet_resource->GetActiveAruid(); + auto* data = applet_resource->GetAruidData(aruid); + + if (data == nullptr) { + return; + } + + TouchScreenSharedMemoryFormat& shared_memory = data->shared_memory_format->touch_screen; shared_memory.touch_screen_lifo.timestamp = core_timing.GetGlobalTimeNs().count(); if (!IsControllerActivated()) { diff --git a/src/core/hle/service/hid/controllers/touchscreen.h b/src/core/hle/service/hid/controllers/touchscreen.h index 5b6305bfc..945d359be 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.h +++ b/src/core/hle/service/hid/controllers/touchscreen.h @@ -18,8 +18,7 @@ struct TouchScreenSharedMemoryFormat; class TouchScreen final : public ControllerBase { public: - explicit TouchScreen(Core::HID::HIDCore& hid_core_, - TouchScreenSharedMemoryFormat& touch_shared_memory); + explicit TouchScreen(Core::HID::HIDCore& hid_core_); ~TouchScreen() override; // Called when the controller is initialized @@ -35,7 +34,6 @@ public: private: TouchScreenState next_state{}; - TouchScreenSharedMemoryFormat& shared_memory; Core::HID::EmulatedConsole* console = nullptr; std::array fingers{}; diff --git a/src/core/hle/service/hid/controllers/types/shared_memory_format.h b/src/core/hle/service/hid/controllers/types/shared_memory_format.h new file mode 100644 index 000000000..2986c113e --- /dev/null +++ b/src/core/hle/service/hid/controllers/types/shared_memory_format.h @@ -0,0 +1,240 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include "common/common_funcs.h" +#include "common/common_types.h" +#include "common/vector_math.h" +#include "core/hid/hid_types.h" +#include "core/hle/service/hid//controllers/types/debug_pad_types.h" +#include "core/hle/service/hid//controllers/types/keyboard_types.h" +#include "core/hle/service/hid//controllers/types/mouse_types.h" +#include "core/hle/service/hid//controllers/types/npad_types.h" +#include "core/hle/service/hid//controllers/types/touch_types.h" +#include "core/hle/service/hid/ring_lifo.h" + +namespace Service::HID { +static const std::size_t HidEntryCount = 17; + +struct CommonHeader { + s64 timestamp{}; + s64 total_entry_count{}; + s64 last_entry_index{}; + s64 entry_count{}; +}; +static_assert(sizeof(CommonHeader) == 0x20, "CommonHeader is an invalid size"); + +// This is nn::hid::detail::DebugPadSharedMemoryFormat +struct DebugPadSharedMemoryFormat { + // This is nn::hid::detail::DebugPadLifo + Lifo debug_pad_lifo{}; + static_assert(sizeof(debug_pad_lifo) == 0x2C8, "debug_pad_lifo is an invalid size"); + INSERT_PADDING_WORDS(0x4E); +}; +static_assert(sizeof(DebugPadSharedMemoryFormat) == 0x400, + "DebugPadSharedMemoryFormat is an invalid size"); + +// This is nn::hid::detail::TouchScreenSharedMemoryFormat +struct TouchScreenSharedMemoryFormat { + // This is nn::hid::detail::TouchScreenLifo + Lifo touch_screen_lifo{}; + static_assert(sizeof(touch_screen_lifo) == 0x2C38, "touch_screen_lifo is an invalid size"); + INSERT_PADDING_WORDS(0xF2); +}; +static_assert(sizeof(TouchScreenSharedMemoryFormat) == 0x3000, + "TouchScreenSharedMemoryFormat is an invalid size"); + +// This is nn::hid::detail::MouseSharedMemoryFormat +struct MouseSharedMemoryFormat { + // This is nn::hid::detail::MouseLifo + Lifo mouse_lifo{}; + static_assert(sizeof(mouse_lifo) == 0x350, "mouse_lifo is an invalid size"); + INSERT_PADDING_WORDS(0x2C); +}; +static_assert(sizeof(MouseSharedMemoryFormat) == 0x400, + "MouseSharedMemoryFormat is an invalid size"); + +// This is nn::hid::detail::KeyboardSharedMemoryFormat +struct KeyboardSharedMemoryFormat { + // This is nn::hid::detail::KeyboardLifo + Lifo keyboard_lifo{}; + static_assert(sizeof(keyboard_lifo) == 0x3D8, "keyboard_lifo is an invalid size"); + INSERT_PADDING_WORDS(0xA); +}; +static_assert(sizeof(KeyboardSharedMemoryFormat) == 0x400, + "KeyboardSharedMemoryFormat is an invalid size"); + +// This is nn::hid::detail::DigitizerSharedMemoryFormat +struct DigitizerSharedMemoryFormat { + CommonHeader header; + INSERT_PADDING_BYTES(0xFE0); +}; +static_assert(sizeof(DigitizerSharedMemoryFormat) == 0x1000, + "DigitizerSharedMemoryFormat is an invalid size"); + +// This is nn::hid::detail::HomeButtonSharedMemoryFormat +struct HomeButtonSharedMemoryFormat { + CommonHeader header; + INSERT_PADDING_BYTES(0x1E0); +}; +static_assert(sizeof(HomeButtonSharedMemoryFormat) == 0x200, + "HomeButtonSharedMemoryFormat is an invalid size"); + +// This is nn::hid::detail::SleepButtonSharedMemoryFormat +struct SleepButtonSharedMemoryFormat { + CommonHeader header; + INSERT_PADDING_BYTES(0x1E0); +}; +static_assert(sizeof(SleepButtonSharedMemoryFormat) == 0x200, + "SleepButtonSharedMemoryFormat is an invalid size"); + +// This is nn::hid::detail::CaptureButtonSharedMemoryFormat +struct CaptureButtonSharedMemoryFormat { + CommonHeader header; + INSERT_PADDING_BYTES(0x1E0); +}; +static_assert(sizeof(CaptureButtonSharedMemoryFormat) == 0x200, + "CaptureButtonSharedMemoryFormat is an invalid size"); + +// This is nn::hid::detail::InputDetectorSharedMemoryFormat +struct InputDetectorSharedMemoryFormat { + CommonHeader header; + INSERT_PADDING_BYTES(0x7E0); +}; +static_assert(sizeof(InputDetectorSharedMemoryFormat) == 0x800, + "InputDetectorSharedMemoryFormat is an invalid size"); + +// This is nn::hid::detail::UniquePadSharedMemoryFormat +struct UniquePadSharedMemoryFormat { + CommonHeader header; + INSERT_PADDING_BYTES(0x3FE0); +}; +static_assert(sizeof(UniquePadSharedMemoryFormat) == 0x4000, + "UniquePadSharedMemoryFormat is an invalid size"); + +// This is nn::hid::detail::NpadSixAxisSensorLifo +struct NpadSixAxisSensorLifo { + Lifo lifo; +}; + +// This is nn::hid::detail::NpadInternalState +struct NpadInternalState { + Core::HID::NpadStyleTag style_tag{Core::HID::NpadStyleSet::None}; + NpadJoyAssignmentMode assignment_mode{NpadJoyAssignmentMode::Dual}; + NpadFullKeyColorState fullkey_color{}; + NpadJoyColorState joycon_color{}; + Lifo fullkey_lifo{}; + Lifo handheld_lifo{}; + Lifo joy_dual_lifo{}; + Lifo joy_left_lifo{}; + Lifo joy_right_lifo{}; + Lifo palma_lifo{}; + Lifo system_ext_lifo{}; + NpadSixAxisSensorLifo sixaxis_fullkey_lifo{}; + NpadSixAxisSensorLifo sixaxis_handheld_lifo{}; + NpadSixAxisSensorLifo sixaxis_dual_left_lifo{}; + NpadSixAxisSensorLifo sixaxis_dual_right_lifo{}; + NpadSixAxisSensorLifo sixaxis_left_lifo{}; + NpadSixAxisSensorLifo sixaxis_right_lifo{}; + DeviceType device_type{}; + INSERT_PADDING_BYTES(0x4); // Reserved + NPadSystemProperties system_properties{}; + NpadSystemButtonProperties button_properties{}; + Core::HID::NpadBatteryLevel battery_level_dual{}; + Core::HID::NpadBatteryLevel battery_level_left{}; + Core::HID::NpadBatteryLevel battery_level_right{}; + AppletFooterUiAttributes applet_footer_attributes{}; + AppletFooterUiType applet_footer_type{AppletFooterUiType::None}; + INSERT_PADDING_BYTES(0x5B); // Reserved + INSERT_PADDING_BYTES(0x20); // Unknown + Lifo gc_trigger_lifo{}; + NpadLarkType lark_type_l_and_main{}; + NpadLarkType lark_type_r{}; + NpadLuciaType lucia_type{}; + NpadLagerType lager_type{}; + Core::HID::SixAxisSensorProperties sixaxis_fullkey_properties; + Core::HID::SixAxisSensorProperties sixaxis_handheld_properties; + Core::HID::SixAxisSensorProperties sixaxis_dual_left_properties; + Core::HID::SixAxisSensorProperties sixaxis_dual_right_properties; + Core::HID::SixAxisSensorProperties sixaxis_left_properties; + Core::HID::SixAxisSensorProperties sixaxis_right_properties; +}; +static_assert(sizeof(NpadInternalState) == 0x43F8, "NpadInternalState is an invalid size"); + +// This is nn::hid::detail::NpadSharedMemoryEntry +struct NpadSharedMemoryEntry { + NpadInternalState internal_state; + INSERT_PADDING_BYTES(0xC08); +}; +static_assert(sizeof(NpadSharedMemoryEntry) == 0x5000, "NpadSharedMemoryEntry is an invalid size"); + +// This is nn::hid::detail::NpadSharedMemoryFormat +struct NpadSharedMemoryFormat { + std::array npad_entry; +}; +static_assert(sizeof(NpadSharedMemoryFormat) == 0x32000, + "NpadSharedMemoryFormat is an invalid size"); + +// This is nn::hid::detail::GestureSharedMemoryFormat +struct GestureSharedMemoryFormat { + // This is nn::hid::detail::GestureLifo + Lifo gesture_lifo{}; + static_assert(sizeof(gesture_lifo) == 0x708, "gesture_lifo is an invalid size"); + INSERT_PADDING_WORDS(0x3E); +}; +static_assert(sizeof(GestureSharedMemoryFormat) == 0x800, + "GestureSharedMemoryFormat is an invalid size"); + +// This is nn::hid::detail::ConsoleSixAxisSensorSharedMemoryFormat +struct ConsoleSixAxisSensorSharedMemoryFormat { + u64 sampling_number{}; + bool is_seven_six_axis_sensor_at_rest{}; + INSERT_PADDING_BYTES(3); // padding + f32 verticalization_error{}; + Common::Vec3f gyro_bias{}; + INSERT_PADDING_BYTES(4); // padding +}; +static_assert(sizeof(ConsoleSixAxisSensorSharedMemoryFormat) == 0x20, + "ConsoleSixAxisSensorSharedMemoryFormat is an invalid size"); + +// This is nn::hid::detail::SharedMemoryFormat +struct SharedMemoryFormat { + void Initialize() {} + + DebugPadSharedMemoryFormat debug_pad; + TouchScreenSharedMemoryFormat touch_screen; + MouseSharedMemoryFormat mouse; + KeyboardSharedMemoryFormat keyboard; + DigitizerSharedMemoryFormat digitizer; + HomeButtonSharedMemoryFormat home_button; + SleepButtonSharedMemoryFormat sleep_button; + CaptureButtonSharedMemoryFormat capture_button; + InputDetectorSharedMemoryFormat input_detector; + UniquePadSharedMemoryFormat unique_pad; + NpadSharedMemoryFormat npad; + GestureSharedMemoryFormat gesture; + ConsoleSixAxisSensorSharedMemoryFormat console; + INSERT_PADDING_BYTES(0x19E0); + MouseSharedMemoryFormat debug_mouse; + INSERT_PADDING_BYTES(0x2000); +}; +static_assert(offsetof(SharedMemoryFormat, debug_pad) == 0x0, "debug_pad has wrong offset"); +static_assert(offsetof(SharedMemoryFormat, touch_screen) == 0x400, "touch_screen has wrong offset"); +static_assert(offsetof(SharedMemoryFormat, mouse) == 0x3400, "mouse has wrong offset"); +static_assert(offsetof(SharedMemoryFormat, keyboard) == 0x3800, "keyboard has wrong offset"); +static_assert(offsetof(SharedMemoryFormat, digitizer) == 0x3C00, "digitizer has wrong offset"); +static_assert(offsetof(SharedMemoryFormat, home_button) == 0x4C00, "home_button has wrong offset"); +static_assert(offsetof(SharedMemoryFormat, sleep_button) == 0x4E00, + "sleep_button has wrong offset"); +static_assert(offsetof(SharedMemoryFormat, capture_button) == 0x5000, + "capture_button has wrong offset"); +static_assert(offsetof(SharedMemoryFormat, input_detector) == 0x5200, + "input_detector has wrong offset"); +static_assert(offsetof(SharedMemoryFormat, npad) == 0x9A00, "npad has wrong offset"); +static_assert(offsetof(SharedMemoryFormat, gesture) == 0x3BA00, "gesture has wrong offset"); +static_assert(offsetof(SharedMemoryFormat, console) == 0x3C200, "console has wrong offset"); +static_assert(offsetof(SharedMemoryFormat, debug_mouse) == 0x3DC00, "debug_mouse has wrong offset"); +static_assert(sizeof(SharedMemoryFormat) == 0x40000, "SharedMemoryFormat is an invalid size"); + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/unique_pad.cpp b/src/core/hle/service/hid/controllers/unique_pad.cpp new file mode 100644 index 000000000..8230501a5 --- /dev/null +++ b/src/core/hle/service/hid/controllers/unique_pad.cpp @@ -0,0 +1,38 @@ +// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/core_timing.h" +#include "core/hle/service/hid/controllers/applet_resource.h" +#include "core/hle/service/hid/controllers/types/shared_memory_format.h" +#include "core/hle/service/hid/controllers/unique_pad.h" + +namespace Service::HID { + +UniquePad::UniquePad(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {} + +UniquePad::~UniquePad() = default; + +void UniquePad::OnInit() {} + +void UniquePad::OnRelease() {} + +void UniquePad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + if (!smart_update) { + return; + } + + const u64 aruid = applet_resource->GetActiveAruid(); + auto* data = applet_resource->GetAruidData(aruid); + + if (data == nullptr) { + return; + } + + auto& header = data->shared_memory_format->capture_button.header; + header.timestamp = core_timing.GetGlobalTimeNs().count(); + header.total_entry_count = 17; + header.entry_count = 0; + header.last_entry_index = 0; +} + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/unique_pad.h b/src/core/hle/service/hid/controllers/unique_pad.h new file mode 100644 index 000000000..966368264 --- /dev/null +++ b/src/core/hle/service/hid/controllers/unique_pad.h @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/hle/service/hid/controllers/controller_base.h" + +namespace Service::HID { + +class UniquePad final : public ControllerBase { +public: + explicit UniquePad(Core::HID::HIDCore& hid_core_); + ~UniquePad() override; + + // Called when the controller is initialized + void OnInit() override; + + // When the controller is released + void OnRelease() override; + + // When the controller is requesting an update for the shared memory + void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; + +private: + bool smart_update{}; +}; +} // namespace Service::HID diff --git a/src/core/hle/service/hid/resource_manager.cpp b/src/core/hle/service/hid/resource_manager.cpp index 6c6cbd802..7b689d085 100644 --- a/src/core/hle/service/hid/resource_manager.cpp +++ b/src/core/hle/service/hid/resource_manager.cpp @@ -10,18 +10,23 @@ #include "core/hle/service/ipc_helpers.h" #include "core/hle/service/hid/controllers/applet_resource.h" +#include "core/hle/service/hid/controllers/capture_button.h" #include "core/hle/service/hid/controllers/console_six_axis.h" +#include "core/hle/service/hid/controllers/debug_mouse.h" #include "core/hle/service/hid/controllers/debug_pad.h" +#include "core/hle/service/hid/controllers/digitizer.h" #include "core/hle/service/hid/controllers/gesture.h" +#include "core/hle/service/hid/controllers/home_button.h" #include "core/hle/service/hid/controllers/keyboard.h" #include "core/hle/service/hid/controllers/mouse.h" #include "core/hle/service/hid/controllers/npad.h" #include "core/hle/service/hid/controllers/palma.h" #include "core/hle/service/hid/controllers/seven_six_axis.h" -#include "core/hle/service/hid/controllers/shared_memory_format.h" #include "core/hle/service/hid/controllers/six_axis.h" -#include "core/hle/service/hid/controllers/stubbed.h" +#include "core/hle/service/hid/controllers/sleep_button.h" #include "core/hle/service/hid/controllers/touchscreen.h" +#include "core/hle/service/hid/controllers/types/shared_memory_format.h" +#include "core/hle/service/hid/controllers/unique_pad.h" namespace Service::HID { @@ -46,42 +51,13 @@ void ResourceManager::Initialize() { } system.HIDCore().ReloadInputDevices(); - is_initialized = true; -} - -void ResourceManager::InitializeController(u64 aruid) { - SharedMemoryFormat* shared_memory = nullptr; - const auto result = applet_resource->GetSharedMemoryFormat(&shared_memory, aruid); - if (result.IsError()) { - return; - } - - debug_pad = std::make_shared(system.HIDCore(), shared_memory->debug_pad); - mouse = std::make_shared(system.HIDCore(), shared_memory->mouse); - debug_mouse = std::make_shared(system.HIDCore(), shared_memory->debug_mouse); - keyboard = std::make_shared(system.HIDCore(), shared_memory->keyboard); - unique_pad = std::make_shared(system.HIDCore(), shared_memory->unique_pad.header); - npad = std::make_shared(system.HIDCore(), shared_memory->npad, service_context); - gesture = std::make_shared(system.HIDCore(), shared_memory->gesture); - touch_screen = std::make_shared(system.HIDCore(), shared_memory->touch_screen); - palma = std::make_shared(system.HIDCore(), service_context); + InitializeHidCommonSampler(); + InitializeTouchScreenSampler(); + InitializeConsoleSixAxisSampler(); + InitializeAHidSampler(); - home_button = std::make_shared(system.HIDCore(), shared_memory->home_button.header); - sleep_button = - std::make_shared(system.HIDCore(), shared_memory->sleep_button.header); - capture_button = - std::make_shared(system.HIDCore(), shared_memory->capture_button.header); - digitizer = std::make_shared(system.HIDCore(), shared_memory->digitizer.header); - - six_axis = std::make_shared(system.HIDCore(), npad); - console_six_axis = std::make_shared(system.HIDCore(), shared_memory->console); - seven_six_axis = std::make_shared(system); - - // Homebrew doesn't try to activate some controllers, so we activate them by default - npad->Activate(); - six_axis->Activate(); - touch_screen->Activate(); + is_initialized = true; } std::shared_ptr ResourceManager::GetAppletResource() const { @@ -165,16 +141,65 @@ Result ResourceManager::CreateAppletResource(u64 aruid) { if (result.IsError()) { return result; } + + // Homebrew doesn't try to activate some controllers, so we activate them by default + npad->Activate(); + six_axis->Activate(); + touch_screen->Activate(); + return GetNpad()->Activate(aruid); } Result ResourceManager::CreateAppletResourceImpl(u64 aruid) { std::scoped_lock lock{shared_mutex}; - const auto result = applet_resource->CreateAppletResource(aruid); - if (result.IsSuccess()) { - InitializeController(aruid); - } - return result; + return applet_resource->CreateAppletResource(aruid); +} + +void ResourceManager::InitializeHidCommonSampler() { + debug_pad = std::make_shared(system.HIDCore()); + mouse = std::make_shared(system.HIDCore()); + debug_mouse = std::make_shared(system.HIDCore()); + keyboard = std::make_shared(system.HIDCore()); + unique_pad = std::make_shared(system.HIDCore()); + npad = std::make_shared(system.HIDCore(), service_context); + gesture = std::make_shared(system.HIDCore()); + home_button = std::make_shared(system.HIDCore()); + sleep_button = std::make_shared(system.HIDCore()); + capture_button = std::make_shared(system.HIDCore()); + digitizer = std::make_shared(system.HIDCore()); + + palma = std::make_shared(system.HIDCore(), service_context); + six_axis = std::make_shared(system.HIDCore(), npad); + + debug_pad->SetAppletResource(applet_resource); + digitizer->SetAppletResource(applet_resource); + keyboard->SetAppletResource(applet_resource); + npad->SetAppletResource(applet_resource); + six_axis->SetAppletResource(applet_resource); + mouse->SetAppletResource(applet_resource); + debug_mouse->SetAppletResource(applet_resource); + home_button->SetAppletResource(applet_resource); + sleep_button->SetAppletResource(applet_resource); + capture_button->SetAppletResource(applet_resource); +} + +void ResourceManager::InitializeTouchScreenSampler() { + gesture = std::make_shared(system.HIDCore()); + touch_screen = std::make_shared(system.HIDCore()); + + touch_screen->SetAppletResource(applet_resource); + gesture->SetAppletResource(applet_resource); +} + +void ResourceManager::InitializeConsoleSixAxisSampler() { + console_six_axis = std::make_shared(system.HIDCore()); + seven_six_axis = std::make_shared(system); + + console_six_axis->SetAppletResource(applet_resource); +} + +void ResourceManager::InitializeAHidSampler() { + // TODO } Result ResourceManager::RegisterCoreAppletResource() { diff --git a/src/core/hle/service/hid/resource_manager.h b/src/core/hle/service/hid/resource_manager.h index 5ad7cb564..7df1567cc 100644 --- a/src/core/hle/service/hid/resource_manager.h +++ b/src/core/hle/service/hid/resource_manager.h @@ -20,24 +20,23 @@ class KSharedMemory; namespace Service::HID { class AppletResource; +class CaptureButton; class Controller_Stubbed; class ConsoleSixAxis; +class DebugMouse; class DebugPad; +class Digitizer; class Gesture; +class HomeButton; class Keyboard; class Mouse; class NPad; class Palma; class SevenSixAxis; class SixAxis; +class SleepButton; class TouchScreen; - -using CaptureButton = Controller_Stubbed; -using DebugMouse = Mouse; -using Digitizer = Controller_Stubbed; -using HomeButton = Controller_Stubbed; -using SleepButton = Controller_Stubbed; -using UniquePad = Controller_Stubbed; +class UniquePad; class ResourceManager { @@ -46,7 +45,6 @@ public: ~ResourceManager(); void Initialize(); - void InitializeController(u64 aruid); std::shared_ptr GetAppletResource() const; std::shared_ptr GetCaptureButton() const; @@ -88,6 +86,10 @@ public: private: Result CreateAppletResourceImpl(u64 aruid); + void InitializeHidCommonSampler(); + void InitializeTouchScreenSampler(); + void InitializeConsoleSixAxisSampler(); + void InitializeAHidSampler(); bool is_initialized{false}; -- cgit v1.2.3