From 9f09aa725b0bf8b086668b12e8ff01b8a0ae0500 Mon Sep 17 00:00:00 2001 From: Stuart Kenny Date: Mon, 30 May 2022 13:53:45 +0100 Subject: [PATCH] pad: Expose Analog mode button. --- .../ControllerBindingWidget_DualShock2.ui | 290 +++++++++--------- pcsx2/PAD/Host/Global.h | 3 +- pcsx2/PAD/Host/KeyStatus.cpp | 5 +- pcsx2/PAD/Host/KeyStatus.h | 4 +- pcsx2/PAD/Host/PAD.cpp | 1 + pcsx2/PAD/Host/StateManagement.cpp | 16 +- 6 files changed, 161 insertions(+), 158 deletions(-) diff --git a/pcsx2-qt/Settings/ControllerBindingWidget_DualShock2.ui b/pcsx2-qt/Settings/ControllerBindingWidget_DualShock2.ui index 6b6ffe7012..f0f203b8e6 100644 --- a/pcsx2-qt/Settings/ControllerBindingWidget_DualShock2.ui +++ b/pcsx2-qt/Settings/ControllerBindingWidget_DualShock2.ui @@ -397,86 +397,6 @@ - - - - L2 - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - 100 - 0 - - - - - 100 - 16777215 - - - - PushButton - - - - - - - - - - R1 - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - 100 - 0 - - - - - 100 - 16777215 - - - - PushButton - - - - - - @@ -497,12 +417,142 @@ - + 100 - 0 + 16777215 + + PushButton + + + + + + + + + + L2 + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + R1 + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + R2 + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 100 + 16777215 + + + + PushButton + + + + + + + + + + Start + + + + 6 + + + 6 + + + 6 + + + 6 + + + 100 @@ -537,12 +587,6 @@ - - - 100 - 0 - - 100 @@ -557,32 +601,14 @@ - - + + - R2 + Analog - - - 6 - - - 6 - - - 6 - - - 6 - + - - - - 100 - 0 - - + 100 @@ -597,47 +623,7 @@ - - - - Start - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - 100 - 0 - - - - - 100 - 16777215 - - - - PushButton - - - - - - - + Axis Scale diff --git a/pcsx2/PAD/Host/Global.h b/pcsx2/PAD/Host/Global.h index f7fef15e61..58793cbc94 100644 --- a/pcsx2/PAD/Host/Global.h +++ b/pcsx2/PAD/Host/Global.h @@ -28,7 +28,7 @@ #include "common/Pcsx2Defs.h" static const u32 GAMEPAD_NUMBER = 2; -static const u32 MAX_KEYS = 24; +static const u32 MAX_KEYS = 25; enum gamePadValues { @@ -48,6 +48,7 @@ enum gamePadValues PAD_R2, // R2 button PAD_L3, // Left joystick button (L3) PAD_R3, // Right joystick button (R3) + PAD_ANALOG, // Analog mode toggle PAD_L_UP, // Left joystick (Up) ↑ PAD_L_RIGHT, // Left joystick (Right) → PAD_L_DOWN, // Left joystick (Down) ↓ diff --git a/pcsx2/PAD/Host/KeyStatus.cpp b/pcsx2/PAD/Host/KeyStatus.cpp index e94d70f30f..cdad4d38e7 100644 --- a/pcsx2/PAD/Host/KeyStatus.cpp +++ b/pcsx2/PAD/Host/KeyStatus.cpp @@ -31,7 +31,7 @@ void KeyStatus::Init() { for (u32 pad = 0; pad < GAMEPAD_NUMBER; pad++) { - m_button[pad] = 0xFFFF; + m_button[pad] = 0xFFFFFFFF; for (u32 index = 0; index < MAX_KEYS; index++) m_button_pressure[pad][index] = 0; @@ -107,6 +107,7 @@ void KeyStatus::Set(u32 pad, u32 index, float value) 1, // PAD_R2 9, // PAD_L3 10, // PAD_R3 + 16, // Analog // remainder are analogs and not used here } }; @@ -118,7 +119,7 @@ void KeyStatus::Set(u32 pad, u32 index, float value) } } -u16 KeyStatus::GetButtons(u32 pad) +u32 KeyStatus::GetButtons(u32 pad) { return m_button[pad]; } diff --git a/pcsx2/PAD/Host/KeyStatus.h b/pcsx2/PAD/Host/KeyStatus.h index d2b543d543..163440384d 100644 --- a/pcsx2/PAD/Host/KeyStatus.h +++ b/pcsx2/PAD/Host/KeyStatus.h @@ -28,7 +28,7 @@ private: u8 rx, ry; }; - u16 m_button[GAMEPAD_NUMBER]; + u32 m_button[GAMEPAD_NUMBER]; u8 m_button_pressure[GAMEPAD_NUMBER][MAX_KEYS]; PADAnalog m_analog[GAMEPAD_NUMBER]; float m_axis_scale[GAMEPAD_NUMBER]; @@ -44,7 +44,7 @@ public: __fi float GetVibrationScale(u32 pad, u32 motor) const { return m_vibration_scale[pad][motor]; } __fi void SetVibrationScale(u32 pad, u32 motor, float scale) { m_vibration_scale[pad][motor] = scale; } - u16 GetButtons(u32 pad); + u32 GetButtons(u32 pad); u8 GetPressure(u32 pad, u32 index); }; diff --git a/pcsx2/PAD/Host/PAD.cpp b/pcsx2/PAD/Host/PAD.cpp index 7557d0b06c..ee05d13aac 100644 --- a/pcsx2/PAD/Host/PAD.cpp +++ b/pcsx2/PAD/Host/PAD.cpp @@ -303,6 +303,7 @@ static const ControllerBindingInfo s_dualshock2_binds[] = { {"R2", GenericInputBinding::R2 }, {"L3", GenericInputBinding::L3 }, {"R3", GenericInputBinding::R3 }, + {"Analog", GenericInputBinding::System}, {"LUp", GenericInputBinding::LeftStickUp }, {"LRight", GenericInputBinding::LeftStickRight }, {"LDown", GenericInputBinding::LeftStickDown }, diff --git a/pcsx2/PAD/Host/StateManagement.cpp b/pcsx2/PAD/Host/StateManagement.cpp index b2530202c9..e48ab51620 100644 --- a/pcsx2/PAD/Host/StateManagement.cpp +++ b/pcsx2/PAD/Host/StateManagement.cpp @@ -241,7 +241,21 @@ u8 pad_poll(u8 value) b1=b1 & 0x1f; #endif - uint16_t buttons = g_key_status.GetButtons(query.port); + uint32_t buttons = g_key_status.GetButtons(query.port); + if (!test_bit(buttons, PAD_ANALOG) && !pad->modeLock) + { + switch (pad->mode) + { + case MODE_ANALOG: + case MODE_DS2_NATIVE: + pad->set_mode(MODE_DIGITAL); + break; + case MODE_DIGITAL: + default: + pad->set_mode(MODE_ANALOG); + break; + } + } query.numBytes = 5;