diff --git a/src/emulator.cpp b/src/emulator.cpp index 05a21240..be13ba7b 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -1,3 +1,4 @@ +#include "emulator.h" // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -45,6 +46,7 @@ Emulator::Emulator() : window{WindowWidth, WindowHeight, controller} { // Initialize kernel and library facilities. Libraries::Kernel::init_pthreads(); + Libraries::InitHLELibs(&linker->GetHLESymbols()); } Emulator::~Emulator() { @@ -54,10 +56,6 @@ Emulator::~Emulator() { } void Emulator::Run(const std::filesystem::path& file) { - // Initialize linker - auto linker = Common::Singleton::Instance(); - Libraries::InitHLELibs(&linker->GetHLESymbols()); - // Applications expect to be run from /app0 so mount the file's parent path as app0. auto* mnt = Common::Singleton::Instance(); mnt->Mount(file.parent_path(), "/app0"); @@ -92,13 +90,8 @@ void Emulator::Run(const std::filesystem::path& file) { linker->LoadModule(file); // check if we have system modules to load - 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") { - LOG_INFO(Loader, "Loading {}", entry.path().string().c_str()); - linker->LoadModule(entry.path().string().c_str()); - } - } + LoadSystemModules(file); + // Check if there is a libc.prx in sce_module folder bool found = false; if (Config::isLleLibc()) { @@ -109,7 +102,7 @@ void Emulator::Run(const std::filesystem::path& file) { entry.path().filename() == "libSceFios2.prx") { found = true; LOG_INFO(Loader, "Loading {}", entry.path().string().c_str()); - linker->LoadModule(entry.path().string().c_str()); + linker->LoadModule(entry.path()); } } } @@ -119,7 +112,8 @@ void Emulator::Run(const std::filesystem::path& file) { } // start execution - std::thread mainthread([linker]() { linker->Execute(); }); + std::jthread mainthread = + std::jthread([this](std::stop_token stop_token) { linker->Execute(); }); // Begin main window loop until the application exits static constexpr std::chrono::microseconds FlipPeriod{100000}; @@ -133,4 +127,14 @@ void Emulator::Run(const std::filesystem::path& file) { std::exit(0); } +void Emulator::LoadSystemModules(const std::filesystem::path& file) { + 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") { + LOG_INFO(Loader, "Loading {}", entry.path().string().c_str()); + linker->LoadModule(entry.path()); + } + } +} + } // namespace Core \ No newline at end of file diff --git a/src/emulator.h b/src/emulator.h index ade76044..7364af8c 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -22,8 +22,10 @@ public: void Run(const std::filesystem::path& file); private: + void LoadSystemModules(const std::filesystem::path& file); Discord::RPC discord_rpc; Input::GameController* controller = Common::Singleton::Instance(); + Core::Linker* linker = Common::Singleton::Instance(); Frontend::WindowSDL window; };