diff --git a/src/audio_core/sdl_audio.cpp b/src/audio_core/sdl_audio.cpp index 188307e5..72f0f9ef 100644 --- a/src/audio_core/sdl_audio.cpp +++ b/src/audio_core/sdl_audio.cpp @@ -145,4 +145,13 @@ bool SDLAudio::AudioOutSetVolume(s32 handle, s32 bitflag, s32* volume) { return true; } +bool SDLAudio::AudioOutGetStatus(s32 handle, int* type, int* channels_num) { + std::scoped_lock lock{m_mutex}; + auto& port = portsOut[handle - 1]; + *type = port.type; + *channels_num = port.channels_num; + + return true; +} + } // namespace Audio diff --git a/src/audio_core/sdl_audio.h b/src/audio_core/sdl_audio.h index ae5e7276..7d0b0b80 100644 --- a/src/audio_core/sdl_audio.h +++ b/src/audio_core/sdl_audio.h @@ -18,6 +18,7 @@ public: Libraries::AudioOut::OrbisAudioOutParam format); s32 AudioOutOutput(s32 handle, const void* ptr); bool AudioOutSetVolume(s32 handle, s32 bitflag, s32* volume); + bool AudioOutGetStatus(s32 handle, int* type, int* channels_num); private: struct PortOut { diff --git a/src/core/libraries/audio/audioout.cpp b/src/core/libraries/audio/audioout.cpp index 0207eaff..0ec4fe15 100644 --- a/src/core/libraries/audio/audioout.cpp +++ b/src/core/libraries/audio/audioout.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include #include #include "audio_core/sdl_audio.h" #include "common/logging/log.h" @@ -160,8 +161,38 @@ int PS4_SYSV_ABI sceAudioOutGetLastOutputTime() { return ORBIS_OK; } -int PS4_SYSV_ABI sceAudioOutGetPortState() { - LOG_ERROR(Lib_AudioOut, "(STUBBED) called"); +int PS4_SYSV_ABI sceAudioOutGetPortState(s32 handle, OrbisAudioOutPortState* state) { + + int type = 0; + int channels_num = 0; + + if (!audio->AudioOutGetStatus(handle, &type, &channels_num)) { + return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT; + } + + state->rerouteCounter = 0; + state->volume = 127; // max volume + + switch (type) { + case ORBIS_AUDIO_OUT_PORT_TYPE_MAIN: + case ORBIS_AUDIO_OUT_PORT_TYPE_BGM: + case ORBIS_AUDIO_OUT_PORT_TYPE_VOICE: + state->output = 1; + state->channel = (channels_num > 2 ? 2 : channels_num); + break; + case ORBIS_AUDIO_OUT_PORT_TYPE_PERSONAL: + case ORBIS_AUDIO_OUT_PORT_TYPE_PADSPK: + state->output = 4; + state->channel = 1; + break; + case ORBIS_AUDIO_OUT_PORT_TYPE_AUX: + state->output = 0; + state->channel = 0; + break; + default: + UNREACHABLE(); + } + return ORBIS_OK; } diff --git a/src/core/libraries/audio/audioout.h b/src/core/libraries/audio/audioout.h index 3b2c73df..c5a62dc6 100644 --- a/src/core/libraries/audio/audioout.h +++ b/src/core/libraries/audio/audioout.h @@ -34,6 +34,16 @@ struct OrbisAudioOutOutputParam { const void* ptr; }; +struct OrbisAudioOutPortState { + u16 output; + u8 channel; + u8 reserved8_1[1]; + s16 volume; + u16 rerouteCounter; + u64 flag; + u64 reserved64[2]; +}; + int PS4_SYSV_ABI sceAudioOutDeviceIdOpen(); int PS4_SYSV_ABI sceAudioDeviceControlGet(); int PS4_SYSV_ABI sceAudioDeviceControlSet(); @@ -55,7 +65,7 @@ int PS4_SYSV_ABI sceAudioOutGetHandleStatusInfo(); int PS4_SYSV_ABI sceAudioOutGetInfo(); int PS4_SYSV_ABI sceAudioOutGetInfoOpenNum(); int PS4_SYSV_ABI sceAudioOutGetLastOutputTime(); -int PS4_SYSV_ABI sceAudioOutGetPortState(); +int PS4_SYSV_ABI sceAudioOutGetPortState(s32 handle, OrbisAudioOutPortState* state); int PS4_SYSV_ABI sceAudioOutGetSimulatedBusUsableStatusByBusType(); int PS4_SYSV_ABI sceAudioOutGetSimulatedHandleStatusInfo(); int PS4_SYSV_ABI sceAudioOutGetSimulatedHandleStatusInfo2(); diff --git a/src/core/libraries/kernel/file_system.cpp b/src/core/libraries/kernel/file_system.cpp index b3449cfd..3ef4b6a0 100644 --- a/src/core/libraries/kernel/file_system.cpp +++ b/src/core/libraries/kernel/file_system.cpp @@ -105,7 +105,7 @@ int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) { } int PS4_SYSV_ABI posix_open(const char* path, int flags, /* SceKernelMode*/ u16 mode) { - LOG_INFO(Kernel_Fs, "posix open redirect to sceKernelOpen\n"); + LOG_INFO(Kernel_Fs, "posix open redirect to sceKernelOpen"); int result = sceKernelOpen(path, flags, mode); // Posix calls different only for their return values ASSERT(result >= 0); diff --git a/src/core/libraries/kernel/libkernel.cpp b/src/core/libraries/kernel/libkernel.cpp index 15b290f7..6edb5449 100644 --- a/src/core/libraries/kernel/libkernel.cpp +++ b/src/core/libraries/kernel/libkernel.cpp @@ -88,7 +88,7 @@ int PS4_SYSV_ABI sceKernelMmap(void* addr, u64 len, int prot, int flags, int fd, void* PS4_SYSV_ABI posix_mmap(void* addr, u64 len, int prot, int flags, int fd, u64 offset) { void* ptr; - LOG_INFO(Kernel_Vmm, "posix mmap redirect to sceKernelMmap\n"); + LOG_INFO(Kernel_Vmm, "posix mmap redirect to sceKernelMmap"); // posix call the difference is that there is a different behaviour when it doesn't return 0 or // SCE_OK const VAddr ret_addr = (VAddr)__builtin_return_address(0); @@ -288,9 +288,21 @@ int PS4_SYSV_ABI sceKernelUuidCreate(OrbisKernelUuid* orbisUuid) { return 0; } +char* PS4_SYSV_ABI sceKernelGetFsSandboxRandomWord() { + char* path = "sys"; + return path; +} + +int PS4_SYSV_ABI posix_connect() { + return -1; +} + void LibKernel_Register(Core::Loader::SymbolsResolver* sym) { // obj LIB_OBJ("f7uOxY9mM1U", "libkernel", 1, "libkernel", 1, 1, &g_stack_chk_guard); + // misc + LIB_FUNCTION("JGfTMBOdUJo", "libkernel", 1, "libkernel", 1, 1, sceKernelGetFsSandboxRandomWord); + LIB_FUNCTION("XVL8So3QJUk", "libkernel", 1, "libkernel", 1, 1, posix_connect); // memory LIB_FUNCTION("OMDRKKAZ8I4", "libkernel", 1, "libkernel", 1, 1, sceKernelDebugRaiseException); LIB_FUNCTION("rTXw65xmLIA", "libkernel", 1, "libkernel", 1, 1, sceKernelAllocateDirectMemory); diff --git a/src/core/libraries/libs.cpp b/src/core/libraries/libs.cpp index f163a9d8..46ada931 100644 --- a/src/core/libraries/libs.cpp +++ b/src/core/libraries/libs.cpp @@ -63,10 +63,7 @@ void InitHLELibs(Core::Loader::SymbolsResolver* sym) { Libraries::NpScore::RegisterlibSceNpScore(sym); Libraries::NpTrophy::RegisterlibSceNpTrophy(sym); Libraries::ScreenShot::RegisterlibSceScreenShot(sym); - Libraries::LibcInternal::RegisterlibSceLibcInternal(sym); Libraries::AppContent::RegisterlibSceAppContent(sym); - Libraries::Rtc::RegisterlibSceRtc(sym); - Libraries::DiscMap::RegisterlibSceDiscMap(sym); Libraries::PngDec::RegisterlibScePngDec(sym); Libraries::PlayGo::RegisterlibScePlayGo(sym); Libraries::Usbd::RegisterlibSceUsbd(sym); diff --git a/src/emulator.cpp b/src/emulator.cpp index 2da7513b..77ba91f0 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -4,7 +4,10 @@ #include #include #include +#include #include +#include +#include #include #include #include "common/config.h" @@ -136,12 +139,38 @@ void Emulator::Run(const std::filesystem::path& file) { } void Emulator::LoadSystemModules(const std::filesystem::path& file) { + + constexpr std::array ModulesToLoad{ + {{"libSceNgs2.sprx", nullptr}, + {"libSceLibcInternal.sprx", &Libraries::LibcInternal::RegisterlibSceLibcInternal}, + {"libSceDiscMap.sprx", &Libraries::DiscMap::RegisterlibSceDiscMap}, + {"libSceRtc.sprx", &Libraries::Rtc::RegisterlibSceRtc}}}; + + std::vector found_modules; const auto& sys_module_path = Common::FS::GetUserPath(Common::FS::PathType::SysModuleDir); for (const auto& entry : std::filesystem::directory_iterator(sys_module_path)) { - if (entry.path().filename() == "libSceNgs2.sprx" || - entry.path().filename() == "libSceLibcInternal.sprx") { - LOG_INFO(Loader, "Loading {}", entry.path().string().c_str()); - linker->LoadModule(entry.path()); + found_modules.push_back(entry.path()); + } + for (auto it : ModulesToLoad) { + bool found = false; + std::filesystem::path foundpath; + for (auto f : found_modules) { + if (f.filename().string() == it.module_name) { + found = true; + foundpath = f; + break; + } + } + if (found) { + LOG_INFO(Loader, "Loading {}", foundpath.string().c_str()); + linker->LoadModule(foundpath); + } else { + if (it.callback != nullptr) { + LOG_INFO(Loader, "Can't Load {} switching to HLE", it.module_name); + it.callback(&linker->GetHLESymbols()); + } else { + LOG_INFO(Loader, "No HLE available for {} module", it.module_name); + } } } } diff --git a/src/emulator.h b/src/emulator.h index 36faaad3..3267b8fd 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -13,6 +13,13 @@ namespace Core { +using HLEInitDef = void (*)(Core::Loader::SymbolsResolver* sym); + +struct SysModules { + std::string_view module_name; + HLEInitDef callback; +}; + class Emulator { public: Emulator();