mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-12-10 13:48:40 +00:00
@@ -486,6 +486,8 @@ else()
|
|||||||
${SHADER_RECOMPILER}
|
${SHADER_RECOMPILER}
|
||||||
${VIDEO_CORE}
|
${VIDEO_CORE}
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
|
src/emulator.cpp
|
||||||
|
src/emulator.h
|
||||||
src/sdl_window.h
|
src/sdl_window.h
|
||||||
src/sdl_window.cpp
|
src/sdl_window.cpp
|
||||||
)
|
)
|
||||||
|
|||||||
2
externals/cryptopp
vendored
2
externals/cryptopp
vendored
Submodule externals/cryptopp updated: 782057f5f1...9bb6680cfa
2
externals/cryptopp-cmake
vendored
2
externals/cryptopp-cmake
vendored
Submodule externals/cryptopp-cmake updated: 19cd13af5f...2c384c2826
2
externals/fmt
vendored
2
externals/fmt
vendored
Submodule externals/fmt updated: d2473b7b73...18a325f370
2
externals/glslang
vendored
2
externals/glslang
vendored
Submodule externals/glslang updated: 2b19bf7e1b...73eccd4b67
2
externals/magic_enum
vendored
2
externals/magic_enum
vendored
Submodule externals/magic_enum updated: db0b726c05...bf3c74ab7e
2
externals/sdl3
vendored
2
externals/sdl3
vendored
Submodule externals/sdl3 updated: bcbf09acde...4fc68a48f2
2
externals/sirit
vendored
2
externals/sirit
vendored
Submodule externals/sirit updated: 8c281cc0b7...fc65ebb5b5
2
externals/vma
vendored
2
externals/vma
vendored
Submodule externals/vma updated: eaf8fc27ee...7942b79828
2
externals/vulkan-headers
vendored
2
externals/vulkan-headers
vendored
Submodule externals/vulkan-headers updated: 192d051db3...d192041a2f
2
externals/zlib-ng
vendored
2
externals/zlib-ng
vendored
Submodule externals/zlib-ng updated: 1007e7a9c7...2e3e5f30a0
@@ -1,6 +1,9 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include <SDL3/SDL_audio.h>
|
||||||
|
#include <SDL3/SDL_init.h>
|
||||||
|
#include <SDL3/SDL_timer.h>
|
||||||
#include <common/assert.h>
|
#include <common/assert.h>
|
||||||
#include <core/libraries/error_codes.h>
|
#include <core/libraries/error_codes.h>
|
||||||
#include "sdl_audio.h"
|
#include "sdl_audio.h"
|
||||||
|
|||||||
@@ -4,8 +4,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <SDL.h>
|
#include <SDL3/SDL_audio.h>
|
||||||
|
|
||||||
#include "core/libraries/audio/audioout.h"
|
#include "core/libraries/audio/audioout.h"
|
||||||
|
|
||||||
namespace Audio {
|
namespace Audio {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
namespace Config {
|
namespace Config {
|
||||||
|
|
||||||
static bool isNeo = false;
|
static bool isNeo = false;
|
||||||
static bool isFullscreen = true;
|
static bool isFullscreen = false;
|
||||||
static u32 screenWidth = 1280;
|
static u32 screenWidth = 1280;
|
||||||
static u32 screenHeight = 720;
|
static u32 screenHeight = 720;
|
||||||
static s32 gpuId = -1; // Vulkan physical device index. Set to negative for auto select
|
static s32 gpuId = -1; // Vulkan physical device index. Set to negative for auto select
|
||||||
|
|||||||
@@ -208,10 +208,11 @@ int PS4_SYSV_ABI sceKernelStat(const char* path, OrbisKernelStat* sb) {
|
|||||||
|
|
||||||
int PS4_SYSV_ABI posix_stat(const char* path, OrbisKernelStat* sb) {
|
int PS4_SYSV_ABI posix_stat(const char* path, OrbisKernelStat* sb) {
|
||||||
int result = sceKernelStat(path, sb);
|
int result = sceKernelStat(path, sb);
|
||||||
if (result < 0) {
|
if (result != 0) {
|
||||||
UNREACHABLE(); // TODO
|
LOG_ERROR(Kernel_Pthread, "posix_stat: error = {}", result);
|
||||||
|
result += ORBIS_KERNEL_ERROR_UNKNOWN;
|
||||||
}
|
}
|
||||||
return ORBIS_OK;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
s64 PS4_SYSV_ABI sceKernelPread(int d, void* buf, size_t nbytes, s64 offset) {
|
s64 PS4_SYSV_ABI sceKernelPread(int d, void* buf, size_t nbytes, s64 offset) {
|
||||||
|
|||||||
@@ -201,7 +201,9 @@ int PS4_SYSV_ABI scePthreadRwlockInit(OrbisPthreadRwlock* rwlock,
|
|||||||
if (attr == nullptr || *attr == nullptr) {
|
if (attr == nullptr || *attr == nullptr) {
|
||||||
attr = g_pthread_cxt->getDefaultRwattr();
|
attr = g_pthread_cxt->getDefaultRwattr();
|
||||||
}
|
}
|
||||||
(*rwlock)->name = name;
|
if (name != nullptr) {
|
||||||
|
(*rwlock)->name = name;
|
||||||
|
}
|
||||||
int result = pthread_rwlock_init(&(*rwlock)->pth_rwlock, &(*attr)->attr_rwlock);
|
int result = pthread_rwlock_init(&(*rwlock)->pth_rwlock, &(*attr)->attr_rwlock);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
LOG_ERROR(Kernel_Pthread, "scePthreadRwlockInit: error = {}", result);
|
LOG_ERROR(Kernel_Pthread, "scePthreadRwlockInit: error = {}", result);
|
||||||
|
|||||||
139
src/emulator.cpp
Normal file
139
src/emulator.cpp
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include <common/logging/log.h>
|
||||||
|
#include <core/file_format/psf.h>
|
||||||
|
#include <core/file_format/splash.h>
|
||||||
|
#include <core/libraries/libc/libc.h>
|
||||||
|
#include <core/libraries/videoout/video_out.h>
|
||||||
|
#include <fmt/core.h>
|
||||||
|
#include "common/config.h"
|
||||||
|
#include "common/logging/backend.h"
|
||||||
|
#include "common/path_util.h"
|
||||||
|
#include "common/singleton.h"
|
||||||
|
#include "core/file_sys/fs.h"
|
||||||
|
#include "core/libraries/kernel/thread_management.h"
|
||||||
|
#include "core/libraries/libs.h"
|
||||||
|
#include "core/linker.h"
|
||||||
|
#include "core/memory.h"
|
||||||
|
#include "emulator.h"
|
||||||
|
|
||||||
|
Frontend::WindowSDL* g_window = nullptr;
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
|
||||||
|
static constexpr s32 WindowWidth = 1280;
|
||||||
|
static constexpr s32 WindowHeight = 720;
|
||||||
|
|
||||||
|
Emulator::Emulator() : window{WindowWidth, WindowHeight, controller} {
|
||||||
|
g_window = &window;
|
||||||
|
|
||||||
|
// Initialize memory system as early as possible to reserve mappings.
|
||||||
|
[[maybe_unused]] const auto* memory = Core::Memory::Instance();
|
||||||
|
|
||||||
|
// Read configuration file.
|
||||||
|
const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
|
||||||
|
Config::load(config_dir / "config.toml");
|
||||||
|
|
||||||
|
// Start logger.
|
||||||
|
Common::Log::Initialize();
|
||||||
|
Common::Log::Start();
|
||||||
|
|
||||||
|
// Start discord integration
|
||||||
|
discord_rpc.init();
|
||||||
|
discord_rpc.update(Discord::RPCStatus::Idling, "");
|
||||||
|
|
||||||
|
// Initialize kernel and library facilities.
|
||||||
|
Libraries::Kernel::init_pthreads();
|
||||||
|
Libraries::InitHLELibs(&linker->GetHLESymbols());
|
||||||
|
}
|
||||||
|
|
||||||
|
Emulator::~Emulator() {
|
||||||
|
const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
|
||||||
|
Config::save(config_dir / "config.toml");
|
||||||
|
discord_rpc.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Emulator::Run(const std::filesystem::path& file) {
|
||||||
|
// Applications expect to be run from /app0 so mount the file's parent path as app0.
|
||||||
|
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
|
||||||
|
mnt->Mount(file.parent_path(), "/app0");
|
||||||
|
|
||||||
|
// Loading param.sfo file if exists
|
||||||
|
std::filesystem::path sce_sys_folder = file.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);
|
||||||
|
} 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the module with the linker
|
||||||
|
linker->LoadModule(file);
|
||||||
|
|
||||||
|
// check if we have system modules to load
|
||||||
|
LoadSystemModules(file);
|
||||||
|
|
||||||
|
// Check if there is a libc.prx in sce_module folder
|
||||||
|
bool found = false;
|
||||||
|
if (Config::isLleLibc()) {
|
||||||
|
std::filesystem::path sce_module_folder = file.parent_path() / "sce_module";
|
||||||
|
if (std::filesystem::is_directory(sce_module_folder)) {
|
||||||
|
for (const auto& entry : std::filesystem::directory_iterator(sce_module_folder)) {
|
||||||
|
if (entry.path().filename() == "libc.prx" ||
|
||||||
|
entry.path().filename() == "libSceFios2.prx") {
|
||||||
|
found = true;
|
||||||
|
LOG_INFO(Loader, "Loading {}", entry.path().string().c_str());
|
||||||
|
linker->LoadModule(entry.path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
Libraries::LibC::libcSymbolsRegister(&linker->GetHLESymbols());
|
||||||
|
}
|
||||||
|
|
||||||
|
// start execution
|
||||||
|
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};
|
||||||
|
|
||||||
|
while (window.isOpen()) {
|
||||||
|
window.waitEvent();
|
||||||
|
Libraries::VideoOut::Flip(FlipPeriod);
|
||||||
|
Libraries::VideoOut::Vblank();
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
32
src/emulator.h
Normal file
32
src/emulator.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
#include <common/singleton.h>
|
||||||
|
#include "common/discord.h"
|
||||||
|
#include "core/linker.h"
|
||||||
|
#include "input/controller.h"
|
||||||
|
#include "sdl_window.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
|
||||||
|
class Emulator {
|
||||||
|
public:
|
||||||
|
Emulator();
|
||||||
|
~Emulator();
|
||||||
|
|
||||||
|
void Run(const std::filesystem::path& file);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void LoadSystemModules(const std::filesystem::path& file);
|
||||||
|
Discord::RPC discord_rpc;
|
||||||
|
Input::GameController* controller = Common::Singleton<Input::GameController>::Instance();
|
||||||
|
Core::Linker* linker = Common::Singleton<Core::Linker>::Instance();
|
||||||
|
Frontend::WindowSDL window;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Core
|
||||||
116
src/main.cpp
116
src/main.cpp
@@ -1,126 +1,16 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include <thread>
|
#include <emulator.h>
|
||||||
#include <SDL3/SDL.h>
|
|
||||||
#include <Zydis/Zydis.h>
|
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
|
||||||
#include <core/file_format/psf.h>
|
|
||||||
#include "common/config.h"
|
|
||||||
#include "common/discord.h"
|
|
||||||
#include "common/logging/backend.h"
|
|
||||||
#include "common/logging/log.h"
|
|
||||||
#include "common/path_util.h"
|
|
||||||
#include "common/singleton.h"
|
|
||||||
#include "core/file_format/splash.h"
|
|
||||||
#include "core/file_sys/fs.h"
|
|
||||||
#include "core/libraries/kernel/thread_management.h"
|
|
||||||
#include "core/libraries/libc/libc.h"
|
|
||||||
#include "core/libraries/libs.h"
|
|
||||||
#include "core/libraries/videoout/video_out.h"
|
|
||||||
#include "core/linker.h"
|
|
||||||
#include "core/memory.h"
|
|
||||||
#include "input/controller.h"
|
|
||||||
#include "sdl_window.h"
|
|
||||||
|
|
||||||
Frontend::WindowSDL* g_window;
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
fmt::print("Usage: {} <elf or eboot.bin path>\n", argv[0]);
|
fmt::print("Usage: {} <elf or eboot.bin path>\n", argv[0]);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// Initialize memory system as early as possible to reserve mappings.
|
|
||||||
[[maybe_unused]] const auto* memory = Core::Memory::Instance();
|
|
||||||
const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
|
|
||||||
Config::load(config_dir / "config.toml");
|
|
||||||
Common::Log::Initialize();
|
|
||||||
Common::Log::Start();
|
|
||||||
Libraries::Kernel::init_pthreads();
|
|
||||||
s32 width = Config::getScreenWidth();
|
|
||||||
s32 height = Config::getScreenHeight();
|
|
||||||
|
|
||||||
auto* controller = Common::Singleton<Input::GameController>::Instance();
|
Core::Emulator emulator;
|
||||||
Frontend::WindowSDL window{width, height, controller};
|
emulator.Run(argv[1]);
|
||||||
g_window = &window;
|
|
||||||
|
|
||||||
// Argument 1 is the path of self file to boot
|
|
||||||
const char* const path = argv[1];
|
|
||||||
|
|
||||||
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
|
|
||||||
std::filesystem::path p = std::string(path);
|
|
||||||
mnt->Mount(p.parent_path(), "/app0");
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
} 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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto linker = Common::Singleton<Core::Linker>::Instance();
|
|
||||||
Libraries::InitHLELibs(&linker->GetHLESymbols());
|
|
||||||
linker->LoadModule(path);
|
|
||||||
|
|
||||||
// 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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Check if there is a libc.prx in sce_module folder
|
|
||||||
bool found = false;
|
|
||||||
if (Config::isLleLibc()) {
|
|
||||||
std::filesystem::path sce_module_folder = p.parent_path() / "sce_module";
|
|
||||||
if (std::filesystem::is_directory(sce_module_folder)) {
|
|
||||||
for (const auto& entry : std::filesystem::directory_iterator(sce_module_folder)) {
|
|
||||||
if (entry.path().filename() == "libc.prx" ||
|
|
||||||
entry.path().filename() == "libSceFios2.prx") {
|
|
||||||
found = true;
|
|
||||||
LOG_INFO(Loader, "Loading {}", entry.path().string().c_str());
|
|
||||||
linker->LoadModule(entry.path().string().c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
Libraries::LibC::libcSymbolsRegister(&linker->GetHLESymbols());
|
|
||||||
}
|
|
||||||
std::thread mainthread([linker]() { linker->Execute(); });
|
|
||||||
Discord::RPC discordRPC;
|
|
||||||
discordRPC.init();
|
|
||||||
discordRPC.update(Discord::RPCStatus::Idling, "");
|
|
||||||
|
|
||||||
static constexpr std::chrono::microseconds FlipPeriod{100000};
|
|
||||||
|
|
||||||
while (window.isOpen()) {
|
|
||||||
window.waitEvent();
|
|
||||||
Libraries::VideoOut::Flip(FlipPeriod);
|
|
||||||
Libraries::VideoOut::Vblank();
|
|
||||||
}
|
|
||||||
|
|
||||||
discordRPC.stop();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL3/SDL_events.h>
|
||||||
|
#include <SDL3/SDL_init.h>
|
||||||
|
#include <SDL3/SDL_properties.h>
|
||||||
|
#include <SDL3/SDL_video.h>
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/config.h"
|
#include "common/config.h"
|
||||||
#include "common/version.h"
|
#include "common/version.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user