From 64a3e69cce84bad0a86e6baa55ffe6b0cc621720 Mon Sep 17 00:00:00 2001 From: zilmar Date: Tue, 7 Jul 2020 11:56:40 +0930 Subject: [PATCH] Project64-input: Get axis on GetKeys --- Source/Project64-input/CProject64Input.cpp | 2 ++ Source/Project64-input/DirectInput.cpp | 29 ++++++++++++++++++++++ Source/Project64-input/DirectInput.h | 1 + 3 files changed, 32 insertions(+) diff --git a/Source/Project64-input/CProject64Input.cpp b/Source/Project64-input/CProject64Input.cpp index f45450bd1..480c57fee 100644 --- a/Source/Project64-input/CProject64Input.cpp +++ b/Source/Project64-input/CProject64Input.cpp @@ -63,6 +63,8 @@ void CProject64Input::GetKeys(int32_t Control, BUTTONS * Keys) Keys->U_CBUTTON = m_DirectInput->IsButtonPressed(Controller.U_CBUTTON); Keys->R_TRIG = m_DirectInput->IsButtonPressed(Controller.R_TRIG); Keys->L_TRIG = m_DirectInput->IsButtonPressed(Controller.L_TRIG); + Keys->Y_AXIS = m_DirectInput->AxisPos(Controller.U_ANALOG, Controller.D_ANALOG, Controller.Range); + Keys->X_AXIS = m_DirectInput->AxisPos(Controller.R_ANALOG, Controller.L_ANALOG, Controller.Range); } void CProject64Input::StartScanDevices(int32_t DisplayCtrlId) diff --git a/Source/Project64-input/DirectInput.cpp b/Source/Project64-input/DirectInput.cpp index 743e804d9..e53e0cbc3 100644 --- a/Source/Project64-input/DirectInput.cpp +++ b/Source/Project64-input/DirectInput.cpp @@ -230,6 +230,35 @@ bool CDirectInput::IsButtonPressed(BUTTON & Button) return false; } +int8_t CDirectInput::AxisPos(BUTTON & PosBtn, BUTTON & NegBtn, uint8_t Range) +{ + int8_t Pos = 0; + if (PosBtn.Device != nullptr) + { + DEVICE & Device = *(DEVICE *)PosBtn.Device; + switch (PosBtn.BtnType) + { + case BTNTYPE_KEYBUTTON: + Pos += (Device.State.Keyboard[PosBtn.Offset] & 0x80) != 0 ? 127 : 0; + } + } + if (NegBtn.Device != nullptr) + { + DEVICE & Device = *(DEVICE *)NegBtn.Device; + switch (NegBtn.BtnType) + { + case BTNTYPE_KEYBUTTON: + Pos -= (Device.State.Keyboard[NegBtn.Offset] & 0x80) != 0 ? 127 : 0; + } + } + + if (Pos != 0) + { + Pos = (int8_t)(Pos * (Range / 100.0)); + } + return Pos; +} + void CDirectInput::UpdateDeviceData(void) { for (DEVICE_MAP::iterator itr = m_Devices.begin(); itr != m_Devices.end(); itr++) diff --git a/Source/Project64-input/DirectInput.h b/Source/Project64-input/DirectInput.h index b33178a73..709469d16 100644 --- a/Source/Project64-input/DirectInput.h +++ b/Source/Project64-input/DirectInput.h @@ -26,6 +26,7 @@ public: ScanResult ScanDevices(BUTTON & Button); std::wstring ButtonAssignment(BUTTON & Button); bool IsButtonPressed(BUTTON & Button); + int8_t AxisPos(BUTTON & PosBtn, BUTTON & NegBtn, uint8_t Range); void UpdateDeviceData(void); private: