diff options
Diffstat (limited to 'src')
19 files changed, 238 insertions, 167 deletions
diff --git a/src/core/hle/service/hid/controllers/controller_base.cpp b/src/core/hle/service/hid/controllers/controller_base.cpp index f2aef5642..1625e9c3d 100644 --- a/src/core/hle/service/hid/controllers/controller_base.cpp +++ b/src/core/hle/service/hid/controllers/controller_base.cpp | |||
| @@ -5,6 +5,8 @@ | |||
| 5 | #include "core/hle/service/hid/controllers/controller_base.h" | 5 | #include "core/hle/service/hid/controllers/controller_base.h" |
| 6 | 6 | ||
| 7 | namespace Service::HID { | 7 | namespace Service::HID { |
| 8 | ControllerBase::~ControllerBase() = default; | ||
| 9 | |||
| 8 | void ControllerBase::ActivateController() { | 10 | void ControllerBase::ActivateController() { |
| 9 | if (is_activated) { | 11 | if (is_activated) { |
| 10 | OnRelease(); | 12 | OnRelease(); |
| @@ -23,5 +25,4 @@ void ControllerBase::DeactivateController() { | |||
| 23 | bool ControllerBase::IsControllerActivated() const { | 25 | bool ControllerBase::IsControllerActivated() const { |
| 24 | return is_activated; | 26 | return is_activated; |
| 25 | } | 27 | } |
| 26 | // ControllerBase::~ControllerBase() = default; | 28 | } // namespace Service::HID |
| 27 | }; // 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 3b1c8aad6..fa98e2354 100644 --- a/src/core/hle/service/hid/controllers/controller_base.h +++ b/src/core/hle/service/hid/controllers/controller_base.h | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | |||
| 6 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 7 | #include "common/swap.h" | 8 | #include "common/swap.h" |
| 8 | 9 | ||
| @@ -10,6 +11,7 @@ namespace Service::HID { | |||
| 10 | class ControllerBase { | 11 | class ControllerBase { |
| 11 | public: | 12 | public: |
| 12 | ControllerBase() = default; | 13 | ControllerBase() = default; |
| 14 | virtual ~ControllerBase() = 0; | ||
| 13 | 15 | ||
| 14 | // Called when the controller is initialized | 16 | // Called when the controller is initialized |
| 15 | virtual void OnInit() = 0; | 17 | virtual void OnInit() = 0; |
| @@ -18,7 +20,7 @@ public: | |||
| 18 | virtual void OnRelease() = 0; | 20 | virtual void OnRelease() = 0; |
| 19 | 21 | ||
| 20 | // When the controller is requesting an update for the shared memory | 22 | // When the controller is requesting an update for the shared memory |
| 21 | virtual void OnUpdate(u8* data, size_t size) = 0; | 23 | virtual void OnUpdate(u8* data, std::size_t size) = 0; |
| 22 | 24 | ||
| 23 | // Called when input devices should be loaded | 25 | // Called when input devices should be loaded |
| 24 | virtual void OnLoadInputDevices() = 0; | 26 | virtual void OnLoadInputDevices() = 0; |
| @@ -40,4 +42,4 @@ protected: | |||
| 40 | }; | 42 | }; |
| 41 | static_assert(sizeof(CommonHeader) == 0x20, "CommonHeader is an invalid size"); | 43 | static_assert(sizeof(CommonHeader) == 0x20, "CommonHeader is an invalid size"); |
| 42 | }; | 44 | }; |
| 43 | }; // namespace Service::HID | 45 | } // 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 04799b233..6f8ef6e3f 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.cpp +++ b/src/core/hle/service/hid/controllers/debug_pad.cpp | |||
| @@ -2,15 +2,21 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <cstring> | ||
| 5 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 6 | #include "common/swap.h" | 7 | #include "common/swap.h" |
| 7 | #include "core/core_timing.h" | 8 | #include "core/core_timing.h" |
| 8 | #include "core/hle/service/hid/controllers/debug_pad.h" | 9 | #include "core/hle/service/hid/controllers/debug_pad.h" |
| 9 | 10 | ||
| 10 | namespace Service::HID { | 11 | namespace Service::HID { |
| 12 | |||
| 13 | Controller_DebugPad::Controller_DebugPad() = default; | ||
| 14 | |||
| 11 | void Controller_DebugPad::OnInit() {} | 15 | void Controller_DebugPad::OnInit() {} |
| 16 | |||
| 12 | void Controller_DebugPad::OnRelease() {} | 17 | void Controller_DebugPad::OnRelease() {} |
| 13 | void Controller_DebugPad::OnUpdate(u8* data, size_t size) { | 18 | |
| 19 | void Controller_DebugPad::OnUpdate(u8* data, std::size_t size) { | ||
| 14 | shared_memory.header.timestamp = CoreTiming::GetTicks(); | 20 | shared_memory.header.timestamp = CoreTiming::GetTicks(); |
| 15 | shared_memory.header.total_entry_count = 17; | 21 | shared_memory.header.total_entry_count = 17; |
| 16 | 22 | ||
| @@ -21,7 +27,7 @@ void Controller_DebugPad::OnUpdate(u8* data, size_t size) { | |||
| 21 | } | 27 | } |
| 22 | shared_memory.header.entry_count = 16; | 28 | shared_memory.header.entry_count = 16; |
| 23 | 29 | ||
| 24 | auto& last_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; | 30 | const auto& last_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; |
| 25 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; | 31 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; |
| 26 | auto& cur_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; | 32 | auto& cur_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; |
| 27 | 33 | ||
| @@ -31,5 +37,6 @@ void Controller_DebugPad::OnUpdate(u8* data, size_t size) { | |||
| 31 | 37 | ||
| 32 | std::memcpy(data, &shared_memory, sizeof(SharedMemory)); | 38 | std::memcpy(data, &shared_memory, sizeof(SharedMemory)); |
| 33 | } | 39 | } |
| 40 | |||
| 34 | void Controller_DebugPad::OnLoadInputDevices() {} | 41 | void Controller_DebugPad::OnLoadInputDevices() {} |
| 35 | }; // namespace Service::HID | 42 | } // 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 fc6f99a0b..e35675fa1 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.h +++ b/src/core/hle/service/hid/controllers/debug_pad.h | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | |||
| 6 | #include <array> | 7 | #include <array> |
| 7 | #include "common/common_funcs.h" | 8 | #include "common/common_funcs.h" |
| 8 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| @@ -12,7 +13,7 @@ | |||
| 12 | namespace Service::HID { | 13 | namespace Service::HID { |
| 13 | class Controller_DebugPad final : public ControllerBase { | 14 | class Controller_DebugPad final : public ControllerBase { |
| 14 | public: | 15 | public: |
| 15 | Controller_DebugPad() = default; | 16 | Controller_DebugPad(); |
| 16 | 17 | ||
| 17 | // Called when the controller is initialized | 18 | // Called when the controller is initialized |
| 18 | void OnInit() override; | 19 | void OnInit() override; |
| @@ -21,7 +22,7 @@ public: | |||
| 21 | void OnRelease() override; | 22 | void OnRelease() override; |
| 22 | 23 | ||
| 23 | // When the controller is requesting an update for the shared memory | 24 | // When the controller is requesting an update for the shared memory |
| 24 | void OnUpdate(u8* data, size_t size) override; | 25 | void OnUpdate(u8* data, std::size_t size) override; |
| 25 | 26 | ||
| 26 | // Called when input devices should be loaded | 27 | // Called when input devices should be loaded |
| 27 | void OnLoadInputDevices() override; | 28 | void OnLoadInputDevices() override; |
| @@ -51,4 +52,4 @@ private: | |||
| 51 | static_assert(sizeof(SharedMemory) == 0x400, "SharedMemory is an invalid size"); | 52 | static_assert(sizeof(SharedMemory) == 0x400, "SharedMemory is an invalid size"); |
| 52 | SharedMemory shared_memory{}; | 53 | SharedMemory shared_memory{}; |
| 53 | }; | 54 | }; |
| 54 | }; // namespace Service::HID | 55 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/gesture.cpp b/src/core/hle/service/hid/controllers/gesture.cpp index 851ea66f3..b473b9e2b 100644 --- a/src/core/hle/service/hid/controllers/gesture.cpp +++ b/src/core/hle/service/hid/controllers/gesture.cpp | |||
| @@ -2,16 +2,22 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <cstring> | ||
| 5 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 6 | #include "common/swap.h" | 7 | #include "common/swap.h" |
| 7 | #include "core/core_timing.h" | 8 | #include "core/core_timing.h" |
| 8 | #include "core/hle/service/hid/controllers/gesture.h" | 9 | #include "core/hle/service/hid/controllers/gesture.h" |
| 9 | 10 | ||
| 10 | namespace Service::HID { | 11 | namespace Service::HID { |
| 11 | constexpr size_t SHARED_MEMORY_OFFSET = 0x3BA00; | 12 | constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3BA00; |
| 13 | |||
| 14 | Controller_Gesture::Controller_Gesture() = default; | ||
| 15 | |||
| 12 | void Controller_Gesture::OnInit() {} | 16 | void Controller_Gesture::OnInit() {} |
| 17 | |||
| 13 | void Controller_Gesture::OnRelease() {} | 18 | void Controller_Gesture::OnRelease() {} |
| 14 | void Controller_Gesture::OnUpdate(u8* data, size_t size) { | 19 | |
| 20 | void Controller_Gesture::OnUpdate(u8* data, std::size_t size) { | ||
| 15 | shared_memory.header.timestamp = CoreTiming::GetTicks(); | 21 | shared_memory.header.timestamp = CoreTiming::GetTicks(); |
| 16 | shared_memory.header.total_entry_count = 17; | 22 | shared_memory.header.total_entry_count = 17; |
| 17 | 23 | ||
| @@ -22,7 +28,7 @@ void Controller_Gesture::OnUpdate(u8* data, size_t size) { | |||
| 22 | } | 28 | } |
| 23 | shared_memory.header.entry_count = 16; | 29 | shared_memory.header.entry_count = 16; |
| 24 | 30 | ||
| 25 | auto& last_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; | 31 | const auto& last_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; |
| 26 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; | 32 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; |
| 27 | auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; | 33 | auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; |
| 28 | 34 | ||
| @@ -32,5 +38,6 @@ void Controller_Gesture::OnUpdate(u8* data, size_t size) { | |||
| 32 | 38 | ||
| 33 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory)); | 39 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory)); |
| 34 | } | 40 | } |
| 41 | |||
| 35 | void Controller_Gesture::OnLoadInputDevices() {} | 42 | void Controller_Gesture::OnLoadInputDevices() {} |
| 36 | }; // namespace Service::HID | 43 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/gesture.h b/src/core/hle/service/hid/controllers/gesture.h index f46819829..0ced50dfd 100644 --- a/src/core/hle/service/hid/controllers/gesture.h +++ b/src/core/hle/service/hid/controllers/gesture.h | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | |||
| 6 | #include <array> | 7 | #include <array> |
| 7 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 8 | #include "common/swap.h" | 9 | #include "common/swap.h" |
| @@ -11,7 +12,7 @@ | |||
| 11 | namespace Service::HID { | 12 | namespace Service::HID { |
| 12 | class Controller_Gesture final : public ControllerBase { | 13 | class Controller_Gesture final : public ControllerBase { |
| 13 | public: | 14 | public: |
| 14 | Controller_Gesture() = default; | 15 | Controller_Gesture(); |
| 15 | 16 | ||
| 16 | // Called when the controller is initialized | 17 | // Called when the controller is initialized |
| 17 | void OnInit() override; | 18 | void OnInit() override; |
| @@ -48,7 +49,7 @@ private: | |||
| 48 | f32 scale; | 49 | f32 scale; |
| 49 | f32 rotation; | 50 | f32 rotation; |
| 50 | s32_le location_count; | 51 | s32_le location_count; |
| 51 | std::array<Locations, 4> locations{}; | 52 | std::array<Locations, 4> locations; |
| 52 | }; | 53 | }; |
| 53 | static_assert(sizeof(GestureState) == 0x68, "GestureState is an invalid size"); | 54 | static_assert(sizeof(GestureState) == 0x68, "GestureState is an invalid size"); |
| 54 | 55 | ||
| @@ -58,4 +59,4 @@ private: | |||
| 58 | }; | 59 | }; |
| 59 | SharedMemory shared_memory{}; | 60 | SharedMemory shared_memory{}; |
| 60 | }; | 61 | }; |
| 61 | }; // namespace Service::HID | 62 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/keyboard.cpp b/src/core/hle/service/hid/controllers/keyboard.cpp index 27c39ad08..089c02ac4 100644 --- a/src/core/hle/service/hid/controllers/keyboard.cpp +++ b/src/core/hle/service/hid/controllers/keyboard.cpp | |||
| @@ -2,16 +2,22 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <cstring> | ||
| 5 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 6 | #include "common/swap.h" | 7 | #include "common/swap.h" |
| 7 | #include "core/core_timing.h" | 8 | #include "core/core_timing.h" |
| 8 | #include "core/hle/service/hid/controllers/keyboard.h" | 9 | #include "core/hle/service/hid/controllers/keyboard.h" |
| 9 | 10 | ||
| 10 | namespace Service::HID { | 11 | namespace Service::HID { |
| 11 | constexpr size_t SHARED_MEMORY_OFFSET = 0x3800; | 12 | constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3800; |
| 13 | |||
| 14 | Controller_Keyboard::Controller_Keyboard() = default; | ||
| 15 | |||
| 12 | void Controller_Keyboard::OnInit() {} | 16 | void Controller_Keyboard::OnInit() {} |
| 17 | |||
| 13 | void Controller_Keyboard::OnRelease() {} | 18 | void Controller_Keyboard::OnRelease() {} |
| 14 | void Controller_Keyboard::OnUpdate(u8* data, size_t size) { | 19 | |
| 20 | void Controller_Keyboard::OnUpdate(u8* data, std::size_t size) { | ||
| 15 | shared_memory.header.timestamp = CoreTiming::GetTicks(); | 21 | shared_memory.header.timestamp = CoreTiming::GetTicks(); |
| 16 | shared_memory.header.total_entry_count = 17; | 22 | shared_memory.header.total_entry_count = 17; |
| 17 | 23 | ||
| @@ -22,7 +28,7 @@ void Controller_Keyboard::OnUpdate(u8* data, size_t size) { | |||
| 22 | } | 28 | } |
| 23 | shared_memory.header.entry_count = 16; | 29 | shared_memory.header.entry_count = 16; |
| 24 | 30 | ||
| 25 | auto& last_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; | 31 | const auto& last_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; |
| 26 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; | 32 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; |
| 27 | auto& cur_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; | 33 | auto& cur_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; |
| 28 | 34 | ||
| @@ -32,5 +38,6 @@ void Controller_Keyboard::OnUpdate(u8* data, size_t size) { | |||
| 32 | 38 | ||
| 33 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory)); | 39 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory)); |
| 34 | } | 40 | } |
| 41 | |||
| 35 | void Controller_Keyboard::OnLoadInputDevices() {} | 42 | void Controller_Keyboard::OnLoadInputDevices() {} |
| 36 | }; // namespace Service::HID | 43 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/keyboard.h b/src/core/hle/service/hid/controllers/keyboard.h index 0463e1619..778e14f7e 100644 --- a/src/core/hle/service/hid/controllers/keyboard.h +++ b/src/core/hle/service/hid/controllers/keyboard.h | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | |||
| 6 | #include <array> | 7 | #include <array> |
| 7 | #include "common/common_funcs.h" | 8 | #include "common/common_funcs.h" |
| 8 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| @@ -12,7 +13,7 @@ | |||
| 12 | namespace Service::HID { | 13 | namespace Service::HID { |
| 13 | class Controller_Keyboard final : public ControllerBase { | 14 | class Controller_Keyboard final : public ControllerBase { |
| 14 | public: | 15 | public: |
| 15 | Controller_Keyboard() = default; | 16 | Controller_Keyboard(); |
| 16 | 17 | ||
| 17 | // Called when the controller is initialized | 18 | // Called when the controller is initialized |
| 18 | void OnInit() override; | 19 | void OnInit() override; |
| @@ -21,7 +22,7 @@ public: | |||
| 21 | void OnRelease() override; | 22 | void OnRelease() override; |
| 22 | 23 | ||
| 23 | // When the controller is requesting an update for the shared memory | 24 | // When the controller is requesting an update for the shared memory |
| 24 | void OnUpdate(u8* data, size_t size) override; | 25 | void OnUpdate(u8* data, std::size_t size) override; |
| 25 | 26 | ||
| 26 | // Called when input devices should be loaded | 27 | // Called when input devices should be loaded |
| 27 | void OnLoadInputDevices() override; | 28 | void OnLoadInputDevices() override; |
| @@ -33,7 +34,7 @@ private: | |||
| 33 | 34 | ||
| 34 | s32_le modifier; | 35 | s32_le modifier; |
| 35 | s32_le attribute; | 36 | s32_le attribute; |
| 36 | std::array<u8, 32> key{}; | 37 | std::array<u8, 32> key; |
| 37 | }; | 38 | }; |
| 38 | static_assert(sizeof(KeyboardState) == 0x38, "KeyboardState is an invalid size"); | 39 | static_assert(sizeof(KeyboardState) == 0x38, "KeyboardState is an invalid size"); |
| 39 | 40 | ||
| @@ -45,4 +46,4 @@ private: | |||
| 45 | static_assert(sizeof(SharedMemory) == 0x400, "SharedMemory is an invalid size"); | 46 | static_assert(sizeof(SharedMemory) == 0x400, "SharedMemory is an invalid size"); |
| 46 | SharedMemory shared_memory{}; | 47 | SharedMemory shared_memory{}; |
| 47 | }; | 48 | }; |
| 48 | }; // namespace Service::HID | 49 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/mouse.cpp b/src/core/hle/service/hid/controllers/mouse.cpp index df30239e2..78e9b5e9e 100644 --- a/src/core/hle/service/hid/controllers/mouse.cpp +++ b/src/core/hle/service/hid/controllers/mouse.cpp | |||
| @@ -2,16 +2,22 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <cstring> | ||
| 5 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 6 | #include "common/swap.h" | 7 | #include "common/swap.h" |
| 7 | #include "core/core_timing.h" | 8 | #include "core/core_timing.h" |
| 8 | #include "core/hle/service/hid/controllers/mouse.h" | 9 | #include "core/hle/service/hid/controllers/mouse.h" |
| 9 | 10 | ||
| 10 | namespace Service::HID { | 11 | namespace Service::HID { |
| 11 | constexpr size_t SHARED_MEMORY_OFFSET = 0x3400; | 12 | constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3400; |
| 13 | |||
| 14 | Controller_Mouse::Controller_Mouse() = default; | ||
| 15 | |||
| 12 | void Controller_Mouse::OnInit() {} | 16 | void Controller_Mouse::OnInit() {} |
| 17 | |||
| 13 | void Controller_Mouse::OnRelease() {} | 18 | void Controller_Mouse::OnRelease() {} |
| 14 | void Controller_Mouse::OnUpdate(u8* data, size_t size) { | 19 | |
| 20 | void Controller_Mouse::OnUpdate(u8* data, std::size_t size) { | ||
| 15 | shared_memory.header.timestamp = CoreTiming::GetTicks(); | 21 | shared_memory.header.timestamp = CoreTiming::GetTicks(); |
| 16 | shared_memory.header.total_entry_count = 17; | 22 | shared_memory.header.total_entry_count = 17; |
| 17 | 23 | ||
| @@ -32,5 +38,6 @@ void Controller_Mouse::OnUpdate(u8* data, size_t size) { | |||
| 32 | 38 | ||
| 33 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory)); | 39 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory)); |
| 34 | } | 40 | } |
| 41 | |||
| 35 | void Controller_Mouse::OnLoadInputDevices() {} | 42 | void Controller_Mouse::OnLoadInputDevices() {} |
| 36 | }; // namespace Service::HID | 43 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/mouse.h b/src/core/hle/service/hid/controllers/mouse.h index 0d7fd372d..05358a4f5 100644 --- a/src/core/hle/service/hid/controllers/mouse.h +++ b/src/core/hle/service/hid/controllers/mouse.h | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | |||
| 6 | #include <array> | 7 | #include <array> |
| 7 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 8 | #include "common/swap.h" | 9 | #include "common/swap.h" |
| @@ -11,7 +12,7 @@ | |||
| 11 | namespace Service::HID { | 12 | namespace Service::HID { |
| 12 | class Controller_Mouse final : public ControllerBase { | 13 | class Controller_Mouse final : public ControllerBase { |
| 13 | public: | 14 | public: |
| 14 | Controller_Mouse() = default; | 15 | Controller_Mouse(); |
| 15 | 16 | ||
| 16 | // Called when the controller is initialized | 17 | // Called when the controller is initialized |
| 17 | void OnInit() override; | 18 | void OnInit() override; |
| @@ -20,7 +21,7 @@ public: | |||
| 20 | void OnRelease() override; | 21 | void OnRelease() override; |
| 21 | 22 | ||
| 22 | // When the controller is requesting an update for the shared memory | 23 | // When the controller is requesting an update for the shared memory |
| 23 | void OnUpdate(u8* data, size_t size) override; | 24 | void OnUpdate(u8* data, std::size_t size) override; |
| 24 | 25 | ||
| 25 | // Called when input devices should be loaded | 26 | // Called when input devices should be loaded |
| 26 | void OnLoadInputDevices() override; | 27 | void OnLoadInputDevices() override; |
| @@ -45,4 +46,4 @@ private: | |||
| 45 | }; | 46 | }; |
| 46 | SharedMemory shared_memory{}; | 47 | SharedMemory shared_memory{}; |
| 47 | }; | 48 | }; |
| 48 | }; // namespace Service::HID | 49 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index a53687b91..8a713a407 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp | |||
| @@ -3,10 +3,14 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | |||
| 7 | #include <algorithm> | ||
| 6 | #include <array> | 8 | #include <array> |
| 9 | #include <cstring> | ||
| 7 | #include "common/assert.h" | 10 | #include "common/assert.h" |
| 8 | #include "common/bit_field.h" | 11 | #include "common/bit_field.h" |
| 9 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 13 | #include "common/logging/log.h" | ||
| 10 | #include "common/swap.h" | 14 | #include "common/swap.h" |
| 11 | #include "core/core.h" | 15 | #include "core/core.h" |
| 12 | #include "core/core_timing.h" | 16 | #include "core/core_timing.h" |
| @@ -22,15 +26,13 @@ constexpr u32 JOYCON_BODY_NEON_BLUE = 0x0AB9E6; | |||
| 22 | constexpr u32 JOYCON_BUTTONS_NEON_BLUE = 0x001E1E; | 26 | constexpr u32 JOYCON_BUTTONS_NEON_BLUE = 0x001E1E; |
| 23 | constexpr s32 HID_JOYSTICK_MAX = 0x7fff; | 27 | constexpr s32 HID_JOYSTICK_MAX = 0x7fff; |
| 24 | constexpr s32 HID_JOYSTICK_MIN = -0x7fff; | 28 | constexpr s32 HID_JOYSTICK_MIN = -0x7fff; |
| 25 | constexpr size_t NPAD_OFFSET = 0x9A00; | 29 | constexpr std::size_t NPAD_OFFSET = 0x9A00; |
| 26 | constexpr size_t MAX_CONTROLLER_COUNT = 9; | 30 | |
| 31 | enum class JoystickId : std::size_t { Joystick_Left, Joystick_Right }; | ||
| 27 | 32 | ||
| 28 | enum class JoystickId : size_t { Joystick_Left, Joystick_Right }; | 33 | Controller_NPad::Controller_NPad() = default; |
| 29 | constexpr std::array<u32, MAX_CONTROLLER_COUNT> NPAD_ID_LIST{0, 1, 2, 3, 4, 5, 6, 7, 32}; | ||
| 30 | size_t CONTROLLER_COUNT{}; | ||
| 31 | std::array<Controller_NPad::NPadControllerType, MAX_CONTROLLER_COUNT> CONNECTED_CONTROLLERS{}; | ||
| 32 | 34 | ||
| 33 | void Controller_NPad::InitNewlyAddedControler(size_t controller_idx) { | 35 | void Controller_NPad::InitNewlyAddedControler(std::size_t controller_idx) { |
| 34 | const auto controller_type = CONNECTED_CONTROLLERS[controller_idx]; | 36 | const auto controller_type = CONNECTED_CONTROLLERS[controller_idx]; |
| 35 | auto& controller = shared_memory_entries[controller_idx]; | 37 | auto& controller = shared_memory_entries[controller_idx]; |
| 36 | if (controller_type == NPadControllerType::None) { | 38 | if (controller_type == NPadControllerType::None) { |
| @@ -79,7 +81,7 @@ void Controller_NPad::InitNewlyAddedControler(size_t controller_idx) { | |||
| 79 | controller.right_color.body_color = JOYCON_BODY_NEON_RED; | 81 | controller.right_color.body_color = JOYCON_BODY_NEON_RED; |
| 80 | controller.right_color.button_color = JOYCON_BUTTONS_NEON_RED; | 82 | controller.right_color.button_color = JOYCON_BUTTONS_NEON_RED; |
| 81 | 83 | ||
| 82 | controller.properties.is_verticle.Assign(1); // TODO(ogniK): Swap joycons orientations | 84 | controller.properties.is_vertical.Assign(1); // TODO(ogniK): Swap joycons orientations |
| 83 | } | 85 | } |
| 84 | 86 | ||
| 85 | void Controller_NPad::OnInit() { | 87 | void Controller_NPad::OnInit() { |
| @@ -89,7 +91,7 @@ void Controller_NPad::OnInit() { | |||
| 89 | 91 | ||
| 90 | if (!IsControllerActivated()) | 92 | if (!IsControllerActivated()) |
| 91 | return; | 93 | return; |
| 92 | size_t controller{}; | 94 | std::size_t controller{}; |
| 93 | supported_npad_id_types.resize(NPAD_ID_LIST.size()); | 95 | supported_npad_id_types.resize(NPAD_ID_LIST.size()); |
| 94 | if (style.raw == 0) { | 96 | if (style.raw == 0) { |
| 95 | // We want to support all controllers | 97 | // We want to support all controllers |
| @@ -118,10 +120,10 @@ void Controller_NPad::OnLoadInputDevices() { | |||
| 118 | 120 | ||
| 119 | void Controller_NPad::OnRelease() {} | 121 | void Controller_NPad::OnRelease() {} |
| 120 | 122 | ||
| 121 | void Controller_NPad::OnUpdate(u8* data, size_t data_len) { | 123 | void Controller_NPad::OnUpdate(u8* data, std::size_t data_len) { |
| 122 | if (!IsControllerActivated()) | 124 | if (!IsControllerActivated()) |
| 123 | return; | 125 | return; |
| 124 | for (size_t i = 0; i < shared_memory_entries.size(); i++) { | 126 | for (std::size_t i = 0; i < shared_memory_entries.size(); i++) { |
| 125 | auto& npad = shared_memory_entries[i]; | 127 | auto& npad = shared_memory_entries[i]; |
| 126 | const std::array<NPadGeneric*, 7> controller_npads{&npad.main_controller_states, | 128 | const std::array<NPadGeneric*, 7> controller_npads{&npad.main_controller_states, |
| 127 | &npad.handheld_states, | 129 | &npad.handheld_states, |
| @@ -131,11 +133,12 @@ void Controller_NPad::OnUpdate(u8* data, size_t data_len) { | |||
| 131 | &npad.pokeball_states, | 133 | &npad.pokeball_states, |
| 132 | &npad.libnx}; | 134 | &npad.libnx}; |
| 133 | 135 | ||
| 134 | for (auto main_controller : controller_npads) { | 136 | for (auto* main_controller : controller_npads) { |
| 135 | main_controller->common.entry_count = 16; | 137 | main_controller->common.entry_count = 16; |
| 136 | main_controller->common.total_entry_count = 17; | 138 | main_controller->common.total_entry_count = 17; |
| 137 | 139 | ||
| 138 | auto& last_entry = main_controller->npad[main_controller->common.last_entry_index]; | 140 | const auto& last_entry = |
| 141 | main_controller->npad[main_controller->common.last_entry_index]; | ||
| 139 | 142 | ||
| 140 | main_controller->common.timestamp = CoreTiming::GetTicks(); | 143 | main_controller->common.timestamp = CoreTiming::GetTicks(); |
| 141 | main_controller->common.last_entry_index = | 144 | main_controller->common.last_entry_index = |
| @@ -154,7 +157,7 @@ void Controller_NPad::OnUpdate(u8* data, size_t data_len) { | |||
| 154 | const auto& controller_type = CONNECTED_CONTROLLERS[i]; | 157 | const auto& controller_type = CONNECTED_CONTROLLERS[i]; |
| 155 | 158 | ||
| 156 | // Pad states | 159 | // Pad states |
| 157 | auto pad_state = ControllerPadState{}; | 160 | ControllerPadState pad_state{}; |
| 158 | using namespace Settings::NativeButton; | 161 | using namespace Settings::NativeButton; |
| 159 | pad_state.a.Assign(buttons[A - BUTTON_HID_BEGIN]->GetStatus()); | 162 | pad_state.a.Assign(buttons[A - BUTTON_HID_BEGIN]->GetStatus()); |
| 160 | pad_state.b.Assign(buttons[B - BUTTON_HID_BEGIN]->GetStatus()); | 163 | pad_state.b.Assign(buttons[B - BUTTON_HID_BEGIN]->GetStatus()); |
| @@ -169,20 +172,20 @@ void Controller_NPad::OnUpdate(u8* data, size_t data_len) { | |||
| 169 | pad_state.plus.Assign(buttons[Plus - BUTTON_HID_BEGIN]->GetStatus()); | 172 | pad_state.plus.Assign(buttons[Plus - BUTTON_HID_BEGIN]->GetStatus()); |
| 170 | pad_state.minus.Assign(buttons[Minus - BUTTON_HID_BEGIN]->GetStatus()); | 173 | pad_state.minus.Assign(buttons[Minus - BUTTON_HID_BEGIN]->GetStatus()); |
| 171 | 174 | ||
| 172 | pad_state.dleft.Assign(buttons[DLeft - BUTTON_HID_BEGIN]->GetStatus()); | 175 | pad_state.d_left.Assign(buttons[DLeft - BUTTON_HID_BEGIN]->GetStatus()); |
| 173 | pad_state.dup.Assign(buttons[DUp - BUTTON_HID_BEGIN]->GetStatus()); | 176 | pad_state.d_up.Assign(buttons[DUp - BUTTON_HID_BEGIN]->GetStatus()); |
| 174 | pad_state.dright.Assign(buttons[DRight - BUTTON_HID_BEGIN]->GetStatus()); | 177 | pad_state.d_right.Assign(buttons[DRight - BUTTON_HID_BEGIN]->GetStatus()); |
| 175 | pad_state.ddown.Assign(buttons[DDown - BUTTON_HID_BEGIN]->GetStatus()); | 178 | pad_state.d_down.Assign(buttons[DDown - BUTTON_HID_BEGIN]->GetStatus()); |
| 176 | 179 | ||
| 177 | pad_state.lstickleft.Assign(buttons[LStick_Left - BUTTON_HID_BEGIN]->GetStatus()); | 180 | pad_state.l_stick_left.Assign(buttons[LStick_Left - BUTTON_HID_BEGIN]->GetStatus()); |
| 178 | pad_state.lstickup.Assign(buttons[LStick_Up - BUTTON_HID_BEGIN]->GetStatus()); | 181 | pad_state.l_stick_up.Assign(buttons[LStick_Up - BUTTON_HID_BEGIN]->GetStatus()); |
| 179 | pad_state.lstickright.Assign(buttons[LStick_Right - BUTTON_HID_BEGIN]->GetStatus()); | 182 | pad_state.l_stick_right.Assign(buttons[LStick_Right - BUTTON_HID_BEGIN]->GetStatus()); |
| 180 | pad_state.lstickdown.Assign(buttons[LStick_Down - BUTTON_HID_BEGIN]->GetStatus()); | 183 | pad_state.l_stick_down.Assign(buttons[LStick_Down - BUTTON_HID_BEGIN]->GetStatus()); |
| 181 | 184 | ||
| 182 | pad_state.rstickleft.Assign(buttons[RStick_Left - BUTTON_HID_BEGIN]->GetStatus()); | 185 | pad_state.r_stick_left.Assign(buttons[RStick_Left - BUTTON_HID_BEGIN]->GetStatus()); |
| 183 | pad_state.rstickup.Assign(buttons[RStick_Up - BUTTON_HID_BEGIN]->GetStatus()); | 186 | pad_state.r_stick_up.Assign(buttons[RStick_Up - BUTTON_HID_BEGIN]->GetStatus()); |
| 184 | pad_state.rstickright.Assign(buttons[RStick_Right - BUTTON_HID_BEGIN]->GetStatus()); | 187 | pad_state.r_stick_right.Assign(buttons[RStick_Right - BUTTON_HID_BEGIN]->GetStatus()); |
| 185 | pad_state.rstickdown.Assign(buttons[RStick_Down - BUTTON_HID_BEGIN]->GetStatus()); | 188 | pad_state.r_stick_down.Assign(buttons[RStick_Down - BUTTON_HID_BEGIN]->GetStatus()); |
| 186 | 189 | ||
| 187 | pad_state.sl.Assign(buttons[SL - BUTTON_HID_BEGIN]->GetStatus()); | 190 | pad_state.sl.Assign(buttons[SL - BUTTON_HID_BEGIN]->GetStatus()); |
| 188 | pad_state.sr.Assign(buttons[SR - BUTTON_HID_BEGIN]->GetStatus()); | 191 | pad_state.sr.Assign(buttons[SR - BUTTON_HID_BEGIN]->GetStatus()); |
| @@ -191,9 +194,9 @@ void Controller_NPad::OnUpdate(u8* data, size_t data_len) { | |||
| 191 | AnalogPosition rstick_entry{}; | 194 | AnalogPosition rstick_entry{}; |
| 192 | 195 | ||
| 193 | const auto [stick_l_x_f, stick_l_y_f] = | 196 | const auto [stick_l_x_f, stick_l_y_f] = |
| 194 | sticks[static_cast<size_t>(JoystickId::Joystick_Left)]->GetStatus(); | 197 | sticks[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetStatus(); |
| 195 | const auto [stick_r_x_f, stick_r_y_f] = | 198 | const auto [stick_r_x_f, stick_r_y_f] = |
| 196 | sticks[static_cast<size_t>(JoystickId::Joystick_Right)]->GetStatus(); | 199 | sticks[static_cast<std::size_t>(JoystickId::Joystick_Right)]->GetStatus(); |
| 197 | lstick_entry.x = static_cast<s32>(stick_l_x_f * HID_JOYSTICK_MAX); | 200 | lstick_entry.x = static_cast<s32>(stick_l_x_f * HID_JOYSTICK_MAX); |
| 198 | lstick_entry.y = static_cast<s32>(stick_l_y_f * HID_JOYSTICK_MAX); | 201 | lstick_entry.y = static_cast<s32>(stick_l_y_f * HID_JOYSTICK_MAX); |
| 199 | rstick_entry.x = static_cast<s32>(stick_r_x_f * HID_JOYSTICK_MAX); | 202 | rstick_entry.x = static_cast<s32>(stick_r_x_f * HID_JOYSTICK_MAX); |
| @@ -220,26 +223,26 @@ void Controller_NPad::OnUpdate(u8* data, size_t data_len) { | |||
| 220 | handheld_entry.connection_status.IsConnected.Assign(1); | 223 | handheld_entry.connection_status.IsConnected.Assign(1); |
| 221 | handheld_entry.connection_status.IsWired.Assign(1); | 224 | handheld_entry.connection_status.IsWired.Assign(1); |
| 222 | handheld_entry.pad_states.raw = pad_state.raw; | 225 | handheld_entry.pad_states.raw = pad_state.raw; |
| 223 | handheld_entry.lstick = lstick_entry; | 226 | handheld_entry.l_stick = lstick_entry; |
| 224 | handheld_entry.rstick = rstick_entry; | 227 | handheld_entry.r_stick = rstick_entry; |
| 225 | break; | 228 | break; |
| 226 | case NPadControllerType::JoyLeft: | 229 | case NPadControllerType::JoyLeft: |
| 227 | left_entry.connection_status.IsConnected.Assign(1); | 230 | left_entry.connection_status.IsConnected.Assign(1); |
| 228 | left_entry.pad_states.raw = pad_state.raw; | 231 | left_entry.pad_states.raw = pad_state.raw; |
| 229 | left_entry.lstick = lstick_entry; | 232 | left_entry.l_stick = lstick_entry; |
| 230 | left_entry.rstick = rstick_entry; | 233 | left_entry.r_stick = rstick_entry; |
| 231 | break; | 234 | break; |
| 232 | case NPadControllerType::JoyRight: | 235 | case NPadControllerType::JoyRight: |
| 233 | right_entry.connection_status.IsConnected.Assign(1); | 236 | right_entry.connection_status.IsConnected.Assign(1); |
| 234 | right_entry.pad_states.raw = pad_state.raw; | 237 | right_entry.pad_states.raw = pad_state.raw; |
| 235 | right_entry.lstick = lstick_entry; | 238 | right_entry.l_stick = lstick_entry; |
| 236 | right_entry.rstick = rstick_entry; | 239 | right_entry.r_stick = rstick_entry; |
| 237 | break; | 240 | break; |
| 238 | case NPadControllerType::Tabletop: | 241 | case NPadControllerType::Tabletop: |
| 239 | // TODO(ogniK): Figure out how to add proper tabletop support | 242 | // TODO(ogniK): Figure out how to add proper tabletop support |
| 240 | dual_entry.pad_states.raw = pad_state.raw; | 243 | dual_entry.pad_states.raw = pad_state.raw; |
| 241 | dual_entry.lstick = lstick_entry; | 244 | dual_entry.l_stick = lstick_entry; |
| 242 | dual_entry.rstick = rstick_entry; | 245 | dual_entry.r_stick = rstick_entry; |
| 243 | dual_entry.connection_status.IsConnected.Assign(1); | 246 | dual_entry.connection_status.IsConnected.Assign(1); |
| 244 | break; | 247 | break; |
| 245 | case NPadControllerType::Pokeball: | 248 | case NPadControllerType::Pokeball: |
| @@ -247,13 +250,13 @@ void Controller_NPad::OnUpdate(u8* data, size_t data_len) { | |||
| 247 | pokeball_entry.connection_status.IsWired.Assign(1); | 250 | pokeball_entry.connection_status.IsWired.Assign(1); |
| 248 | 251 | ||
| 249 | pokeball_entry.pad_states.raw = pad_state.raw; | 252 | pokeball_entry.pad_states.raw = pad_state.raw; |
| 250 | pokeball_entry.lstick = lstick_entry; | 253 | pokeball_entry.l_stick = lstick_entry; |
| 251 | pokeball_entry.rstick = rstick_entry; | 254 | pokeball_entry.r_stick = rstick_entry; |
| 252 | break; | 255 | break; |
| 253 | case NPadControllerType::ProController: | 256 | case NPadControllerType::ProController: |
| 254 | main_controller.pad_states.raw = pad_state.raw; | 257 | main_controller.pad_states.raw = pad_state.raw; |
| 255 | main_controller.lstick = lstick_entry; | 258 | main_controller.l_stick = lstick_entry; |
| 256 | main_controller.rstick = rstick_entry; | 259 | main_controller.r_stick = rstick_entry; |
| 257 | main_controller.connection_status.IsConnected.Assign(1); | 260 | main_controller.connection_status.IsConnected.Assign(1); |
| 258 | main_controller.connection_status.IsWired.Assign(1); | 261 | main_controller.connection_status.IsWired.Assign(1); |
| 259 | break; | 262 | break; |
| @@ -264,8 +267,8 @@ void Controller_NPad::OnUpdate(u8* data, size_t data_len) { | |||
| 264 | libnx_entry.connection_status.IsConnected.Assign(1); | 267 | libnx_entry.connection_status.IsConnected.Assign(1); |
| 265 | libnx_entry.connection_status.IsWired.Assign(1); | 268 | libnx_entry.connection_status.IsWired.Assign(1); |
| 266 | libnx_entry.pad_states.raw = pad_state.raw; | 269 | libnx_entry.pad_states.raw = pad_state.raw; |
| 267 | libnx_entry.lstick = lstick_entry; | 270 | libnx_entry.l_stick = lstick_entry; |
| 268 | libnx_entry.rstick = rstick_entry; | 271 | libnx_entry.r_stick = rstick_entry; |
| 269 | } | 272 | } |
| 270 | std::memcpy(data + NPAD_OFFSET, shared_memory_entries.data(), | 273 | std::memcpy(data + NPAD_OFFSET, shared_memory_entries.data(), |
| 271 | shared_memory_entries.size() * sizeof(NPadEntry)); | 274 | shared_memory_entries.size() * sizeof(NPadEntry)); |
| @@ -279,18 +282,18 @@ Controller_NPad::NPadType Controller_NPad::GetSupportedStyleSet() const { | |||
| 279 | return style; | 282 | return style; |
| 280 | } | 283 | } |
| 281 | 284 | ||
| 282 | void Controller_NPad::SetSupportedNPadIdTypes(u8* data, size_t length) { | 285 | void Controller_NPad::SetSupportedNPadIdTypes(u8* data, std::size_t length) { |
| 283 | ASSERT(length > 0 && (length % sizeof(u32)) == 0); | 286 | ASSERT(length > 0 && (length % sizeof(u32)) == 0); |
| 284 | supported_npad_id_types.resize(length / 4); | 287 | supported_npad_id_types.resize(length / sizeof(u32)); |
| 285 | std::memcpy(supported_npad_id_types.data(), data, length); | 288 | std::memcpy(supported_npad_id_types.data(), data, length); |
| 286 | } | 289 | } |
| 287 | 290 | ||
| 288 | void Controller_NPad::GetSupportedNpadIdTypes(u32* data, size_t max_length) { | 291 | const void Controller_NPad::GetSupportedNpadIdTypes(u32* data, std::size_t max_length) { |
| 289 | ASSERT(max_length < supported_npad_id_types.size()); | 292 | ASSERT(max_length < supported_npad_id_types.size()); |
| 290 | std::memcpy(data, supported_npad_id_types.data(), supported_npad_id_types.size()); | 293 | std::memcpy(data, supported_npad_id_types.data(), supported_npad_id_types.size()); |
| 291 | } | 294 | } |
| 292 | 295 | ||
| 293 | size_t Controller_NPad::GetSupportedNPadIdTypesSize() const { | 296 | std::size_t Controller_NPad::GetSupportedNPadIdTypesSize() const { |
| 294 | return supported_npad_id_types.size(); | 297 | return supported_npad_id_types.size(); |
| 295 | } | 298 | } |
| 296 | 299 | ||
| @@ -308,7 +311,7 @@ void Controller_NPad::SetNpadMode(u32 npad_id, NPadAssignments assignment_mode) | |||
| 308 | 311 | ||
| 309 | void Controller_NPad::VibrateController(const std::vector<u32>& controller_ids, | 312 | void Controller_NPad::VibrateController(const std::vector<u32>& controller_ids, |
| 310 | const std::vector<Vibration>& vibrations) { | 313 | const std::vector<Vibration>& vibrations) { |
| 311 | for (size_t i = 0; i < controller_ids.size(); i++) { | 314 | for (std::size_t i = 0; i < controller_ids.size(); i++) { |
| 312 | if (i >= CONTROLLER_COUNT) { | 315 | if (i >= CONTROLLER_COUNT) { |
| 313 | continue; | 316 | continue; |
| 314 | } | 317 | } |
| @@ -326,11 +329,11 @@ Controller_NPad::Vibration Controller_NPad::GetLastVibration() const { | |||
| 326 | return last_processed_vibration; | 329 | return last_processed_vibration; |
| 327 | } | 330 | } |
| 328 | void Controller_NPad::AddNewController(NPadControllerType controller) { | 331 | void Controller_NPad::AddNewController(NPadControllerType controller) { |
| 329 | if (CONTROLLER_COUNT >= MAX_CONTROLLER_COUNT) { | 332 | if (CONTROLLER_COUNT >= CONNECTED_CONTROLLERS.size()) { |
| 330 | LOG_ERROR(Service_HID, "Cannot connect any more controllers!"); | 333 | LOG_ERROR(Service_HID, "Cannot connect any more controllers!"); |
| 331 | return; | 334 | return; |
| 332 | } | 335 | } |
| 333 | CONNECTED_CONTROLLERS[CONTROLLER_COUNT] = controller; | 336 | CONNECTED_CONTROLLERS[CONTROLLER_COUNT] = controller; |
| 334 | InitNewlyAddedControler(CONTROLLER_COUNT++); | 337 | InitNewlyAddedControler(CONTROLLER_COUNT++); |
| 335 | } | 338 | } |
| 336 | }; // namespace Service::HID | 339 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index e57b67da4..e5c212aa5 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h | |||
| @@ -3,17 +3,24 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | |||
| 6 | #include <array> | 7 | #include <array> |
| 7 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 8 | #include "core/frontend/input.h" | ||
| 9 | #include "core/hle/service/hid/controllers/controller_base.h" | 9 | #include "core/hle/service/hid/controllers/controller_base.h" |
| 10 | #include "core/settings.h" | 10 | #include "core/settings.h" |
| 11 | 11 | ||
| 12 | namespace Input { | ||
| 13 | template <typename StatusType> | ||
| 14 | class InputDevice; | ||
| 15 | using ButtonDevice = InputDevice<bool>; | ||
| 16 | using AnalogDevice = InputDevice<std::tuple<float, float>>; | ||
| 17 | } // namespace Input | ||
| 18 | |||
| 12 | namespace Service::HID { | 19 | namespace Service::HID { |
| 13 | 20 | ||
| 14 | class Controller_NPad final : public ControllerBase { | 21 | class Controller_NPad final : public ControllerBase { |
| 15 | public: | 22 | public: |
| 16 | Controller_NPad() = default; | 23 | Controller_NPad(); |
| 17 | 24 | ||
| 18 | // Called when the controller is initialized | 25 | // Called when the controller is initialized |
| 19 | void OnInit() override; | 26 | void OnInit() override; |
| @@ -22,7 +29,7 @@ public: | |||
| 22 | void OnRelease() override; | 29 | void OnRelease() override; |
| 23 | 30 | ||
| 24 | // When the controller is requesting an update for the shared memory | 31 | // When the controller is requesting an update for the shared memory |
| 25 | void OnUpdate(u8* data, size_t size) override; | 32 | void OnUpdate(u8* data, std::size_t size) override; |
| 26 | 33 | ||
| 27 | // Called when input devices should be loaded | 34 | // Called when input devices should be loaded |
| 28 | void OnLoadInputDevices() override; | 35 | void OnLoadInputDevices() override; |
| @@ -67,15 +74,15 @@ public: | |||
| 67 | JoyLeft, | 74 | JoyLeft, |
| 68 | JoyRight, | 75 | JoyRight, |
| 69 | Tabletop, | 76 | Tabletop, |
| 70 | Pokeball | 77 | Pokeball, |
| 71 | }; | 78 | }; |
| 72 | 79 | ||
| 73 | void SetSupportedStyleSet(NPadType style_set); | 80 | void SetSupportedStyleSet(NPadType style_set); |
| 74 | NPadType GetSupportedStyleSet() const; | 81 | NPadType GetSupportedStyleSet() const; |
| 75 | 82 | ||
| 76 | void SetSupportedNPadIdTypes(u8* data, size_t length); | 83 | void SetSupportedNPadIdTypes(u8* data, std::size_t length); |
| 77 | void GetSupportedNpadIdTypes(u32* data, size_t max_length); | 84 | const void GetSupportedNpadIdTypes(u32* data, std::size_t max_length); |
| 78 | size_t GetSupportedNPadIdTypesSize() const; | 85 | std::size_t GetSupportedNPadIdTypesSize() const; |
| 79 | 86 | ||
| 80 | void SetHoldType(NpadHoldType joy_hold_type); | 87 | void SetHoldType(NpadHoldType joy_hold_type); |
| 81 | NpadHoldType GetHoldType() const; | 88 | NpadHoldType GetHoldType() const; |
| @@ -123,22 +130,22 @@ private: | |||
| 123 | BitField<11, 1, u64_le> minus; | 130 | BitField<11, 1, u64_le> minus; |
| 124 | 131 | ||
| 125 | // D-Pad | 132 | // D-Pad |
| 126 | BitField<12, 1, u64_le> dleft; | 133 | BitField<12, 1, u64_le> d_left; |
| 127 | BitField<13, 1, u64_le> dup; | 134 | BitField<13, 1, u64_le> d_up; |
| 128 | BitField<14, 1, u64_le> dright; | 135 | BitField<14, 1, u64_le> d_right; |
| 129 | BitField<15, 1, u64_le> ddown; | 136 | BitField<15, 1, u64_le> d_down; |
| 130 | 137 | ||
| 131 | // Left JoyStick | 138 | // Left JoyStick |
| 132 | BitField<16, 1, u64_le> lstickleft; | 139 | BitField<16, 1, u64_le> l_stick_left; |
| 133 | BitField<17, 1, u64_le> lstickup; | 140 | BitField<17, 1, u64_le> l_stick_up; |
| 134 | BitField<18, 1, u64_le> lstickright; | 141 | BitField<18, 1, u64_le> l_stick_right; |
| 135 | BitField<19, 1, u64_le> lstickdown; | 142 | BitField<19, 1, u64_le> l_stick_down; |
| 136 | 143 | ||
| 137 | // Right JoyStick | 144 | // Right JoyStick |
| 138 | BitField<20, 1, u64_le> rstickleft; | 145 | BitField<20, 1, u64_le> r_stick_left; |
| 139 | BitField<21, 1, u64_le> rstickup; | 146 | BitField<21, 1, u64_le> r_stick_up; |
| 140 | BitField<22, 1, u64_le> rstickright; | 147 | BitField<22, 1, u64_le> r_stick_right; |
| 141 | BitField<23, 1, u64_le> rstickdown; | 148 | BitField<23, 1, u64_le> r_stick_down; |
| 142 | 149 | ||
| 143 | // Not always active? | 150 | // Not always active? |
| 144 | BitField<24, 1, u64_le> sl; | 151 | BitField<24, 1, u64_le> sl; |
| @@ -166,8 +173,8 @@ private: | |||
| 166 | s64_le timestamp; | 173 | s64_le timestamp; |
| 167 | s64_le timestamp2; | 174 | s64_le timestamp2; |
| 168 | ControllerPadState pad_states; | 175 | ControllerPadState pad_states; |
| 169 | AnalogPosition lstick; | 176 | AnalogPosition l_stick; |
| 170 | AnalogPosition rstick; | 177 | AnalogPosition r_stick; |
| 171 | ConnectionState connection_status; | 178 | ConnectionState connection_status; |
| 172 | }; | 179 | }; |
| 173 | static_assert(sizeof(GenericStates) == 0x30, "NPadGenericStates is an invalid size"); | 180 | static_assert(sizeof(GenericStates) == 0x30, "NPadGenericStates is an invalid size"); |
| @@ -187,7 +194,7 @@ private: | |||
| 187 | struct NPadProperties { | 194 | struct NPadProperties { |
| 188 | union { | 195 | union { |
| 189 | s64_le raw{}; | 196 | s64_le raw{}; |
| 190 | BitField<11, 1, s64_le> is_verticle; | 197 | BitField<11, 1, s64_le> is_vertical; |
| 191 | BitField<12, 1, s64_le> is_horizontal; | 198 | BitField<12, 1, s64_le> is_horizontal; |
| 192 | }; | 199 | }; |
| 193 | }; | 200 | }; |
| @@ -226,7 +233,7 @@ private: | |||
| 226 | // relying on this for the time being | 233 | // relying on this for the time being |
| 227 | INSERT_PADDING_BYTES( | 234 | INSERT_PADDING_BYTES( |
| 228 | 0x708 * | 235 | 0x708 * |
| 229 | 6); // TODO(ogniK)L SixAxis states, require more information before implementation | 236 | 6); // TODO(ogniK): SixAxis states, require more information before implementation |
| 230 | NPadDevice device_type; | 237 | NPadDevice device_type; |
| 231 | NPadProperties properties; | 238 | NPadProperties properties; |
| 232 | INSERT_PADDING_WORDS(4); | 239 | INSERT_PADDING_WORDS(4); |
| @@ -242,8 +249,12 @@ private: | |||
| 242 | std::vector<u32> supported_npad_id_types{}; | 249 | std::vector<u32> supported_npad_id_types{}; |
| 243 | NpadHoldType hold_type{NpadHoldType::Vertical}; | 250 | NpadHoldType hold_type{NpadHoldType::Vertical}; |
| 244 | Kernel::SharedPtr<Kernel::Event> styleset_changed_event; | 251 | Kernel::SharedPtr<Kernel::Event> styleset_changed_event; |
| 245 | size_t dump_idx{}; | 252 | std::size_t dump_idx{}; |
| 246 | Vibration last_processed_vibration{}; | 253 | Vibration last_processed_vibration{}; |
| 247 | void InitNewlyAddedControler(size_t controller_idx); | 254 | std::size_t CONTROLLER_COUNT{}; |
| 255 | const std::array<u32, 9> NPAD_ID_LIST{0, 1, 2, 3, 4, 5, 6, 7, 32}; | ||
| 256 | std::array<Controller_NPad::NPadControllerType, 9> CONNECTED_CONTROLLERS{}; | ||
| 257 | |||
| 258 | void InitNewlyAddedControler(std::size_t controller_idx); | ||
| 248 | }; | 259 | }; |
| 249 | }; // namespace Service::HID | 260 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/stubbed.cpp b/src/core/hle/service/hid/controllers/stubbed.cpp index 0a602fce2..3a13d5991 100644 --- a/src/core/hle/service/hid/controllers/stubbed.cpp +++ b/src/core/hle/service/hid/controllers/stubbed.cpp | |||
| @@ -2,15 +2,21 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <cstring> | ||
| 5 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 6 | #include "common/swap.h" | 7 | #include "common/swap.h" |
| 7 | #include "core/core_timing.h" | 8 | #include "core/core_timing.h" |
| 8 | #include "core/hle/service/hid/controllers/stubbed.h" | 9 | #include "core/hle/service/hid/controllers/stubbed.h" |
| 9 | 10 | ||
| 10 | namespace Service::HID { | 11 | namespace Service::HID { |
| 12 | |||
| 13 | Controller_Stubbed::Controller_Stubbed() = default; | ||
| 14 | |||
| 11 | void Controller_Stubbed::OnInit() {} | 15 | void Controller_Stubbed::OnInit() {} |
| 16 | |||
| 12 | void Controller_Stubbed::OnRelease() {} | 17 | void Controller_Stubbed::OnRelease() {} |
| 13 | void Controller_Stubbed::OnUpdate(u8* data, size_t size) { | 18 | |
| 19 | void Controller_Stubbed::OnUpdate(u8* data, std::size_t size) { | ||
| 14 | if (!smart_update) { | 20 | if (!smart_update) { |
| 15 | return; | 21 | return; |
| 16 | } | 22 | } |
| @@ -23,10 +29,11 @@ void Controller_Stubbed::OnUpdate(u8* data, size_t size) { | |||
| 23 | 29 | ||
| 24 | std::memcpy(data + common_offset, &header, sizeof(CommonHeader)); | 30 | std::memcpy(data + common_offset, &header, sizeof(CommonHeader)); |
| 25 | } | 31 | } |
| 32 | |||
| 26 | void Controller_Stubbed::OnLoadInputDevices() {} | 33 | void Controller_Stubbed::OnLoadInputDevices() {} |
| 27 | 34 | ||
| 28 | void Controller_Stubbed::SetCommonHeaderOffset(size_t off) { | 35 | void Controller_Stubbed::SetCommonHeaderOffset(std::size_t off) { |
| 29 | common_offset = off; | 36 | common_offset = off; |
| 30 | smart_update = true; | 37 | smart_update = true; |
| 31 | } | 38 | } |
| 32 | }; // 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 ec7adacb3..9c1b57f83 100644 --- a/src/core/hle/service/hid/controllers/stubbed.h +++ b/src/core/hle/service/hid/controllers/stubbed.h | |||
| @@ -3,13 +3,14 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | |||
| 6 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 7 | #include "core/hle/service/hid/controllers/controller_base.h" | 8 | #include "core/hle/service/hid/controllers/controller_base.h" |
| 8 | 9 | ||
| 9 | namespace Service::HID { | 10 | namespace Service::HID { |
| 10 | class Controller_Stubbed final : public ControllerBase { | 11 | class Controller_Stubbed final : public ControllerBase { |
| 11 | public: | 12 | public: |
| 12 | Controller_Stubbed() = default; | 13 | Controller_Stubbed(); |
| 13 | 14 | ||
| 14 | // Called when the controller is initialized | 15 | // Called when the controller is initialized |
| 15 | void OnInit() override; | 16 | void OnInit() override; |
| @@ -18,15 +19,15 @@ public: | |||
| 18 | void OnRelease() override; | 19 | void OnRelease() override; |
| 19 | 20 | ||
| 20 | // When the controller is requesting an update for the shared memory | 21 | // When the controller is requesting an update for the shared memory |
| 21 | void OnUpdate(u8* data, size_t size) override; | 22 | void OnUpdate(u8* data, std::size_t size) override; |
| 22 | 23 | ||
| 23 | // Called when input devices should be loaded | 24 | // Called when input devices should be loaded |
| 24 | void OnLoadInputDevices() override; | 25 | void OnLoadInputDevices() override; |
| 25 | 26 | ||
| 26 | void SetCommonHeaderOffset(size_t off); | 27 | void SetCommonHeaderOffset(std::size_t off); |
| 27 | 28 | ||
| 28 | private: | 29 | private: |
| 29 | bool smart_update{}; | 30 | bool smart_update{}; |
| 30 | size_t common_offset{}; | 31 | std::size_t common_offset{}; |
| 31 | }; | 32 | }; |
| 32 | }; // namespace Service::HID | 33 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/core/hle/service/hid/controllers/touchscreen.cpp index b675dec8e..e97f84ea1 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.cpp +++ b/src/core/hle/service/hid/controllers/touchscreen.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <cstring> | ||
| 5 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 6 | #include "common/swap.h" | 7 | #include "common/swap.h" |
| 7 | #include "core/core_timing.h" | 8 | #include "core/core_timing.h" |
| @@ -11,10 +12,15 @@ | |||
| 11 | #include "core/settings.h" | 12 | #include "core/settings.h" |
| 12 | 13 | ||
| 13 | namespace Service::HID { | 14 | namespace Service::HID { |
| 14 | constexpr size_t SHARED_MEMORY_OFFSET = 0x400; | 15 | constexpr std::size_t SHARED_MEMORY_OFFSET = 0x400; |
| 16 | |||
| 17 | Controller_Touchscreen::Controller_Touchscreen() = default; | ||
| 18 | |||
| 15 | void Controller_Touchscreen::OnInit() {} | 19 | void Controller_Touchscreen::OnInit() {} |
| 20 | |||
| 16 | void Controller_Touchscreen::OnRelease() {} | 21 | void Controller_Touchscreen::OnRelease() {} |
| 17 | void Controller_Touchscreen::OnUpdate(u8* data, size_t size) { | 22 | |
| 23 | void Controller_Touchscreen::OnUpdate(u8* data, std::size_t size) { | ||
| 18 | shared_memory.header.timestamp = CoreTiming::GetTicks(); | 24 | shared_memory.header.timestamp = CoreTiming::GetTicks(); |
| 19 | shared_memory.header.total_entry_count = 17; | 25 | shared_memory.header.total_entry_count = 17; |
| 20 | 26 | ||
| @@ -25,14 +31,15 @@ void Controller_Touchscreen::OnUpdate(u8* data, size_t size) { | |||
| 25 | } | 31 | } |
| 26 | shared_memory.header.entry_count = 16; | 32 | shared_memory.header.entry_count = 16; |
| 27 | 33 | ||
| 28 | auto& last_entry = shared_memory.shared_memory_entries[shared_memory.header.last_entry_index]; | 34 | const auto& last_entry = |
| 35 | shared_memory.shared_memory_entries[shared_memory.header.last_entry_index]; | ||
| 29 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; | 36 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; |
| 30 | auto& cur_entry = shared_memory.shared_memory_entries[shared_memory.header.last_entry_index]; | 37 | auto& cur_entry = shared_memory.shared_memory_entries[shared_memory.header.last_entry_index]; |
| 31 | 38 | ||
| 32 | cur_entry.sampling_number = last_entry.sampling_number + 1; | 39 | cur_entry.sampling_number = last_entry.sampling_number + 1; |
| 33 | cur_entry.sampling_number2 = cur_entry.sampling_number; | 40 | cur_entry.sampling_number2 = cur_entry.sampling_number; |
| 34 | 41 | ||
| 35 | auto [x, y, pressed] = touch_device->GetStatus(); | 42 | const auto [x, y, pressed] = touch_device->GetStatus(); |
| 36 | auto& touch_entry = cur_entry.states[0]; | 43 | auto& touch_entry = cur_entry.states[0]; |
| 37 | if (pressed) { | 44 | if (pressed) { |
| 38 | touch_entry.x = static_cast<u16>(x * Layout::ScreenUndocked::Width); | 45 | touch_entry.x = static_cast<u16>(x * Layout::ScreenUndocked::Width); |
| @@ -55,4 +62,4 @@ void Controller_Touchscreen::OnUpdate(u8* data, size_t size) { | |||
| 55 | void Controller_Touchscreen::OnLoadInputDevices() { | 62 | void Controller_Touchscreen::OnLoadInputDevices() { |
| 56 | touch_device = Input::CreateDevice<Input::TouchDevice>(Settings::values.touch_device); | 63 | touch_device = Input::CreateDevice<Input::TouchDevice>(Settings::values.touch_device); |
| 57 | } | 64 | } |
| 58 | }; // namespace Service::HID | 65 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/touchscreen.h b/src/core/hle/service/hid/controllers/touchscreen.h index a516128ac..82a3d4a1a 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.h +++ b/src/core/hle/service/hid/controllers/touchscreen.h | |||
| @@ -3,16 +3,22 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | |||
| 6 | #include "common/common_funcs.h" | 7 | #include "common/common_funcs.h" |
| 7 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 8 | #include "common/swap.h" | 9 | #include "common/swap.h" |
| 9 | #include "core/frontend/input.h" | ||
| 10 | #include "core/hle/service/hid/controllers/controller_base.h" | 10 | #include "core/hle/service/hid/controllers/controller_base.h" |
| 11 | 11 | ||
| 12 | namespace Input { | ||
| 13 | template <typename StatusType> | ||
| 14 | class InputDevice; | ||
| 15 | using TouchDevice = InputDevice<std::tuple<float, float, bool>>; | ||
| 16 | } // namespace Input | ||
| 17 | |||
| 12 | namespace Service::HID { | 18 | namespace Service::HID { |
| 13 | class Controller_Touchscreen final : public ControllerBase { | 19 | class Controller_Touchscreen final : public ControllerBase { |
| 14 | public: | 20 | public: |
| 15 | Controller_Touchscreen() = default; | 21 | Controller_Touchscreen(); |
| 16 | 22 | ||
| 17 | // Called when the controller is initialized | 23 | // Called when the controller is initialized |
| 18 | void OnInit() override; | 24 | void OnInit() override; |
| @@ -21,7 +27,7 @@ public: | |||
| 21 | void OnRelease() override; | 27 | void OnRelease() override; |
| 22 | 28 | ||
| 23 | // When the controller is requesting an update for the shared memory | 29 | // When the controller is requesting an update for the shared memory |
| 24 | void OnUpdate(u8* data, size_t size) override; | 30 | void OnUpdate(u8* data, std::size_t size) override; |
| 25 | 31 | ||
| 26 | // Called when input devices should be loaded | 32 | // Called when input devices should be loaded |
| 27 | void OnLoadInputDevices() override; | 33 | void OnLoadInputDevices() override; |
| @@ -58,4 +64,4 @@ private: | |||
| 58 | std::unique_ptr<Input::TouchDevice> touch_device; | 64 | std::unique_ptr<Input::TouchDevice> touch_device; |
| 59 | s64_le last_touch{}; | 65 | s64_le last_touch{}; |
| 60 | }; | 66 | }; |
| 61 | }; // namespace Service::HID | 67 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/xpad.cpp b/src/core/hle/service/hid/controllers/xpad.cpp index 521e925b7..df0b48451 100644 --- a/src/core/hle/service/hid/controllers/xpad.cpp +++ b/src/core/hle/service/hid/controllers/xpad.cpp | |||
| @@ -2,16 +2,22 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <cstring> | ||
| 5 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 6 | #include "common/swap.h" | 7 | #include "common/swap.h" |
| 7 | #include "core/core_timing.h" | 8 | #include "core/core_timing.h" |
| 8 | #include "core/hle/service/hid/controllers/xpad.h" | 9 | #include "core/hle/service/hid/controllers/xpad.h" |
| 9 | 10 | ||
| 10 | namespace Service::HID { | 11 | namespace Service::HID { |
| 11 | constexpr size_t SHARED_MEMORY_OFFSET = 0x3C00; | 12 | constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C00; |
| 13 | |||
| 14 | Controller_XPad::Controller_XPad() = default; | ||
| 15 | |||
| 12 | void Controller_XPad::OnInit() {} | 16 | void Controller_XPad::OnInit() {} |
| 17 | |||
| 13 | void Controller_XPad::OnRelease() {} | 18 | void Controller_XPad::OnRelease() {} |
| 14 | void Controller_XPad::OnUpdate(u8* data, size_t size) { | 19 | |
| 20 | void Controller_XPad::OnUpdate(u8* data, std::size_t size) { | ||
| 15 | for (auto& xpad_entry : shared_memory.shared_memory_entries) { | 21 | for (auto& xpad_entry : shared_memory.shared_memory_entries) { |
| 16 | xpad_entry.header.timestamp = CoreTiming::GetTicks(); | 22 | xpad_entry.header.timestamp = CoreTiming::GetTicks(); |
| 17 | xpad_entry.header.total_entry_count = 17; | 23 | xpad_entry.header.total_entry_count = 17; |
| @@ -23,7 +29,7 @@ void Controller_XPad::OnUpdate(u8* data, size_t size) { | |||
| 23 | } | 29 | } |
| 24 | xpad_entry.header.entry_count = 16; | 30 | xpad_entry.header.entry_count = 16; |
| 25 | 31 | ||
| 26 | auto& last_entry = xpad_entry.pad_states[xpad_entry.header.last_entry_index]; | 32 | const auto& last_entry = xpad_entry.pad_states[xpad_entry.header.last_entry_index]; |
| 27 | xpad_entry.header.last_entry_index = (xpad_entry.header.last_entry_index + 1) % 17; | 33 | xpad_entry.header.last_entry_index = (xpad_entry.header.last_entry_index + 1) % 17; |
| 28 | auto& cur_entry = xpad_entry.pad_states[xpad_entry.header.last_entry_index]; | 34 | auto& cur_entry = xpad_entry.pad_states[xpad_entry.header.last_entry_index]; |
| 29 | 35 | ||
| @@ -34,5 +40,6 @@ void Controller_XPad::OnUpdate(u8* data, size_t size) { | |||
| 34 | 40 | ||
| 35 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory)); | 41 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory)); |
| 36 | } | 42 | } |
| 43 | |||
| 37 | void Controller_XPad::OnLoadInputDevices() {} | 44 | void Controller_XPad::OnLoadInputDevices() {} |
| 38 | }; // namespace Service::HID | 45 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/xpad.h b/src/core/hle/service/hid/controllers/xpad.h index 898fadfdc..e2007183d 100644 --- a/src/core/hle/service/hid/controllers/xpad.h +++ b/src/core/hle/service/hid/controllers/xpad.h | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | |||
| 6 | #include "common/common_funcs.h" | 7 | #include "common/common_funcs.h" |
| 7 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 8 | #include "common/swap.h" | 9 | #include "common/swap.h" |
| @@ -12,7 +13,7 @@ | |||
| 12 | namespace Service::HID { | 13 | namespace Service::HID { |
| 13 | class Controller_XPad final : public ControllerBase { | 14 | class Controller_XPad final : public ControllerBase { |
| 14 | public: | 15 | public: |
| 15 | Controller_XPad() = default; | 16 | Controller_XPad(); |
| 16 | 17 | ||
| 17 | // Called when the controller is initialized | 18 | // Called when the controller is initialized |
| 18 | void OnInit() override; | 19 | void OnInit() override; |
| @@ -21,7 +22,7 @@ public: | |||
| 21 | void OnRelease() override; | 22 | void OnRelease() override; |
| 22 | 23 | ||
| 23 | // When the controller is requesting an update for the shared memory | 24 | // When the controller is requesting an update for the shared memory |
| 24 | void OnUpdate(u8* data, size_t size) override; | 25 | void OnUpdate(u8* data, std::size_t size) override; |
| 25 | 26 | ||
| 26 | // Called when input devices should be loaded | 27 | // Called when input devices should be loaded |
| 27 | void OnLoadInputDevices() override; | 28 | void OnLoadInputDevices() override; |
| @@ -56,4 +57,4 @@ private: | |||
| 56 | static_assert(sizeof(SharedMemory) == 0x1000, "SharedMemory is an invalid size"); | 57 | static_assert(sizeof(SharedMemory) == 0x1000, "SharedMemory is an invalid size"); |
| 57 | SharedMemory shared_memory{}; | 58 | SharedMemory shared_memory{}; |
| 58 | }; | 59 | }; |
| 59 | }; // namespace Service::HID | 60 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 757b3b770..ba4aefa6c 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp | |||
| @@ -38,8 +38,8 @@ namespace Service::HID { | |||
| 38 | constexpr u64 pad_update_ticks = CoreTiming::BASE_CLOCK_RATE / 100; | 38 | constexpr u64 pad_update_ticks = CoreTiming::BASE_CLOCK_RATE / 100; |
| 39 | constexpr u64 accelerometer_update_ticks = CoreTiming::BASE_CLOCK_RATE / 100; | 39 | constexpr u64 accelerometer_update_ticks = CoreTiming::BASE_CLOCK_RATE / 100; |
| 40 | constexpr u64 gyroscope_update_ticks = CoreTiming::BASE_CLOCK_RATE / 100; | 40 | constexpr u64 gyroscope_update_ticks = CoreTiming::BASE_CLOCK_RATE / 100; |
| 41 | constexpr size_t SHARED_MEMORY_SIZE = 0x40000; | 41 | constexpr std::size_t SHARED_MEMORY_SIZE = 0x40000; |
| 42 | enum class HidController : size_t { | 42 | enum class HidController : std::size_t { |
| 43 | DebugPad, | 43 | DebugPad, |
| 44 | Touchscreen, | 44 | Touchscreen, |
| 45 | Mouse, | 45 | Mouse, |
| @@ -52,7 +52,7 @@ enum class HidController : size_t { | |||
| 52 | NPad, | 52 | NPad, |
| 53 | Gesture, | 53 | Gesture, |
| 54 | 54 | ||
| 55 | MaxControllers | 55 | MaxControllers, |
| 56 | }; | 56 | }; |
| 57 | 57 | ||
| 58 | class IAppletResource final : public ServiceFramework<IAppletResource> { | 58 | class IAppletResource final : public ServiceFramework<IAppletResource> { |
| @@ -68,33 +68,21 @@ public: | |||
| 68 | kernel, nullptr, SHARED_MEMORY_SIZE, Kernel::MemoryPermission::ReadWrite, | 68 | kernel, nullptr, SHARED_MEMORY_SIZE, Kernel::MemoryPermission::ReadWrite, |
| 69 | Kernel::MemoryPermission::Read, 0, Kernel::MemoryRegion::BASE, "HID:SharedMemory"); | 69 | Kernel::MemoryPermission::Read, 0, Kernel::MemoryRegion::BASE, "HID:SharedMemory"); |
| 70 | 70 | ||
| 71 | controllers[static_cast<size_t>(HidController::DebugPad)] = | 71 | MakeController<Controller_DebugPad>(HidController::DebugPad); |
| 72 | std::make_unique<Controller_DebugPad>(); | 72 | MakeController<Controller_Touchscreen>(HidController::Touchscreen); |
| 73 | controllers[static_cast<size_t>(HidController::Touchscreen)] = | 73 | MakeController<Controller_Mouse>(HidController::Mouse); |
| 74 | std::make_unique<Controller_Touchscreen>(); | 74 | MakeController<Controller_Keyboard>(HidController::Keyboard); |
| 75 | controllers[static_cast<size_t>(HidController::Mouse)] = | 75 | MakeController<Controller_XPad>(HidController::XPad); |
| 76 | std::make_unique<Controller_Mouse>(); | 76 | MakeController<Controller_Stubbed>(HidController::Unknown1); |
| 77 | controllers[static_cast<size_t>(HidController::Keyboard)] = | 77 | MakeController<Controller_Stubbed>(HidController::Unknown2); |
| 78 | std::make_unique<Controller_Keyboard>(); | 78 | MakeController<Controller_Stubbed>(HidController::Unknown3); |
| 79 | controllers[static_cast<size_t>(HidController::XPad)] = std::make_unique<Controller_XPad>(); | 79 | MakeController<Controller_Stubbed>(HidController::SixAxisSensor); |
| 80 | 80 | MakeController<Controller_NPad>(HidController::NPad); | |
| 81 | controllers[static_cast<size_t>(HidController::Unknown1)] = | 81 | MakeController<Controller_Gesture>(HidController::Gesture); |
| 82 | std::make_unique<Controller_Stubbed>(); | ||
| 83 | controllers[static_cast<size_t>(HidController::Unknown2)] = | ||
| 84 | std::make_unique<Controller_Stubbed>(); | ||
| 85 | controllers[static_cast<size_t>(HidController::Unknown3)] = | ||
| 86 | std::make_unique<Controller_Stubbed>(); | ||
| 87 | |||
| 88 | controllers[static_cast<size_t>(HidController::SixAxisSensor)] = | ||
| 89 | std::make_unique<Controller_Stubbed>(); | ||
| 90 | |||
| 91 | controllers[static_cast<size_t>(HidController::NPad)] = std::make_unique<Controller_NPad>(); | ||
| 92 | controllers[static_cast<size_t>(HidController::Gesture)] = | ||
| 93 | std::make_unique<Controller_Gesture>(); | ||
| 94 | 82 | ||
| 95 | // Homebrew doesn't try to activate some controllers, so we activate them by default | 83 | // Homebrew doesn't try to activate some controllers, so we activate them by default |
| 96 | controllers[static_cast<size_t>(HidController::NPad)]->ActivateController(); | 84 | GetController<Controller_NPad>(HidController::NPad).ActivateController(); |
| 97 | controllers[static_cast<size_t>(HidController::Touchscreen)]->ActivateController(); | 85 | GetController<Controller_Touchscreen>(HidController::Touchscreen).ActivateController(); |
| 98 | 86 | ||
| 99 | GetController<Controller_Stubbed>(HidController::Unknown1).SetCommonHeaderOffset(0x4c00); | 87 | GetController<Controller_Stubbed>(HidController::Unknown1).SetCommonHeaderOffset(0x4c00); |
| 100 | GetController<Controller_Stubbed>(HidController::Unknown2).SetCommonHeaderOffset(0x4e00); | 88 | GetController<Controller_Stubbed>(HidController::Unknown2).SetCommonHeaderOffset(0x4e00); |
| @@ -119,6 +107,11 @@ public: | |||
| 119 | } | 107 | } |
| 120 | 108 | ||
| 121 | template <typename T> | 109 | template <typename T> |
| 110 | void MakeController(HidController controller) { | ||
| 111 | controllers[static_cast<std::size_t>(controller)] = std::make_unique<T>(); | ||
| 112 | } | ||
| 113 | |||
| 114 | template <typename T> | ||
| 122 | T& GetController(HidController controller) { | 115 | T& GetController(HidController controller) { |
| 123 | return static_cast<T&>(*controllers[static_cast<size_t>(controller)]); | 116 | return static_cast<T&>(*controllers[static_cast<size_t>(controller)]); |
| 124 | } | 117 | } |
| @@ -136,7 +129,7 @@ private: | |||
| 136 | } | 129 | } |
| 137 | 130 | ||
| 138 | void UpdateControllers(u64 userdata, int cycles_late) { | 131 | void UpdateControllers(u64 userdata, int cycles_late) { |
| 139 | bool should_reload = Settings::values.is_device_reload_pending.exchange(false); | 132 | const bool should_reload = Settings::values.is_device_reload_pending.exchange(false); |
| 140 | for (const auto& controller : controllers) { | 133 | for (const auto& controller : controllers) { |
| 141 | if (should_reload) { | 134 | if (should_reload) { |
| 142 | controller->OnLoadInputDevices(); | 135 | controller->OnLoadInputDevices(); |
| @@ -386,7 +379,6 @@ private: | |||
| 386 | } | 379 | } |
| 387 | 380 | ||
| 388 | void GetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx) { | 381 | void GetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx) { |
| 389 | std::string blah = ctx.Description(); | ||
| 390 | auto& controller = applet_resource->GetController<Controller_NPad>(HidController::NPad); | 382 | auto& controller = applet_resource->GetController<Controller_NPad>(HidController::NPad); |
| 391 | 383 | ||
| 392 | IPC::ResponseBuilder rb{ctx, 3}; | 384 | IPC::ResponseBuilder rb{ctx, 3}; |
| @@ -434,7 +426,7 @@ private: | |||
| 434 | void SetNpadJoyHoldType(Kernel::HLERequestContext& ctx) { | 426 | void SetNpadJoyHoldType(Kernel::HLERequestContext& ctx) { |
| 435 | auto& controller = applet_resource->GetController<Controller_NPad>(HidController::NPad); | 427 | auto& controller = applet_resource->GetController<Controller_NPad>(HidController::NPad); |
| 436 | IPC::RequestParser rp{ctx}; | 428 | IPC::RequestParser rp{ctx}; |
| 437 | auto hold_type = rp.PopRaw<u64>(); | 429 | const auto hold_type = rp.PopRaw<u64>(); |
| 438 | controller.SetHoldType(Controller_NPad::NpadHoldType{hold_type}); | 430 | controller.SetHoldType(Controller_NPad::NpadHoldType{hold_type}); |
| 439 | 431 | ||
| 440 | IPC::ResponseBuilder rb{ctx, 2}; | 432 | IPC::ResponseBuilder rb{ctx, 2}; |
| @@ -443,7 +435,8 @@ private: | |||
| 443 | } | 435 | } |
| 444 | 436 | ||
| 445 | void GetNpadJoyHoldType(Kernel::HLERequestContext& ctx) { | 437 | void GetNpadJoyHoldType(Kernel::HLERequestContext& ctx) { |
| 446 | auto& controller = applet_resource->GetController<Controller_NPad>(HidController::NPad); | 438 | const auto& controller = |
| 439 | applet_resource->GetController<Controller_NPad>(HidController::NPad); | ||
| 447 | IPC::ResponseBuilder rb{ctx, 4}; | 440 | IPC::ResponseBuilder rb{ctx, 4}; |
| 448 | rb.Push(RESULT_SUCCESS); | 441 | rb.Push(RESULT_SUCCESS); |
| 449 | rb.Push<u64>(static_cast<u64>(controller.GetHoldType())); | 442 | rb.Push<u64>(static_cast<u64>(controller.GetHoldType())); |
| @@ -458,8 +451,8 @@ private: | |||
| 458 | 451 | ||
| 459 | void SendVibrationValue(Kernel::HLERequestContext& ctx) { | 452 | void SendVibrationValue(Kernel::HLERequestContext& ctx) { |
| 460 | IPC::RequestParser rp{ctx}; | 453 | IPC::RequestParser rp{ctx}; |
| 461 | auto controller_id = rp.PopRaw<u32>(); | 454 | const auto controller_id = rp.PopRaw<u32>(); |
| 462 | auto vibration_values = rp.PopRaw<Controller_NPad::Vibration>(); | 455 | const auto vibration_values = rp.PopRaw<Controller_NPad::Vibration>(); |
| 463 | 456 | ||
| 464 | IPC::ResponseBuilder rb{ctx, 2}; | 457 | IPC::ResponseBuilder rb{ctx, 2}; |
| 465 | rb.Push(RESULT_SUCCESS); | 458 | rb.Push(RESULT_SUCCESS); |
| @@ -470,8 +463,8 @@ private: | |||
| 470 | } | 463 | } |
| 471 | 464 | ||
| 472 | void SendVibrationValues(Kernel::HLERequestContext& ctx) { | 465 | void SendVibrationValues(Kernel::HLERequestContext& ctx) { |
| 473 | auto controllers = ctx.ReadBuffer(0); | 466 | const auto controllers = ctx.ReadBuffer(0); |
| 474 | auto vibrations = ctx.ReadBuffer(1); | 467 | const auto vibrations = ctx.ReadBuffer(1); |
| 475 | 468 | ||
| 476 | std::vector<u32> controller_list(controllers.size() / sizeof(u32)); | 469 | std::vector<u32> controller_list(controllers.size() / sizeof(u32)); |
| 477 | std::vector<Controller_NPad::Vibration> vibration_list(vibrations.size() / | 470 | std::vector<Controller_NPad::Vibration> vibration_list(vibrations.size() / |
| @@ -501,7 +494,7 @@ private: | |||
| 501 | 494 | ||
| 502 | void SetNpadJoyAssignmentModeDual(Kernel::HLERequestContext& ctx) { | 495 | void SetNpadJoyAssignmentModeDual(Kernel::HLERequestContext& ctx) { |
| 503 | IPC::RequestParser rp{ctx}; | 496 | IPC::RequestParser rp{ctx}; |
| 504 | auto npad_id = rp.PopRaw<u32>(); | 497 | const auto npad_id = rp.PopRaw<u32>(); |
| 505 | auto& controller = applet_resource->GetController<Controller_NPad>(HidController::NPad); | 498 | auto& controller = applet_resource->GetController<Controller_NPad>(HidController::NPad); |
| 506 | controller.SetNpadMode(npad_id, Controller_NPad::NPadAssignments::Dual); | 499 | controller.SetNpadMode(npad_id, Controller_NPad::NPadAssignments::Dual); |
| 507 | 500 | ||