summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-11-01 22:01:11 -0400
committerGravatar Zach Hilman2018-11-18 23:22:36 -0500
commit06cf050c0a541bc0bf9b4ca41fdec75f133c91d3 (patch)
treef71861b3bcec9a23091f476c4ebefd6d40cd8cb9 /src
parentyuzu/config: Add (de-)serialization for multiplayer (diff)
downloadyuzu-06cf050c0a541bc0bf9b4ca41fdec75f133c91d3.tar.gz
yuzu-06cf050c0a541bc0bf9b4ca41fdec75f133c91d3.tar.xz
yuzu-06cf050c0a541bc0bf9b4ca41fdec75f133c91d3.zip
hid: Add controller bindings for DebugPad controller
Used by developers to test games, not present on retail systems. Some games are known to respond to DebugPad input though, for example Kirby Star Allies.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/hid/controllers/debug_pad.cpp57
-rw-r--r--src/core/hle/service/hid/controllers/debug_pad.h7
2 files changed, 43 insertions, 21 deletions
diff --git a/src/core/hle/service/hid/controllers/debug_pad.cpp b/src/core/hle/service/hid/controllers/debug_pad.cpp
index ac9b23bb8..e76c83aee 100644
--- a/src/core/hle/service/hid/controllers/debug_pad.cpp
+++ b/src/core/hle/service/hid/controllers/debug_pad.cpp
@@ -6,9 +6,14 @@
6#include "common/common_types.h" 6#include "common/common_types.h"
7#include "core/core_timing.h" 7#include "core/core_timing.h"
8#include "core/hle/service/hid/controllers/debug_pad.h" 8#include "core/hle/service/hid/controllers/debug_pad.h"
9#include "core/settings.h"
9 10
10namespace Service::HID { 11namespace Service::HID {
11 12
13constexpr s32 HID_JOYSTICK_MAX = 0x7fff;
14constexpr s32 HID_JOYSTICK_MIN = -0x7fff;
15enum class JoystickId : std::size_t { Joystick_Left, Joystick_Right };
16
12Controller_DebugPad::Controller_DebugPad() = default; 17Controller_DebugPad::Controller_DebugPad() = default;
13Controller_DebugPad::~Controller_DebugPad() = default; 18Controller_DebugPad::~Controller_DebugPad() = default;
14 19
@@ -33,33 +38,43 @@ void Controller_DebugPad::OnUpdate(u8* data, std::size_t size) {
33 38
34 cur_entry.sampling_number = last_entry.sampling_number + 1; 39 cur_entry.sampling_number = last_entry.sampling_number + 1;
35 cur_entry.sampling_number2 = cur_entry.sampling_number; 40 cur_entry.sampling_number2 = cur_entry.sampling_number;
36 // TODO(ogniK): Update debug pad states
37 cur_entry.attribute.connected.Assign(1); 41 cur_entry.attribute.connected.Assign(1);
38 auto& pad = cur_entry.pad_state; 42 auto& pad = cur_entry.pad_state;
39 43
40 pad.a.Assign(0); 44 using namespace Settings::NativeButton;
41 pad.b.Assign(0); 45 pad.a.Assign(buttons[A - BUTTON_HID_BEGIN]->GetStatus());
42 pad.x.Assign(0); 46 pad.b.Assign(buttons[B - BUTTON_HID_BEGIN]->GetStatus());
43 pad.y.Assign(0); 47 pad.x.Assign(buttons[X - BUTTON_HID_BEGIN]->GetStatus());
44 pad.l.Assign(0); 48 pad.y.Assign(buttons[Y - BUTTON_HID_BEGIN]->GetStatus());
45 pad.r.Assign(0); 49 pad.l.Assign(buttons[L - BUTTON_HID_BEGIN]->GetStatus());
46 pad.zl.Assign(0); 50 pad.r.Assign(buttons[R - BUTTON_HID_BEGIN]->GetStatus());
47 pad.zr.Assign(0); 51 pad.zl.Assign(buttons[ZL - BUTTON_HID_BEGIN]->GetStatus());
48 pad.plus.Assign(0); 52 pad.zr.Assign(buttons[ZR - BUTTON_HID_BEGIN]->GetStatus());
49 pad.minus.Assign(0); 53 pad.plus.Assign(buttons[Plus - BUTTON_HID_BEGIN]->GetStatus());
50 pad.d_left.Assign(0); 54 pad.minus.Assign(buttons[Minus - BUTTON_HID_BEGIN]->GetStatus());
51 pad.d_up.Assign(0); 55 pad.d_left.Assign(buttons[DLeft - BUTTON_HID_BEGIN]->GetStatus());
52 pad.d_right.Assign(0); 56 pad.d_up.Assign(buttons[DUp - BUTTON_HID_BEGIN]->GetStatus());
53 pad.d_down.Assign(0); 57 pad.d_right.Assign(buttons[DRight - BUTTON_HID_BEGIN]->GetStatus());
54 58 pad.d_down.Assign(buttons[DDown - BUTTON_HID_BEGIN]->GetStatus());
55 cur_entry.l_stick.x = 0;
56 cur_entry.l_stick.y = 0;
57 59
58 cur_entry.r_stick.x = 0; 60 const auto [stick_l_x_f, stick_l_y_f] =
59 cur_entry.r_stick.y = 0; 61 analogs[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetStatus();
62 const auto [stick_r_x_f, stick_r_y_f] =
63 analogs[static_cast<std::size_t>(JoystickId::Joystick_Right)]->GetStatus();
64 cur_entry.l_stick.x = static_cast<s32>(stick_l_x_f * HID_JOYSTICK_MAX);
65 cur_entry.l_stick.y = static_cast<s32>(stick_l_y_f * HID_JOYSTICK_MAX);
66 cur_entry.r_stick.x = static_cast<s32>(stick_r_x_f * HID_JOYSTICK_MAX);
67 cur_entry.r_stick.y = static_cast<s32>(stick_r_y_f * HID_JOYSTICK_MAX);
60 68
61 std::memcpy(data, &shared_memory, sizeof(SharedMemory)); 69 std::memcpy(data, &shared_memory, sizeof(SharedMemory));
62} 70}
63 71
64void Controller_DebugPad::OnLoadInputDevices() {} 72void Controller_DebugPad::OnLoadInputDevices() {
73 std::transform(Settings::values.debug_pad_buttons.begin(),
74 Settings::values.debug_pad_buttons.end(), buttons.begin(),
75 Input::CreateDevice<Input::ButtonDevice>);
76 std::transform(Settings::values.debug_pad_analogs.begin(),
77 Settings::values.debug_pad_analogs.end(), analogs.begin(),
78 Input::CreateDevice<Input::AnalogDevice>);
79}
65} // namespace Service::HID 80} // 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 a41564b4d..68b734248 100644
--- a/src/core/hle/service/hid/controllers/debug_pad.h
+++ b/src/core/hle/service/hid/controllers/debug_pad.h
@@ -9,7 +9,9 @@
9#include "common/common_funcs.h" 9#include "common/common_funcs.h"
10#include "common/common_types.h" 10#include "common/common_types.h"
11#include "common/swap.h" 11#include "common/swap.h"
12#include "core/frontend/input.h"
12#include "core/hle/service/hid/controllers/controller_base.h" 13#include "core/hle/service/hid/controllers/controller_base.h"
14#include "core/settings.h"
13 15
14namespace Service::HID { 16namespace Service::HID {
15class Controller_DebugPad final : public ControllerBase { 17class Controller_DebugPad final : public ControllerBase {
@@ -82,5 +84,10 @@ private:
82 }; 84 };
83 static_assert(sizeof(SharedMemory) == 0x400, "SharedMemory is an invalid size"); 85 static_assert(sizeof(SharedMemory) == 0x400, "SharedMemory is an invalid size");
84 SharedMemory shared_memory{}; 86 SharedMemory shared_memory{};
87
88 std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID>
89 buttons;
90 std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NUM_STICKS_HID>
91 analogs;
85}; 92};
86} // namespace Service::HID 93} // namespace Service::HID