diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 75 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.h | 6 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.cpp | 3 |
3 files changed, 83 insertions, 1 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 0e06468da..631aa6ad2 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | namespace Core::HID { | 12 | namespace Core::HID { |
| 13 | constexpr s32 HID_JOYSTICK_MAX = 0x7fff; | 13 | constexpr s32 HID_JOYSTICK_MAX = 0x7fff; |
| 14 | constexpr s32 HID_TRIGGER_MAX = 0x7fff; | 14 | constexpr s32 HID_TRIGGER_MAX = 0x7fff; |
| 15 | constexpr u32 TURBO_BUTTON_DELAY = 4; | ||
| 15 | // Use a common UUID for TAS and Virtual Gamepad | 16 | // Use a common UUID for TAS and Virtual Gamepad |
| 16 | constexpr Common::UUID TAS_UUID = | 17 | constexpr Common::UUID TAS_UUID = |
| 17 | Common::UUID{{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0xA5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; | 18 | Common::UUID{{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0xA5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; |
| @@ -447,6 +448,7 @@ void EmulatedController::ReloadInput() { | |||
| 447 | }, | 448 | }, |
| 448 | }); | 449 | }); |
| 449 | } | 450 | } |
| 451 | turbo_button_state = 0; | ||
| 450 | } | 452 | } |
| 451 | 453 | ||
| 452 | void EmulatedController::UnloadInput() { | 454 | void EmulatedController::UnloadInput() { |
| @@ -687,6 +689,7 @@ void EmulatedController::SetButton(const Common::Input::CallbackStatus& callback | |||
| 687 | } | 689 | } |
| 688 | 690 | ||
| 689 | current_status.toggle = new_status.toggle; | 691 | current_status.toggle = new_status.toggle; |
| 692 | current_status.turbo = new_status.turbo; | ||
| 690 | current_status.uuid = uuid; | 693 | current_status.uuid = uuid; |
| 691 | 694 | ||
| 692 | // Update button status with current | 695 | // Update button status with current |
| @@ -1548,7 +1551,7 @@ NpadButtonState EmulatedController::GetNpadButtons() const { | |||
| 1548 | if (is_configuring) { | 1551 | if (is_configuring) { |
| 1549 | return {}; | 1552 | return {}; |
| 1550 | } | 1553 | } |
| 1551 | return controller.npad_button_state; | 1554 | return {controller.npad_button_state.raw & GetTurboButtonMask()}; |
| 1552 | } | 1555 | } |
| 1553 | 1556 | ||
| 1554 | DebugPadButton EmulatedController::GetDebugPadButtons() const { | 1557 | DebugPadButton EmulatedController::GetDebugPadButtons() const { |
| @@ -1656,4 +1659,74 @@ void EmulatedController::DeleteCallback(int key) { | |||
| 1656 | } | 1659 | } |
| 1657 | callback_list.erase(iterator); | 1660 | callback_list.erase(iterator); |
| 1658 | } | 1661 | } |
| 1662 | |||
| 1663 | void EmulatedController::TurboButtonUpdate() { | ||
| 1664 | turbo_button_state = (turbo_button_state + 1) % (TURBO_BUTTON_DELAY * 2); | ||
| 1665 | } | ||
| 1666 | |||
| 1667 | NpadButton EmulatedController::GetTurboButtonMask() const { | ||
| 1668 | // Apply no mask when disabled | ||
| 1669 | if (turbo_button_state < TURBO_BUTTON_DELAY) { | ||
| 1670 | return {NpadButton::All}; | ||
| 1671 | } | ||
| 1672 | |||
| 1673 | NpadButtonState button_mask{}; | ||
| 1674 | for (std::size_t index = 0; index < controller.button_values.size(); ++index) { | ||
| 1675 | if (!controller.button_values[index].turbo) { | ||
| 1676 | continue; | ||
| 1677 | } | ||
| 1678 | |||
| 1679 | switch (index) { | ||
| 1680 | case Settings::NativeButton::A: | ||
| 1681 | button_mask.a.Assign(1); | ||
| 1682 | break; | ||
| 1683 | case Settings::NativeButton::B: | ||
| 1684 | button_mask.b.Assign(1); | ||
| 1685 | break; | ||
| 1686 | case Settings::NativeButton::X: | ||
| 1687 | button_mask.x.Assign(1); | ||
| 1688 | break; | ||
| 1689 | case Settings::NativeButton::Y: | ||
| 1690 | button_mask.y.Assign(1); | ||
| 1691 | break; | ||
| 1692 | case Settings::NativeButton::L: | ||
| 1693 | button_mask.l.Assign(1); | ||
| 1694 | break; | ||
| 1695 | case Settings::NativeButton::R: | ||
| 1696 | button_mask.r.Assign(1); | ||
| 1697 | break; | ||
| 1698 | case Settings::NativeButton::ZL: | ||
| 1699 | button_mask.zl.Assign(1); | ||
| 1700 | break; | ||
| 1701 | case Settings::NativeButton::ZR: | ||
| 1702 | button_mask.zr.Assign(1); | ||
| 1703 | break; | ||
| 1704 | case Settings::NativeButton::DLeft: | ||
| 1705 | button_mask.left.Assign(1); | ||
| 1706 | break; | ||
| 1707 | case Settings::NativeButton::DUp: | ||
| 1708 | button_mask.up.Assign(1); | ||
| 1709 | break; | ||
| 1710 | case Settings::NativeButton::DRight: | ||
| 1711 | button_mask.right.Assign(1); | ||
| 1712 | break; | ||
| 1713 | case Settings::NativeButton::DDown: | ||
| 1714 | button_mask.down.Assign(1); | ||
| 1715 | break; | ||
| 1716 | case Settings::NativeButton::SL: | ||
| 1717 | button_mask.left_sl.Assign(1); | ||
| 1718 | button_mask.right_sl.Assign(1); | ||
| 1719 | break; | ||
| 1720 | case Settings::NativeButton::SR: | ||
| 1721 | button_mask.left_sr.Assign(1); | ||
| 1722 | button_mask.right_sr.Assign(1); | ||
| 1723 | break; | ||
| 1724 | default: | ||
| 1725 | break; | ||
| 1726 | } | ||
| 1727 | } | ||
| 1728 | |||
| 1729 | return static_cast<NpadButton>(~button_mask.raw); | ||
| 1730 | } | ||
| 1731 | |||
| 1659 | } // namespace Core::HID | 1732 | } // namespace Core::HID |
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index 3ac77b2b5..b02bf35c4 100644 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h | |||
| @@ -411,6 +411,9 @@ public: | |||
| 411 | */ | 411 | */ |
| 412 | void DeleteCallback(int key); | 412 | void DeleteCallback(int key); |
| 413 | 413 | ||
| 414 | /// Swaps the state of the turbo buttons | ||
| 415 | void TurboButtonUpdate(); | ||
| 416 | |||
| 414 | private: | 417 | private: |
| 415 | /// creates input devices from params | 418 | /// creates input devices from params |
| 416 | void LoadDevices(); | 419 | void LoadDevices(); |
| @@ -511,6 +514,8 @@ private: | |||
| 511 | */ | 514 | */ |
| 512 | void TriggerOnChange(ControllerTriggerType type, bool is_service_update); | 515 | void TriggerOnChange(ControllerTriggerType type, bool is_service_update); |
| 513 | 516 | ||
| 517 | NpadButton GetTurboButtonMask() const; | ||
| 518 | |||
| 514 | const NpadIdType npad_id_type; | 519 | const NpadIdType npad_id_type; |
| 515 | NpadStyleIndex npad_type{NpadStyleIndex::None}; | 520 | NpadStyleIndex npad_type{NpadStyleIndex::None}; |
| 516 | NpadStyleIndex original_npad_type{NpadStyleIndex::None}; | 521 | NpadStyleIndex original_npad_type{NpadStyleIndex::None}; |
| @@ -520,6 +525,7 @@ private: | |||
| 520 | bool system_buttons_enabled{true}; | 525 | bool system_buttons_enabled{true}; |
| 521 | f32 motion_sensitivity{0.01f}; | 526 | f32 motion_sensitivity{0.01f}; |
| 522 | bool force_update_motion{false}; | 527 | bool force_update_motion{false}; |
| 528 | u32 turbo_button_state{0}; | ||
| 523 | 529 | ||
| 524 | // Temporary values to avoid doing changes while the controller is in configuring mode | 530 | // Temporary values to avoid doing changes while the controller is in configuring mode |
| 525 | NpadStyleIndex tmp_npad_type{NpadStyleIndex::None}; | 531 | NpadStyleIndex tmp_npad_type{NpadStyleIndex::None}; |
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 5713f1288..3afda9e3f 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp | |||
| @@ -428,6 +428,9 @@ void Controller_NPad::RequestPadStateUpdate(Core::HID::NpadIdType npad_id) { | |||
| 428 | return; | 428 | return; |
| 429 | } | 429 | } |
| 430 | 430 | ||
| 431 | // This function is unique to yuzu for the turbo buttons to work properly | ||
| 432 | controller.device->TurboButtonUpdate(); | ||
| 433 | |||
| 431 | auto& pad_entry = controller.npad_pad_state; | 434 | auto& pad_entry = controller.npad_pad_state; |
| 432 | auto& trigger_entry = controller.npad_trigger_state; | 435 | auto& trigger_entry = controller.npad_trigger_state; |
| 433 | const auto button_state = controller.device->GetNpadButtons(); | 436 | const auto button_state = controller.device->GetNpadButtons(); |