shadPS4/src/main.cpp

82 lines
2.7 KiB
C++
Raw Normal View History

2024-02-23 22:32:32 +01:00
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
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>
#include <cinttypes>
#include <cstdio>
#include <thread>
2024-03-25 08:26:59 +01:00
#include <core/hle/libraries/libc/libc.h>
#include <core/hle/libraries/libkernel/thread_management.h>
#include "common/config.h"
2023-11-05 12:41:10 +01:00
#include "common/discord.h"
#include "common/logging/backend.h"
#include "common/path_util.h"
2023-11-05 12:41:10 +01:00
#include "common/singleton.h"
2023-11-10 18:52:41 +01:00
#include "common/types.h"
2023-11-06 00:11:54 +01:00
#include "core/PS4/HLE/Graphics/video_out.h"
#include "core/file_sys/fs.h"
2023-11-06 00:11:54 +01:00
#include "core/hle/libraries/libs.h"
#include "core/linker.h"
#include "core/tls.h"
2023-11-10 18:52:41 +01:00
#include "emulator.h"
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) {
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
}
const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
Config::load(config_dir / "config.toml");
Common::Log::Initialize();
Common::Log::Start();
2023-11-10 18:52:41 +01:00
Core::Libraries::LibKernel::init_pthreads();
2023-08-22 22:59:59 +02:00
auto width = Config::getScreenWidth();
auto height = Config::getScreenHeight();
2023-10-13 08:40:59 +02:00
Emu::emuInit(width, height);
2023-08-22 22:59:59 +02:00
HLE::Libs::Graphics::VideoOut::videoOutInit(width, height);
// Argument 1 is the path of self file to boot
const char* const path = argv[1];
2023-09-12 18:39:08 +02:00
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
std::filesystem::path p = std::string(path);
mnt->Mount(p.parent_path(), "/app0");
2023-11-06 00:11:54 +01:00
auto linker = Common::Singleton<Core::Linker>::Instance();
OldLibraries::InitHLELibs(&linker->getHLESymbols());
Core::InstallTlsHandler();
linker->LoadModule(path);
2024-03-25 08:26:59 +01:00
// check if there is a libc.prx in sce_module folder
bool found = false;
if (Config::isLleLibc()) {
std::filesystem::path sce_module_folder =
std::string(p.parent_path().string() + "\\sce_module");
if (std::filesystem::exists(sce_module_folder)) {
for (const auto& entry : std::filesystem::directory_iterator(sce_module_folder)) {
if (entry.path().filename() == "libc.prx") {
2024-03-25 08:46:36 +01:00
found = true;
2024-03-25 08:26:59 +01:00
printf("%s\n", 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
}
}
}
}
if (!found) // load HLE libc
{
Core::Libraries::LibC::libcSymbolsRegister(&linker->getHLESymbols());
}
std::jthread mainthread([linker](std::stop_token stop_token, void*) { linker->Execute(); },
nullptr);
2023-08-11 19:22:26 +02:00
Discord::RPC discordRPC;
discordRPC.init();
discordRPC.update(Discord::RPCStatus::Idling, "");
2023-10-13 08:40:59 +02:00
Emu::emuRun();
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;
}