From 92e4c6b7982b7a1096b46d3ebb8fc46390805a6a Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 1 Apr 2024 14:21:40 +0300 Subject: [PATCH 01/15] scePthreadMutexDestroy implemented --- .../libraries/libkernel/thread_management.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/core/hle/libraries/libkernel/thread_management.cpp b/src/core/hle/libraries/libkernel/thread_management.cpp index 850e64a8..d2568e7c 100644 --- a/src/core/hle/libraries/libkernel/thread_management.cpp +++ b/src/core/hle/libraries/libkernel/thread_management.cpp @@ -244,6 +244,29 @@ int PS4_SYSV_ABI scePthreadMutexInit(ScePthreadMutex* mutex, const ScePthreadMut } } +int PS4_SYSV_ABI scePthreadMutexDestroy(ScePthreadMutex* mutex) { + + if (mutex == nullptr || *mutex == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + int result = pthread_mutex_destroy(&(*mutex)->pth_mutex); + + LOG_INFO(Kernel_Pthread, "name={}, result={}", (*mutex)->name, result); + + delete *mutex; + *mutex = nullptr; + + switch (result) { + case 0: + return SCE_OK; + case EBUSY: + return SCE_KERNEL_ERROR_EBUSY; + case EINVAL: + default: + return SCE_KERNEL_ERROR_EINVAL; + } +} int PS4_SYSV_ABI scePthreadMutexattrInit(ScePthreadMutexattr* attr) { *attr = new PthreadMutexattrInternal{}; @@ -512,6 +535,7 @@ void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("6UgtwV+0zb4", "libkernel", 1, "libkernel", 1, 1, scePthreadCreate); // mutex calls LIB_FUNCTION("cmo1RIYva9o", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexInit); + LIB_FUNCTION("2Of0f+3mhhE", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexDestroy); LIB_FUNCTION("F8bUHwAG284", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrInit); LIB_FUNCTION("smWEktiyyG0", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrDestroy); LIB_FUNCTION("iMp8QpE+XO4", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrSettype); From 6066c89607761999cb0e068d2d0a89178df5e8f8 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 1 Apr 2024 14:45:27 +0300 Subject: [PATCH 02/15] scePadGetControllerInformation added , dummy scePadSetMotionSensorState --- src/common/types.h | 2 +- src/core/hle/kernel/memory_management.cpp | 2 +- src/core/hle/libraries/libpad/pad.cpp | 26 +++++++++++++++++++++-- src/core/hle/libraries/libpad/pad.h | 23 ++++++++++++++++++++ 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/common/types.h b/src/common/types.h index f3c0862c..313d2fa2 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -6,7 +6,7 @@ #include #include -using s08 = std::int8_t; +using s8 = std::int8_t; using s16 = std::int16_t; using s32 = std::int32_t; using s64 = std::int64_t; diff --git a/src/core/hle/kernel/memory_management.cpp b/src/core/hle/kernel/memory_management.cpp index d6aa8cdb..9cee047d 100644 --- a/src/core/hle/kernel/memory_management.cpp +++ b/src/core/hle/kernel/memory_management.cpp @@ -18,7 +18,7 @@ bool is16KBAligned(u64 n) { } u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize() { - LOG_WARNING(Kernel_Vmm, "(STUBBED) called"); + LOG_WARNING(Kernel_Vmm, "called"); return SCE_KERNEL_MAIN_DMEM_SIZE; } diff --git a/src/core/hle/libraries/libpad/pad.cpp b/src/core/hle/libraries/libpad/pad.cpp index 3d3f3b8d..f224367f 100644 --- a/src/core/hle/libraries/libpad/pad.cpp +++ b/src/core/hle/libraries/libpad/pad.cpp @@ -11,13 +11,13 @@ namespace OldLibraries::LibPad { int PS4_SYSV_ABI scePadInit() { - LOG_WARNING(Lib_Pad, "(STUBBED) called"); + 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, "(STUBBED) called user_id = {} type = {} index = {}", user_id, type, index); + LOG_INFO(Lib_Pad, "(DUMMY) called user_id = {} type = {} index = {}", user_id, type, index); return 1; // dummy } @@ -48,10 +48,32 @@ int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) { return SCE_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; +} + +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("gjP9-KQzoUk", "libScePad", 1, "libScePad", 1, 1, scePadGetControllerInformation); + LIB_FUNCTION("clVvL4ZDntw", "libScePad", 1, "libScePad", 1, 1, scePadSetMotionSensorState); } } // namespace OldLibraries::LibPad diff --git a/src/core/hle/libraries/libpad/pad.h b/src/core/hle/libraries/libpad/pad.h index fc0bad2e..f2f5d663 100644 --- a/src/core/hle/libraries/libpad/pad.h +++ b/src/core/hle/libraries/libpad/pad.h @@ -12,6 +12,16 @@ class SymbolsResolver; namespace OldLibraries::LibPad { +#define ORBIS_PAD_PORT_TYPE_STANDARD 0 +#define ORBIS_PAD_PORT_TYPE_SPECIAL 2 + +#define ORBIS_PAD_DEVICE_CLASS_PAD 0 +#define ORBIS_PAD_DEVICE_CLASS_GUITAR 1 +#define ORBIS_PAD_DEVICE_CLASS_DRUMS 2 + +#define ORBIS_PAD_CONNECTION_TYPE_STANDARD 0 +#define ORBIS_PAD_CONNECTION_TYPE_REMOTE 2 + enum ScePadButton : u32 { L3 = 0x00000002, R3 = 0x00000004, @@ -95,6 +105,19 @@ struct ScePadData { 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); From 9d8fc6195460d45e8a24dae87afc8d2495322633 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 1 Apr 2024 22:31:25 +0300 Subject: [PATCH 03/15] sceSaveDataMount2 just return save data not found for now --- src/core/libraries/libscecommondialog.cpp | 2 +- src/core/libraries/libscesavedata.cpp | 13 +++++++-- src/core/libraries/libscesavedata.h | 34 ++++++++++++++++++++++- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/core/libraries/libscecommondialog.cpp b/src/core/libraries/libscecommondialog.cpp index f940401d..2d1ea97a 100644 --- a/src/core/libraries/libscecommondialog.cpp +++ b/src/core/libraries/libscecommondialog.cpp @@ -84,7 +84,7 @@ int PS4_SYSV_ABI _ZTVN3sce16CommonDialogUtil6ClientE() { } int PS4_SYSV_ABI sceCommonDialogInitialize() { - LOG_ERROR(Lib_CommonDlg, "(STUBBED) called"); + LOG_ERROR(Lib_CommonDlg, "(DUMMY) called"); return ORBIS_OK; } diff --git a/src/core/libraries/libscesavedata.cpp b/src/core/libraries/libscesavedata.cpp index e3ae6e35..89dd1e7d 100644 --- a/src/core/libraries/libscesavedata.cpp +++ b/src/core/libraries/libscesavedata.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Generated By moduleGenerator +#include #include "common/logging/log.h" #include "error_codes.h" #include "libscesavedata.h" @@ -328,9 +329,15 @@ int PS4_SYSV_ABI sceSaveDataMount() { return ORBIS_OK; } -int PS4_SYSV_ABI sceSaveDataMount2() { - LOG_ERROR(Lib_SaveData, "(STUBBED) called"); - return ORBIS_OK; +s32 PS4_SYSV_ABI sceSaveDataMount2(const OrbisSaveDataMount2* mount, + OrbisSaveDataMountResult* mount_result) { + // will return save data not found , breakpoint for others + LOG_ERROR(Lib_SaveData, "(DUMMY) called user_id = {} dir_name = {} blocks = {} mount_mode = {}", + mount->user_id, mount->dir_name->data, mount->blocks, mount->mount_mode); + if (mount->mount_mode == 1) { // open + return 0x809F0008; // save data not found + } + UNREACHABLE(); } int PS4_SYSV_ABI sceSaveDataMount5() { diff --git a/src/core/libraries/libscesavedata.h b/src/core/libraries/libscesavedata.h index 93f902c1..a15e4f84 100644 --- a/src/core/libraries/libscesavedata.h +++ b/src/core/libraries/libscesavedata.h @@ -7,6 +7,37 @@ namespace Libraries::SaveData { +constexpr int ORBIS_SAVE_DATA_DIRNAME_DATA_MAXSIZE = + 32; // Maximum size for a save data directory name +constexpr int ORBIS_SAVE_DATA_MOUNT_POINT_DATA_MAXSIZE = 16; // Maximum size for a mount point name + +struct OrbisSaveDataDirName { + char data[ORBIS_SAVE_DATA_DIRNAME_DATA_MAXSIZE]; +}; + +struct OrbisSaveDataMount2 { + s32 user_id; + s32 unk1; + const OrbisSaveDataDirName* dir_name; + u64 blocks; + u32 mount_mode; + u8 reserved[32]; + s32 unk2; +}; + +struct OrbisSaveDataMountPoint { + char data[ORBIS_SAVE_DATA_MOUNT_POINT_DATA_MAXSIZE]; +}; + +struct OrbisSaveDataMountResult { + OrbisSaveDataMountPoint mount_point; + u64 required_blocks; + u32 unused; + u32 mount_status; + u8 reserved[28]; + s32 unk1; +}; + int PS4_SYSV_ABI sceSaveDataAbort(); int PS4_SYSV_ABI sceSaveDataBackup(); int PS4_SYSV_ABI sceSaveDataBindPsnAccount(); @@ -71,7 +102,8 @@ int PS4_SYSV_ABI sceSaveDataIsDeletingUsbDb(); int PS4_SYSV_ABI sceSaveDataIsMounted(); int PS4_SYSV_ABI sceSaveDataLoadIcon(); int PS4_SYSV_ABI sceSaveDataMount(); -int PS4_SYSV_ABI sceSaveDataMount2(); +s32 PS4_SYSV_ABI sceSaveDataMount2(const OrbisSaveDataMount2* mount, + OrbisSaveDataMountResult* mount_result); int PS4_SYSV_ABI sceSaveDataMount5(); int PS4_SYSV_ABI sceSaveDataMountInternal(); int PS4_SYSV_ABI sceSaveDataMountSys(); From 0b8cc8eba90ef16ab9a89f8ffa9b48293c9ae88b Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Tue, 2 Apr 2024 08:51:17 +0300 Subject: [PATCH 04/15] added sceKernelClockGettime --- .../libraries/libkernel/thread_management.cpp | 29 +++++++++++++++++++ .../libraries/libkernel/thread_management.h | 5 ++++ 2 files changed, 34 insertions(+) diff --git a/src/core/hle/libraries/libkernel/thread_management.cpp b/src/core/hle/libraries/libkernel/thread_management.cpp index d2568e7c..1c09a2dd 100644 --- a/src/core/hle/libraries/libkernel/thread_management.cpp +++ b/src/core/hle/libraries/libkernel/thread_management.cpp @@ -519,6 +519,33 @@ int PS4_SYSV_ABI posix_pthread_cond_broadcast(ScePthreadCond* cond) { return result; } +int PS4_SYSV_ABI sceKernelClockGettime(s32 clock_id, SceKernelTimespec* tp) { + if (tp == nullptr) { + return SCE_KERNEL_ERROR_EFAULT; + } + clockid_t pclock_id = CLOCK_REALTIME; + switch (clock_id) { + case 0: + pclock_id = CLOCK_REALTIME; + break; + case 13: + case 4: + pclock_id = CLOCK_MONOTONIC; + break; + default: + UNREACHABLE(); + } + + timespec t{}; + int result = clock_gettime(pclock_id, &t); + tp->tv_sec = t.tv_sec; + tp->tv_nsec = t.tv_nsec; + if (result == 0) { + return SCE_OK; + } + return SCE_KERNEL_ERROR_EINVAL; +} + void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("4+h9EzwKF4I", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetschedpolicy); LIB_FUNCTION("-Wreprtu0Qs", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetdetachstate); @@ -552,6 +579,8 @@ void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("2Z+PpY6CaJg", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_mutex_unlock); LIB_FUNCTION("mkx2fVhNMsg", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_cond_broadcast); + LIB_FUNCTION("QBi7HCK03hw", "libkernel", 1, "libkernel", 1, 1, sceKernelClockGettime); + // openorbis weird functions LIB_FUNCTION("7H0iTOciTLo", "libkernel", 1, "libkernel", 1, 1, posix_pthread_mutex_lock); LIB_FUNCTION("2Z+PpY6CaJg", "libkernel", 1, "libkernel", 1, 1, posix_pthread_mutex_unlock); diff --git a/src/core/hle/libraries/libkernel/thread_management.h b/src/core/hle/libraries/libkernel/thread_management.h index ba3c513e..922f8ef8 100644 --- a/src/core/hle/libraries/libkernel/thread_management.h +++ b/src/core/hle/libraries/libkernel/thread_management.h @@ -33,6 +33,11 @@ using ScePthreadCondattr = PthreadCondAttrInternal*; using pthreadEntryFunc = PS4_SYSV_ABI void* (*)(void*); +struct SceKernelTimespec { + int64_t tv_sec; + int64_t tv_nsec; +}; + struct PthreadInternal { u8 reserved[4096]; std::string name; From 2cc03e851e074b870a499857868ace8f027a104e Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Tue, 2 Apr 2024 17:21:04 +0300 Subject: [PATCH 05/15] added some debug info to gnm --- .../libscegnmdriver/libscegnmdriver.cpp | 47 +++++++++++++++++-- .../libscegnmdriver/libscegnmdriver.h | 4 +- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.cpp b/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.cpp index 9f24c280..d4afca15 100644 --- a/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.cpp +++ b/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.cpp @@ -9,19 +9,60 @@ namespace Core::Libraries::LibSceGnmDriver { -int32_t sceGnmSubmitDone() { +int32_t PS4_SYSV_ABI sceGnmSubmitDone() { LOG_WARNING(Lib_GnmDriver, "(STUBBED) called"); return 0; } -void sceGnmFlushGarlic() { +void PS4_SYSV_ABI sceGnmFlushGarlic() { LOG_WARNING(Lib_GnmDriver, "(STUBBED) called"); GPU::flushGarlic(Emu::getGraphicCtx()); } +s32 PS4_SYSV_ABI sceGnmDrawIndex(u32* cmd, u64 size, u32 index_count, const void* index_addr, + u32 flags, u32 type) { + LOG_INFO(Lib_GnmDriver, + "(STUBBED) called cmd_buffer = 0x{:x} size = {} index_count = {} index_addr = 0x{:x} " + "flags = 0x{:x} type = {}", + reinterpret_cast(cmd), size, index_count, + reinterpret_cast(index_addr), flags, type); + return 0; +} + +int PS4_SYSV_ABI sceGnmSetVsShader(u32* cmd, u64 size, const u32* vs_regs, u32 shader_modifier) { + LOG_INFO(Lib_GnmDriver, + "(STUBBED) called cmd_buffer = 0x{:x} size = {} shader_modifier = {} vs_reg0 = " + "0x{:x} vs_reg1 = 0x{:x} vs_reg2 = 0x{:x} vs_reg3 = 0x{:x} vs_reg4 = 0x{:x} vs_reg5 = " + "0x{:x} vs_reg6 = 0x{:x}", + reinterpret_cast(cmd), size, shader_modifier, vs_regs[0], vs_regs[1], + vs_regs[2], vs_regs[3], vs_regs[4], vs_regs[5], vs_regs[6]); + return 0; +} + +int PS4_SYSV_ABI sceGnmUpdateVsShader(u32* cmd, u64 size, const u32* vs_regs, u32 shader_modifier) { + LOG_INFO(Lib_GnmDriver, + "(STUBBED) called cmd_buffer = 0x{:x} size = {} shader_modifier = {} vs_reg0 = " + "0x{:x} vs_reg1 = 0x{:x} vs_reg2 = 0x{:x} vs_reg3 = 0x{:x} vs_reg4 = 0x{:x} vs_reg5 = " + "0x{:x} vs_reg6 = 0x{:x}", + reinterpret_cast(cmd), size, shader_modifier, vs_regs[0], vs_regs[1], + vs_regs[2], vs_regs[3], vs_regs[4], vs_regs[5], vs_regs[6]); + return 0; +} + +u32 PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState350(u32* cmd, u64 size) { + LOG_INFO(Lib_GnmDriver, "(STUBBED) called cmd_buffer = 0x{:x} size = {}", + reinterpret_cast(cmd), size); + return 0; +} + void LibSceGnmDriver_Register(Loader::SymbolsResolver* sym) { LIB_FUNCTION("yvZ73uQUqrk", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSubmitDone); LIB_FUNCTION("iBt3Oe00Kvc", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmFlushGarlic); + LIB_FUNCTION("HlTPoZ-oY7Y", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmDrawIndex); + LIB_FUNCTION("gAhCn6UiU4Y", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSetVsShader); + LIB_FUNCTION("V31V01UiScY", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, + sceGnmUpdateVsShader); + LIB_FUNCTION("yb2cRhagD1I", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, + sceGnmDrawInitDefaultHardwareState350); } - }; // namespace Core::Libraries::LibSceGnmDriver diff --git a/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.h b/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.h index 3a9dc178..6768bb44 100644 --- a/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.h +++ b/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.h @@ -11,8 +11,8 @@ class SymbolsResolver; namespace Core::Libraries::LibSceGnmDriver { -int32_t sceGnmSubmitDone(); -void sceGnmFlushGarlic(); +int32_t PS4_SYSV_ABI sceGnmSubmitDone(); +void PS4_SYSV_ABI sceGnmFlushGarlic(); void LibSceGnmDriver_Register(Loader::SymbolsResolver* sym); From c832e3831a7617daebe555e79b64258cafd5210c Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Tue, 2 Apr 2024 18:07:24 +0300 Subject: [PATCH 06/15] scePthreadAttrGet , and some mutex work --- .../libraries/libkernel/thread_management.cpp | 223 +++++++++++++++++- 1 file changed, 216 insertions(+), 7 deletions(-) diff --git a/src/core/hle/libraries/libkernel/thread_management.cpp b/src/core/hle/libraries/libkernel/thread_management.cpp index 1c09a2dd..103e766a 100644 --- a/src/core/hle/libraries/libkernel/thread_management.cpp +++ b/src/core/hle/libraries/libkernel/thread_management.cpp @@ -70,6 +70,72 @@ int PS4_SYSV_ABI scePthreadAttrDestroy(ScePthreadAttr* attr) { return SCE_KERNEL_ERROR_EINVAL; } +int PS4_SYSV_ABI scePthreadAttrSetguardsize(ScePthreadAttr* attr, size_t guard_size) { + if (attr == nullptr || *attr == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + (*attr)->guard_size = guard_size; + + return SCE_OK; +} + +int PS4_SYSV_ABI scePthreadAttrGetguardsize(const ScePthreadAttr* attr, size_t* guard_size) { + if (guard_size == nullptr || attr == nullptr || *attr == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + *guard_size = (*attr)->guard_size; + + return SCE_OK; +} + +int PS4_SYSV_ABI scePthreadAttrGetinheritsched(const ScePthreadAttr* attr, int* inherit_sched) { + + if (inherit_sched == nullptr || attr == nullptr || *attr == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + int result = pthread_attr_getinheritsched(&(*attr)->pth_attr, inherit_sched); + + switch (*inherit_sched) { + case PTHREAD_EXPLICIT_SCHED: + *inherit_sched = 0; + break; + case PTHREAD_INHERIT_SCHED: + *inherit_sched = 4; + break; + default: + UNREACHABLE(); + } + + return (result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL); +} + +int PS4_SYSV_ABI scePthreadAttrGetdetachstate(const ScePthreadAttr* attr, int* state) { + if (state == nullptr || attr == nullptr || *attr == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + // int result = pthread_attr_getdetachstate(&(*attr)->p, state); + int result = 0; + + *state = ((*attr)->detached ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE); + + switch (*state) { + case PTHREAD_CREATE_JOINABLE: + *state = 0; + break; + case PTHREAD_CREATE_DETACHED: + *state = 1; + break; + default: + UNREACHABLE(); + } + + return (result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL); +} + int PS4_SYSV_ABI scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate) { if (attr == nullptr || *attr == nullptr) { return SCE_KERNEL_ERROR_EINVAL; @@ -118,6 +184,26 @@ int PS4_SYSV_ABI scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inherit return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL; } +int PS4_SYSV_ABI scePthreadAttrGetschedparam(const ScePthreadAttr* attr, + SceKernelSchedParam* param) { + + if (param == nullptr || attr == nullptr || *attr == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + int result = pthread_attr_getschedparam(&(*attr)->pth_attr, param); + + if (param->sched_priority <= -2) { + param->sched_priority = 767; + } else if (param->sched_priority >= +2) { + param->sched_priority = 256; + } else { + param->sched_priority = 700; + } + + return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL; +} + int PS4_SYSV_ABI scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param) { if (param == nullptr || attr == nullptr || *attr == nullptr) { @@ -138,6 +224,31 @@ int PS4_SYSV_ABI scePthreadAttrSetschedparam(ScePthreadAttr* attr, return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL; } +int PS4_SYSV_ABI scePthreadAttrGetschedpolicy(const ScePthreadAttr* attr, int* policy) { + + if (policy == nullptr || attr == nullptr || *attr == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + int result = pthread_attr_getschedpolicy(&(*attr)->pth_attr, policy); + + switch (*policy) { + case SCHED_OTHER: + *policy = (*attr)->policy; + break; + case SCHED_FIFO: + *policy = 1; + break; + case SCHED_RR: + *policy = 3; + break; + default: + UNREACHABLE(); + } + + return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL; +} + int PS4_SYSV_ABI scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) { if (attr == nullptr || *attr == nullptr) { return SCE_KERNEL_ERROR_EINVAL; @@ -180,6 +291,51 @@ int PS4_SYSV_ABI scePthreadAttrGetaffinity(const ScePthreadAttr* pattr, return SCE_OK; } + +int PS4_SYSV_ABI scePthreadAttrGetstackaddr(const ScePthreadAttr* attr, void** stack_addr) { + + if (stack_addr == nullptr || attr == nullptr || *attr == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + int result = pthread_attr_getstackaddr(&(*attr)->pth_attr, stack_addr); + + return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL; +} + +int PS4_SYSV_ABI scePthreadAttrGetstacksize(const ScePthreadAttr* attr, size_t* stack_size) { + + if (stack_size == nullptr || attr == nullptr || *attr == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + int result = pthread_attr_getstacksize(&(*attr)->pth_attr, stack_size); + + return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL; +} + +int PS4_SYSV_ABI scePthreadAttrSetstackaddr(ScePthreadAttr* attr, void* addr) { + + if (addr == nullptr || attr == nullptr || *attr == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + int result = pthread_attr_setstackaddr(&(*attr)->pth_attr, addr); + + return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL; +} + +int PS4_SYSV_ABI scePthreadAttrSetstacksize(ScePthreadAttr* attr, size_t stack_size) { + + if (stack_size == 0 || attr == nullptr || *attr == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + int result = pthread_attr_setstacksize(&(*attr)->pth_attr, stack_size); + + return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL; +} + int PS4_SYSV_ABI scePthreadSetaffinity(ScePthread thread, const /*SceKernelCpumask*/ u64 mask) { LOG_INFO(Kernel_Pthread, "called"); @@ -191,6 +347,7 @@ int PS4_SYSV_ABI scePthreadSetaffinity(ScePthread thread, const /*SceKernelCpuma return result; } + int PS4_SYSV_ABI scePthreadCreate(ScePthread* thread, const ScePthreadAttr* attr, pthreadEntryFunc start_routine, void* arg, const char* name) { LOG_INFO(Kernel_Pthread, "(STUBBED) called"); @@ -330,7 +487,6 @@ int PS4_SYSV_ABI scePthreadMutexattrSetprotocol(ScePthreadMutexattr* attr, int p return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL; } int PS4_SYSV_ABI scePthreadMutexLock(ScePthreadMutex* mutex) { - LOG_INFO(Kernel_Pthread, "called"); mutex = static_cast(createMutex(mutex)); if (mutex == nullptr) { @@ -338,7 +494,9 @@ int PS4_SYSV_ABI scePthreadMutexLock(ScePthreadMutex* mutex) { } int result = pthread_mutex_lock(&(*mutex)->pth_mutex); - LOG_INFO(Kernel_Pthread, "name={}, result={}", (*mutex)->name, result); + if (result != 0) { + LOG_INFO(Kernel_Pthread, "name={}, result={}", (*mutex)->name, result); + } switch (result) { case 0: return SCE_OK; @@ -353,14 +511,15 @@ int PS4_SYSV_ABI scePthreadMutexLock(ScePthreadMutex* mutex) { } } int PS4_SYSV_ABI scePthreadMutexUnlock(ScePthreadMutex* mutex) { - LOG_INFO(Kernel_Pthread, "called"); mutex = static_cast(createMutex(mutex)); if (mutex == nullptr) { return SCE_KERNEL_ERROR_EINVAL; } int result = pthread_mutex_unlock(&(*mutex)->pth_mutex); - LOG_INFO(Kernel_Pthread, "name={}, result={}", (*mutex)->name, result); + if (result != 0) { + LOG_INFO(Kernel_Pthread, "name={}, result={}", (*mutex)->name, result); + } switch (result) { case 0: return SCE_OK; @@ -471,7 +630,7 @@ int PS4_SYSV_ABI scePthreadCondBroadcast(ScePthreadCond* cond) { } int PS4_SYSV_ABI posix_pthread_mutex_init(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr) { - LOG_INFO(Kernel_Pthread, "posix pthread_mutex_init redirect to scePthreadMutexInit"); + // LOG_INFO(Kernel_Pthread, "posix pthread_mutex_init redirect to scePthreadMutexInit"); int result = scePthreadMutexInit(mutex, attr, nullptr); if (result < 0) { int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP @@ -483,7 +642,7 @@ int PS4_SYSV_ABI posix_pthread_mutex_init(ScePthreadMutex* mutex, const ScePthre } int PS4_SYSV_ABI posix_pthread_mutex_lock(ScePthreadMutex* mutex) { - LOG_INFO(Kernel_Pthread, "posix pthread_mutex_lock redirect to scePthreadMutexLock"); + // LOG_INFO(Kernel_Pthread, "posix pthread_mutex_lock redirect to scePthreadMutexLock"); int result = scePthreadMutexLock(mutex); if (result < 0) { int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP @@ -495,7 +654,7 @@ int PS4_SYSV_ABI posix_pthread_mutex_lock(ScePthreadMutex* mutex) { } int PS4_SYSV_ABI posix_pthread_mutex_unlock(ScePthreadMutex* mutex) { - LOG_INFO(Kernel_Pthread, "posix pthread_mutex_unlock redirect to scePthreadMutexUnlock"); + // LOG_INFO(Kernel_Pthread, "posix pthread_mutex_unlock redirect to scePthreadMutexUnlock"); int result = scePthreadMutexUnlock(mutex); if (result < 0) { int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP @@ -546,6 +705,55 @@ int PS4_SYSV_ABI sceKernelClockGettime(s32 clock_id, SceKernelTimespec* tp) { return SCE_KERNEL_ERROR_EINVAL; } +static int pthread_copy_attributes(ScePthreadAttr* dst, const ScePthreadAttr* src) { + if (dst == nullptr || *dst == nullptr || src == nullptr || *src == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + u64 mask = 0; + int state = 0; + size_t guard_size = 0; + int inherit_sched = 0; + SceKernelSchedParam param = {}; + int policy = 0; + void* stack_addr = nullptr; + size_t stack_size = 0; + + int result = 0; + + result = (result == 0 ? scePthreadAttrGetaffinity(src, &mask) : result); + result = (result == 0 ? scePthreadAttrGetdetachstate(src, &state) : result); + result = (result == 0 ? scePthreadAttrGetguardsize(src, &guard_size) : result); + result = (result == 0 ? scePthreadAttrGetinheritsched(src, &inherit_sched) : result); + result = (result == 0 ? scePthreadAttrGetschedparam(src, ¶m) : result); + result = (result == 0 ? scePthreadAttrGetschedpolicy(src, &policy) : result); + result = (result == 0 ? scePthreadAttrGetstackaddr(src, &stack_addr) : result); + result = (result == 0 ? scePthreadAttrGetstacksize(src, &stack_size) : result); + + result = (result == 0 ? scePthreadAttrSetaffinity(dst, mask) : result); + result = (result == 0 ? scePthreadAttrSetdetachstate(dst, state) : result); + result = (result == 0 ? scePthreadAttrSetguardsize(dst, guard_size) : result); + result = (result == 0 ? scePthreadAttrSetinheritsched(dst, inherit_sched) : result); + result = (result == 0 ? scePthreadAttrSetschedparam(dst, ¶m) : result); + result = (result == 0 ? scePthreadAttrSetschedpolicy(dst, policy) : result); + if (stack_addr != nullptr) { + result = (result == 0 ? scePthreadAttrSetstackaddr(dst, stack_addr) : result); + } + if (stack_size != 0) { + result = (result == 0 ? scePthreadAttrSetstacksize(dst, stack_size) : result); + } + + return result; +} + +int PS4_SYSV_ABI scePthreadAttrGet(ScePthread thread, ScePthreadAttr* attr) { + if (thread == nullptr || attr == nullptr || *attr == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + return pthread_copy_attributes(attr, &thread->attr); +} + void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("4+h9EzwKF4I", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetschedpolicy); LIB_FUNCTION("-Wreprtu0Qs", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetdetachstate); @@ -557,6 +765,7 @@ void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("aI+OeCz8xrQ", "libkernel", 1, "libkernel", 1, 1, scePthreadSelf); LIB_FUNCTION("3qxgM4ezETA", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetaffinity); LIB_FUNCTION("8+s5BzZjxSg", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrGetaffinity); + LIB_FUNCTION("x1X76arYMxU", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrGet); LIB_FUNCTION("bt3CTBKmGyI", "libkernel", 1, "libkernel", 1, 1, scePthreadSetaffinity); LIB_FUNCTION("6UgtwV+0zb4", "libkernel", 1, "libkernel", 1, 1, scePthreadCreate); From 121759d836a71b983479593764b3394f5d8448f5 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 4 Apr 2024 19:16:10 +0300 Subject: [PATCH 07/15] somehow working scePthreadCreate --- .../libraries/libkernel/thread_management.cpp | 107 +++++++++++++++++- .../libraries/libkernel/thread_management.h | 33 ++++++ 2 files changed, 134 insertions(+), 6 deletions(-) diff --git a/src/core/hle/libraries/libkernel/thread_management.cpp b/src/core/hle/libraries/libkernel/thread_management.cpp index 103e766a..325736d9 100644 --- a/src/core/hle/libraries/libkernel/thread_management.cpp +++ b/src/core/hle/libraries/libkernel/thread_management.cpp @@ -6,6 +6,7 @@ #include "core/hle/error_codes.h" #include "core/hle/libraries/libkernel/thread_management.h" #include "core/hle/libraries/libs.h" +#include namespace Core::Libraries::LibKernel { @@ -22,6 +23,12 @@ void init_pthreads() { ScePthreadCondattr default_condattr = nullptr; scePthreadCondattrInit(&default_condattr); g_pthread_cxt->setDefaultCondattr(default_condattr); + // default attr init + ScePthreadAttr default_attr = nullptr; + scePthreadAttrInit(&default_attr); + g_pthread_cxt->SetDefaultAttr(default_attr); + + g_pthread_cxt->SetPthreadPool(new PThreadPool); } void pthreadInitSelfMainThread() { @@ -348,12 +355,6 @@ int PS4_SYSV_ABI scePthreadSetaffinity(ScePthread thread, const /*SceKernelCpuma return result; } -int PS4_SYSV_ABI scePthreadCreate(ScePthread* thread, const ScePthreadAttr* attr, - pthreadEntryFunc start_routine, void* arg, const char* name) { - LOG_INFO(Kernel_Pthread, "(STUBBED) called"); - return 0; -} - void* createMutex(void* addr) { if (addr == nullptr || *static_cast(addr) != nullptr) { return addr; @@ -754,6 +755,100 @@ int PS4_SYSV_ABI scePthreadAttrGet(ScePthread thread, ScePthreadAttr* attr) { return pthread_copy_attributes(attr, &thread->attr); } +static void cleanup_thread(void* arg) { + auto* thread = static_cast(arg); + thread->is_almost_done = true; +} + +static void* run_thread(void* arg) { + auto* thread = static_cast(arg); + void* ret = nullptr; + g_pthread_self = thread; + pthread_cleanup_push(cleanup_thread, thread); + thread->is_started = true; + ret = thread->entry(thread->arg); + pthread_cleanup_pop(1); + return ret; +} + +int PS4_SYSV_ABI scePthreadCreate(ScePthread* thread, const ScePthreadAttr* attr, + pthreadEntryFunc start_routine, void* arg, const char* name) { + if (thread == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + auto* pthread_pool = g_pthread_cxt->GetPthreadPool(); + + if (attr == nullptr) { + attr = g_pthread_cxt->GetDefaultAttr(); + } + + *thread = pthread_pool->Create(); + + if ((*thread)->attr != nullptr) { + scePthreadAttrDestroy(&(*thread)->attr); + } + + scePthreadAttrInit(&(*thread)->attr); + + int result = pthread_copy_attributes(&(*thread)->attr, attr); + + if (result == 0) { + (*thread)->name = name; + (*thread)->entry = start_routine; + (*thread)->arg = arg; + (*thread)->is_almost_done = false; + (*thread)->is_detached = (*attr)->detached; + (*thread)->is_started = false; + + result = pthread_create(&(*thread)->pth, &(*attr)->pth_attr, run_thread, *thread); + } + + if (result == 0) { + while (!(*thread)->is_started) { + std::this_thread::sleep_for(std::chrono::microseconds(1000)); + } + } + LOG_INFO(Kernel_Pthread, "thread create name = {}",(*thread)->name); + + switch (result) { + case 0: + return SCE_OK; + case ENOMEM: + return SCE_KERNEL_ERROR_ENOMEM; + case EAGAIN: + return SCE_KERNEL_ERROR_EAGAIN; + case EDEADLK: + return SCE_KERNEL_ERROR_EDEADLK; + case EPERM: + return SCE_KERNEL_ERROR_EPERM; + default: + return SCE_KERNEL_ERROR_EINVAL; + } +} + +ScePthread PThreadPool::Create() { + std::scoped_lock lock{m_mutex}; + + for (auto* p : m_threads) { + if (p->is_free) { + p->is_free = false; + return p; + } + } + + auto* ret = new PthreadInternal{}; + + ret->is_free = false; + ret->is_detached = false; + ret->is_almost_done = false; + ret->attr = nullptr; + + m_threads.push_back(ret); + + return ret; +} + void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("4+h9EzwKF4I", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetschedpolicy); LIB_FUNCTION("-Wreprtu0Qs", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetdetachstate); diff --git a/src/core/hle/libraries/libkernel/thread_management.h b/src/core/hle/libraries/libkernel/thread_management.h index 922f8ef8..67896453 100644 --- a/src/core/hle/libraries/libkernel/thread_management.h +++ b/src/core/hle/libraries/libkernel/thread_management.h @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include "common/types.h" @@ -43,6 +45,12 @@ struct PthreadInternal { std::string name; pthread_t pth; ScePthreadAttr attr; + pthreadEntryFunc entry; + void* arg; + std::atomic_bool is_started; + std::atomic_bool is_detached; + std::atomic_bool is_almost_done; + std::atomic_bool is_free; }; struct PthreadAttrInternal { @@ -77,6 +85,17 @@ struct PthreadCondAttrInternal { pthread_condattr_t cond_attr; }; +class PThreadPool { +public: + ScePthread Create(); + + void FreeDetachedThreads(); + +private: + std::vector m_threads; + std::mutex m_mutex; +}; + class PThreadCxt { public: ScePthreadMutexattr* getDefaultMutexattr() { @@ -91,10 +110,24 @@ public: void setDefaultCondattr(ScePthreadCondattr attr) { m_default_condattr = attr; } + ScePthreadAttr* GetDefaultAttr() { + return &m_default_attr; + } + void SetDefaultAttr(ScePthreadAttr attr) { + m_default_attr = attr; + } + PThreadPool* GetPthreadPool() { + return m_pthread_pool; + } + void SetPthreadPool(PThreadPool* pool) { + m_pthread_pool = pool; + } private: ScePthreadMutexattr m_default_mutexattr = nullptr; ScePthreadCondattr m_default_condattr = nullptr; + ScePthreadAttr m_default_attr = nullptr; + PThreadPool* m_pthread_pool = nullptr; }; void init_pthreads(); From a049d4c491e11b49aaf56938b956c0af27375fbe Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 4 Apr 2024 19:47:59 +0300 Subject: [PATCH 08/15] added clock_gettime --- .../hle/libraries/libkernel/thread_management.cpp | 13 +++++++++++-- .../hle/libraries/libkernel/thread_management.h | 3 --- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/core/hle/libraries/libkernel/thread_management.cpp b/src/core/hle/libraries/libkernel/thread_management.cpp index 325736d9..c69acee8 100644 --- a/src/core/hle/libraries/libkernel/thread_management.cpp +++ b/src/core/hle/libraries/libkernel/thread_management.cpp @@ -1,12 +1,12 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include #include "common/assert.h" #include "common/logging/log.h" #include "core/hle/error_codes.h" #include "core/hle/libraries/libkernel/thread_management.h" #include "core/hle/libraries/libs.h" -#include namespace Core::Libraries::LibKernel { @@ -706,6 +706,14 @@ int PS4_SYSV_ABI sceKernelClockGettime(s32 clock_id, SceKernelTimespec* tp) { return SCE_KERNEL_ERROR_EINVAL; } +int PS4_SYSV_ABI clock_gettime(s32 clock_id, SceKernelTimespec* time) { + int result = sceKernelClockGettime(clock_id, time); + if (result < 0) { + UNREACHABLE(); // TODO return posix error code + } + return result; +} + static int pthread_copy_attributes(ScePthreadAttr* dst, const ScePthreadAttr* src) { if (dst == nullptr || *dst == nullptr || src == nullptr || *src == nullptr) { return SCE_KERNEL_ERROR_EINVAL; @@ -809,7 +817,7 @@ int PS4_SYSV_ABI scePthreadCreate(ScePthread* thread, const ScePthreadAttr* attr std::this_thread::sleep_for(std::chrono::microseconds(1000)); } } - LOG_INFO(Kernel_Pthread, "thread create name = {}",(*thread)->name); + LOG_INFO(Kernel_Pthread, "thread create name = {}", (*thread)->name); switch (result) { case 0: @@ -884,6 +892,7 @@ void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("mkx2fVhNMsg", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_cond_broadcast); LIB_FUNCTION("QBi7HCK03hw", "libkernel", 1, "libkernel", 1, 1, sceKernelClockGettime); + LIB_FUNCTION("lLMT9vJAck0", "libkernel", 1, "libkernel", 1, 1, clock_gettime); // openorbis weird functions LIB_FUNCTION("7H0iTOciTLo", "libkernel", 1, "libkernel", 1, 1, posix_pthread_mutex_lock); diff --git a/src/core/hle/libraries/libkernel/thread_management.h b/src/core/hle/libraries/libkernel/thread_management.h index 67896453..fcfb2dcb 100644 --- a/src/core/hle/libraries/libkernel/thread_management.h +++ b/src/core/hle/libraries/libkernel/thread_management.h @@ -88,9 +88,6 @@ struct PthreadCondAttrInternal { class PThreadPool { public: ScePthread Create(); - - void FreeDetachedThreads(); - private: std::vector m_threads; std::mutex m_mutex; From 935842291ddb2f20ef775f6c9e2a2ee4d54412cb Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 4 Apr 2024 20:04:18 +0300 Subject: [PATCH 09/15] dummy sceAudioIn lib --- CMakeLists.txt | 6 +- src/common/logging/filter.cpp | 1 + src/common/logging/types.h | 1 + src/core/hle/libraries/libs.cpp | 2 + src/core/libraries/libsceaudioin.cpp | 280 +++++++++++++++++++++++++++ src/core/libraries/libsceaudioin.h | 54 ++++++ 6 files changed, 342 insertions(+), 2 deletions(-) create mode 100644 src/core/libraries/libsceaudioin.cpp create mode 100644 src/core/libraries/libsceaudioin.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a64b395e..851e3cb5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,10 @@ set(AUDIO_CORE src/audio_core/sdl_audio.cpp ) set(LIBRARIES src/core/libraries/library_common.h src/core/libraries/error_codes.h + src/core/libraries/libsceaudioin.cpp + src/core/libraries/libsceaudioin.h + src/core/libraries/libsceaudioout.cpp + src/core/libraries/libsceaudioout.h src/core/libraries/libkernel.cpp src/core/libraries/libkernel.h src/core/libraries/libscecommondialog.cpp @@ -124,8 +128,6 @@ set(LIBRARIES src/core/libraries/library_common.h src/core/libraries/libscesystemservice.h src/core/libraries/libsceuserservice.cpp src/core/libraries/libsceuserservice.h - src/core/libraries/libsceaudioout.cpp - src/core/libraries/libsceaudioout.h ) set(LIBC_SOURCES src/core/hle/libraries/libc/libc.cpp diff --git a/src/common/logging/filter.cpp b/src/common/logging/filter.cpp index ac38ab0f..32ffd245 100644 --- a/src/common/logging/filter.cpp +++ b/src/common/logging/filter.cpp @@ -88,6 +88,7 @@ bool ParseFilterRule(Filter& instance, Iterator begin, Iterator end) { SUB(Lib, CommonDlg) \ SUB(Lib, MsgDlg) \ SUB(Lib, AudioOut) \ + SUB(Lib, AudioIn) \ SUB(Lib, Net) \ SUB(Lib, NetCtl) \ SUB(Lib, SaveData) \ diff --git a/src/common/logging/types.h b/src/common/logging/types.h index 897929be..0287a198 100644 --- a/src/common/logging/types.h +++ b/src/common/logging/types.h @@ -55,6 +55,7 @@ enum class Class : u8 { Lib_CommonDlg, ///< The LibSceCommonDialog implementation. Lib_MsgDlg, ///< The LibSceMsgDialog implementation. Lib_AudioOut, ///< The LibSceAudioOut implementation. + Lib_AudioIn, ///< The LibSceAudioIn implementation. Lib_Net, ///< The LibSceNet implementation. Lib_NetCtl, ///< The LibSecNetCtl implementation. Lib_SaveData, ///< The LibSceSaveData implementation. diff --git a/src/core/hle/libraries/libs.cpp b/src/core/hle/libraries/libs.cpp index c379bc36..1e28e100 100644 --- a/src/core/hle/libraries/libs.cpp +++ b/src/core/hle/libraries/libs.cpp @@ -9,6 +9,7 @@ #include "core/hle/libraries/libs.h" #include "core/hle/libraries/libscegnmdriver/libscegnmdriver.h" #include "src/core/libraries/libkernel.h" +#include "src/core/libraries/libsceaudioin.h" #include "src/core/libraries/libsceaudioout.h" #include "src/core/libraries/libscecommondialog.h" #include "src/core/libraries/libscehttp.h" @@ -47,6 +48,7 @@ void InitHLELibs(Core::Loader::SymbolsResolver* sym) { Libraries::SysModule::RegisterlibSceSysmodule(sym); Libraries::Kernel::Registerlibkernel(sym); Libraries::Posix::Registerlibsceposix(sym); + Libraries::AudioIn::RegisterlibSceAudioIn(sym); } } // namespace OldLibraries diff --git a/src/core/libraries/libsceaudioin.cpp b/src/core/libraries/libsceaudioin.cpp new file mode 100644 index 00000000..26bb7a35 --- /dev/null +++ b/src/core/libraries/libsceaudioin.cpp @@ -0,0 +1,280 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +// Generated By moduleGenerator +#include "common/logging/log.h" +#include "error_codes.h" +#include "libsceaudioin.h" + +namespace Libraries::AudioIn { + +int PS4_SYSV_ABI sceAudioInChangeAppModuleState() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInClose() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInCountPorts() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInDeviceHqOpen() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInDeviceIdHqOpen() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInDeviceIdOpen() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInDeviceOpen() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInDeviceOpenEx() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInExtClose() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInExtCtrl() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInExtInput() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInExtOpen() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInExtSetAecMode() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInGetGain() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInGetHandleStatusInfo() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInGetRerouteCount() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInGetSilentState() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInHqOpen() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInHqOpenEx() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInInit() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInInput() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInInputs() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInIsSharedDevice() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInOpen() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInOpenEx() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInSetAllMute() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInSetCompressorPreGain() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInSetConnections() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInSetConnectionsForUser() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInSetDevConnection() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInSetFocusForUser() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInSetMode() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInSetMode2() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInSetPortConnections() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInSetPortStatuses() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInSetSparkParam() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInSetSparkSideTone() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInSetUsbGain() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInSetUserMute() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInVmicCreate() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInVmicDestroy() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +int PS4_SYSV_ABI sceAudioInVmicWrite() { + LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); + return ORBIS_OK; +} + +void RegisterlibSceAudioIn(Core::Loader::SymbolsResolver* sym) { + LIB_FUNCTION("IQtWgnrw6v8", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, + sceAudioInChangeAppModuleState); + LIB_FUNCTION("Jh6WbHhnI68", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInClose); + LIB_FUNCTION("8mtcsG-Qp5E", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInCountPorts); + LIB_FUNCTION("5qRVfxOmbno", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInDeviceHqOpen); + LIB_FUNCTION("gUNabrUkZNg", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, + sceAudioInDeviceIdHqOpen); + LIB_FUNCTION("X-AQLtdxQOo", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInDeviceIdOpen); + LIB_FUNCTION("VoX9InuwwTg", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInDeviceOpen); + LIB_FUNCTION("48-miagyJ2I", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInDeviceOpenEx); + LIB_FUNCTION("kFKJ3MVcDuo", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInExtClose); + LIB_FUNCTION("mhAfefP9m2g", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInExtCtrl); + LIB_FUNCTION("KpBKoHKVKEc", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInExtInput); + LIB_FUNCTION("YZ+3seW7CyY", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInExtOpen); + LIB_FUNCTION("FVGWf8JaHOE", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInExtSetAecMode); + LIB_FUNCTION("S-rDUfQk9sg", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInGetGain); + LIB_FUNCTION("NJam1-F7lNY", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, + sceAudioInGetHandleStatusInfo); + LIB_FUNCTION("3shKmTrTw6c", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, + sceAudioInGetRerouteCount); + LIB_FUNCTION("BohEAQ7DlUE", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, + sceAudioInGetSilentState); + LIB_FUNCTION("nya-R5gDYhM", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInHqOpen); + LIB_FUNCTION("CTh72m+IYbU", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInHqOpenEx); + LIB_FUNCTION("SxQprgjttKE", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInInit); + LIB_FUNCTION("LozEOU8+anM", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInInput); + LIB_FUNCTION("rmgXsZ-2Tyk", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInInputs); + LIB_FUNCTION("6QP1MzdFWhs", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, + sceAudioInIsSharedDevice); + LIB_FUNCTION("5NE8Sjc7VC8", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInOpen); + LIB_FUNCTION("+DY07NwJb0s", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInOpenEx); + LIB_FUNCTION("vYFsze1SqU8", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInSetAllMute); + LIB_FUNCTION("vyh-T6sMqnw", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, + sceAudioInSetCompressorPreGain); + LIB_FUNCTION("YeBSNVAELe4", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, + sceAudioInSetConnections); + LIB_FUNCTION("thLNHvkWSeg", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, + sceAudioInSetConnectionsForUser); + LIB_FUNCTION("rcgv2ciDrtc", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, + sceAudioInSetDevConnection); + LIB_FUNCTION("iN3KqF-8R-w", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, + sceAudioInSetFocusForUser); + LIB_FUNCTION("VAzfxqDwbQ0", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInSetMode); + LIB_FUNCTION("CwBFvAlOv7k", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInSetMode2); + LIB_FUNCTION("tQpOPpYwv7o", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, + sceAudioInSetPortConnections); + LIB_FUNCTION("NUWqWguYcNQ", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, + sceAudioInSetPortStatuses); + LIB_FUNCTION("U0ivfdKFZbA", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInSetSparkParam); + LIB_FUNCTION("hWMCAPpqzDo", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, + sceAudioInSetSparkSideTone); + LIB_FUNCTION("nqXpw3MaN50", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInSetUsbGain); + LIB_FUNCTION("arJp991xk5k", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInSetUserMute); + LIB_FUNCTION("DVTn+iMSpBM", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInVmicCreate); + LIB_FUNCTION("3ULZGIl+Acc", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInVmicDestroy); + LIB_FUNCTION("4kHw99LUG3A", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInVmicWrite); +}; + +} // namespace Libraries::AudioIn \ No newline at end of file diff --git a/src/core/libraries/libsceaudioin.h b/src/core/libraries/libsceaudioin.h new file mode 100644 index 00000000..60ac54d2 --- /dev/null +++ b/src/core/libraries/libsceaudioin.h @@ -0,0 +1,54 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "library_common.h" + +namespace Libraries::AudioIn { + +int PS4_SYSV_ABI sceAudioInChangeAppModuleState(); +int PS4_SYSV_ABI sceAudioInClose(); +int PS4_SYSV_ABI sceAudioInCountPorts(); +int PS4_SYSV_ABI sceAudioInDeviceHqOpen(); +int PS4_SYSV_ABI sceAudioInDeviceIdHqOpen(); +int PS4_SYSV_ABI sceAudioInDeviceIdOpen(); +int PS4_SYSV_ABI sceAudioInDeviceOpen(); +int PS4_SYSV_ABI sceAudioInDeviceOpenEx(); +int PS4_SYSV_ABI sceAudioInExtClose(); +int PS4_SYSV_ABI sceAudioInExtCtrl(); +int PS4_SYSV_ABI sceAudioInExtInput(); +int PS4_SYSV_ABI sceAudioInExtOpen(); +int PS4_SYSV_ABI sceAudioInExtSetAecMode(); +int PS4_SYSV_ABI sceAudioInGetGain(); +int PS4_SYSV_ABI sceAudioInGetHandleStatusInfo(); +int PS4_SYSV_ABI sceAudioInGetRerouteCount(); +int PS4_SYSV_ABI sceAudioInGetSilentState(); +int PS4_SYSV_ABI sceAudioInHqOpen(); +int PS4_SYSV_ABI sceAudioInHqOpenEx(); +int PS4_SYSV_ABI sceAudioInInit(); +int PS4_SYSV_ABI sceAudioInInput(); +int PS4_SYSV_ABI sceAudioInInputs(); +int PS4_SYSV_ABI sceAudioInIsSharedDevice(); +int PS4_SYSV_ABI sceAudioInOpen(); +int PS4_SYSV_ABI sceAudioInOpenEx(); +int PS4_SYSV_ABI sceAudioInSetAllMute(); +int PS4_SYSV_ABI sceAudioInSetCompressorPreGain(); +int PS4_SYSV_ABI sceAudioInSetConnections(); +int PS4_SYSV_ABI sceAudioInSetConnectionsForUser(); +int PS4_SYSV_ABI sceAudioInSetDevConnection(); +int PS4_SYSV_ABI sceAudioInSetFocusForUser(); +int PS4_SYSV_ABI sceAudioInSetMode(); +int PS4_SYSV_ABI sceAudioInSetMode2(); +int PS4_SYSV_ABI sceAudioInSetPortConnections(); +int PS4_SYSV_ABI sceAudioInSetPortStatuses(); +int PS4_SYSV_ABI sceAudioInSetSparkParam(); +int PS4_SYSV_ABI sceAudioInSetSparkSideTone(); +int PS4_SYSV_ABI sceAudioInSetUsbGain(); +int PS4_SYSV_ABI sceAudioInSetUserMute(); +int PS4_SYSV_ABI sceAudioInVmicCreate(); +int PS4_SYSV_ABI sceAudioInVmicDestroy(); +int PS4_SYSV_ABI sceAudioInVmicWrite(); + +void RegisterlibSceAudioIn(Core::Loader::SymbolsResolver* sym); +} // namespace Libraries::AudioIn \ No newline at end of file From c29f514e637a5cb7de729b836cb9aaaaf285d819 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 4 Apr 2024 20:07:33 +0300 Subject: [PATCH 10/15] just disable audioInOpen --- src/core/libraries/libsceaudioin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/libraries/libsceaudioin.cpp b/src/core/libraries/libsceaudioin.cpp index 26bb7a35..27121466 100644 --- a/src/core/libraries/libsceaudioin.cpp +++ b/src/core/libraries/libsceaudioin.cpp @@ -124,8 +124,8 @@ int PS4_SYSV_ABI sceAudioInIsSharedDevice() { } int PS4_SYSV_ABI sceAudioInOpen() { - LOG_ERROR(Lib_AudioIn, "(STUBBED) called"); - return ORBIS_OK; + LOG_ERROR(Lib_AudioIn, "(DUMMY) called"); + return 0x80260005; // ports are full return } int PS4_SYSV_ABI sceAudioInOpenEx() { From 54095761976c314707ca821a0eca01f93269c786 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 4 Apr 2024 20:20:50 +0300 Subject: [PATCH 11/15] posix nanosleep call --- .../libraries/libkernel/thread_management.cpp | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/core/hle/libraries/libkernel/thread_management.cpp b/src/core/hle/libraries/libkernel/thread_management.cpp index c69acee8..9a0e86e4 100644 --- a/src/core/hle/libraries/libkernel/thread_management.cpp +++ b/src/core/hle/libraries/libkernel/thread_management.cpp @@ -714,6 +714,30 @@ int PS4_SYSV_ABI clock_gettime(s32 clock_id, SceKernelTimespec* time) { return result; } +int PS4_SYSV_ABI sceKernelNanosleep(const SceKernelTimespec* rqtp, SceKernelTimespec* rmtp) { + + if (rqtp == nullptr) { + return SCE_KERNEL_ERROR_EFAULT; + } + + if (rqtp->tv_sec < 0 || rqtp->tv_nsec < 0) { + return SCE_KERNEL_ERROR_EINVAL; + } + + u64 nanos = rqtp->tv_sec * 1000000000 + rqtp->tv_nsec; + std::this_thread::sleep_for(std::chrono::nanoseconds(nanos)); + if (rmtp != nullptr) { + UNREACHABLE(); // not supported yet + } + return SCE_OK; +} +int PS4_SYSV_ABI nanosleep(const SceKernelTimespec* rqtp, SceKernelTimespec* rmtp) { + int result = sceKernelNanosleep(rqtp, rmtp); + if (result < 0) { + UNREACHABLE(); // TODO return posix error code + } + return result; +} static int pthread_copy_attributes(ScePthreadAttr* dst, const ScePthreadAttr* src) { if (dst == nullptr || *dst == nullptr || src == nullptr || *src == nullptr) { return SCE_KERNEL_ERROR_EINVAL; @@ -893,6 +917,7 @@ void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("QBi7HCK03hw", "libkernel", 1, "libkernel", 1, 1, sceKernelClockGettime); LIB_FUNCTION("lLMT9vJAck0", "libkernel", 1, "libkernel", 1, 1, clock_gettime); + LIB_FUNCTION("yS8U2TGCe1A", "libScePosix", 1, "libkernel", 1, 1, nanosleep); // openorbis weird functions LIB_FUNCTION("7H0iTOciTLo", "libkernel", 1, "libkernel", 1, 1, posix_pthread_mutex_lock); From 81143b4a9e6bd2fc87e74137bd71755944536ce4 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Fri, 5 Apr 2024 09:27:13 +0300 Subject: [PATCH 12/15] scePadRead,scePthreadYield implementations --- src/Emulator/Host/controller.cpp | 33 ++++++++++++- src/Emulator/Host/controller.h | 6 +++ .../libraries/libkernel/thread_management.cpp | 6 +++ .../libraries/libkernel/thread_management.h | 5 +- src/core/hle/libraries/libpad/pad.cpp | 47 +++++++++++++++++++ 5 files changed, 94 insertions(+), 3 deletions(-) diff --git a/src/Emulator/Host/controller.cpp b/src/Emulator/Host/controller.cpp index fddac073..302e7eac 100644 --- a/src/Emulator/Host/controller.cpp +++ b/src/Emulator/Host/controller.cpp @@ -19,6 +19,37 @@ void GameController::readState(State* state, bool* isConnected, int* connectedCo *state = getLastState(); } +int GameController::ReadStates(State* states, int states_num, bool* isConnected, + int* connectedCount) { + std::scoped_lock lock{m_mutex}; + + *isConnected = m_connected; + *connectedCount = m_connected_count; + + int ret_num = 0; + + if (m_connected) { + if (m_states_num == 0) { + ret_num = 1; + states[0] = m_last_state; + } else { + for (uint32_t i = 0; i < m_states_num; i++) { + if (ret_num >= states_num) { + break; + } + auto index = (m_first_state + i) % MAX_STATES; + if (!m_private[index].obtained) { + m_private[index].obtained = true; + + states[ret_num++] = m_states[index]; + } + } + } + } + + return ret_num; +} + State GameController::getLastState() const { if (m_states_num == 0) { return m_last_state; @@ -39,7 +70,7 @@ void GameController::addState(const State& state) { m_states[index] = state; m_last_state = state; - + m_private[index].obtained = false; m_states_num++; } diff --git a/src/Emulator/Host/controller.h b/src/Emulator/Host/controller.h index de8490d1..8d8236c5 100644 --- a/src/Emulator/Host/controller.h +++ b/src/Emulator/Host/controller.h @@ -20,11 +20,16 @@ public: virtual ~GameController() = default; 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); private: + struct StateInternal { + bool obtained = false; + }; + std::mutex m_mutex; bool m_connected = false; State m_last_state; @@ -32,6 +37,7 @@ private: u32 m_states_num = 0; u32 m_first_state = 0; State m_states[MAX_STATES]; + StateInternal m_private[MAX_STATES]; }; } // namespace Emulator::Host::Controller diff --git a/src/core/hle/libraries/libkernel/thread_management.cpp b/src/core/hle/libraries/libkernel/thread_management.cpp index 9a0e86e4..180077c5 100644 --- a/src/core/hle/libraries/libkernel/thread_management.cpp +++ b/src/core/hle/libraries/libkernel/thread_management.cpp @@ -881,6 +881,10 @@ ScePthread PThreadPool::Create() { return ret; } +void PS4_SYSV_ABI scePthreadYield() { + sched_yield(); +} + void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("4+h9EzwKF4I", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetschedpolicy); LIB_FUNCTION("-Wreprtu0Qs", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetdetachstate); @@ -896,6 +900,8 @@ void pthreadSymbolsRegister(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); + // mutex calls LIB_FUNCTION("cmo1RIYva9o", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexInit); LIB_FUNCTION("2Of0f+3mhhE", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexDestroy); diff --git a/src/core/hle/libraries/libkernel/thread_management.h b/src/core/hle/libraries/libkernel/thread_management.h index fcfb2dcb..3f779a45 100644 --- a/src/core/hle/libraries/libkernel/thread_management.h +++ b/src/core/hle/libraries/libkernel/thread_management.h @@ -4,11 +4,11 @@ #pragma once #define _TIMESPEC_DEFINED +#include #include +#include #include #include -#include -#include #include "common/types.h" @@ -88,6 +88,7 @@ struct PthreadCondAttrInternal { class PThreadPool { public: ScePthread Create(); + private: std::vector m_threads; std::mutex m_mutex; diff --git a/src/core/hle/libraries/libpad/pad.cpp b/src/core/hle/libraries/libpad/pad.cpp index f224367f..47134473 100644 --- a/src/core/hle/libraries/libpad/pad.cpp +++ b/src/core/hle/libraries/libpad/pad.cpp @@ -48,6 +48,51 @@ int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) { return SCE_OK; } +int PS4_SYSV_ABI scePadRead(int handle, ScePadData* pData, int num) { + int connected_count = 0; + bool connected = false; + Emulator::Host::Controller::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; @@ -72,6 +117,8 @@ 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); } From fc5e133c442af345d132d313521816467bdd00cb Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Fri, 5 Apr 2024 09:59:28 +0300 Subject: [PATCH 13/15] added sceAudioOutSetVolume --- src/audio_core/sdl_audio.cpp | 38 +++++++++++++++++++++++++++ src/audio_core/sdl_audio.h | 1 + src/core/libraries/libsceaudioout.cpp | 13 ++++++--- src/core/libraries/libsceaudioout.h | 9 +++++-- 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/audio_core/sdl_audio.cpp b/src/audio_core/sdl_audio.cpp index 457f8802..59e83f8f 100644 --- a/src/audio_core/sdl_audio.cpp +++ b/src/audio_core/sdl_audio.cpp @@ -108,4 +108,42 @@ s32 SDLAudio::AudioOutOutput(s32 handle, const void* ptr) { return result; } +bool SDLAudio::AudioOutSetVolume(s32 handle, s32 bitflag, s32* volume) { + using Libraries::AudioOut::OrbisAudioOutParam; + std::scoped_lock lock{m_mutex}; + auto& port = portsOut[handle - 1]; + if (!port.isOpen) { + return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT; + } + for (int i = 0; i < port.channels_num; i++, bitflag >>= 1u) { + auto bit = bitflag & 0x1u; + + if (bit == 1) { + int src_index = i; + if (port.format == OrbisAudioOutParam::ORBIS_AUDIO_OUT_PARAM_FORMAT_FLOAT_8CH_STD || + port.format == OrbisAudioOutParam::ORBIS_AUDIO_OUT_PARAM_FORMAT_S16_8CH_STD) { + switch (i) { + case 4: + src_index = 6; + break; + case 5: + src_index = 7; + break; + case 6: + src_index = 4; + break; + case 7: + src_index = 5; + break; + default: + break; + } + } + port.volume[i] = volume[src_index]; + } + } + + return true; +} + } // namespace Audio diff --git a/src/audio_core/sdl_audio.h b/src/audio_core/sdl_audio.h index 5c29835c..e6dd903a 100644 --- a/src/audio_core/sdl_audio.h +++ b/src/audio_core/sdl_audio.h @@ -20,6 +20,7 @@ public: int AudioOutOpen(int type, u32 samples_num, u32 freq, Libraries::AudioOut::OrbisAudioOutParam format); s32 AudioOutOutput(s32 handle, const void* ptr); + bool AudioOutSetVolume(s32 handle, s32 bitflag, s32* volume); private: struct PortOut { diff --git a/src/core/libraries/libsceaudioout.cpp b/src/core/libraries/libsceaudioout.cpp index 0b64aef9..59463a67 100644 --- a/src/core/libraries/libsceaudioout.cpp +++ b/src/core/libraries/libsceaudioout.cpp @@ -272,8 +272,11 @@ s32 PS4_SYSV_ABI sceAudioOutOutput(s32 handle, const void* ptr) { return audio->AudioOutOutput(handle, ptr); } -int PS4_SYSV_ABI sceAudioOutOutputs() { - LOG_ERROR(Lib_AudioOut, "(STUBBED) called"); +int PS4_SYSV_ABI sceAudioOutOutputs(OrbisAudioOutOutputParam* param, u32 num) { + for (u32 i = 0; i < num; i++) { + if (auto err = audio->AudioOutOutput(param[i].handle, param[i].ptr); err != 0) + return err; + } return ORBIS_OK; } @@ -367,8 +370,10 @@ int PS4_SYSV_ABI sceAudioOutSetUsbVolume() { return ORBIS_OK; } -int PS4_SYSV_ABI sceAudioOutSetVolume() { - LOG_ERROR(Lib_AudioOut, "(STUBBED) called"); +s32 PS4_SYSV_ABI sceAudioOutSetVolume(s32 handle, s32 flag, s32* vol) { + if (!audio->AudioOutSetVolume(handle, flag, vol)) { + return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT; + } return ORBIS_OK; } diff --git a/src/core/libraries/libsceaudioout.h b/src/core/libraries/libsceaudioout.h index ebbb2ba8..c57dc8bd 100644 --- a/src/core/libraries/libsceaudioout.h +++ b/src/core/libraries/libsceaudioout.h @@ -30,6 +30,11 @@ enum OrbisAudioOutParam { ORBIS_AUDIO_OUT_PARAM_FORMAT_FLOAT_8CH_STD = 7 }; +struct OrbisAudioOutOutputParam { + s32 handle; + const void* ptr; +}; + int PS4_SYSV_ABI sceAudioOutDeviceIdOpen(); int PS4_SYSV_ABI sceAudioDeviceControlGet(); int PS4_SYSV_ABI sceAudioDeviceControlSet(); @@ -69,7 +74,7 @@ s32 PS4_SYSV_ABI sceAudioOutOpen(UserService::OrbisUserServiceUserId user_id, u32 sample_rate, OrbisAudioOutParam param_type); int PS4_SYSV_ABI sceAudioOutOpenEx(); s32 PS4_SYSV_ABI sceAudioOutOutput(s32 handle, const void* ptr); -int PS4_SYSV_ABI sceAudioOutOutputs(); +s32 PS4_SYSV_ABI sceAudioOutOutputs(OrbisAudioOutOutputParam* param, u32 num); int PS4_SYSV_ABI sceAudioOutPtClose(); int PS4_SYSV_ABI sceAudioOutPtGetLastOutputTime(); int PS4_SYSV_ABI sceAudioOutPtOpen(); @@ -88,7 +93,7 @@ int PS4_SYSV_ABI sceAudioOutSetPortStatuses(); int PS4_SYSV_ABI sceAudioOutSetRecMode(); int PS4_SYSV_ABI sceAudioOutSetSparkParam(); int PS4_SYSV_ABI sceAudioOutSetUsbVolume(); -int PS4_SYSV_ABI sceAudioOutSetVolume(); +s32 PS4_SYSV_ABI sceAudioOutSetVolume(s32 handle, s32 flag, s32* vol); int PS4_SYSV_ABI sceAudioOutSetVolumeDown(); int PS4_SYSV_ABI sceAudioOutStartAuxBroadcast(); int PS4_SYSV_ABI sceAudioOutStartSharePlay(); From ea4bb4773ea8961e301a58a32bc00cd845de0bf4 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Fri, 5 Apr 2024 19:33:38 +0300 Subject: [PATCH 14/15] linux build fix --- src/core/hle/libraries/libkernel/thread_management.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/libraries/libkernel/thread_management.h b/src/core/hle/libraries/libkernel/thread_management.h index 3f779a45..94517bf5 100644 --- a/src/core/hle/libraries/libkernel/thread_management.h +++ b/src/core/hle/libraries/libkernel/thread_management.h @@ -4,12 +4,12 @@ #pragma once #define _TIMESPEC_DEFINED +#include #include #include #include #include #include - #include "common/types.h" namespace Core::Loader { From 5663da21c2396452e19793c248a21678320c504e Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Fri, 5 Apr 2024 19:53:54 +0300 Subject: [PATCH 15/15] more linux fix --- src/core/hle/libraries/libkernel/thread_management.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/hle/libraries/libkernel/thread_management.h b/src/core/hle/libraries/libkernel/thread_management.h index 94517bf5..203ed872 100644 --- a/src/core/hle/libraries/libkernel/thread_management.h +++ b/src/core/hle/libraries/libkernel/thread_management.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include