From 783845c56e9e08e0492d077e7a2bf679d5a3d76e Mon Sep 17 00:00:00 2001 From: Gliniak Date: Tue, 20 Dec 2022 19:33:55 +0100 Subject: [PATCH] [XAM] Cleanup in xam_input. - Added some missing xinput flags - Simplified XamInputGetCapabilities - Replaced hardcoded checks to flag --- src/xenia/kernel/xam/xam_input.cc | 75 +++++++++++++++---------------- src/xenia/xbox.h | 1 + 2 files changed, 36 insertions(+), 40 deletions(-) diff --git a/src/xenia/kernel/xam/xam_input.cc b/src/xenia/kernel/xam/xam_input.cc index e88d4bb06..dc1b8cb53 100644 --- a/src/xenia/kernel/xam/xam_input.cc +++ b/src/xenia/kernel/xam/xam_input.cc @@ -26,6 +26,9 @@ using xe::hid::X_INPUT_STATE; using xe::hid::X_INPUT_VIBRATION; constexpr uint32_t XINPUT_FLAG_GAMEPAD = 0x01; +constexpr uint32_t XINPUT_FLAG_KEYBOARD = 0x02; +constexpr uint32_t XINPUT_FLAG_MIC = 0x20; // Based on "karaoke" titles +constexpr uint32_t XINPUT_FLAG_ANYDEVICE = 0xFF; constexpr uint32_t XINPUT_FLAG_ANY_USER = 1 << 30; void XamResetInactivity_entry() { @@ -39,48 +42,29 @@ dword_result_t XamEnableInactivityProcessing_entry(dword_t unk, } DECLARE_XAM_EXPORT1(XamEnableInactivityProcessing, kInput, kStub); -// https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xinputgetcapabilities(v=vs.85).aspx -dword_result_t XamInputGetCapabilities_entry( - dword_t user_index, dword_t _flags, pointer_t caps) { - unsigned flags = _flags; - //chrispy: actually, it appears that caps is never checked for null, it is memset at the start regardless - if (!caps) { - return X_ERROR_BAD_ARGUMENTS; - } - if ((flags & 0x40000000) != 0) { - //should trap - } - - if ((flags & 4) != 0) { - //should trap - } - - - if ((flags & 0xFF) && (flags & XINPUT_FLAG_GAMEPAD) == 0) { - // Ignore any query for other types of devices. - return X_ERROR_DEVICE_NOT_CONNECTED; - } - - uint32_t actual_user_index = user_index; - if ((actual_user_index & 0xFF) == 0xFF || (flags & XINPUT_FLAG_ANY_USER)) { - // Always pin user to 0. - actual_user_index = 0; - } - - auto input_system = kernel_state()->emulator()->input_system(); - auto lock = input_system->lock(); - return input_system->GetCapabilities(actual_user_index, flags, caps); -} -DECLARE_XAM_EXPORT1(XamInputGetCapabilities, kInput, kSketchy); - dword_result_t XamInputGetCapabilitiesEx_entry( dword_t unk, dword_t user_index, dword_t flags, pointer_t caps) { + if (unk > 1) { + return X_ERROR_NOT_SUPPORTED; + } + + // Fail-safe check if (!caps) { return X_ERROR_BAD_ARGUMENTS; } - if ((flags & 0xFF) && (flags & XINPUT_FLAG_GAMEPAD) == 0) { + caps.Zero(); + + if ((flags & XINPUT_FLAG_ANY_USER) != 0) { + // should trap + } + + if ((flags & 4) != 0) { + // should trap + } + + if ((flags & XINPUT_FLAG_ANYDEVICE) && (flags & XINPUT_FLAG_GAMEPAD) == 0) { // Ignore any query for other types of devices. return X_ERROR_DEVICE_NOT_CONNECTED; } @@ -97,6 +81,15 @@ dword_result_t XamInputGetCapabilitiesEx_entry( } DECLARE_XAM_EXPORT1(XamInputGetCapabilitiesEx, kInput, kSketchy); +// https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xinputgetcapabilities(v=vs.85).aspx +dword_result_t XamInputGetCapabilities_entry( + dword_t user_index, dword_t flags, pointer_t caps) { + // chrispy: actually, it appears that caps is never checked for null, it is + // memset at the start regardless + return XamInputGetCapabilitiesEx_entry(1, user_index, flags, caps); +} +DECLARE_XAM_EXPORT1(XamInputGetCapabilities, kInput, kSketchy); + // https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xinputgetstate(v=vs.85).aspx dword_result_t XamInputGetState_entry(dword_t user_index, dword_t flags, pointer_t input_state) { @@ -109,7 +102,7 @@ dword_result_t XamInputGetState_entry(dword_t user_index, dword_t flags, // Games call this with a NULL state ptr, probably as a query. - if ((flags & 0xFF) && (flags & XINPUT_FLAG_GAMEPAD) == 0) { + if ((flags & XINPUT_FLAG_ANYDEVICE) && (flags & XINPUT_FLAG_GAMEPAD) == 0) { // Ignore any query for other types of devices. return X_ERROR_DEVICE_NOT_CONNECTED; } @@ -128,8 +121,10 @@ dword_result_t XamInputGetState_entry(dword_t user_index, dword_t flags, DECLARE_XAM_EXPORT2(XamInputGetState, kInput, kImplemented, kHighFrequency); // https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xinputsetstate(v=vs.85).aspx -dword_result_t XamInputSetState_entry(dword_t user_index, dword_t flags, /* flags, as far as i can see, is not used*/ - pointer_t vibration) { +dword_result_t XamInputSetState_entry( + dword_t user_index, + dword_t flags, /* flags, as far as i can see, is not used*/ + pointer_t vibration) { if (user_index >= 4) { return X_E_DEVICE_NOT_CONNECTED; } @@ -160,7 +155,7 @@ dword_result_t XamInputGetKeystroke_entry( return X_ERROR_BAD_ARGUMENTS; } - if ((flags & 0xFF) && (flags & XINPUT_FLAG_GAMEPAD) == 0) { + if ((flags & XINPUT_FLAG_ANYDEVICE) && (flags & XINPUT_FLAG_GAMEPAD) == 0) { // Ignore any query for other types of devices. return X_ERROR_DEVICE_NOT_CONNECTED; } @@ -185,7 +180,7 @@ dword_result_t XamInputGetKeystrokeEx_entry( return X_ERROR_BAD_ARGUMENTS; } - if ((flags & 0xFF) && (flags & XINPUT_FLAG_GAMEPAD) == 0) { + if ((flags & XINPUT_FLAG_ANYDEVICE) && (flags & XINPUT_FLAG_GAMEPAD) == 0) { // Ignore any query for other types of devices. return X_ERROR_DEVICE_NOT_CONNECTED; } diff --git a/src/xenia/xbox.h b/src/xenia/xbox.h index 349e40886..5469c86c2 100644 --- a/src/xenia/xbox.h +++ b/src/xenia/xbox.h @@ -90,6 +90,7 @@ typedef uint32_t X_RESULT; #define X_ERROR_ACCESS_DENIED X_RESULT_FROM_WIN32(0x00000005L) #define X_ERROR_INVALID_HANDLE X_RESULT_FROM_WIN32(0x00000006L) #define X_ERROR_NO_MORE_FILES X_RESULT_FROM_WIN32(0x00000012L) +#define X_ERROR_NOT_SUPPORTED X_RESULT_FROM_WIN32(0x00000032L) #define X_ERROR_INVALID_PARAMETER X_RESULT_FROM_WIN32(0x00000057L) #define X_ERROR_INSUFFICIENT_BUFFER X_RESULT_FROM_WIN32(0x0000007AL) #define X_ERROR_INVALID_NAME X_RESULT_FROM_WIN32(0x0000007BL)