2024-02-23 22:32:32 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2024-04-13 23:35:48 +02:00
|
|
|
#include <thread>
|
2023-11-06 00:11:54 +01:00
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <Zydis/Zydis.h>
|
2023-11-10 18:52:41 +01:00
|
|
|
#include <fmt/core.h>
|
|
|
|
|
2024-05-02 09:57:45 +02:00
|
|
|
#include <core/file_format/psf.h>
|
2024-03-11 12:26:33 +01:00
|
|
|
#include "common/config.h"
|
2023-11-05 12:41:10 +01:00
|
|
|
#include "common/discord.h"
|
2024-02-27 23:10:34 +01:00
|
|
|
#include "common/logging/backend.h"
|
2024-04-13 23:35:48 +02:00
|
|
|
#include "common/logging/log.h"
|
2024-02-27 23:10:34 +01:00
|
|
|
#include "common/path_util.h"
|
2023-11-05 12:41:10 +01:00
|
|
|
#include "common/singleton.h"
|
2024-05-16 15:58:14 +02:00
|
|
|
#include "core/file_format/splash.h"
|
2024-02-23 21:57:57 +01:00
|
|
|
#include "core/file_sys/fs.h"
|
2024-04-13 23:35:48 +02:00
|
|
|
#include "core/libraries/kernel/thread_management.h"
|
|
|
|
#include "core/libraries/libc/libc.h"
|
|
|
|
#include "core/libraries/libs.h"
|
2024-04-14 16:09:51 +02:00
|
|
|
#include "core/libraries/videoout/video_out.h"
|
2023-11-06 00:11:54 +01:00
|
|
|
#include "core/linker.h"
|
2024-06-10 01:13:44 +02:00
|
|
|
#include "core/memory.h"
|
2024-04-14 16:09:51 +02:00
|
|
|
#include "input/controller.h"
|
|
|
|
#include "sdl_window.h"
|
|
|
|
|
|
|
|
Frontend::WindowSDL* g_window;
|
2023-08-22 22:59:59 +02:00
|
|
|
|
2023-10-13 08:40:59 +02:00
|
|
|
int main(int argc, char* argv[]) {
|
2023-08-03 12:06:23 +02:00
|
|
|
if (argc == 1) {
|
2023-10-26 22:29:05 +02:00
|
|
|
fmt::print("Usage: {} <elf or eboot.bin path>\n", argv[0]);
|
2023-07-07 12:54:44 +02:00
|
|
|
return -1;
|
2023-08-03 12:06:23 +02:00
|
|
|
}
|
2024-06-10 01:13:44 +02:00
|
|
|
// Initialize memory system as early as possible to reserve mappings.
|
|
|
|
[[maybe_unused]] const auto* memory = Core::Memory::Instance();
|
2024-02-27 23:10:34 +01:00
|
|
|
const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
|
|
|
|
Config::load(config_dir / "config.toml");
|
|
|
|
Common::Log::Initialize();
|
|
|
|
Common::Log::Start();
|
2024-04-13 23:35:48 +02:00
|
|
|
Libraries::Kernel::init_pthreads();
|
2024-04-14 16:09:51 +02:00
|
|
|
s32 width = Config::getScreenWidth();
|
|
|
|
s32 height = Config::getScreenHeight();
|
|
|
|
|
|
|
|
auto* controller = Common::Singleton<Input::GameController>::Instance();
|
|
|
|
Frontend::WindowSDL window{width, height, controller};
|
|
|
|
g_window = &window;
|
2023-08-22 22:59:59 +02:00
|
|
|
|
2023-11-05 15:56:28 +01:00
|
|
|
// Argument 1 is the path of self file to boot
|
|
|
|
const char* const path = argv[1];
|
2023-09-12 18:39:08 +02:00
|
|
|
|
2023-11-19 09:22:46 +01:00
|
|
|
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
|
|
|
|
std::filesystem::path p = std::string(path);
|
2024-02-27 23:10:34 +01:00
|
|
|
mnt->Mount(p.parent_path(), "/app0");
|
2023-11-19 09:22:46 +01:00
|
|
|
|
2024-05-02 09:57:45 +02:00
|
|
|
// Loading param.sfo file if exists
|
|
|
|
std::filesystem::path sce_sys_folder = p.parent_path() / "sce_sys";
|
|
|
|
if (std::filesystem::is_directory(sce_sys_folder)) {
|
|
|
|
for (const auto& entry : std::filesystem::directory_iterator(sce_sys_folder)) {
|
|
|
|
if (entry.path().filename() == "param.sfo") {
|
|
|
|
auto* param_sfo = Common::Singleton<PSF>::Instance();
|
|
|
|
param_sfo->open(sce_sys_folder.string() + "/param.sfo");
|
|
|
|
std::string id(param_sfo->GetString("CONTENT_ID"), 7, 9);
|
|
|
|
std::string title(param_sfo->GetString("TITLE"));
|
|
|
|
LOG_INFO(Loader, "Game id: {} Title: {}", id, title);
|
|
|
|
u32 fw_version = param_sfo->GetInteger("SYSTEM_VER");
|
|
|
|
std::string app_version = param_sfo->GetString("APP_VER");
|
|
|
|
LOG_INFO(Loader, "Fw: {:#x} App Version: {}", fw_version, app_version);
|
2024-05-16 15:58:14 +02:00
|
|
|
} else if (entry.path().filename() == "pic0.png" ||
|
|
|
|
entry.path().filename() == "pic1.png") {
|
|
|
|
auto* splash = Common::Singleton<Splash>::Instance();
|
|
|
|
if (splash->IsLoaded()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!splash->Open(entry.path().string())) {
|
|
|
|
LOG_ERROR(Loader, "Game splash: unable to open file");
|
|
|
|
}
|
2024-05-02 09:57:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-06 00:11:54 +01:00
|
|
|
auto linker = Common::Singleton<Core::Linker>::Instance();
|
2024-06-05 21:08:18 +02:00
|
|
|
Libraries::InitHLELibs(&linker->GetHLESymbols());
|
2023-11-05 15:56:28 +01:00
|
|
|
linker->LoadModule(path);
|
2024-04-14 16:09:51 +02:00
|
|
|
|
2024-05-13 14:01:45 +02:00
|
|
|
// 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());
|
|
|
|
}
|
|
|
|
}
|
2024-04-14 16:09:51 +02:00
|
|
|
// Check if there is a libc.prx in sce_module folder
|
2024-03-25 08:26:59 +01:00
|
|
|
bool found = false;
|
|
|
|
if (Config::isLleLibc()) {
|
2024-03-27 07:41:14 +01:00
|
|
|
std::filesystem::path sce_module_folder = p.parent_path() / "sce_module";
|
|
|
|
if (std::filesystem::is_directory(sce_module_folder)) {
|
2024-03-25 08:26:59 +01:00
|
|
|
for (const auto& entry : std::filesystem::directory_iterator(sce_module_folder)) {
|
2024-03-27 12:00:27 +01:00
|
|
|
if (entry.path().filename() == "libc.prx" ||
|
|
|
|
entry.path().filename() == "libSceFios2.prx") {
|
2024-03-25 08:46:36 +01:00
|
|
|
found = true;
|
2024-03-27 07:41:14 +01:00
|
|
|
LOG_INFO(Loader, "Loading {}", entry.path().string().c_str());
|
2024-03-25 08:46:36 +01:00
|
|
|
linker->LoadModule(entry.path().string().c_str());
|
2024-03-25 08:26:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-14 16:09:51 +02:00
|
|
|
if (!found) {
|
2024-06-05 21:08:18 +02:00
|
|
|
Libraries::LibC::libcSymbolsRegister(&linker->GetHLESymbols());
|
2024-03-25 08:26:59 +01:00
|
|
|
}
|
2024-04-29 14:16:42 +02:00
|
|
|
std::thread mainthread([linker]() { linker->Execute(); });
|
2023-08-11 19:22:26 +02:00
|
|
|
Discord::RPC discordRPC;
|
|
|
|
discordRPC.init();
|
|
|
|
discordRPC.update(Discord::RPCStatus::Idling, "");
|
2024-04-14 16:09:51 +02:00
|
|
|
|
|
|
|
static constexpr std::chrono::microseconds FlipPeriod{100000};
|
|
|
|
|
|
|
|
while (window.isOpen()) {
|
|
|
|
window.waitEvent();
|
|
|
|
Libraries::VideoOut::Flip(FlipPeriod);
|
|
|
|
Libraries::VideoOut::Vblank();
|
|
|
|
}
|
2023-08-12 00:02:42 +02:00
|
|
|
|
2023-08-11 19:22:26 +02:00
|
|
|
discordRPC.stop();
|
2023-04-27 18:13:19 +02:00
|
|
|
return 0;
|
|
|
|
}
|