diff --git a/src/core/analog_controller.cpp b/src/core/analog_controller.cpp index 09f171e74..0a362cb6e 100644 --- a/src/core/analog_controller.cpp +++ b/src/core/analog_controller.cpp @@ -151,6 +151,12 @@ u32 AnalogController::GetButtonStateBits() const return m_button_state ^ 0xFFFF; } +std::optional AnalogController::GetAnalogInputBytes() const +{ + return m_axis_state[static_cast(Axis::LeftY)] << 24 | m_axis_state[static_cast(Axis::LeftX)] << 16 | + m_axis_state[static_cast(Axis::RightY)] << 8 | m_axis_state[static_cast(Axis::RightX)]; +} + u32 AnalogController::GetVibrationMotorCount() const { return NUM_MOTORS; diff --git a/src/core/analog_controller.h b/src/core/analog_controller.h index 244318dff..a3544ef41 100644 --- a/src/core/analog_controller.h +++ b/src/core/analog_controller.h @@ -62,6 +62,7 @@ public: void SetAxisState(s32 axis_code, float value) override; void SetButtonState(s32 button_code, bool pressed) override; u32 GetButtonStateBits() const override; + std::optional GetAnalogInputBytes() const override; void ResetTransferState() override; bool Transfer(const u8 data_in, u8* data_out) override; diff --git a/src/core/analog_joystick.cpp b/src/core/analog_joystick.cpp index 6fefb96ce..017e996aa 100644 --- a/src/core/analog_joystick.cpp +++ b/src/core/analog_joystick.cpp @@ -115,6 +115,12 @@ u32 AnalogJoystick::GetButtonStateBits() const return m_button_state ^ 0xFFFF; } +std::optional AnalogJoystick::GetAnalogInputBytes() const +{ + return m_axis_state[static_cast(Axis::LeftY)] << 24 | m_axis_state[static_cast(Axis::LeftX)] << 16 | + m_axis_state[static_cast(Axis::RightY)] << 8 | m_axis_state[static_cast(Axis::RightX)]; +} + void AnalogJoystick::ResetTransferState() { m_transfer_state = TransferState::Idle; diff --git a/src/core/analog_joystick.h b/src/core/analog_joystick.h index d960627ac..5816f3b2d 100644 --- a/src/core/analog_joystick.h +++ b/src/core/analog_joystick.h @@ -60,6 +60,7 @@ public: void SetAxisState(s32 axis_code, float value) override; void SetButtonState(s32 button_code, bool pressed) override; u32 GetButtonStateBits() const override; + std::optional GetAnalogInputBytes() const override; void ResetTransferState() override; bool Transfer(const u8 data_in, u8* data_out) override; diff --git a/src/core/controller.cpp b/src/core/controller.cpp index 4d0dc5a5c..4eaee7431 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -35,6 +35,11 @@ u32 Controller::GetButtonStateBits() const return 0; } +std::optional Controller::GetAnalogInputBytes() const +{ + return std::nullopt; +} + u32 Controller::GetVibrationMotorCount() const { return 0; diff --git a/src/core/controller.h b/src/core/controller.h index 5c7a9a9b4..de3d26da5 100644 --- a/src/core/controller.h +++ b/src/core/controller.h @@ -54,6 +54,9 @@ public: /// Returns a bitmask of the current button states, 1 = on. virtual u32 GetButtonStateBits() const; + /// Returns analog input bytes packed as a u32. Values are specific to controller type. + virtual std::optional GetAnalogInputBytes() const; + /// Returns the number of vibration motors. virtual u32 GetVibrationMotorCount() const; diff --git a/src/core/negcon.cpp b/src/core/negcon.cpp index 5afa28507..65e95ebc0 100644 --- a/src/core/negcon.cpp +++ b/src/core/negcon.cpp @@ -97,6 +97,17 @@ void NeGcon::SetButtonState(Button button, bool pressed) m_button_state |= u16(1) << indices[static_cast(button)]; } +u32 NeGcon::GetButtonStateBits() const +{ + return m_button_state ^ 0xFFFF; +} + +std::optional NeGcon::GetAnalogInputBytes() const +{ + return m_axis_state[static_cast(Axis::L)] << 24 | m_axis_state[static_cast(Axis::II)] << 16 | + m_axis_state[static_cast(Axis::I)] << 8 | m_axis_state[static_cast(Axis::Steering)]; +} + void NeGcon::ResetTransferState() { m_transfer_state = TransferState::Idle; diff --git a/src/core/negcon.h b/src/core/negcon.h index 4ed93c1e5..819678166 100644 --- a/src/core/negcon.h +++ b/src/core/negcon.h @@ -57,6 +57,9 @@ public: void SetAxisState(Axis axis, u8 value); void SetButtonState(Button button, bool pressed); + u32 GetButtonStateBits() const override; + std::optional GetAnalogInputBytes() const override; + void LoadSettings(const char* section) override; private: