diff options
| -rw-r--r-- | src/core/hle/service/hid/controllers/controller_base.h | 11 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/debug_pad.cpp | 68 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/debug_pad.h | 73 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/stubbed.cpp | 3 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/stubbed.h | 11 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/xpad.cpp | 29 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/xpad.h | 51 |
7 files changed, 80 insertions, 166 deletions
diff --git a/src/core/hle/service/hid/controllers/controller_base.h b/src/core/hle/service/hid/controllers/controller_base.h index 1556fb08e..4ba2eda1a 100644 --- a/src/core/hle/service/hid/controllers/controller_base.h +++ b/src/core/hle/service/hid/controllers/controller_base.h | |||
| @@ -35,9 +35,6 @@ public: | |||
| 35 | virtual void OnMotionUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, | 35 | virtual void OnMotionUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, |
| 36 | std::size_t size) {} | 36 | std::size_t size) {} |
| 37 | 37 | ||
| 38 | // Called when input devices should be loaded | ||
| 39 | virtual void OnLoadInputDevices() = 0; | ||
| 40 | |||
| 41 | void ActivateController(); | 38 | void ActivateController(); |
| 42 | 39 | ||
| 43 | void DeactivateController(); | 40 | void DeactivateController(); |
| @@ -47,14 +44,6 @@ public: | |||
| 47 | protected: | 44 | protected: |
| 48 | bool is_activated{false}; | 45 | bool is_activated{false}; |
| 49 | 46 | ||
| 50 | struct CommonHeader { | ||
| 51 | s64_le timestamp; | ||
| 52 | s64_le total_entry_count; | ||
| 53 | s64_le last_entry_index; | ||
| 54 | s64_le entry_count; | ||
| 55 | }; | ||
| 56 | static_assert(sizeof(CommonHeader) == 0x20, "CommonHeader is an invalid size"); | ||
| 57 | |||
| 58 | Core::System& system; | 47 | Core::System& system; |
| 59 | }; | 48 | }; |
| 60 | } // namespace Service::HID | 49 | } // 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 d439b8fb0..b2b4edf51 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.cpp +++ b/src/core/hle/service/hid/controllers/debug_pad.cpp | |||
| @@ -5,7 +5,10 @@ | |||
| 5 | #include <cstring> | 5 | #include <cstring> |
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "common/settings.h" | 7 | #include "common/settings.h" |
| 8 | #include "core/core.h" | ||
| 8 | #include "core/core_timing.h" | 9 | #include "core/core_timing.h" |
| 10 | #include "core/hid/hid_core.h" | ||
| 11 | #include "core/hid/hid_types.h" | ||
| 9 | #include "core/hle/service/hid/controllers/debug_pad.h" | 12 | #include "core/hle/service/hid/controllers/debug_pad.h" |
| 10 | 13 | ||
| 11 | namespace Service::HID { | 14 | namespace Service::HID { |
| @@ -14,7 +17,10 @@ constexpr s32 HID_JOYSTICK_MAX = 0x7fff; | |||
| 14 | [[maybe_unused]] constexpr s32 HID_JOYSTICK_MIN = -0x7fff; | 17 | [[maybe_unused]] constexpr s32 HID_JOYSTICK_MIN = -0x7fff; |
| 15 | enum class JoystickId : std::size_t { Joystick_Left, Joystick_Right }; | 18 | enum class JoystickId : std::size_t { Joystick_Left, Joystick_Right }; |
| 16 | 19 | ||
| 17 | Controller_DebugPad::Controller_DebugPad(Core::System& system_) : ControllerBase{system_} {} | 20 | Controller_DebugPad::Controller_DebugPad(Core::System& system_) : ControllerBase{system_} { |
| 21 | controller = system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Other); | ||
| 22 | } | ||
| 23 | |||
| 18 | Controller_DebugPad::~Controller_DebugPad() = default; | 24 | Controller_DebugPad::~Controller_DebugPad() = default; |
| 19 | 25 | ||
| 20 | void Controller_DebugPad::OnInit() {} | 26 | void Controller_DebugPad::OnInit() {} |
| @@ -23,63 +29,29 @@ void Controller_DebugPad::OnRelease() {} | |||
| 23 | 29 | ||
| 24 | void Controller_DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, | 30 | void Controller_DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, |
| 25 | std::size_t size) { | 31 | std::size_t size) { |
| 26 | shared_memory.header.timestamp = core_timing.GetCPUTicks(); | ||
| 27 | shared_memory.header.total_entry_count = 17; | ||
| 28 | |||
| 29 | if (!IsControllerActivated()) { | 32 | if (!IsControllerActivated()) { |
| 30 | shared_memory.header.entry_count = 0; | 33 | debug_pad_lifo.entry_count = 0; |
| 31 | shared_memory.header.last_entry_index = 0; | 34 | debug_pad_lifo.last_entry_index = 0; |
| 35 | std::memcpy(data, &debug_pad_lifo, sizeof(debug_pad_lifo)); | ||
| 32 | return; | 36 | return; |
| 33 | } | 37 | } |
| 34 | shared_memory.header.entry_count = 16; | ||
| 35 | 38 | ||
| 36 | const auto& last_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; | 39 | const auto& last_entry = debug_pad_lifo.ReadCurrentEntry().state; |
| 37 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; | 40 | next_state.sampling_number = last_entry.sampling_number + 1; |
| 38 | auto& cur_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; | ||
| 39 | |||
| 40 | cur_entry.sampling_number = last_entry.sampling_number + 1; | ||
| 41 | cur_entry.sampling_number2 = cur_entry.sampling_number; | ||
| 42 | 41 | ||
| 43 | if (Settings::values.debug_pad_enabled) { | 42 | if (Settings::values.debug_pad_enabled) { |
| 44 | cur_entry.attribute.connected.Assign(1); | 43 | next_state.attribute.connected.Assign(1); |
| 45 | auto& pad = cur_entry.pad_state; | ||
| 46 | 44 | ||
| 47 | using namespace Settings::NativeButton; | 45 | const auto& button_state = controller->GetDebugPadButtons(); |
| 48 | pad.a.Assign(buttons[A - BUTTON_HID_BEGIN]->GetStatus()); | 46 | const auto& stick_state = controller->GetSticks(); |
| 49 | pad.b.Assign(buttons[B - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 50 | pad.x.Assign(buttons[X - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 51 | pad.y.Assign(buttons[Y - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 52 | pad.l.Assign(buttons[L - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 53 | pad.r.Assign(buttons[R - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 54 | pad.zl.Assign(buttons[ZL - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 55 | pad.zr.Assign(buttons[ZR - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 56 | pad.plus.Assign(buttons[Plus - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 57 | pad.minus.Assign(buttons[Minus - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 58 | pad.d_left.Assign(buttons[DLeft - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 59 | pad.d_up.Assign(buttons[DUp - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 60 | pad.d_right.Assign(buttons[DRight - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 61 | pad.d_down.Assign(buttons[DDown - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 62 | 47 | ||
| 63 | const auto [stick_l_x_f, stick_l_y_f] = | 48 | next_state.pad_state = button_state; |
| 64 | analogs[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetStatus(); | 49 | next_state.l_stick = stick_state.left; |
| 65 | const auto [stick_r_x_f, stick_r_y_f] = | 50 | next_state.r_stick = stick_state.right; |
| 66 | analogs[static_cast<std::size_t>(JoystickId::Joystick_Right)]->GetStatus(); | ||
| 67 | cur_entry.l_stick.x = static_cast<s32>(stick_l_x_f * HID_JOYSTICK_MAX); | ||
| 68 | cur_entry.l_stick.y = static_cast<s32>(stick_l_y_f * HID_JOYSTICK_MAX); | ||
| 69 | cur_entry.r_stick.x = static_cast<s32>(stick_r_x_f * HID_JOYSTICK_MAX); | ||
| 70 | cur_entry.r_stick.y = static_cast<s32>(stick_r_y_f * HID_JOYSTICK_MAX); | ||
| 71 | } | 51 | } |
| 72 | 52 | ||
| 73 | std::memcpy(data, &shared_memory, sizeof(SharedMemory)); | 53 | debug_pad_lifo.WriteNextEntry(next_state); |
| 54 | std::memcpy(data, &debug_pad_lifo, sizeof(debug_pad_lifo)); | ||
| 74 | } | 55 | } |
| 75 | 56 | ||
| 76 | void Controller_DebugPad::OnLoadInputDevices() { | ||
| 77 | std::transform(Settings::values.debug_pad_buttons.begin(), | ||
| 78 | Settings::values.debug_pad_buttons.begin() + | ||
| 79 | Settings::NativeButton::NUM_BUTTONS_HID, | ||
| 80 | buttons.begin(), Input::CreateDevice<Input::ButtonDevice>); | ||
| 81 | std::transform(Settings::values.debug_pad_analogs.begin(), | ||
| 82 | Settings::values.debug_pad_analogs.end(), analogs.begin(), | ||
| 83 | Input::CreateDevice<Input::AnalogDevice>); | ||
| 84 | } | ||
| 85 | } // namespace Service::HID | 57 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/debug_pad.h b/src/core/hle/service/hid/controllers/debug_pad.h index e90ae8415..11b6c669b 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.h +++ b/src/core/hle/service/hid/controllers/debug_pad.h | |||
| @@ -10,8 +10,14 @@ | |||
| 10 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 11 | #include "common/settings.h" | 11 | #include "common/settings.h" |
| 12 | #include "common/swap.h" | 12 | #include "common/swap.h" |
| 13 | #include "core/frontend/input.h" | ||
| 14 | #include "core/hle/service/hid/controllers/controller_base.h" | 13 | #include "core/hle/service/hid/controllers/controller_base.h" |
| 14 | #include "core/hle/service/hid/ring_lifo.h" | ||
| 15 | |||
| 16 | namespace Core::HID { | ||
| 17 | class EmulatedController; | ||
| 18 | struct DebugPadButton; | ||
| 19 | struct AnalogStickState; | ||
| 20 | } // namespace Core::HID | ||
| 15 | 21 | ||
| 16 | namespace Service::HID { | 22 | namespace Service::HID { |
| 17 | class Controller_DebugPad final : public ControllerBase { | 23 | class Controller_DebugPad final : public ControllerBase { |
| @@ -28,66 +34,31 @@ public: | |||
| 28 | // When the controller is requesting an update for the shared memory | 34 | // When the controller is requesting an update for the shared memory |
| 29 | void OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, std::size_t size) override; | 35 | void OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, std::size_t size) override; |
| 30 | 36 | ||
| 31 | // Called when input devices should be loaded | ||
| 32 | void OnLoadInputDevices() override; | ||
| 33 | |||
| 34 | private: | 37 | private: |
| 35 | struct AnalogStick { | 38 | // This is nn::hid::DebugPadAttribute |
| 36 | s32_le x; | 39 | struct DebugPadAttribute { |
| 37 | s32_le y; | ||
| 38 | }; | ||
| 39 | static_assert(sizeof(AnalogStick) == 0x8); | ||
| 40 | |||
| 41 | struct PadState { | ||
| 42 | union { | ||
| 43 | u32_le raw{}; | ||
| 44 | BitField<0, 1, u32> a; | ||
| 45 | BitField<1, 1, u32> b; | ||
| 46 | BitField<2, 1, u32> x; | ||
| 47 | BitField<3, 1, u32> y; | ||
| 48 | BitField<4, 1, u32> l; | ||
| 49 | BitField<5, 1, u32> r; | ||
| 50 | BitField<6, 1, u32> zl; | ||
| 51 | BitField<7, 1, u32> zr; | ||
| 52 | BitField<8, 1, u32> plus; | ||
| 53 | BitField<9, 1, u32> minus; | ||
| 54 | BitField<10, 1, u32> d_left; | ||
| 55 | BitField<11, 1, u32> d_up; | ||
| 56 | BitField<12, 1, u32> d_right; | ||
| 57 | BitField<13, 1, u32> d_down; | ||
| 58 | }; | ||
| 59 | }; | ||
| 60 | static_assert(sizeof(PadState) == 0x4, "PadState is an invalid size"); | ||
| 61 | |||
| 62 | struct Attributes { | ||
| 63 | union { | 40 | union { |
| 64 | u32_le raw{}; | 41 | u32_le raw{}; |
| 65 | BitField<0, 1, u32> connected; | 42 | BitField<0, 1, u32> connected; |
| 66 | }; | 43 | }; |
| 67 | }; | 44 | }; |
| 68 | static_assert(sizeof(Attributes) == 0x4, "Attributes is an invalid size"); | 45 | static_assert(sizeof(DebugPadAttribute) == 0x4, "DebugPadAttribute is an invalid size"); |
| 69 | 46 | ||
| 70 | struct PadStates { | 47 | // This is nn::hid::DebugPadState |
| 48 | struct DebugPadState { | ||
| 71 | s64_le sampling_number; | 49 | s64_le sampling_number; |
| 72 | s64_le sampling_number2; | 50 | DebugPadAttribute attribute; |
| 73 | Attributes attribute; | 51 | Core::HID::DebugPadButton pad_state; |
| 74 | PadState pad_state; | 52 | Core::HID::AnalogStickState r_stick; |
| 75 | AnalogStick r_stick; | 53 | Core::HID::AnalogStickState l_stick; |
| 76 | AnalogStick l_stick; | ||
| 77 | }; | 54 | }; |
| 78 | static_assert(sizeof(PadStates) == 0x28, "PadStates is an invalid state"); | 55 | static_assert(sizeof(DebugPadState) == 0x20, "DebugPadState is an invalid state"); |
| 79 | 56 | ||
| 80 | struct SharedMemory { | 57 | // This is nn::hid::detail::DebugPadLifo |
| 81 | CommonHeader header; | 58 | Lifo<DebugPadState> debug_pad_lifo{}; |
| 82 | std::array<PadStates, 17> pad_states; | 59 | static_assert(sizeof(debug_pad_lifo) == 0x2C8, "debug_pad_lifo is an invalid size"); |
| 83 | INSERT_PADDING_BYTES(0x138); | 60 | DebugPadState next_state{}; |
| 84 | }; | ||
| 85 | static_assert(sizeof(SharedMemory) == 0x400, "SharedMemory is an invalid size"); | ||
| 86 | SharedMemory shared_memory{}; | ||
| 87 | 61 | ||
| 88 | std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID> | 62 | Core::HID::EmulatedController* controller; |
| 89 | buttons; | ||
| 90 | std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NumAnalogs> | ||
| 91 | analogs; | ||
| 92 | }; | 63 | }; |
| 93 | } // namespace Service::HID | 64 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/stubbed.cpp b/src/core/hle/service/hid/controllers/stubbed.cpp index 772c20453..a8c93909d 100644 --- a/src/core/hle/service/hid/controllers/stubbed.cpp +++ b/src/core/hle/service/hid/controllers/stubbed.cpp | |||
| @@ -31,10 +31,9 @@ void Controller_Stubbed::OnUpdate(const Core::Timing::CoreTiming& core_timing, u | |||
| 31 | std::memcpy(data + common_offset, &header, sizeof(CommonHeader)); | 31 | std::memcpy(data + common_offset, &header, sizeof(CommonHeader)); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | void Controller_Stubbed::OnLoadInputDevices() {} | ||
| 35 | |||
| 36 | void Controller_Stubbed::SetCommonHeaderOffset(std::size_t off) { | 34 | void Controller_Stubbed::SetCommonHeaderOffset(std::size_t off) { |
| 37 | common_offset = off; | 35 | common_offset = off; |
| 38 | smart_update = true; | 36 | smart_update = true; |
| 39 | } | 37 | } |
| 38 | |||
| 40 | } // namespace Service::HID | 39 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/stubbed.h b/src/core/hle/service/hid/controllers/stubbed.h index 21092af0d..29f95a100 100644 --- a/src/core/hle/service/hid/controllers/stubbed.h +++ b/src/core/hle/service/hid/controllers/stubbed.h | |||
| @@ -22,12 +22,17 @@ public: | |||
| 22 | // When the controller is requesting an update for the shared memory | 22 | // When the controller is requesting an update for the shared memory |
| 23 | void OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, std::size_t size) override; | 23 | void OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, std::size_t size) override; |
| 24 | 24 | ||
| 25 | // Called when input devices should be loaded | ||
| 26 | void OnLoadInputDevices() override; | ||
| 27 | |||
| 28 | void SetCommonHeaderOffset(std::size_t off); | 25 | void SetCommonHeaderOffset(std::size_t off); |
| 29 | 26 | ||
| 30 | private: | 27 | private: |
| 28 | struct CommonHeader { | ||
| 29 | s64_le timestamp; | ||
| 30 | s64_le total_entry_count; | ||
| 31 | s64_le last_entry_index; | ||
| 32 | s64_le entry_count; | ||
| 33 | }; | ||
| 34 | static_assert(sizeof(CommonHeader) == 0x20, "CommonHeader is an invalid size"); | ||
| 35 | |||
| 31 | bool smart_update{}; | 36 | bool smart_update{}; |
| 32 | std::size_t common_offset{}; | 37 | std::size_t common_offset{}; |
| 33 | }; | 38 | }; |
diff --git a/src/core/hle/service/hid/controllers/xpad.cpp b/src/core/hle/service/hid/controllers/xpad.cpp index 41dc22cf9..29a412ff9 100644 --- a/src/core/hle/service/hid/controllers/xpad.cpp +++ b/src/core/hle/service/hid/controllers/xpad.cpp | |||
| @@ -19,28 +19,19 @@ void Controller_XPad::OnRelease() {} | |||
| 19 | 19 | ||
| 20 | void Controller_XPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, | 20 | void Controller_XPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, |
| 21 | std::size_t size) { | 21 | std::size_t size) { |
| 22 | for (auto& xpad_entry : shared_memory.shared_memory_entries) { | 22 | if (!IsControllerActivated()) { |
| 23 | xpad_entry.header.timestamp = core_timing.GetCPUTicks(); | 23 | basic_xpad_lifo.entry_count = 0; |
| 24 | xpad_entry.header.total_entry_count = 17; | 24 | basic_xpad_lifo.last_entry_index = 0; |
| 25 | 25 | std::memcpy(data, &basic_xpad_lifo, sizeof(basic_xpad_lifo)); | |
| 26 | if (!IsControllerActivated()) { | 26 | return; |
| 27 | xpad_entry.header.entry_count = 0; | ||
| 28 | xpad_entry.header.last_entry_index = 0; | ||
| 29 | return; | ||
| 30 | } | ||
| 31 | xpad_entry.header.entry_count = 16; | ||
| 32 | |||
| 33 | const auto& last_entry = xpad_entry.pad_states[xpad_entry.header.last_entry_index]; | ||
| 34 | xpad_entry.header.last_entry_index = (xpad_entry.header.last_entry_index + 1) % 17; | ||
| 35 | auto& cur_entry = xpad_entry.pad_states[xpad_entry.header.last_entry_index]; | ||
| 36 | |||
| 37 | cur_entry.sampling_number = last_entry.sampling_number + 1; | ||
| 38 | cur_entry.sampling_number2 = cur_entry.sampling_number; | ||
| 39 | } | 27 | } |
| 28 | |||
| 29 | const auto& last_entry = basic_xpad_lifo.ReadCurrentEntry().state; | ||
| 30 | next_state.sampling_number = last_entry.sampling_number + 1; | ||
| 40 | // TODO(ogniK): Update xpad states | 31 | // TODO(ogniK): Update xpad states |
| 41 | 32 | ||
| 42 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory)); | 33 | basic_xpad_lifo.WriteNextEntry(next_state); |
| 34 | std::memcpy(data + SHARED_MEMORY_OFFSET, &basic_xpad_lifo, sizeof(basic_xpad_lifo)); | ||
| 43 | } | 35 | } |
| 44 | 36 | ||
| 45 | void Controller_XPad::OnLoadInputDevices() {} | ||
| 46 | } // namespace Service::HID | 37 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/xpad.h b/src/core/hle/service/hid/controllers/xpad.h index f9ab5facf..a5421f93b 100644 --- a/src/core/hle/service/hid/controllers/xpad.h +++ b/src/core/hle/service/hid/controllers/xpad.h | |||
| @@ -8,7 +8,9 @@ | |||
| 8 | #include "common/common_funcs.h" | 8 | #include "common/common_funcs.h" |
| 9 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 10 | #include "common/swap.h" | 10 | #include "common/swap.h" |
| 11 | #include "core/hid/hid_types.h" | ||
| 11 | #include "core/hle/service/hid/controllers/controller_base.h" | 12 | #include "core/hle/service/hid/controllers/controller_base.h" |
| 13 | #include "core/hle/service/hid/ring_lifo.h" | ||
| 12 | 14 | ||
| 13 | namespace Service::HID { | 15 | namespace Service::HID { |
| 14 | class Controller_XPad final : public ControllerBase { | 16 | class Controller_XPad final : public ControllerBase { |
| @@ -25,11 +27,9 @@ public: | |||
| 25 | // When the controller is requesting an update for the shared memory | 27 | // When the controller is requesting an update for the shared memory |
| 26 | void OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, std::size_t size) override; | 28 | void OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, std::size_t size) override; |
| 27 | 29 | ||
| 28 | // Called when input devices should be loaded | ||
| 29 | void OnLoadInputDevices() override; | ||
| 30 | |||
| 31 | private: | 30 | private: |
| 32 | struct Attributes { | 31 | // This is nn::hid::BasicXpadAttributeSet |
| 32 | struct BasicXpadAttributeSet { | ||
| 33 | union { | 33 | union { |
| 34 | u32_le raw{}; | 34 | u32_le raw{}; |
| 35 | BitField<0, 1, u32> is_connected; | 35 | BitField<0, 1, u32> is_connected; |
| @@ -40,9 +40,10 @@ private: | |||
| 40 | BitField<5, 1, u32> is_right_wired; | 40 | BitField<5, 1, u32> is_right_wired; |
| 41 | }; | 41 | }; |
| 42 | }; | 42 | }; |
| 43 | static_assert(sizeof(Attributes) == 4, "Attributes is an invalid size"); | 43 | static_assert(sizeof(BasicXpadAttributeSet) == 4, "BasicXpadAttributeSet is an invalid size"); |
| 44 | 44 | ||
| 45 | struct Buttons { | 45 | // This is nn::hid::BasicXpadButtonSet |
| 46 | struct BasicXpadButtonSet { | ||
| 46 | union { | 47 | union { |
| 47 | u32_le raw{}; | 48 | u32_le raw{}; |
| 48 | // Button states | 49 | // Button states |
| @@ -88,35 +89,21 @@ private: | |||
| 88 | BitField<30, 1, u32> handheld_left_b; | 89 | BitField<30, 1, u32> handheld_left_b; |
| 89 | }; | 90 | }; |
| 90 | }; | 91 | }; |
| 91 | static_assert(sizeof(Buttons) == 4, "Buttons is an invalid size"); | 92 | static_assert(sizeof(BasicXpadButtonSet) == 4, "BasicXpadButtonSet is an invalid size"); |
| 92 | |||
| 93 | struct AnalogStick { | ||
| 94 | s32_le x; | ||
| 95 | s32_le y; | ||
| 96 | }; | ||
| 97 | static_assert(sizeof(AnalogStick) == 0x8, "AnalogStick is an invalid size"); | ||
| 98 | 93 | ||
| 99 | struct XPadState { | 94 | // This is nn::hid::detail::BasicXpadState |
| 95 | struct BasicXpadState { | ||
| 100 | s64_le sampling_number; | 96 | s64_le sampling_number; |
| 101 | s64_le sampling_number2; | 97 | BasicXpadAttributeSet attributes; |
| 102 | Attributes attributes; | 98 | BasicXpadButtonSet pad_states; |
| 103 | Buttons pad_states; | 99 | Core::HID::AnalogStickState l_stick; |
| 104 | AnalogStick l_stick; | 100 | Core::HID::AnalogStickState r_stick; |
| 105 | AnalogStick r_stick; | ||
| 106 | }; | 101 | }; |
| 107 | static_assert(sizeof(XPadState) == 0x28, "XPadState is an invalid size"); | 102 | static_assert(sizeof(BasicXpadState) == 0x20, "BasicXpadState is an invalid size"); |
| 108 | 103 | ||
| 109 | struct XPadEntry { | 104 | // This is nn::hid::detail::BasicXpadLifo |
| 110 | CommonHeader header; | 105 | Lifo<BasicXpadState> basic_xpad_lifo{}; |
| 111 | std::array<XPadState, 17> pad_states{}; | 106 | static_assert(sizeof(basic_xpad_lifo) == 0x2C8, "basic_xpad_lifo is an invalid size"); |
| 112 | INSERT_PADDING_BYTES(0x138); | 107 | BasicXpadState next_state{}; |
| 113 | }; | ||
| 114 | static_assert(sizeof(XPadEntry) == 0x400, "XPadEntry is an invalid size"); | ||
| 115 | |||
| 116 | struct SharedMemory { | ||
| 117 | std::array<XPadEntry, 4> shared_memory_entries{}; | ||
| 118 | }; | ||
| 119 | static_assert(sizeof(SharedMemory) == 0x1000, "SharedMemory is an invalid size"); | ||
| 120 | SharedMemory shared_memory{}; | ||
| 121 | }; | 108 | }; |
| 122 | } // namespace Service::HID | 109 | } // namespace Service::HID |