From 0aa29428e11f1fe8ed982bcfd8fa288a9ac9c4d9 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Sat, 15 Jun 2024 18:43:01 +0300 Subject: [PATCH 01/11] new pad module structured using modulegenerator , added common pad structures and function signatures --- src/core/libraries/libs.cpp | 2 +- src/core/libraries/pad/old_pad.cpp | 126 ++++++ src/core/libraries/pad/old_pad.h | 128 ++++++ src/core/libraries/pad/pad.cpp | 656 ++++++++++++++++++++++++----- src/core/libraries/pad/pad.h | 343 +++++++++++---- src/sdl_window.cpp | 20 +- 6 files changed, 1090 insertions(+), 185 deletions(-) create mode 100644 src/core/libraries/pad/old_pad.cpp create mode 100644 src/core/libraries/pad/old_pad.h diff --git a/src/core/libraries/libs.cpp b/src/core/libraries/libs.cpp index b4c77f90..f163a9d8 100644 --- a/src/core/libraries/libs.cpp +++ b/src/core/libraries/libs.cpp @@ -40,7 +40,6 @@ void InitHLELibs(Core::Loader::SymbolsResolver* sym) { Libraries::Kernel::LibKernel_Register(sym); Libraries::VideoOut::RegisterLib(sym); Libraries::GnmDriver::RegisterlibSceGnmDriver(sym); - Libraries::LibPad::padSymbolsRegister(sym); if (!Config::isLleLibc()) { Libraries::LibC::libcSymbolsRegister(sym); } @@ -71,6 +70,7 @@ void InitHLELibs(Core::Loader::SymbolsResolver* sym) { Libraries::PngDec::RegisterlibScePngDec(sym); Libraries::PlayGo::RegisterlibScePlayGo(sym); Libraries::Usbd::RegisterlibSceUsbd(sym); + Libraries::Pad::RegisterlibScePad(sym); } } // namespace Libraries diff --git a/src/core/libraries/pad/old_pad.cpp b/src/core/libraries/pad/old_pad.cpp new file mode 100644 index 00000000..e2f73afe --- /dev/null +++ b/src/core/libraries/pad/old_pad.cpp @@ -0,0 +1,126 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "common/logging/log.h" +#include "common/singleton.h" +#include "core/libraries/error_codes.h" +#include "core/libraries/libs.h" +#include "core/libraries/pad/pad.h" +#include "input/controller.h" + +namespace Libraries::LibPad { + +int PS4_SYSV_ABI scePadInit() { + LOG_WARNING(Lib_Pad, "(DUMMY) called"); + return SCE_OK; +} + +int PS4_SYSV_ABI scePadOpen(Libraries::UserService::OrbisUserServiceUserId user_id, s32 type, + s32 index, const ScePadOpenParam* pParam) { + LOG_INFO(Lib_Pad, "(DUMMY) called user_id = {} type = {} index = {}", user_id, type, index); + return 1; // dummy +} + +int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) { + auto* controller = Common::Singleton::Instance(); + + int connectedCount = 0; + bool isConnected = false; + Input::State state; + + controller->readState(&state, &isConnected, &connectedCount); + pData->buttons = state.buttonsState; + pData->leftStick.x = 128; // dummy + pData->leftStick.y = 128; // dummy + pData->rightStick.x = 0; // dummy + pData->rightStick.y = 0; // dummy + pData->analogButtons.r2 = 0; // dummy + pData->analogButtons.l2 = 0; // dummy + pData->orientation.x = 0; + pData->orientation.y = 0; + pData->orientation.z = 0; + pData->orientation.w = 0; + pData->timestamp = state.time; + pData->connected = true; // isConnected; //TODO fix me proper + pData->connectedCount = 1; // connectedCount; + pData->deviceUniqueDataLen = 0; + + return SCE_OK; +} + +int PS4_SYSV_ABI scePadRead(int handle, ScePadData* pData, int num) { + int connected_count = 0; + bool connected = false; + Input::State states[64]; + auto* controller = Common::Singleton::Instance(); + int ret_num = controller->ReadStates(states, num, &connected, &connected_count); + + if (!connected) { + ret_num = 1; + } + + for (int i = 0; i < ret_num; i++) { + pData[i].buttons = states[i].buttonsState; + pData[i].leftStick.x = 128; // dummy + pData[i].leftStick.y = 128; // dummy + pData[i].rightStick.x = 0; // dummy + pData[i].rightStick.y = 0; // dummy + pData[i].analogButtons.l2 = 0; // dummy + pData[i].analogButtons.r2 = 0; // dummy + pData[i].orientation.x = 0.0f; + pData[i].orientation.y = 0.0f; + pData[i].orientation.z = 0.0f; + pData[i].orientation.w = 1.0f; + pData[i].acceleration.x = 0.0f; + pData[i].acceleration.y = 0.0f; + pData[i].acceleration.z = 0.0f; + pData[i].angularVelocity.x = 0.0f; + pData[i].angularVelocity.y = 0.0f; + pData[i].angularVelocity.z = 0.0f; + pData[i].touchData.touchNum = 0; + pData[i].touchData.touch[0].x = 0; + pData[i].touchData.touch[0].y = 0; + pData[i].touchData.touch[0].id = 1; + pData[i].touchData.touch[1].x = 0; + pData[i].touchData.touch[1].y = 0; + pData[i].touchData.touch[1].id = 2; + pData[i].connected = connected; + pData[i].timestamp = states[i].time; + pData[i].connectedCount = connected_count; + pData[i].deviceUniqueDataLen = 0; + } + + return ret_num; +} + +s32 PS4_SYSV_ABI scePadGetControllerInformation(s32 handle, OrbisPadInformation* info) { + LOG_INFO(Lib_Pad, "called handle = {}", handle); + info->touchpadDensity = 1; + info->touchResolutionX = 1920; + info->touchResolutionY = 950; + info->stickDeadzoneL = 2; + info->stickDeadzoneR = 2; + info->connectionType = ORBIS_PAD_CONNECTION_TYPE_STANDARD; + info->count = 1; + info->connected = 1; + info->deviceClass = ORBIS_PAD_PORT_TYPE_STANDARD; + return SCE_OK; +} + +s32 PS4_SYSV_ABI scePadSetMotionSensorState(s32 handle, bool enable) { + LOG_INFO(Lib_Pad, "(DUMMY) called handle = {} enabled = {}", handle, + (enable ? "true" : "false")); + return SCE_OK; +} + +void padSymbolsRegister(Core::Loader::SymbolsResolver* sym) { + LIB_FUNCTION("hv1luiJrqQM", "libScePad", 1, "libScePad", 1, 1, scePadInit); + LIB_FUNCTION("xk0AcarP3V4", "libScePad", 1, "libScePad", 1, 1, scePadOpen); + LIB_FUNCTION("YndgXqQVV7c", "libScePad", 1, "libScePad", 1, 1, scePadReadState); + LIB_FUNCTION("q1cHNfGycLI", "libScePad", 1, "libScePad", 1, 1, scePadRead); + + LIB_FUNCTION("gjP9-KQzoUk", "libScePad", 1, "libScePad", 1, 1, scePadGetControllerInformation); + LIB_FUNCTION("clVvL4ZDntw", "libScePad", 1, "libScePad", 1, 1, scePadSetMotionSensorState); +} + +} // namespace Libraries::LibPad diff --git a/src/core/libraries/pad/old_pad.h b/src/core/libraries/pad/old_pad.h new file mode 100644 index 00000000..7895da7e --- /dev/null +++ b/src/core/libraries/pad/old_pad.h @@ -0,0 +1,128 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "common/types.h" +#include "src/core/libraries/system/userservice.h" + +namespace Core::Loader { +class SymbolsResolver; +} + +namespace Libraries::LibPad { + +constexpr s8 ORBIS_PAD_PORT_TYPE_STANDARD = 0; +constexpr s8 ORBIS_PAD_PORT_TYPE_SPECIAL = 2; + +constexpr s8 ORBIS_PAD_DEVICE_CLASS_PAD = 0; +constexpr s8 ORBIS_PAD_DEVICE_CLASS_GUITAR = 1; +constexpr s8 ORBIS_PAD_DEVICE_CLASS_DRUMS = 2; + +constexpr s8 ORBIS_PAD_CONNECTION_TYPE_STANDARD = 0; +constexpr s8 ORBIS_PAD_CONNECTION_TYPE_REMOTE = 2; + +enum ScePadButton : u32 { + L3 = 0x00000002, + R3 = 0x00000004, + OPTIONS = 0x00000008, + UP = 0x00000010, + RIGHT = 0x00000020, + DOWN = 0x00000040, + LEFT = 0x00000080, + L2 = 0x00000100, + R2 = 0x00000200, + L1 = 0x00000400, + R1 = 0x00000800, + TRIANGLE = 0x00001000, + CIRCLE = 0x00002000, + CROSS = 0x00004000, + SQUARE = 0x00008000, + TOUCH_PAD = 0x00100000, + INTERCEPTED = 0x80000000, +}; + +struct ScePadOpenParam { + u8 reserve[8]; +}; + +struct ScePadAnalogStick { + u8 x; + u8 y; +}; +struct ScePadAnalogButtons { + u8 l2; + u8 r2; + u8 padding[2]; +}; + +struct SceFQuaternion { + float x, y, z, w; +}; + +struct SceFVector3 { + float x, y, z; +}; + +struct ScePadTouch { + u16 x; + u16 y; + u8 id; + u8 reserve[3]; +}; + +constexpr int SCE_PAD_MAX_TOUCH_NUM = 2; + +typedef struct ScePadTouchData { + u8 touchNum; + u8 reserve[3]; + u32 reserve1; + ScePadTouch touch[SCE_PAD_MAX_TOUCH_NUM]; +} ScePadTouchData; + +struct ScePadExtensionUnitData { + u32 extensionUnitId; + u8 reserve[1]; + u8 dataLength; + u8 data[10]; +}; + +struct ScePadData { + u32 buttons; + ScePadAnalogStick leftStick; + ScePadAnalogStick rightStick; + ScePadAnalogButtons analogButtons; + SceFQuaternion orientation; + SceFVector3 acceleration; + SceFVector3 angularVelocity; + ScePadTouchData touchData; + bool connected; + u64 timestamp; + ScePadExtensionUnitData extensionUnitData; + uint8_t connectedCount; + uint8_t reserve[2]; + uint8_t deviceUniqueDataLen; + uint8_t deviceUniqueData[12]; +}; + +struct OrbisPadInformation { + float touchpadDensity; + u16 touchResolutionX; + u16 touchResolutionY; + u8 stickDeadzoneL; + u8 stickDeadzoneR; + u8 connectionType; + u8 count; + s8 connected; + s8 deviceClass; + u8 unknown[8]; +}; + +int PS4_SYSV_ABI scePadInit(); +int PS4_SYSV_ABI scePadOpen(Libraries::UserService::OrbisUserServiceUserId userId, s32 type, + s32 index, const ScePadOpenParam* pParam); +int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData); + +void padSymbolsRegister(Core::Loader::SymbolsResolver* sym); + +}; // namespace Libraries::LibPad diff --git a/src/core/libraries/pad/pad.cpp b/src/core/libraries/pad/pad.cpp index e2f73afe..fc927f52 100644 --- a/src/core/libraries/pad/pad.cpp +++ b/src/core/libraries/pad/pad.cpp @@ -1,126 +1,580 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +// Generated By moduleGenerator #include "common/logging/log.h" -#include "common/singleton.h" #include "core/libraries/error_codes.h" #include "core/libraries/libs.h" -#include "core/libraries/pad/pad.h" -#include "input/controller.h" +#include "pad.h" -namespace Libraries::LibPad { +namespace Libraries::Pad { + +int PS4_SYSV_ABI scePadClose(s32 handle) { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadConnectPort() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadDeviceClassGetExtendedInformation( + s32 handle, OrbisPadDeviceClassExtendedInformation* pExtInfo) { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadDeviceClassParseData(s32 handle, const OrbisPadData* pData, + OrbisPadDeviceClassData* pDeviceClassData) { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadDeviceOpen() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadDisableVibration() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadDisconnectDevice() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadDisconnectPort() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadEnableAutoDetect() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadEnableExtensionPort() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadEnableSpecificDeviceClass() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadEnableUsbConnection() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadGetBluetoothAddress() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadGetCapability() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadGetControllerInformation(s32 handle, OrbisPadControllerInformation* pInfo) { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadGetDataInternal() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadGetDeviceId() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadGetDeviceInfo() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadGetExtControllerInformation() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadGetExtensionUnitInfo() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadGetFeatureReport() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadGetHandle(s32 userId, s32 type, s32 index) { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadGetIdleCount() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadGetInfo() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadGetInfoByPortType() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadGetLicenseControllerInformation() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadGetMotionSensorPosition() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadGetMotionTimerUnit() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadGetSphereRadius() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadGetVersionInfo() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} int PS4_SYSV_ABI scePadInit() { - LOG_WARNING(Lib_Pad, "(DUMMY) called"); - return SCE_OK; + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; } -int PS4_SYSV_ABI scePadOpen(Libraries::UserService::OrbisUserServiceUserId user_id, s32 type, - s32 index, const ScePadOpenParam* pParam) { - LOG_INFO(Lib_Pad, "(DUMMY) called user_id = {} type = {} index = {}", user_id, type, index); - return 1; // dummy +int PS4_SYSV_ABI scePadIsBlasterConnected() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; } -int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) { - auto* controller = Common::Singleton::Instance(); - - int connectedCount = 0; - bool isConnected = false; - Input::State state; - - controller->readState(&state, &isConnected, &connectedCount); - pData->buttons = state.buttonsState; - pData->leftStick.x = 128; // dummy - pData->leftStick.y = 128; // dummy - pData->rightStick.x = 0; // dummy - pData->rightStick.y = 0; // dummy - pData->analogButtons.r2 = 0; // dummy - pData->analogButtons.l2 = 0; // dummy - pData->orientation.x = 0; - pData->orientation.y = 0; - pData->orientation.z = 0; - pData->orientation.w = 0; - pData->timestamp = state.time; - pData->connected = true; // isConnected; //TODO fix me proper - pData->connectedCount = 1; // connectedCount; - pData->deviceUniqueDataLen = 0; - - return SCE_OK; +int PS4_SYSV_ABI scePadIsDS4Connected() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; } -int PS4_SYSV_ABI scePadRead(int handle, ScePadData* pData, int num) { - int connected_count = 0; - bool connected = false; - Input::State states[64]; - auto* controller = Common::Singleton::Instance(); - int ret_num = controller->ReadStates(states, num, &connected, &connected_count); - - if (!connected) { - ret_num = 1; - } - - for (int i = 0; i < ret_num; i++) { - pData[i].buttons = states[i].buttonsState; - pData[i].leftStick.x = 128; // dummy - pData[i].leftStick.y = 128; // dummy - pData[i].rightStick.x = 0; // dummy - pData[i].rightStick.y = 0; // dummy - pData[i].analogButtons.l2 = 0; // dummy - pData[i].analogButtons.r2 = 0; // dummy - pData[i].orientation.x = 0.0f; - pData[i].orientation.y = 0.0f; - pData[i].orientation.z = 0.0f; - pData[i].orientation.w = 1.0f; - pData[i].acceleration.x = 0.0f; - pData[i].acceleration.y = 0.0f; - pData[i].acceleration.z = 0.0f; - pData[i].angularVelocity.x = 0.0f; - pData[i].angularVelocity.y = 0.0f; - pData[i].angularVelocity.z = 0.0f; - pData[i].touchData.touchNum = 0; - pData[i].touchData.touch[0].x = 0; - pData[i].touchData.touch[0].y = 0; - pData[i].touchData.touch[0].id = 1; - pData[i].touchData.touch[1].x = 0; - pData[i].touchData.touch[1].y = 0; - pData[i].touchData.touch[1].id = 2; - pData[i].connected = connected; - pData[i].timestamp = states[i].time; - pData[i].connectedCount = connected_count; - pData[i].deviceUniqueDataLen = 0; - } - - return ret_num; +int PS4_SYSV_ABI scePadIsLightBarBaseBrightnessControllable() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; } -s32 PS4_SYSV_ABI scePadGetControllerInformation(s32 handle, OrbisPadInformation* info) { - LOG_INFO(Lib_Pad, "called handle = {}", handle); - info->touchpadDensity = 1; - info->touchResolutionX = 1920; - info->touchResolutionY = 950; - info->stickDeadzoneL = 2; - info->stickDeadzoneR = 2; - info->connectionType = ORBIS_PAD_CONNECTION_TYPE_STANDARD; - info->count = 1; - info->connected = 1; - info->deviceClass = ORBIS_PAD_PORT_TYPE_STANDARD; - return SCE_OK; +int PS4_SYSV_ABI scePadIsMoveConnected() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; } -s32 PS4_SYSV_ABI scePadSetMotionSensorState(s32 handle, bool enable) { - LOG_INFO(Lib_Pad, "(DUMMY) called handle = {} enabled = {}", handle, - (enable ? "true" : "false")); - return SCE_OK; +int PS4_SYSV_ABI scePadIsMoveReproductionModel() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; } -void padSymbolsRegister(Core::Loader::SymbolsResolver* sym) { - LIB_FUNCTION("hv1luiJrqQM", "libScePad", 1, "libScePad", 1, 1, scePadInit); - LIB_FUNCTION("xk0AcarP3V4", "libScePad", 1, "libScePad", 1, 1, scePadOpen); - LIB_FUNCTION("YndgXqQVV7c", "libScePad", 1, "libScePad", 1, 1, scePadReadState); - LIB_FUNCTION("q1cHNfGycLI", "libScePad", 1, "libScePad", 1, 1, scePadRead); +int PS4_SYSV_ABI scePadIsValidHandle() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} +int PS4_SYSV_ABI scePadMbusInit() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadMbusTerm() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadOpen(s32 userId, s32 type, s32 index, const OrbisPadOpenParam* pParam) { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadOpenExt() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadOpenExt2() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadOutputReport() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadRead(s32 handle, OrbisPadData* pData, s32 num) { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadReadBlasterForTracker() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadReadExt() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadReadForTracker() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadReadHistory() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadReadState(s32 handle, OrbisPadData* pData) { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadReadStateExt() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadResetLightBar(s32 handle) { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadResetLightBarAll() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadResetLightBarAllByPortType() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadResetOrientation(s32 handle) { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadResetOrientationForTracker() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetAngularVelocityDeadbandState(s32 handle, bool bEnable) { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetAutoPowerOffCount() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetButtonRemappingInfo() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetConnection() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetExtensionReport() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetFeatureReport() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetForceIntercepted() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetLightBar(s32 handle, const OrbisPadLightBarParam* pParam) { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetLightBarBaseBrightness() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetLightBarBlinking() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetLightBarForTracker() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetLoginUserNumber() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetMotionSensorState(s32 handle, bool bEnable) { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetProcessFocus() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetProcessPrivilege() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetProcessPrivilegeOfButtonRemapping() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetShareButtonMaskForRemotePlay() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetTiltCorrectionState(s32 handle, bool bEnable) { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetUserColor() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetVibration(s32 handle, const OrbisPadVibrationParam* pParam) { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetVibrationForce() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSetVrTrackingMode() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadShareOutputData() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadStartRecording() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadStopRecording() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadSwitchConnection() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadVertualDeviceAddDevice() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadVirtualDeviceAddDevice() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadVirtualDeviceDeleteDevice() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadVirtualDeviceDisableButtonRemapping() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadVirtualDeviceGetRemoteSetting() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI scePadVirtualDeviceInsertData() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI Func_28B998C7D8A3DA1D() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI Func_298D21481F94C9FA() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI Func_51E514BCD3A05CA5() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI Func_89C9237E393DA243() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI Func_EF103E845B6F0420() { + LOG_ERROR(Lib_Pad, "(STUBBED) called"); + return ORBIS_OK; +} + +void RegisterlibScePad(Core::Loader::SymbolsResolver* sym) { + LIB_FUNCTION("6ncge5+l5Qs", "libScePad", 1, "libScePad", 1, 1, scePadClose); + LIB_FUNCTION("kazv1NzSB8c", "libScePad", 1, "libScePad", 1, 1, scePadConnectPort); + LIB_FUNCTION("AcslpN1jHR8", "libScePad", 1, "libScePad", 1, 1, + scePadDeviceClassGetExtendedInformation); + LIB_FUNCTION("IHPqcbc0zCA", "libScePad", 1, "libScePad", 1, 1, scePadDeviceClassParseData); + LIB_FUNCTION("d7bXuEBycDI", "libScePad", 1, "libScePad", 1, 1, scePadDeviceOpen); + LIB_FUNCTION("0aziJjRZxqQ", "libScePad", 1, "libScePad", 1, 1, scePadDisableVibration); + LIB_FUNCTION("pnZXireDoeI", "libScePad", 1, "libScePad", 1, 1, scePadDisconnectDevice); + LIB_FUNCTION("9ez71nWSvD0", "libScePad", 1, "libScePad", 1, 1, scePadDisconnectPort); + LIB_FUNCTION("77ooWxGOIVs", "libScePad", 1, "libScePad", 1, 1, scePadEnableAutoDetect); + LIB_FUNCTION("+cE4Jx431wc", "libScePad", 1, "libScePad", 1, 1, scePadEnableExtensionPort); + LIB_FUNCTION("E1KEw5XMGQQ", "libScePad", 1, "libScePad", 1, 1, scePadEnableSpecificDeviceClass); + LIB_FUNCTION("DD-KiRLBqkQ", "libScePad", 1, "libScePad", 1, 1, scePadEnableUsbConnection); + LIB_FUNCTION("Q66U8FdrMaw", "libScePad", 1, "libScePad", 1, 1, scePadGetBluetoothAddress); + LIB_FUNCTION("qtasqbvwgV4", "libScePad", 1, "libScePad", 1, 1, scePadGetCapability); LIB_FUNCTION("gjP9-KQzoUk", "libScePad", 1, "libScePad", 1, 1, scePadGetControllerInformation); + LIB_FUNCTION("Uq6LgTJEmQs", "libScePad", 1, "libScePad", 1, 1, scePadGetDataInternal); + LIB_FUNCTION("hDgisSGkOgw", "libScePad", 1, "libScePad", 1, 1, scePadGetDeviceId); + LIB_FUNCTION("4rS5zG7RFaM", "libScePad", 1, "libScePad", 1, 1, scePadGetDeviceInfo); + LIB_FUNCTION("hGbf2QTBmqc", "libScePad", 1, "libScePad", 1, 1, + scePadGetExtControllerInformation); + LIB_FUNCTION("1DmZjZAuzEM", "libScePad", 1, "libScePad", 1, 1, scePadGetExtensionUnitInfo); + LIB_FUNCTION("PZSoY8j0Pko", "libScePad", 1, "libScePad", 1, 1, scePadGetFeatureReport); + LIB_FUNCTION("u1GRHp+oWoY", "libScePad", 1, "libScePad", 1, 1, scePadGetHandle); + LIB_FUNCTION("kiA9bZhbnAg", "libScePad", 1, "libScePad", 1, 1, scePadGetIdleCount); + LIB_FUNCTION("1Odcw19nADw", "libScePad", 1, "libScePad", 1, 1, scePadGetInfo); + LIB_FUNCTION("4x5Im8pr0-4", "libScePad", 1, "libScePad", 1, 1, scePadGetInfoByPortType); + LIB_FUNCTION("vegw8qax5MI", "libScePad", 1, "libScePad", 1, 1, + scePadGetLicenseControllerInformation); + LIB_FUNCTION("WPIB7zBWxVE", "libScePad", 1, "libScePad", 1, 1, scePadGetMotionSensorPosition); + LIB_FUNCTION("k4+nDV9vbT0", "libScePad", 1, "libScePad", 1, 1, scePadGetMotionTimerUnit); + LIB_FUNCTION("do-JDWX+zRs", "libScePad", 1, "libScePad", 1, 1, scePadGetSphereRadius); + LIB_FUNCTION("QuOaoOcSOw0", "libScePad", 1, "libScePad", 1, 1, scePadGetVersionInfo); + LIB_FUNCTION("hv1luiJrqQM", "libScePad", 1, "libScePad", 1, 1, scePadInit); + LIB_FUNCTION("bi0WNvZ1nug", "libScePad", 1, "libScePad", 1, 1, scePadIsBlasterConnected); + LIB_FUNCTION("mEC+xJKyIjQ", "libScePad", 1, "libScePad", 1, 1, scePadIsDS4Connected); + LIB_FUNCTION("d2Qk-i8wGak", "libScePad", 1, "libScePad", 1, 1, + scePadIsLightBarBaseBrightnessControllable); + LIB_FUNCTION("4y9RNPSBsqg", "libScePad", 1, "libScePad", 1, 1, scePadIsMoveConnected); + LIB_FUNCTION("9e56uLgk5y0", "libScePad", 1, "libScePad", 1, 1, scePadIsMoveReproductionModel); + LIB_FUNCTION("pFTi-yOrVeQ", "libScePad", 1, "libScePad", 1, 1, scePadIsValidHandle); + LIB_FUNCTION("CfwUlQtCFi4", "libScePad", 1, "libScePad", 1, 1, scePadMbusInit); + LIB_FUNCTION("s7CvzS+9ZIs", "libScePad", 1, "libScePad", 1, 1, scePadMbusTerm); + LIB_FUNCTION("xk0AcarP3V4", "libScePad", 1, "libScePad", 1, 1, scePadOpen); + LIB_FUNCTION("WFIiSfXGUq8", "libScePad", 1, "libScePad", 1, 1, scePadOpenExt); + LIB_FUNCTION("71E9e6n+2R8", "libScePad", 1, "libScePad", 1, 1, scePadOpenExt2); + LIB_FUNCTION("DrUu8cPrje8", "libScePad", 1, "libScePad", 1, 1, scePadOutputReport); + LIB_FUNCTION("q1cHNfGycLI", "libScePad", 1, "libScePad", 1, 1, scePadRead); + LIB_FUNCTION("fm1r2vv5+OU", "libScePad", 1, "libScePad", 1, 1, scePadReadBlasterForTracker); + LIB_FUNCTION("QjwkT2Ycmew", "libScePad", 1, "libScePad", 1, 1, scePadReadExt); + LIB_FUNCTION("2NhkFTRnXHk", "libScePad", 1, "libScePad", 1, 1, scePadReadForTracker); + LIB_FUNCTION("3u4M8ck9vJM", "libScePad", 1, "libScePad", 1, 1, scePadReadHistory); + LIB_FUNCTION("YndgXqQVV7c", "libScePad", 1, "libScePad", 1, 1, scePadReadState); + LIB_FUNCTION("5Wf4q349s+Q", "libScePad", 1, "libScePad", 1, 1, scePadReadStateExt); + LIB_FUNCTION("DscD1i9HX1w", "libScePad", 1, "libScePad", 1, 1, scePadResetLightBar); + LIB_FUNCTION("+4c9xRLmiXQ", "libScePad", 1, "libScePad", 1, 1, scePadResetLightBarAll); + LIB_FUNCTION("+Yp6+orqf1M", "libScePad", 1, "libScePad", 1, 1, + scePadResetLightBarAllByPortType); + LIB_FUNCTION("rIZnR6eSpvk", "libScePad", 1, "libScePad", 1, 1, scePadResetOrientation); + LIB_FUNCTION("jbAqAvLEP4A", "libScePad", 1, "libScePad", 1, 1, + scePadResetOrientationForTracker); + LIB_FUNCTION("r44mAxdSG+U", "libScePad", 1, "libScePad", 1, 1, + scePadSetAngularVelocityDeadbandState); + LIB_FUNCTION("ew647HuKi2Y", "libScePad", 1, "libScePad", 1, 1, scePadSetAutoPowerOffCount); + LIB_FUNCTION("MbTt1EHYCTg", "libScePad", 1, "libScePad", 1, 1, scePadSetButtonRemappingInfo); + LIB_FUNCTION("MLA06oNfF+4", "libScePad", 1, "libScePad", 1, 1, scePadSetConnection); + LIB_FUNCTION("bsbHFI0bl5s", "libScePad", 1, "libScePad", 1, 1, scePadSetExtensionReport); + LIB_FUNCTION("xqgVCEflEDY", "libScePad", 1, "libScePad", 1, 1, scePadSetFeatureReport); + LIB_FUNCTION("lrjFx4xWnY8", "libScePad", 1, "libScePad", 1, 1, scePadSetForceIntercepted); + LIB_FUNCTION("RR4novUEENY", "libScePad", 1, "libScePad", 1, 1, scePadSetLightBar); + LIB_FUNCTION("dhQXEvmrVNQ", "libScePad", 1, "libScePad", 1, 1, scePadSetLightBarBaseBrightness); + LIB_FUNCTION("etaQhgPHDRY", "libScePad", 1, "libScePad", 1, 1, scePadSetLightBarBlinking); + LIB_FUNCTION("iHuOWdvQVpg", "libScePad", 1, "libScePad", 1, 1, scePadSetLightBarForTracker); + LIB_FUNCTION("o-6Y99a8dKU", "libScePad", 1, "libScePad", 1, 1, scePadSetLoginUserNumber); LIB_FUNCTION("clVvL4ZDntw", "libScePad", 1, "libScePad", 1, 1, scePadSetMotionSensorState); -} + LIB_FUNCTION("flYYxek1wy8", "libScePad", 1, "libScePad", 1, 1, scePadSetProcessFocus); + LIB_FUNCTION("DmBx8K+jDWw", "libScePad", 1, "libScePad", 1, 1, scePadSetProcessPrivilege); + LIB_FUNCTION("FbxEpTRDou8", "libScePad", 1, "libScePad", 1, 1, + scePadSetProcessPrivilegeOfButtonRemapping); + LIB_FUNCTION("yah8Bk4TcYY", "libScePad", 1, "libScePad", 1, 1, + scePadSetShareButtonMaskForRemotePlay); + LIB_FUNCTION("vDLMoJLde8I", "libScePad", 1, "libScePad", 1, 1, scePadSetTiltCorrectionState); + LIB_FUNCTION("z+GEemoTxOo", "libScePad", 1, "libScePad", 1, 1, scePadSetUserColor); + LIB_FUNCTION("yFVnOdGxvZY", "libScePad", 1, "libScePad", 1, 1, scePadSetVibration); + LIB_FUNCTION("8BOObG94-tc", "libScePad", 1, "libScePad", 1, 1, scePadSetVibrationForce); + LIB_FUNCTION("--jrY4SHfm8", "libScePad", 1, "libScePad", 1, 1, scePadSetVrTrackingMode); + LIB_FUNCTION("zFJ35q3RVnY", "libScePad", 1, "libScePad", 1, 1, scePadShareOutputData); + LIB_FUNCTION("80XdmVYsNPA", "libScePad", 1, "libScePad", 1, 1, scePadStartRecording); + LIB_FUNCTION("gAHvg6JPIic", "libScePad", 1, "libScePad", 1, 1, scePadStopRecording); + LIB_FUNCTION("Oi7FzRWFr0Y", "libScePad", 1, "libScePad", 1, 1, scePadSwitchConnection); + LIB_FUNCTION("0MB5x-ieRGI", "libScePad", 1, "libScePad", 1, 1, scePadVertualDeviceAddDevice); + LIB_FUNCTION("N7tpsjWQ87s", "libScePad", 1, "libScePad", 1, 1, scePadVirtualDeviceAddDevice); + LIB_FUNCTION("PFec14-UhEQ", "libScePad", 1, "libScePad", 1, 1, scePadVirtualDeviceDeleteDevice); + LIB_FUNCTION("pjPCronWdxI", "libScePad", 1, "libScePad", 1, 1, + scePadVirtualDeviceDisableButtonRemapping); + LIB_FUNCTION("LKXfw7VJYqg", "libScePad", 1, "libScePad", 1, 1, + scePadVirtualDeviceGetRemoteSetting); + LIB_FUNCTION("IWOyO5jKuZg", "libScePad", 1, "libScePad", 1, 1, scePadVirtualDeviceInsertData); + LIB_FUNCTION("KLmYx9ij2h0", "libScePad", 1, "libScePad", 1, 1, Func_28B998C7D8A3DA1D); + LIB_FUNCTION("KY0hSB+Uyfo", "libScePad", 1, "libScePad", 1, 1, Func_298D21481F94C9FA); + LIB_FUNCTION("UeUUvNOgXKU", "libScePad", 1, "libScePad", 1, 1, Func_51E514BCD3A05CA5); + LIB_FUNCTION("ickjfjk9okM", "libScePad", 1, "libScePad", 1, 1, Func_89C9237E393DA243); + LIB_FUNCTION("7xA+hFtvBCA", "libScePad", 1, "libScePad", 1, 1, Func_EF103E845B6F0420); +}; -} // namespace Libraries::LibPad +} // namespace Libraries::Pad \ No newline at end of file diff --git a/src/core/libraries/pad/pad.h b/src/core/libraries/pad/pad.h index 7895da7e..4b48890c 100644 --- a/src/core/libraries/pad/pad.h +++ b/src/core/libraries/pad/pad.h @@ -4,125 +4,322 @@ #pragma once #include "common/types.h" -#include "src/core/libraries/system/userservice.h" namespace Core::Loader { class SymbolsResolver; } -namespace Libraries::LibPad { +namespace Libraries::Pad { -constexpr s8 ORBIS_PAD_PORT_TYPE_STANDARD = 0; -constexpr s8 ORBIS_PAD_PORT_TYPE_SPECIAL = 2; +constexpr int ORBIS_PAD_MAX_TOUCH_NUM = 2; +constexpr int ORBIS_PAD_MAX_DEVICE_UNIQUE_DATA_SIZE = 12; -constexpr s8 ORBIS_PAD_DEVICE_CLASS_PAD = 0; -constexpr s8 ORBIS_PAD_DEVICE_CLASS_GUITAR = 1; -constexpr s8 ORBIS_PAD_DEVICE_CLASS_DRUMS = 2; - -constexpr s8 ORBIS_PAD_CONNECTION_TYPE_STANDARD = 0; -constexpr s8 ORBIS_PAD_CONNECTION_TYPE_REMOTE = 2; - -enum ScePadButton : u32 { - L3 = 0x00000002, - R3 = 0x00000004, - OPTIONS = 0x00000008, - UP = 0x00000010, - RIGHT = 0x00000020, - DOWN = 0x00000040, - LEFT = 0x00000080, - L2 = 0x00000100, - R2 = 0x00000200, - L1 = 0x00000400, - R1 = 0x00000800, - TRIANGLE = 0x00001000, - CIRCLE = 0x00002000, - CROSS = 0x00004000, - SQUARE = 0x00008000, - TOUCH_PAD = 0x00100000, - INTERCEPTED = 0x80000000, +enum OrbisPadDeviceClass { + ORBIS_PAD_DEVICE_CLASS_INVALID = -1, + ORBIS_PAD_DEVICE_CLASS_STANDARD = 0, + ORBIS_PAD_DEVICE_CLASS_GUITAR = 1, + ORBIS_PAD_DEVICE_CLASS_DRUM = 2, + ORBIS_PAD_DEVICE_CLASS_DJ_TURNTABLE = 3, + ORBIS_PAD_DEVICE_CLASS_DANCEMAT = 4, + ORBIS_PAD_DEVICE_CLASS_NAVIGATION = 5, + ORBIS_PAD_DEVICE_CLASS_STEERING_WHEEL = 6, + ORBIS_PAD_DEVICE_CLASS_STICK = 7, + ORBIS_PAD_DEVICE_CLASS_FLIGHT_STICK = 8, + ORBIS_PAD_DEVICE_CLASS_GUN = 9, }; -struct ScePadOpenParam { - u8 reserve[8]; +struct OrbisPadDeviceClassExtendedInformation { + OrbisPadDeviceClass deviceClass; + u8 reserved[4]; + union { + struct { + u8 capability; + u8 reserved1[1]; + u16 maxPhysicalWheelAngle; + u8 reserved2[8]; + } steeringWheel; + struct { + u8 capability; + u8 quantityOfSelectorSwitch; + u8 reserved[10]; + } guitar; + struct { + u8 capability; + u8 reserved[11]; + } drum; + struct { + u8 capability; + u8 reserved[11]; + } flightStick; + u8 data[12]; + } classData; }; -struct ScePadAnalogStick { - u8 x; - u8 y; +struct OrbisPadDeviceClassData { + OrbisPadDeviceClass deviceClass; + bool bDataValid; + union { + struct { + float steeringWheelAngle; + u16 steeringWheel; + u16 acceleratorPedal; + u16 brakePedal; + u16 clutchPedal; + u16 handBrake; + u8 gear; + u8 reserved[1]; + } steeringWheel; + struct { + u8 toneNumber; + u8 whammyBar; + u8 tilt; + u8 fret; + u8 fretSolo; + u8 reserved[11]; + } guitar; + struct { + u8 snare; + u8 tom1; + u8 tom2; + u8 floorTom; + u8 hihatCymbal; + u8 rideCymbal; + u8 crashCymbal; + u8 reserved[9]; + } drum; + struct { + u16 stickAxisX; + u16 stickAxisY; + u8 stickTwist; + u8 throttle; + u8 trigger; + u8 rudderPedal; + u8 brakePedalLeft; + u8 brakePedalRight; + u8 antennaKnob; + u8 rangeKnob; + u8 reserved[4]; + } flightStick; + struct { + u8 dataLen; + u8 reserved[3]; + u8 data[ORBIS_PAD_MAX_DEVICE_UNIQUE_DATA_SIZE]; + } others; + } classData; }; -struct ScePadAnalogButtons { + +struct OrbisPadAnalogButtons { u8 l2; u8 r2; u8 padding[2]; }; -struct SceFQuaternion { +struct OrbisPadAnalogStick { + u8 x; + u8 y; +}; + +enum OrbisPadButtonDataOffset { + ORBIS_PAD_BUTTON_L3 = 0x00000002, + ORBIS_PAD_BUTTON_R3 = 0x00000004, + ORBIS_PAD_BUTTON_OPTIONS = 0x00000008, + ORBIS_PAD_BUTTON_UP = 0x00000010, + ORBIS_PAD_BUTTON_RIGHT = 0x00000020, + ORBIS_PAD_BUTTON_DOWN = 0x00000040, + ORBIS_PAD_BUTTON_LEFT = 0x00000080, + ORBIS_PAD_BUTTON_L2 = 0x00000100, + ORBIS_PAD_BUTTON_R2 = 0x00000200, + ORBIS_PAD_BUTTON_L1 = 0x00000400, + ORBIS_PAD_BUTTON_R1 = 0x00000800, + ORBIS_PAD_BUTTON_TRIANGLE = 0x00001000, + ORBIS_PAD_BUTTON_CIRCLE = 0x00002000, + ORBIS_PAD_BUTTON_CROSS = 0x00004000, + ORBIS_PAD_BUTTON_SQUARE = 0x00008000, + ORBIS_PAD_BUTTON_TOUCH_PAD = 0x00100000, + ORBIS_PAD_BUTTON_INTERCEPTED = 0x80000000, +}; + +struct OrbisFQuaternion { float x, y, z, w; }; -struct SceFVector3 { +struct OrbisFVector3 { float x, y, z; }; -struct ScePadTouch { +struct OrbisPadTouch { u16 x; u16 y; u8 id; u8 reserve[3]; }; -constexpr int SCE_PAD_MAX_TOUCH_NUM = 2; - -typedef struct ScePadTouchData { +struct OrbisPadTouchData { u8 touchNum; u8 reserve[3]; u32 reserve1; - ScePadTouch touch[SCE_PAD_MAX_TOUCH_NUM]; -} ScePadTouchData; + OrbisPadTouch touch[ORBIS_PAD_MAX_TOUCH_NUM]; +}; -struct ScePadExtensionUnitData { +struct OrbisPadExtensionUnitData { u32 extensionUnitId; u8 reserve[1]; u8 dataLength; u8 data[10]; }; -struct ScePadData { +struct OrbisPadData { u32 buttons; - ScePadAnalogStick leftStick; - ScePadAnalogStick rightStick; - ScePadAnalogButtons analogButtons; - SceFQuaternion orientation; - SceFVector3 acceleration; - SceFVector3 angularVelocity; - ScePadTouchData touchData; + OrbisPadAnalogStick leftStick; + OrbisPadAnalogStick rightStick; + OrbisPadAnalogButtons analogButtons; + OrbisFQuaternion orientation; + OrbisFVector3 acceleration; + OrbisFVector3 angularVelocity; + OrbisPadTouchData touchData; bool connected; u64 timestamp; - ScePadExtensionUnitData extensionUnitData; - uint8_t connectedCount; - uint8_t reserve[2]; - uint8_t deviceUniqueDataLen; - uint8_t deviceUniqueData[12]; + OrbisPadExtensionUnitData extensionUnitData; + u8 connectedCount; + u8 reserve[2]; + u8 deviceUniqueDataLen; + u8 deviceUniqueData[ORBIS_PAD_MAX_DEVICE_UNIQUE_DATA_SIZE]; }; -struct OrbisPadInformation { - float touchpadDensity; - u16 touchResolutionX; - u16 touchResolutionY; - u8 stickDeadzoneL; - u8 stickDeadzoneR; +struct OrbisPadTouchPadInformation { + float pixelDensity; + struct { + u8 x; + u8 y; + } resolution; +}; + +struct OrbisPadStickInformation { + u8 deadZoneLeft; + u8 deadZoneRight; +}; + +struct OrbisPadControllerInformation { + OrbisPadTouchPadInformation touchPadInfo; + OrbisPadStickInformation stickInfo; u8 connectionType; - u8 count; - s8 connected; - s8 deviceClass; - u8 unknown[8]; + u8 connectedCount; + bool connected; + OrbisPadDeviceClass deviceClass; + u8 reserve[8]; }; +struct OrbisPadOpenParam { + u8 reserve[8]; +}; + +struct OrbisPadLightBarParam { + u8 r; + u8 g; + u8 b; + u8 reserve[1]; +}; + +struct OrbisPadVibrationParam { + u8 largeMotor; + u8 smallMotor; +}; + +int PS4_SYSV_ABI scePadClose(s32 handle); +int PS4_SYSV_ABI scePadConnectPort(); +int PS4_SYSV_ABI scePadDeviceClassGetExtendedInformation( + s32 handle, OrbisPadDeviceClassExtendedInformation* pExtInfo); +int PS4_SYSV_ABI scePadDeviceClassParseData(s32 handle, const OrbisPadData* pData, + OrbisPadDeviceClassData* pDeviceClassData); +int PS4_SYSV_ABI scePadDeviceOpen(); +int PS4_SYSV_ABI scePadDisableVibration(); +int PS4_SYSV_ABI scePadDisconnectDevice(); +int PS4_SYSV_ABI scePadDisconnectPort(); +int PS4_SYSV_ABI scePadEnableAutoDetect(); +int PS4_SYSV_ABI scePadEnableExtensionPort(); +int PS4_SYSV_ABI scePadEnableSpecificDeviceClass(); +int PS4_SYSV_ABI scePadEnableUsbConnection(); +int PS4_SYSV_ABI scePadGetBluetoothAddress(); +int PS4_SYSV_ABI scePadGetCapability(); +int PS4_SYSV_ABI scePadGetControllerInformation(s32 handle, OrbisPadControllerInformation* pInfo); +int PS4_SYSV_ABI scePadGetDataInternal(); +int PS4_SYSV_ABI scePadGetDeviceId(); +int PS4_SYSV_ABI scePadGetDeviceInfo(); +int PS4_SYSV_ABI scePadGetExtControllerInformation(); +int PS4_SYSV_ABI scePadGetExtensionUnitInfo(); +int PS4_SYSV_ABI scePadGetFeatureReport(); +int PS4_SYSV_ABI scePadGetHandle(s32 userId, s32 type, s32 index); +int PS4_SYSV_ABI scePadGetIdleCount(); +int PS4_SYSV_ABI scePadGetInfo(); +int PS4_SYSV_ABI scePadGetInfoByPortType(); +int PS4_SYSV_ABI scePadGetLicenseControllerInformation(); +int PS4_SYSV_ABI scePadGetMotionSensorPosition(); +int PS4_SYSV_ABI scePadGetMotionTimerUnit(); +int PS4_SYSV_ABI scePadGetSphereRadius(); +int PS4_SYSV_ABI scePadGetVersionInfo(); int PS4_SYSV_ABI scePadInit(); -int PS4_SYSV_ABI scePadOpen(Libraries::UserService::OrbisUserServiceUserId userId, s32 type, - s32 index, const ScePadOpenParam* pParam); -int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData); +int PS4_SYSV_ABI scePadIsBlasterConnected(); +int PS4_SYSV_ABI scePadIsDS4Connected(); +int PS4_SYSV_ABI scePadIsLightBarBaseBrightnessControllable(); +int PS4_SYSV_ABI scePadIsMoveConnected(); +int PS4_SYSV_ABI scePadIsMoveReproductionModel(); +int PS4_SYSV_ABI scePadIsValidHandle(); +int PS4_SYSV_ABI scePadMbusInit(); +int PS4_SYSV_ABI scePadMbusTerm(); +int PS4_SYSV_ABI scePadOpen(s32 userId, s32 type, s32 index, + const OrbisPadOpenParam* pParam); +int PS4_SYSV_ABI scePadOpenExt(); +int PS4_SYSV_ABI scePadOpenExt2(); +int PS4_SYSV_ABI scePadOutputReport(); +int PS4_SYSV_ABI scePadRead(s32 handle, OrbisPadData* pData, s32 num); +int PS4_SYSV_ABI scePadReadBlasterForTracker(); +int PS4_SYSV_ABI scePadReadExt(); +int PS4_SYSV_ABI scePadReadForTracker(); +int PS4_SYSV_ABI scePadReadHistory(); +int PS4_SYSV_ABI scePadReadState(s32 handle, OrbisPadData* pData); +int PS4_SYSV_ABI scePadReadStateExt(); +int PS4_SYSV_ABI scePadResetLightBar(s32 handle); +int PS4_SYSV_ABI scePadResetLightBarAll(); +int PS4_SYSV_ABI scePadResetLightBarAllByPortType(); +int PS4_SYSV_ABI scePadResetOrientation(s32 handle); +int PS4_SYSV_ABI scePadResetOrientationForTracker(); +int PS4_SYSV_ABI scePadSetAngularVelocityDeadbandState(s32 handle, bool bEnable); +int PS4_SYSV_ABI scePadSetAutoPowerOffCount(); +int PS4_SYSV_ABI scePadSetButtonRemappingInfo(); +int PS4_SYSV_ABI scePadSetConnection(); +int PS4_SYSV_ABI scePadSetExtensionReport(); +int PS4_SYSV_ABI scePadSetFeatureReport(); +int PS4_SYSV_ABI scePadSetForceIntercepted(); +int PS4_SYSV_ABI scePadSetLightBar(s32 handle, const OrbisPadLightBarParam* pParam); +int PS4_SYSV_ABI scePadSetLightBarBaseBrightness(); +int PS4_SYSV_ABI scePadSetLightBarBlinking(); +int PS4_SYSV_ABI scePadSetLightBarForTracker(); +int PS4_SYSV_ABI scePadSetLoginUserNumber(); +int PS4_SYSV_ABI scePadSetMotionSensorState(s32 handle, bool bEnable); +int PS4_SYSV_ABI scePadSetProcessFocus(); +int PS4_SYSV_ABI scePadSetProcessPrivilege(); +int PS4_SYSV_ABI scePadSetProcessPrivilegeOfButtonRemapping(); +int PS4_SYSV_ABI scePadSetShareButtonMaskForRemotePlay(); +int PS4_SYSV_ABI scePadSetTiltCorrectionState(s32 handle, bool bEnable); +int PS4_SYSV_ABI scePadSetUserColor(); +int PS4_SYSV_ABI scePadSetVibration(s32 handle, const OrbisPadVibrationParam* pParam); +int PS4_SYSV_ABI scePadSetVibrationForce(); +int PS4_SYSV_ABI scePadSetVrTrackingMode(); +int PS4_SYSV_ABI scePadShareOutputData(); +int PS4_SYSV_ABI scePadStartRecording(); +int PS4_SYSV_ABI scePadStopRecording(); +int PS4_SYSV_ABI scePadSwitchConnection(); +int PS4_SYSV_ABI scePadVertualDeviceAddDevice(); +int PS4_SYSV_ABI scePadVirtualDeviceAddDevice(); +int PS4_SYSV_ABI scePadVirtualDeviceDeleteDevice(); +int PS4_SYSV_ABI scePadVirtualDeviceDisableButtonRemapping(); +int PS4_SYSV_ABI scePadVirtualDeviceGetRemoteSetting(); +int PS4_SYSV_ABI scePadVirtualDeviceInsertData(); +int PS4_SYSV_ABI Func_28B998C7D8A3DA1D(); +int PS4_SYSV_ABI Func_298D21481F94C9FA(); +int PS4_SYSV_ABI Func_51E514BCD3A05CA5(); +int PS4_SYSV_ABI Func_89C9237E393DA243(); +int PS4_SYSV_ABI Func_EF103E845B6F0420(); -void padSymbolsRegister(Core::Loader::SymbolsResolver* sym); - -}; // namespace Libraries::LibPad +void RegisterlibScePad(Core::Loader::SymbolsResolver* sym); +} // namespace Libraries::Pad \ No newline at end of file diff --git a/src/sdl_window.cpp b/src/sdl_window.cpp index ce9ff729..acbcb97d 100644 --- a/src/sdl_window.cpp +++ b/src/sdl_window.cpp @@ -96,36 +96,36 @@ void WindowSDL::onResize() { } void WindowSDL::onKeyPress(const SDL_Event* event) { - using Libraries::LibPad::ScePadButton; + using Libraries::Pad::OrbisPadButtonDataOffset; u32 button = 0; switch (event->key.keysym.sym) { case SDLK_UP: - button = ScePadButton::UP; + button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_UP; break; case SDLK_DOWN: - button = ScePadButton::DOWN; + button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_DOWN; break; case SDLK_LEFT: - button = ScePadButton::LEFT; + button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_LEFT; break; case SDLK_RIGHT: - button = ScePadButton::RIGHT; + button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_RIGHT; break; case SDLK_KP_8: - button = ScePadButton::TRIANGLE; + button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_TRIANGLE; break; case SDLK_KP_6: - button = ScePadButton::CIRCLE; + button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_CIRCLE; break; case SDLK_KP_2: - button = ScePadButton::CROSS; + button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_CROSS; break; case SDLK_KP_4: - button = ScePadButton::SQUARE; + button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_SQUARE; break; case SDLK_RETURN: - button = ScePadButton::OPTIONS; + button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_OPTIONS; break; default: break; From 9501bd77d44db008b01e194882b78f357b895e14 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Sat, 15 Jun 2024 18:47:35 +0300 Subject: [PATCH 02/11] clang fix --- src/core/libraries/pad/pad.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/libraries/pad/pad.h b/src/core/libraries/pad/pad.h index 4b48890c..f42e45b9 100644 --- a/src/core/libraries/pad/pad.h +++ b/src/core/libraries/pad/pad.h @@ -266,8 +266,7 @@ int PS4_SYSV_ABI scePadIsMoveReproductionModel(); int PS4_SYSV_ABI scePadIsValidHandle(); int PS4_SYSV_ABI scePadMbusInit(); int PS4_SYSV_ABI scePadMbusTerm(); -int PS4_SYSV_ABI scePadOpen(s32 userId, s32 type, s32 index, - const OrbisPadOpenParam* pParam); +int PS4_SYSV_ABI scePadOpen(s32 userId, s32 type, s32 index, const OrbisPadOpenParam* pParam); int PS4_SYSV_ABI scePadOpenExt(); int PS4_SYSV_ABI scePadOpenExt2(); int PS4_SYSV_ABI scePadOutputReport(); From 57c65cadb82249dc2cc31af8605c88011d59755c Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Sun, 16 Jun 2024 21:27:08 +0300 Subject: [PATCH 03/11] fixes to the old pad code --- src/core/libraries/pad/old_pad.cpp | 126 ---------------------------- src/core/libraries/pad/old_pad.h | 128 ----------------------------- src/core/libraries/pad/pad.cpp | 89 ++++++++++++++++++-- src/core/libraries/pad/pad.h | 7 +- 4 files changed, 86 insertions(+), 264 deletions(-) delete mode 100644 src/core/libraries/pad/old_pad.cpp delete mode 100644 src/core/libraries/pad/old_pad.h diff --git a/src/core/libraries/pad/old_pad.cpp b/src/core/libraries/pad/old_pad.cpp deleted file mode 100644 index e2f73afe..00000000 --- a/src/core/libraries/pad/old_pad.cpp +++ /dev/null @@ -1,126 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "common/logging/log.h" -#include "common/singleton.h" -#include "core/libraries/error_codes.h" -#include "core/libraries/libs.h" -#include "core/libraries/pad/pad.h" -#include "input/controller.h" - -namespace Libraries::LibPad { - -int PS4_SYSV_ABI scePadInit() { - LOG_WARNING(Lib_Pad, "(DUMMY) called"); - return SCE_OK; -} - -int PS4_SYSV_ABI scePadOpen(Libraries::UserService::OrbisUserServiceUserId user_id, s32 type, - s32 index, const ScePadOpenParam* pParam) { - LOG_INFO(Lib_Pad, "(DUMMY) called user_id = {} type = {} index = {}", user_id, type, index); - return 1; // dummy -} - -int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) { - auto* controller = Common::Singleton::Instance(); - - int connectedCount = 0; - bool isConnected = false; - Input::State state; - - controller->readState(&state, &isConnected, &connectedCount); - pData->buttons = state.buttonsState; - pData->leftStick.x = 128; // dummy - pData->leftStick.y = 128; // dummy - pData->rightStick.x = 0; // dummy - pData->rightStick.y = 0; // dummy - pData->analogButtons.r2 = 0; // dummy - pData->analogButtons.l2 = 0; // dummy - pData->orientation.x = 0; - pData->orientation.y = 0; - pData->orientation.z = 0; - pData->orientation.w = 0; - pData->timestamp = state.time; - pData->connected = true; // isConnected; //TODO fix me proper - pData->connectedCount = 1; // connectedCount; - pData->deviceUniqueDataLen = 0; - - return SCE_OK; -} - -int PS4_SYSV_ABI scePadRead(int handle, ScePadData* pData, int num) { - int connected_count = 0; - bool connected = false; - Input::State states[64]; - auto* controller = Common::Singleton::Instance(); - int ret_num = controller->ReadStates(states, num, &connected, &connected_count); - - if (!connected) { - ret_num = 1; - } - - for (int i = 0; i < ret_num; i++) { - pData[i].buttons = states[i].buttonsState; - pData[i].leftStick.x = 128; // dummy - pData[i].leftStick.y = 128; // dummy - pData[i].rightStick.x = 0; // dummy - pData[i].rightStick.y = 0; // dummy - pData[i].analogButtons.l2 = 0; // dummy - pData[i].analogButtons.r2 = 0; // dummy - pData[i].orientation.x = 0.0f; - pData[i].orientation.y = 0.0f; - pData[i].orientation.z = 0.0f; - pData[i].orientation.w = 1.0f; - pData[i].acceleration.x = 0.0f; - pData[i].acceleration.y = 0.0f; - pData[i].acceleration.z = 0.0f; - pData[i].angularVelocity.x = 0.0f; - pData[i].angularVelocity.y = 0.0f; - pData[i].angularVelocity.z = 0.0f; - pData[i].touchData.touchNum = 0; - pData[i].touchData.touch[0].x = 0; - pData[i].touchData.touch[0].y = 0; - pData[i].touchData.touch[0].id = 1; - pData[i].touchData.touch[1].x = 0; - pData[i].touchData.touch[1].y = 0; - pData[i].touchData.touch[1].id = 2; - pData[i].connected = connected; - pData[i].timestamp = states[i].time; - pData[i].connectedCount = connected_count; - pData[i].deviceUniqueDataLen = 0; - } - - return ret_num; -} - -s32 PS4_SYSV_ABI scePadGetControllerInformation(s32 handle, OrbisPadInformation* info) { - LOG_INFO(Lib_Pad, "called handle = {}", handle); - info->touchpadDensity = 1; - info->touchResolutionX = 1920; - info->touchResolutionY = 950; - info->stickDeadzoneL = 2; - info->stickDeadzoneR = 2; - info->connectionType = ORBIS_PAD_CONNECTION_TYPE_STANDARD; - info->count = 1; - info->connected = 1; - info->deviceClass = ORBIS_PAD_PORT_TYPE_STANDARD; - return SCE_OK; -} - -s32 PS4_SYSV_ABI scePadSetMotionSensorState(s32 handle, bool enable) { - LOG_INFO(Lib_Pad, "(DUMMY) called handle = {} enabled = {}", handle, - (enable ? "true" : "false")); - return SCE_OK; -} - -void padSymbolsRegister(Core::Loader::SymbolsResolver* sym) { - LIB_FUNCTION("hv1luiJrqQM", "libScePad", 1, "libScePad", 1, 1, scePadInit); - LIB_FUNCTION("xk0AcarP3V4", "libScePad", 1, "libScePad", 1, 1, scePadOpen); - LIB_FUNCTION("YndgXqQVV7c", "libScePad", 1, "libScePad", 1, 1, scePadReadState); - LIB_FUNCTION("q1cHNfGycLI", "libScePad", 1, "libScePad", 1, 1, scePadRead); - - LIB_FUNCTION("gjP9-KQzoUk", "libScePad", 1, "libScePad", 1, 1, scePadGetControllerInformation); - LIB_FUNCTION("clVvL4ZDntw", "libScePad", 1, "libScePad", 1, 1, scePadSetMotionSensorState); -} - -} // namespace Libraries::LibPad diff --git a/src/core/libraries/pad/old_pad.h b/src/core/libraries/pad/old_pad.h deleted file mode 100644 index 7895da7e..00000000 --- a/src/core/libraries/pad/old_pad.h +++ /dev/null @@ -1,128 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include "common/types.h" -#include "src/core/libraries/system/userservice.h" - -namespace Core::Loader { -class SymbolsResolver; -} - -namespace Libraries::LibPad { - -constexpr s8 ORBIS_PAD_PORT_TYPE_STANDARD = 0; -constexpr s8 ORBIS_PAD_PORT_TYPE_SPECIAL = 2; - -constexpr s8 ORBIS_PAD_DEVICE_CLASS_PAD = 0; -constexpr s8 ORBIS_PAD_DEVICE_CLASS_GUITAR = 1; -constexpr s8 ORBIS_PAD_DEVICE_CLASS_DRUMS = 2; - -constexpr s8 ORBIS_PAD_CONNECTION_TYPE_STANDARD = 0; -constexpr s8 ORBIS_PAD_CONNECTION_TYPE_REMOTE = 2; - -enum ScePadButton : u32 { - L3 = 0x00000002, - R3 = 0x00000004, - OPTIONS = 0x00000008, - UP = 0x00000010, - RIGHT = 0x00000020, - DOWN = 0x00000040, - LEFT = 0x00000080, - L2 = 0x00000100, - R2 = 0x00000200, - L1 = 0x00000400, - R1 = 0x00000800, - TRIANGLE = 0x00001000, - CIRCLE = 0x00002000, - CROSS = 0x00004000, - SQUARE = 0x00008000, - TOUCH_PAD = 0x00100000, - INTERCEPTED = 0x80000000, -}; - -struct ScePadOpenParam { - u8 reserve[8]; -}; - -struct ScePadAnalogStick { - u8 x; - u8 y; -}; -struct ScePadAnalogButtons { - u8 l2; - u8 r2; - u8 padding[2]; -}; - -struct SceFQuaternion { - float x, y, z, w; -}; - -struct SceFVector3 { - float x, y, z; -}; - -struct ScePadTouch { - u16 x; - u16 y; - u8 id; - u8 reserve[3]; -}; - -constexpr int SCE_PAD_MAX_TOUCH_NUM = 2; - -typedef struct ScePadTouchData { - u8 touchNum; - u8 reserve[3]; - u32 reserve1; - ScePadTouch touch[SCE_PAD_MAX_TOUCH_NUM]; -} ScePadTouchData; - -struct ScePadExtensionUnitData { - u32 extensionUnitId; - u8 reserve[1]; - u8 dataLength; - u8 data[10]; -}; - -struct ScePadData { - u32 buttons; - ScePadAnalogStick leftStick; - ScePadAnalogStick rightStick; - ScePadAnalogButtons analogButtons; - SceFQuaternion orientation; - SceFVector3 acceleration; - SceFVector3 angularVelocity; - ScePadTouchData touchData; - bool connected; - u64 timestamp; - ScePadExtensionUnitData extensionUnitData; - uint8_t connectedCount; - uint8_t reserve[2]; - uint8_t deviceUniqueDataLen; - uint8_t deviceUniqueData[12]; -}; - -struct OrbisPadInformation { - float touchpadDensity; - u16 touchResolutionX; - u16 touchResolutionY; - u8 stickDeadzoneL; - u8 stickDeadzoneR; - u8 connectionType; - u8 count; - s8 connected; - s8 deviceClass; - u8 unknown[8]; -}; - -int PS4_SYSV_ABI scePadInit(); -int PS4_SYSV_ABI scePadOpen(Libraries::UserService::OrbisUserServiceUserId userId, s32 type, - s32 index, const ScePadOpenParam* pParam); -int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData); - -void padSymbolsRegister(Core::Loader::SymbolsResolver* sym); - -}; // namespace Libraries::LibPad diff --git a/src/core/libraries/pad/pad.cpp b/src/core/libraries/pad/pad.cpp index fc927f52..7cc930ce 100644 --- a/src/core/libraries/pad/pad.cpp +++ b/src/core/libraries/pad/pad.cpp @@ -2,9 +2,11 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Generated By moduleGenerator +#include #include "common/logging/log.h" #include "core/libraries/error_codes.h" #include "core/libraries/libs.h" +#include "input/controller.h" #include "pad.h" namespace Libraries::Pad { @@ -82,8 +84,17 @@ int PS4_SYSV_ABI scePadGetCapability() { } int PS4_SYSV_ABI scePadGetControllerInformation(s32 handle, OrbisPadControllerInformation* pInfo) { - LOG_ERROR(Lib_Pad, "(STUBBED) called"); - return ORBIS_OK; + LOG_INFO(Lib_Pad, "called handle = {}", handle); + pInfo->touchPadInfo.pixelDensity = 1; + pInfo->touchPadInfo.resolution.x = 1920; + pInfo->touchPadInfo.resolution.y = 950; + pInfo->stickInfo.deadZoneLeft = 2; + pInfo->stickInfo.deadZoneRight = 2; + pInfo->connectionType = ORBIS_PAD_PORT_TYPE_STANDARD; + pInfo->connectedCount = 1; + pInfo->connected = 1; + pInfo->deviceClass = ORBIS_PAD_DEVICE_CLASS_STANDARD; + return SCE_OK; } int PS4_SYSV_ABI scePadGetDataInternal() { @@ -207,8 +218,8 @@ int PS4_SYSV_ABI scePadMbusTerm() { } int PS4_SYSV_ABI scePadOpen(s32 userId, s32 type, s32 index, const OrbisPadOpenParam* pParam) { - LOG_ERROR(Lib_Pad, "(STUBBED) called"); - return ORBIS_OK; + LOG_INFO(Lib_Pad, "(DUMMY) called user_id = {} type = {} index = {}", userId, type, index); + return 1; // dummy } int PS4_SYSV_ABI scePadOpenExt() { @@ -227,8 +238,48 @@ int PS4_SYSV_ABI scePadOutputReport() { } int PS4_SYSV_ABI scePadRead(s32 handle, OrbisPadData* pData, s32 num) { - LOG_ERROR(Lib_Pad, "(STUBBED) called"); - return ORBIS_OK; + int connected_count = 0; + bool connected = false; + Input::State states[64]; + auto* controller = Common::Singleton::Instance(); + int ret_num = controller->ReadStates(states, num, &connected, &connected_count); + + if (!connected) { + ret_num = 1; + } + + for (int i = 0; i < ret_num; i++) { + pData[i].buttons = states[i].buttonsState; + pData[i].leftStick.x = 128; // dummy + pData[i].leftStick.y = 128; // dummy + pData[i].rightStick.x = 0; // dummy + pData[i].rightStick.y = 0; // dummy + pData[i].analogButtons.l2 = 0; // dummy + pData[i].analogButtons.r2 = 0; // dummy + pData[i].orientation.x = 0.0f; + pData[i].orientation.y = 0.0f; + pData[i].orientation.z = 0.0f; + pData[i].orientation.w = 1.0f; + pData[i].acceleration.x = 0.0f; + pData[i].acceleration.y = 0.0f; + pData[i].acceleration.z = 0.0f; + pData[i].angularVelocity.x = 0.0f; + pData[i].angularVelocity.y = 0.0f; + pData[i].angularVelocity.z = 0.0f; + pData[i].touchData.touchNum = 0; + pData[i].touchData.touch[0].x = 0; + pData[i].touchData.touch[0].y = 0; + pData[i].touchData.touch[0].id = 1; + pData[i].touchData.touch[1].x = 0; + pData[i].touchData.touch[1].y = 0; + pData[i].touchData.touch[1].id = 2; + pData[i].connected = connected; + pData[i].timestamp = states[i].time; + pData[i].connectedCount = connected_count; + pData[i].deviceUniqueDataLen = 0; + } + + return ret_num; } int PS4_SYSV_ABI scePadReadBlasterForTracker() { @@ -252,8 +303,30 @@ int PS4_SYSV_ABI scePadReadHistory() { } int PS4_SYSV_ABI scePadReadState(s32 handle, OrbisPadData* pData) { - LOG_ERROR(Lib_Pad, "(STUBBED) called"); - return ORBIS_OK; + auto* controller = Common::Singleton::Instance(); + + int connectedCount = 0; + bool isConnected = false; + Input::State state; + + controller->readState(&state, &isConnected, &connectedCount); + pData->buttons = state.buttonsState; + pData->leftStick.x = 128; // dummy + pData->leftStick.y = 128; // dummy + pData->rightStick.x = 0; // dummy + pData->rightStick.y = 0; // dummy + pData->analogButtons.r2 = 0; // dummy + pData->analogButtons.l2 = 0; // dummy + pData->orientation.x = 0; + pData->orientation.y = 0; + pData->orientation.z = 0; + pData->orientation.w = 0; + pData->timestamp = state.time; + pData->connected = true; // isConnected; //TODO fix me proper + pData->connectedCount = 1; // connectedCount; + pData->deviceUniqueDataLen = 0; + + return SCE_OK; } int PS4_SYSV_ABI scePadReadStateExt() { diff --git a/src/core/libraries/pad/pad.h b/src/core/libraries/pad/pad.h index f42e45b9..4f854290 100644 --- a/src/core/libraries/pad/pad.h +++ b/src/core/libraries/pad/pad.h @@ -14,6 +14,9 @@ namespace Libraries::Pad { constexpr int ORBIS_PAD_MAX_TOUCH_NUM = 2; constexpr int ORBIS_PAD_MAX_DEVICE_UNIQUE_DATA_SIZE = 12; +constexpr int ORBIS_PAD_PORT_TYPE_STANDARD = 0; +constexpr int ORBIS_PAD_PORT_TYPE_SPECIAL = 2; + enum OrbisPadDeviceClass { ORBIS_PAD_DEVICE_CLASS_INVALID = -1, ORBIS_PAD_DEVICE_CLASS_STANDARD = 0, @@ -189,8 +192,8 @@ struct OrbisPadData { struct OrbisPadTouchPadInformation { float pixelDensity; struct { - u8 x; - u8 y; + u16 x; + u16 y; } resolution; }; From 48d6ccd9bb78301bae73c91fbce814168e21c326 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 17 Jun 2024 12:52:25 +0300 Subject: [PATCH 04/11] partially added analog controls --- src/core/libraries/pad/pad.cpp | 26 ++++++++++---------- src/input/controller.cpp | 45 ++++++++++++++++++++++++++++------ src/input/controller.h | 26 +++++++++++++++++--- src/sdl_window.cpp | 2 +- 4 files changed, 73 insertions(+), 26 deletions(-) diff --git a/src/core/libraries/pad/pad.cpp b/src/core/libraries/pad/pad.cpp index 7cc930ce..0faa01ba 100644 --- a/src/core/libraries/pad/pad.cpp +++ b/src/core/libraries/pad/pad.cpp @@ -250,12 +250,12 @@ int PS4_SYSV_ABI scePadRead(s32 handle, OrbisPadData* pData, s32 num) { for (int i = 0; i < ret_num; i++) { pData[i].buttons = states[i].buttonsState; - pData[i].leftStick.x = 128; // dummy - pData[i].leftStick.y = 128; // dummy - pData[i].rightStick.x = 0; // dummy - pData[i].rightStick.y = 0; // dummy - pData[i].analogButtons.l2 = 0; // dummy - pData[i].analogButtons.r2 = 0; // dummy + pData[i].leftStick.x = states[i].axes[static_cast(Input::Axis::LeftX)]; + pData[i].leftStick.y = states[i].axes[static_cast(Input::Axis::LeftY)]; + pData[i].rightStick.x = states[i].axes[static_cast(Input::Axis::RightX)]; + pData[i].rightStick.y = states[i].axes[static_cast(Input::Axis::RightY)]; + pData[i].analogButtons.l2 = states[i].axes[static_cast(Input::Axis::TriggerLeft)]; + pData[i].analogButtons.r2 = states[i].axes[static_cast(Input::Axis::TriggerRight)]; pData[i].orientation.x = 0.0f; pData[i].orientation.y = 0.0f; pData[i].orientation.z = 0.0f; @@ -309,14 +309,14 @@ int PS4_SYSV_ABI scePadReadState(s32 handle, OrbisPadData* pData) { bool isConnected = false; Input::State state; - controller->readState(&state, &isConnected, &connectedCount); + controller->ReadState(&state, &isConnected, &connectedCount); pData->buttons = state.buttonsState; - pData->leftStick.x = 128; // dummy - pData->leftStick.y = 128; // dummy - pData->rightStick.x = 0; // dummy - pData->rightStick.y = 0; // dummy - pData->analogButtons.r2 = 0; // dummy - pData->analogButtons.l2 = 0; // dummy + pData->leftStick.x = state.axes[static_cast(Input::Axis::LeftX)]; + pData->leftStick.y = state.axes[static_cast(Input::Axis::LeftY)]; + pData->rightStick.x = state.axes[static_cast(Input::Axis::RightX)]; + pData->rightStick.y = state.axes[static_cast(Input::Axis::RightY)]; + pData->analogButtons.l2 = state.axes[static_cast(Input::Axis::TriggerLeft)]; + pData->analogButtons.r2 = state.axes[static_cast(Input::Axis::TriggerRight)]; pData->orientation.x = 0; pData->orientation.y = 0; pData->orientation.z = 0; diff --git a/src/input/controller.cpp b/src/input/controller.cpp index 08be2838..fd66c98a 100644 --- a/src/input/controller.cpp +++ b/src/input/controller.cpp @@ -3,7 +3,7 @@ #include "core/libraries/kernel/time_management.h" #include "input/controller.h" - +#include "core/libraries/pad/pad.h" namespace Input { GameController::GameController() { @@ -11,12 +11,12 @@ GameController::GameController() { m_last_state = State(); } -void GameController::readState(State* state, bool* isConnected, int* connectedCount) { +void GameController::ReadState(State* state, bool* isConnected, int* connectedCount) { std::scoped_lock lock{m_mutex}; *isConnected = m_connected; *connectedCount = m_connected_count; - *state = getLastState(); + *state = GetLastState(); } int GameController::ReadStates(State* states, int states_num, bool* isConnected, @@ -50,7 +50,7 @@ int GameController::ReadStates(State* states, int states_num, bool* isConnected, return ret_num; } -State GameController::getLastState() const { +State GameController::GetLastState() const { if (m_states_num == 0) { return m_last_state; } @@ -60,7 +60,7 @@ State GameController::getLastState() const { return m_states[last]; } -void GameController::addState(const State& state) { +void GameController::AddState(const State& state) { if (m_states_num >= MAX_STATES) { m_states_num = MAX_STATES - 1; m_first_state = (m_first_state + 1) % MAX_STATES; @@ -74,9 +74,9 @@ void GameController::addState(const State& state) { m_states_num++; } -void GameController::checkButton(int id, u32 button, bool isPressed) { +void GameController::CheckButton(int id, u32 button, bool isPressed) { std::scoped_lock lock{m_mutex}; - auto state = getLastState(); + auto state = GetLastState(); state.time = Libraries::Kernel::sceKernelGetProcessTime(); if (isPressed) { state.buttonsState |= button; @@ -84,7 +84,36 @@ void GameController::checkButton(int id, u32 button, bool isPressed) { state.buttonsState &= ~button; } - addState(state); + AddState(state); +} + +void GameController::Axis(int id, Input::Axis axis, int value) { + std::scoped_lock lock{m_mutex}; + auto state = GetLastState(); + + state.time = Libraries::Kernel::sceKernelGetProcessTime(); + + int axis_id = static_cast(axis); + + state.axes[axis_id] = value; + + if (axis == Input::Axis::TriggerLeft) { + if (value > 0) { + state.buttonsState |= Libraries::Pad::OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_L2; + } else { + state.buttonsState &= ~Libraries::Pad::OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_L2; + } + } + + if (axis == Input::Axis::TriggerRight) { + if (value > 0) { + state.buttonsState |= Libraries::Pad::OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_R2; + } else { + state.buttonsState &= ~Libraries::Pad::OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_R2; + } + } + + AddState(state); } } // namespace Input diff --git a/src/input/controller.h b/src/input/controller.h index 774bbca7..a16f7dd0 100644 --- a/src/input/controller.h +++ b/src/input/controller.h @@ -8,11 +8,28 @@ namespace Input { +enum class Axis { + LeftX = 0, + LeftY = 1, + RightX = 2, + RightY = 3, + TriggerLeft = 4, + TriggerRight = 5, + + AxisMax +}; + struct State { u32 buttonsState = 0; u64 time = 0; + int axes[static_cast(Axis::AxisMax)] = {128, 128, 128, 128, 0, 0}; }; +inline int GetAxis(int min, int max, int value) { + int v = (255 * (value - min)) / (max - min); + return (v < 0 ? 0 : (v > 255 ? 255 : v)); +} + constexpr u32 MAX_STATES = 64; class GameController { @@ -20,11 +37,12 @@ public: GameController(); virtual ~GameController() = default; - void readState(State* state, bool* isConnected, int* connectedCount); + void ReadState(State* state, bool* isConnected, int* connectedCount); int ReadStates(State* states, int states_num, bool* isConnected, int* connectedCount); - State getLastState() const; - void checkButton(int id, u32 button, bool isPressed); - void addState(const State& state); + State GetLastState() const; + void CheckButton(int id, u32 button, bool isPressed); + void AddState(const State& state); + void Axis(int id, Input::Axis axis, int value); private: struct StateInternal { diff --git a/src/sdl_window.cpp b/src/sdl_window.cpp index acbcb97d..a990b93d 100644 --- a/src/sdl_window.cpp +++ b/src/sdl_window.cpp @@ -131,7 +131,7 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { break; } if (button != 0) { - controller->checkButton(0, button, event->type == SDL_EVENT_KEY_DOWN); + controller->CheckButton(0, button, event->type == SDL_EVENT_KEY_DOWN); } } From 91e6d35e8905b9eaea49449b457a681287930e09 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 17 Jun 2024 13:42:39 +0300 Subject: [PATCH 05/11] analog support via keyboard --- src/sdl_window.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/sdl_window.cpp b/src/sdl_window.cpp index a990b93d..0bbc61ee 100644 --- a/src/sdl_window.cpp +++ b/src/sdl_window.cpp @@ -99,6 +99,9 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { using Libraries::Pad::OrbisPadButtonDataOffset; u32 button = 0; + Input::Axis axis = Input::Axis::AxisMax; + int axisvalue = 0; + int ax = 0; switch (event->key.keysym.sym) { case SDLK_UP: button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_UP; @@ -127,12 +130,55 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { case SDLK_RETURN: button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_OPTIONS; break; + case SDLK_a: + axis = Input::Axis::LeftX; + axisvalue += -127; + ax = Input::GetAxis(-0x80, 0x80, axisvalue); + break; + case SDLK_d: + axis = Input::Axis::LeftX; + axisvalue += 127; + ax = Input::GetAxis(-0x80, 0x80, axisvalue); + break; + case SDLK_w: + axis = Input::Axis::LeftY; + axisvalue += -127; + ax = Input::GetAxis(-0x80, 0x80, axisvalue); + break; + case SDLK_s: + axis = Input::Axis::LeftY; + axisvalue += 127; + ax = Input::GetAxis(-0x80, 0x80, axisvalue); + break; + case SDLK_j: + axis = Input::Axis::RightX; + axisvalue += -127; + ax = Input::GetAxis(-0x80, 0x80, axisvalue); + break; + case SDLK_l: + axis = Input::Axis::RightX; + axisvalue += 127; + ax = Input::GetAxis(-0x80, 0x80, axisvalue); + break; + case SDLK_i: + axis = Input::Axis::RightY; + axisvalue += -127; + ax = Input::GetAxis(-0x80, 0x80, axisvalue); + break; + case SDLK_k: + axis = Input::Axis::RightY; + axisvalue += 127; + ax = Input::GetAxis(-0x80, 0x80, axisvalue); + break; default: break; } if (button != 0) { controller->CheckButton(0, button, event->type == SDL_EVENT_KEY_DOWN); } + if (axis != Input::Axis::AxisMax&& event->type == SDL_EVENT_KEY_DOWN) { + controller->Axis(0, axis, ax); + } } } // namespace Frontend From b17a57cb3d813949128de5f58e2082680aa99b02 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 17 Jun 2024 14:33:03 +0300 Subject: [PATCH 06/11] analog sticks works better now --- src/sdl_window.cpp | 50 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/src/sdl_window.cpp b/src/sdl_window.cpp index 0bbc61ee..3a676e01 100644 --- a/src/sdl_window.cpp +++ b/src/sdl_window.cpp @@ -132,42 +132,74 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { break; case SDLK_a: axis = Input::Axis::LeftX; - axisvalue += -127; + if (event->type == SDL_EVENT_KEY_DOWN) { + axisvalue += -127; + } else { + axisvalue = 0; + } ax = Input::GetAxis(-0x80, 0x80, axisvalue); break; case SDLK_d: axis = Input::Axis::LeftX; - axisvalue += 127; + if (event->type == SDL_EVENT_KEY_DOWN) { + axisvalue += 127; + } else { + axisvalue = 0; + } ax = Input::GetAxis(-0x80, 0x80, axisvalue); break; case SDLK_w: axis = Input::Axis::LeftY; - axisvalue += -127; + if (event->type == SDL_EVENT_KEY_DOWN) { + axisvalue += -127; + } else { + axisvalue = 0; + } ax = Input::GetAxis(-0x80, 0x80, axisvalue); break; case SDLK_s: axis = Input::Axis::LeftY; - axisvalue += 127; + if (event->type == SDL_EVENT_KEY_DOWN) { + axisvalue += 127; + } else { + axisvalue = 0; + } ax = Input::GetAxis(-0x80, 0x80, axisvalue); break; case SDLK_j: axis = Input::Axis::RightX; - axisvalue += -127; + if (event->type == SDL_EVENT_KEY_DOWN) { + axisvalue += -127; + } else { + axisvalue = 0; + } ax = Input::GetAxis(-0x80, 0x80, axisvalue); break; case SDLK_l: axis = Input::Axis::RightX; - axisvalue += 127; + if (event->type == SDL_EVENT_KEY_DOWN) { + axisvalue += 127; + } else { + axisvalue = 0; + } ax = Input::GetAxis(-0x80, 0x80, axisvalue); break; case SDLK_i: axis = Input::Axis::RightY; - axisvalue += -127; + if (event->type == SDL_EVENT_KEY_DOWN) { + axisvalue += -127; + } else { + axisvalue = 0; + } ax = Input::GetAxis(-0x80, 0x80, axisvalue); break; case SDLK_k: axis = Input::Axis::RightY; - axisvalue += 127; + if (event->type == SDL_EVENT_KEY_DOWN) { + axisvalue += 127; + } else { + axisvalue = 0; + } ax = Input::GetAxis(-0x80, 0x80, axisvalue); break; default: @@ -176,7 +208,7 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { if (button != 0) { controller->CheckButton(0, button, event->type == SDL_EVENT_KEY_DOWN); } - if (axis != Input::Axis::AxisMax&& event->type == SDL_EVENT_KEY_DOWN) { + if (axis != Input::Axis::AxisMax) { controller->Axis(0, axis, ax); } } From 0325e4795a86801d6ed0314047434ad16b88e3cd Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 20 Jun 2024 17:10:14 +0300 Subject: [PATCH 07/11] posix_pthread_yield , scePadGetHandle --- src/core/libraries/kernel/thread_management.cpp | 6 ++++++ src/core/libraries/pad/pad.cpp | 4 ++-- src/input/controller.cpp | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/libraries/kernel/thread_management.cpp b/src/core/libraries/kernel/thread_management.cpp index 07669f84..de9ec316 100644 --- a/src/core/libraries/kernel/thread_management.cpp +++ b/src/core/libraries/kernel/thread_management.cpp @@ -995,6 +995,10 @@ void PS4_SYSV_ABI scePthreadYield() { sched_yield(); } +void PS4_SYSV_ABI posix_pthread_yield() { + sched_yield(); +} + int PS4_SYSV_ABI scePthreadAttrGetstack(ScePthreadAttr* attr, void** addr, size_t* size) { int result = pthread_attr_getstack(&(*attr)->pth_attr, addr, size); @@ -1308,6 +1312,8 @@ void pthreadSymbolsRegister(Core::Loader::SymbolsResolver* sym) { LIB_FUNCTION("bt3CTBKmGyI", "libkernel", 1, "libkernel", 1, 1, scePthreadSetaffinity); LIB_FUNCTION("6UgtwV+0zb4", "libkernel", 1, "libkernel", 1, 1, scePthreadCreate); LIB_FUNCTION("T72hz6ffq08", "libkernel", 1, "libkernel", 1, 1, scePthreadYield); + LIB_FUNCTION("B5GmVDKwpn0", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_yield); + LIB_FUNCTION("-quPa4SEJUw", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrGetstack); LIB_FUNCTION("Ru36fiTtJzA", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrGetstackaddr); LIB_FUNCTION("-fA+7ZlGDQs", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrGetstacksize); diff --git a/src/core/libraries/pad/pad.cpp b/src/core/libraries/pad/pad.cpp index 0faa01ba..949b71be 100644 --- a/src/core/libraries/pad/pad.cpp +++ b/src/core/libraries/pad/pad.cpp @@ -128,8 +128,8 @@ int PS4_SYSV_ABI scePadGetFeatureReport() { } int PS4_SYSV_ABI scePadGetHandle(s32 userId, s32 type, s32 index) { - LOG_ERROR(Lib_Pad, "(STUBBED) called"); - return ORBIS_OK; + LOG_DEBUG(Lib_Pad, "(DUMMY) called"); + return 1; } int PS4_SYSV_ABI scePadGetIdleCount() { diff --git a/src/input/controller.cpp b/src/input/controller.cpp index fd66c98a..7bfecadc 100644 --- a/src/input/controller.cpp +++ b/src/input/controller.cpp @@ -2,8 +2,8 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "core/libraries/kernel/time_management.h" -#include "input/controller.h" #include "core/libraries/pad/pad.h" +#include "input/controller.h" namespace Input { GameController::GameController() { From 49601f58ed7ad0f5a2b57810baeba2c03c10e5a5 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 20 Jun 2024 18:09:40 +0300 Subject: [PATCH 08/11] initial dents support --- src/core/file_sys/fs.cpp | 14 ++- src/core/file_sys/fs.h | 7 +- src/core/libraries/kernel/file_system.cpp | 105 ++++++++++++++++++++-- src/core/libraries/kernel/file_system.h | 10 +++ src/sdl_window.cpp | 16 ++-- 5 files changed, 128 insertions(+), 24 deletions(-) diff --git a/src/core/file_sys/fs.cpp b/src/core/file_sys/fs.cpp index c42a0d3e..912c74bf 100644 --- a/src/core/file_sys/fs.cpp +++ b/src/core/file_sys/fs.cpp @@ -28,15 +28,13 @@ void MntPoints::UnmountAll() { std::string MntPoints::GetHostDirectory(const std::string& guest_directory) { std::scoped_lock lock{m_mutex}; for (auto& pair : m_mnt_pairs) { - if (pair.guest_path.starts_with(guest_directory)) { - return pair.host_path + guest_directory; - } - } - // hack for relative path , get app0 and assuming it goes from there - for (auto& pair : m_mnt_pairs) { - if (pair.guest_path.starts_with("/app0")) { + // horrible code but it works :D + int find = guest_directory.find(pair.guest_path); + if (find == 0) { + std::string npath = + guest_directory.substr(pair.guest_path.size(), guest_directory.size() - 1); std::replace(pair.host_path.begin(), pair.host_path.end(), '\\', '/'); - return pair.host_path + guest_directory; + return pair.host_path + npath; } } return ""; diff --git a/src/core/file_sys/fs.h b/src/core/file_sys/fs.h index 7d7b9985..4ba01685 100644 --- a/src/core/file_sys/fs.h +++ b/src/core/file_sys/fs.h @@ -32,13 +32,18 @@ private: std::mutex m_mutex; }; +struct DirEntry { + std::string name; + bool isFile; +}; + struct File { std::atomic_bool is_opened{}; std::atomic_bool is_directory{}; std::string m_host_name; std::string m_guest_name; Common::FS::IOFile f; - // std::vector dirents; + std::vector dirents; u32 dirents_index; std::mutex m_mutex; }; diff --git a/src/core/libraries/kernel/file_system.cpp b/src/core/libraries/kernel/file_system.cpp index bc9ff214..3057b2c7 100644 --- a/src/core/libraries/kernel/file_system.cpp +++ b/src/core/libraries/kernel/file_system.cpp @@ -11,6 +11,29 @@ namespace Libraries::Kernel { +std::vector GetDirectoryEntries(const std::string& path) { + std::string curpath = path; + if (!curpath.ends_with("/")) { + curpath = std::string(curpath + "/"); + } + std::vector files; + + for (const auto& entry : std::filesystem::directory_iterator(curpath)) { + Core::FileSys::DirEntry e = {}; + if (std::filesystem::is_regular_file(entry.path().string())) { + e.name = entry.path().filename().string(); + e.isFile = true; + } else { + Core::FileSys::DirEntry e = {}; + e.name = entry.path().filename().string() + + "/"; // hmmm not sure if it has to be like this... + e.isFile = false; + } + files.push_back(e); + } + + return files; +} int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) { LOG_INFO(Kernel_Fs, "path = {} flags = {:#x} mode = {}", path, flags, mode); auto* h = Common::Singleton::Instance(); @@ -34,12 +57,23 @@ int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) { if (std::string_view{path} == "/dev/console" || std::string_view{path} == "/dev/deci_tty6") { return ORBIS_OK; } - + u32 handle = h->CreateHandle(); + auto* file = h->GetFile(handle); if (directory) { - LOG_ERROR(Kernel_Fs, "called on directory"); + file->is_directory = true; + file->m_guest_name = path; + file->m_host_name = mnt->GetHostDirectory(file->m_guest_name); + if (!std::filesystem::is_directory(file->m_host_name)) { // directory doesn't exist + UNREACHABLE(); // not supported yet + } else { + if (create) { + return handle; // dir already exists + } else { + file->dirents = GetDirectoryEntries(file->m_host_name); + file->dirents_index = 0; + } + } } else { - u32 handle = h->CreateHandle(); - auto* file = h->GetFile(handle); file->m_guest_name = path; file->m_host_name = mnt->GetHostFile(file->m_guest_name); if (read) { @@ -61,10 +95,9 @@ int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) { h->DeleteHandle(handle); return SCE_KERNEL_ERROR_EACCES; } - file->is_opened = true; - return handle; } - return -1; // dummy + file->is_opened = true; + return handle; } int PS4_SYSV_ABI posix_open(const char* path, int flags, /* SceKernelMode*/ u16 mode) { @@ -310,6 +343,62 @@ s32 PS4_SYSV_ABI sceKernelFsync(int fd) { return ORBIS_OK; } +int PS4_SYSV_ABI sceKernelGetdents(int fd, char* buf, int nbytes) { + LOG_INFO(Kernel_Fs, "(PARTIAL) fd = {}", fd); + // TODO error codes + auto* h = Common::Singleton::Instance(); + auto* file = h->GetFile(fd); + + if (file->dirents_index == file->dirents.size()) { + return 0; + } + + const auto& entry = file->dirents.at(file->dirents_index++); + auto str = entry.name; + auto str_size = str.size() - 1; + static int fileno = 1000; // random + OrbisKernelDirent* sce_ent = (OrbisKernelDirent*)buf; + sce_ent->d_fileno = fileno++; // TODO this should be unique but atm it changes maybe switch to a + // hash or something? + sce_ent->d_reclen = sizeof(OrbisKernelDirent); + sce_ent->d_type = (entry.isFile ? 8 : 4); + sce_ent->d_namlen = str_size; + strncpy(sce_ent->d_name, str.c_str(), ORBIS_MAX_PATH); + sce_ent->d_name[ORBIS_MAX_PATH] = '\0'; + + return sizeof(OrbisKernelDirent); +} + +int PS4_SYSV_ABI sceKernelGetdirentries(int fd, char* buf, int nbytes, s64* basep) { + LOG_INFO(Kernel_Fs, "(PARTIAL) fd = {}", fd); + + // TODO error codes + auto* h = Common::Singleton::Instance(); + auto* file = h->GetFile(fd); + if (basep != nullptr) { + *basep = file->dirents_index; + } + + if (file->dirents_index == file->dirents.size()) { + return 0; + } + + const auto& entry = file->dirents.at(file->dirents_index++); + auto str = entry.name; + auto str_size = str.size() - 1; + static int fileno = 1000; // random + OrbisKernelDirent* sce_ent = (OrbisKernelDirent*)buf; + sce_ent->d_fileno = fileno++; // TODO this should be unique but atm it changes maybe switch to a + // hash or something? + sce_ent->d_reclen = sizeof(OrbisKernelDirent); + sce_ent->d_type = (entry.isFile ? 8 : 4); + sce_ent->d_namlen = str_size; + strncpy(sce_ent->d_name, str.c_str(), ORBIS_MAX_PATH); + sce_ent->d_name[ORBIS_MAX_PATH] = '\0'; + + return sizeof(OrbisKernelDirent); +} + void fileSystemSymbolsRegister(Core::Loader::SymbolsResolver* sym) { LIB_FUNCTION("1G3lF1Gg1k8", "libkernel", 1, "libkernel", 1, 1, sceKernelOpen); LIB_FUNCTION("wuCroIGjt2g", "libScePosix", 1, "libkernel", 1, 1, posix_open); @@ -333,6 +422,8 @@ void fileSystemSymbolsRegister(Core::Loader::SymbolsResolver* sym) { LIB_FUNCTION("+r3rMFwItV4", "libkernel", 1, "libkernel", 1, 1, sceKernelPread); LIB_FUNCTION("uWyW3v98sU4", "libkernel", 1, "libkernel", 1, 1, sceKernelCheckReachability); LIB_FUNCTION("fTx66l5iWIA", "libkernel", 1, "libkernel", 1, 1, sceKernelFsync); + LIB_FUNCTION("j2AIqSqJP0w", "libkernel", 1, "libkernel", 1, 1, sceKernelGetdents); + LIB_FUNCTION("taRWhTJFTgE", "libkernel", 1, "libkernel", 1, 1, sceKernelGetdirentries); // openOrbis (to check if it is valid out of OpenOrbis LIB_FUNCTION("6c3rCVE-fTU", "libkernel", 1, "libkernel", 1, 1, diff --git a/src/core/libraries/kernel/file_system.h b/src/core/libraries/kernel/file_system.h index c0284310..1174dd86 100644 --- a/src/core/libraries/kernel/file_system.h +++ b/src/core/libraries/kernel/file_system.h @@ -12,6 +12,8 @@ class SymbolsResolver; namespace Libraries::Kernel { +constexpr int ORBIS_MAX_PATH = 255; + struct SceKernelIovec { void* iov_base; std::size_t iov_len; @@ -39,6 +41,14 @@ struct OrbisKernelStat { unsigned int : (8 / 2) * (16 - static_cast(sizeof(OrbisKernelTimespec))); }; +struct OrbisKernelDirent { + u32 d_fileno; /* file number of entry */ + u16 d_reclen; /* length of this record */ + u8 d_type; /* file type, see below */ + u8 d_namlen; /* length of string in d_name */ + char d_name[ORBIS_MAX_PATH + 1]; /* name must be no longer than this */ +}; + // flags for Open constexpr int ORBIS_KERNEL_O_RDONLY = 0x0000; constexpr int ORBIS_KERNEL_O_WRONLY = 0x0001; diff --git a/src/sdl_window.cpp b/src/sdl_window.cpp index 3a676e01..57297d0a 100644 --- a/src/sdl_window.cpp +++ b/src/sdl_window.cpp @@ -136,7 +136,7 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { axisvalue += -127; } else { axisvalue = 0; - } + } ax = Input::GetAxis(-0x80, 0x80, axisvalue); break; case SDLK_d: @@ -145,7 +145,7 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { axisvalue += 127; } else { axisvalue = 0; - } + } ax = Input::GetAxis(-0x80, 0x80, axisvalue); break; case SDLK_w: @@ -154,7 +154,7 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { axisvalue += -127; } else { axisvalue = 0; - } + } ax = Input::GetAxis(-0x80, 0x80, axisvalue); break; case SDLK_s: @@ -163,7 +163,7 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { axisvalue += 127; } else { axisvalue = 0; - } + } ax = Input::GetAxis(-0x80, 0x80, axisvalue); break; case SDLK_j: @@ -172,7 +172,7 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { axisvalue += -127; } else { axisvalue = 0; - } + } ax = Input::GetAxis(-0x80, 0x80, axisvalue); break; case SDLK_l: @@ -181,7 +181,7 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { axisvalue += 127; } else { axisvalue = 0; - } + } ax = Input::GetAxis(-0x80, 0x80, axisvalue); break; case SDLK_i: @@ -190,7 +190,7 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { axisvalue += -127; } else { axisvalue = 0; - } + } ax = Input::GetAxis(-0x80, 0x80, axisvalue); break; case SDLK_k: @@ -199,7 +199,7 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { axisvalue += 127; } else { axisvalue = 0; - } + } ax = Input::GetAxis(-0x80, 0x80, axisvalue); break; default: From 1b2c3ccc421d38d6607246a151efd45c7062fe15 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 20 Jun 2024 21:13:17 +0300 Subject: [PATCH 09/11] better dirents --- src/core/libraries/kernel/file_system.cpp | 45 +++++++---------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/src/core/libraries/kernel/file_system.cpp b/src/core/libraries/kernel/file_system.cpp index 3057b2c7..88166b6f 100644 --- a/src/core/libraries/kernel/file_system.cpp +++ b/src/core/libraries/kernel/file_system.cpp @@ -20,14 +20,14 @@ std::vector GetDirectoryEntries(const std::string& path for (const auto& entry : std::filesystem::directory_iterator(curpath)) { Core::FileSys::DirEntry e = {}; - if (std::filesystem::is_regular_file(entry.path().string())) { - e.name = entry.path().filename().string(); - e.isFile = true; - } else { + if (std::filesystem::is_directory(entry.path().string())) { Core::FileSys::DirEntry e = {}; e.name = entry.path().filename().string() + "/"; // hmmm not sure if it has to be like this... e.isFile = false; + } else { + e.name = entry.path().filename().string(); + e.isFile = true; } files.push_back(e); } @@ -343,8 +343,7 @@ s32 PS4_SYSV_ABI sceKernelFsync(int fd) { return ORBIS_OK; } -int PS4_SYSV_ABI sceKernelGetdents(int fd, char* buf, int nbytes) { - LOG_INFO(Kernel_Fs, "(PARTIAL) fd = {}", fd); +int GetDents(int fd, char* buf, int nbytes, s64* basep) { // TODO error codes auto* h = Common::Singleton::Instance(); auto* file = h->GetFile(fd); @@ -366,39 +365,21 @@ int PS4_SYSV_ABI sceKernelGetdents(int fd, char* buf, int nbytes) { strncpy(sce_ent->d_name, str.c_str(), ORBIS_MAX_PATH); sce_ent->d_name[ORBIS_MAX_PATH] = '\0'; - return sizeof(OrbisKernelDirent); -} - -int PS4_SYSV_ABI sceKernelGetdirentries(int fd, char* buf, int nbytes, s64* basep) { - LOG_INFO(Kernel_Fs, "(PARTIAL) fd = {}", fd); - - // TODO error codes - auto* h = Common::Singleton::Instance(); - auto* file = h->GetFile(fd); if (basep != nullptr) { *basep = file->dirents_index; } - if (file->dirents_index == file->dirents.size()) { - return 0; - } - - const auto& entry = file->dirents.at(file->dirents_index++); - auto str = entry.name; - auto str_size = str.size() - 1; - static int fileno = 1000; // random - OrbisKernelDirent* sce_ent = (OrbisKernelDirent*)buf; - sce_ent->d_fileno = fileno++; // TODO this should be unique but atm it changes maybe switch to a - // hash or something? - sce_ent->d_reclen = sizeof(OrbisKernelDirent); - sce_ent->d_type = (entry.isFile ? 8 : 4); - sce_ent->d_namlen = str_size; - strncpy(sce_ent->d_name, str.c_str(), ORBIS_MAX_PATH); - sce_ent->d_name[ORBIS_MAX_PATH] = '\0'; - return sizeof(OrbisKernelDirent); } +int PS4_SYSV_ABI sceKernelGetdents(int fd, char* buf, int nbytes) { + return GetDents(fd, buf, nbytes, nullptr); +} + +int PS4_SYSV_ABI sceKernelGetdirentries(int fd, char* buf, int nbytes, s64* basep) { + return GetDents(fd, buf, nbytes, basep); +} + void fileSystemSymbolsRegister(Core::Loader::SymbolsResolver* sym) { LIB_FUNCTION("1G3lF1Gg1k8", "libkernel", 1, "libkernel", 1, 1, sceKernelOpen); LIB_FUNCTION("wuCroIGjt2g", "libScePosix", 1, "libkernel", 1, 1, posix_open); From 19edb8155f5f92af2253c68ae17a4c1474e000d9 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 20 Jun 2024 22:29:08 +0300 Subject: [PATCH 10/11] fixed stupid directory iterator issue --- src/core/libraries/kernel/file_system.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/core/libraries/kernel/file_system.cpp b/src/core/libraries/kernel/file_system.cpp index 88166b6f..286d93d5 100644 --- a/src/core/libraries/kernel/file_system.cpp +++ b/src/core/libraries/kernel/file_system.cpp @@ -21,9 +21,7 @@ std::vector GetDirectoryEntries(const std::string& path for (const auto& entry : std::filesystem::directory_iterator(curpath)) { Core::FileSys::DirEntry e = {}; if (std::filesystem::is_directory(entry.path().string())) { - Core::FileSys::DirEntry e = {}; - e.name = entry.path().filename().string() + - "/"; // hmmm not sure if it has to be like this... + e.name = entry.path().filename().string(); e.isFile = false; } else { e.name = entry.path().filename().string(); From 7519d4610c012347a4a0865d36f44dd6cc5dd2c1 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Fri, 21 Jun 2024 14:37:49 +0300 Subject: [PATCH 11/11] added missing buttons and analog buttons to keyboard --- src/core/libraries/kernel/file_system.cpp | 10 +++++-- src/sdl_window.cpp | 35 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/core/libraries/kernel/file_system.cpp b/src/core/libraries/kernel/file_system.cpp index 286d93d5..2a874c63 100644 --- a/src/core/libraries/kernel/file_system.cpp +++ b/src/core/libraries/kernel/file_system.cpp @@ -52,8 +52,14 @@ int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) { bool direct = (flags & ORBIS_KERNEL_O_DIRECT) != 0; bool directory = (flags & ORBIS_KERNEL_O_DIRECTORY) != 0; - if (std::string_view{path} == "/dev/console" || std::string_view{path} == "/dev/deci_tty6") { - return ORBIS_OK; + if (std::string_view{path} == "/dev/console") { + return 2000; + } + if (std::string_view{path} == "/dev/deci_tty6") { + return 2001; + } + if (std::string_view{path} == "/dev/stdout") { + return 2002; } u32 handle = h->CreateHandle(); auto* file = h->GetFile(handle); diff --git a/src/sdl_window.cpp b/src/sdl_window.cpp index 57297d0a..ef492db6 100644 --- a/src/sdl_window.cpp +++ b/src/sdl_window.cpp @@ -202,6 +202,41 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { } ax = Input::GetAxis(-0x80, 0x80, axisvalue); break; + case SDLK_x: + button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_L3; + break; + case SDLK_m: + button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_R3; + break; + case SDLK_q: + button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_L1; + break; + case SDLK_u: + button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_R1; + break; + case SDLK_e: + button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_L2; + axis = Input::Axis::TriggerLeft; + if (event->type == SDL_EVENT_KEY_DOWN) { + axisvalue += 255; + } else { + axisvalue = 0; + } + ax = Input::GetAxis(0, 0x80, axisvalue); + break; + case SDLK_o: + button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_R2; + axis = Input::Axis::TriggerRight; + if (event->type == SDL_EVENT_KEY_DOWN) { + axisvalue += 255; + } else { + axisvalue = 0; + } + ax = Input::GetAxis(0, 0x80, axisvalue); + break; + case SDLK_SPACE: + button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_TOUCH_PAD; + break; default: break; }