mirror of
https://github.com/ran-j/PS2Recomp.git
synced 2026-09-27 09:05:28 -04:00
Feature/runtime ecosystem refactor (#107)
* feat: remove memory and pad from stub section * feat: add support for resume entry targets in CodeGenerator (this allow jumps in address outside function) feat: refactor entry point discovery one more try to reduce big generated file * feat: optmizations for release build * feat: remove unused file * feat: added some test cases for code gen * feat: added log macro and remove win specific code * feat: refactor runtime folder structure feat: added reset sound driver RPC state and compatibility layout feat: rename and added new test feat: update RPC calls to use defined constants feat: added more PSMC(16, 32) feat: change cd read to try find the asset ignoring case sensitive fix: fix some render problems feat: add logs on pad feat: added more RPC handles * feat: added game override for code veronica * feat: apply vita patch * feat: flags to disable build * feat: fix merges feat: break a lot of tests * feat: better throw error on empty cd path feat: remove recompiler unusde function feat: apply missing patch * feat: gamedp is now part of lib feat: missing file * feat: small cleanup * feat: missing vita changes * feat: fix more merge * feat: fix tests * feat: last missing feature * feat: added missing import * feat: rename test local functions * feat: init syscall on ps2 list * feat: added DMA helpers * feat: faster builds feat: more implement for darkcloud * feat: back missing file * feat: added missing includes * feat: remove test * feat: missing include * feat: read register funtion * feat: build fix * feat: force exit on detach thread
This commit is contained in:
+123
-44
@@ -1,6 +1,7 @@
|
||||
#include "ps2_runtime.h"
|
||||
#include "register_functions.h"
|
||||
#include "games_database.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include "ps2_log.h"
|
||||
#endif
|
||||
@@ -8,66 +9,144 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include <exception>
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
|
||||
std::string normalizeGameId(const std::string& folderName)
|
||||
namespace
|
||||
{
|
||||
std::string result = folderName;
|
||||
void setupTerminateLogger() // to help on release build crashs
|
||||
{
|
||||
std::set_terminate([]()
|
||||
{
|
||||
std::cerr << "[terminate] unhandled exception" << std::endl;
|
||||
const std::exception_ptr ep = std::current_exception();
|
||||
if (ep)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::rethrow_exception(ep);
|
||||
}
|
||||
catch (const std::system_error &e)
|
||||
{
|
||||
std::cerr << "[terminate] std::system_error code=" << e.code().value()
|
||||
<< " category=" << e.code().category().name()
|
||||
<< " message=" << e.what() << std::endl;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
std::cerr << "[terminate] std::exception: " << e.what() << std::endl;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << "[terminate] non-std exception" << std::endl;
|
||||
}
|
||||
}
|
||||
std::abort(); });
|
||||
}
|
||||
|
||||
size_t underscore = result.find('_');
|
||||
if (underscore != std::string::npos)
|
||||
result[underscore] = '-';
|
||||
std::string normalizeGameId(const std::string &folderName)
|
||||
{
|
||||
std::string result = folderName;
|
||||
|
||||
size_t dot = result.find('.');
|
||||
if (dot != std::string::npos)
|
||||
result.erase(dot, 1);
|
||||
size_t underscore = result.find('_');
|
||||
if (underscore != std::string::npos)
|
||||
result[underscore] = '-';
|
||||
|
||||
return result;
|
||||
size_t dot = result.find('.');
|
||||
if (dot != std::string::npos)
|
||||
result.erase(dot, 1);
|
||||
|
||||
std::ranges::transform(result, result.begin(), [](unsigned char character)
|
||||
{ return static_cast<char>(std::toupper(character)); });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::filesystem::path getExecutablePath(int argc, char *argv[])
|
||||
{
|
||||
if (argc >= 2 && argv[1] && argv[1][0] != '\0')
|
||||
{
|
||||
std::cout << "Using argv boot path" << std::endl;
|
||||
return std::filesystem::path(argv[1]);
|
||||
}
|
||||
#if defined(PS2X_DEFAULT_BOOT_ELF)
|
||||
std::cout << "Using default boot file" << std::endl;
|
||||
const std::filesystem::path configuredPath = std::filesystem::path(PS2X_DEFAULT_BOOT_ELF);
|
||||
#if defined(PLATFORM_VITA)
|
||||
return configuredPath;
|
||||
#endif
|
||||
if (configuredPath.is_absolute())
|
||||
{
|
||||
return configuredPath;
|
||||
}
|
||||
return (std::filesystem::current_path() / configuredPath).lexically_normal();
|
||||
#else
|
||||
throw std::runtime_error("Unable to determine executable path. Pass the guest ELF as argv[1] or define PS2X_DEFAULT_BOOT_ELF.");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
setupTerminateLogger();
|
||||
|
||||
try
|
||||
{
|
||||
std::cout << "Usage: " << argv[0] << " <elf_file>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::filesystem::path pathObj = getExecutablePath(argc, argv);
|
||||
|
||||
std::string elfPath = argv[1];
|
||||
std::filesystem::path pathObj(elfPath);
|
||||
std::string folderName = pathObj.filename().string();
|
||||
std::string normalizedId = normalizeGameId(folderName);
|
||||
std::string filePathStr = pathObj.string();
|
||||
std::string elfName = pathObj.filename().string();
|
||||
std::string normalizedId = normalizeGameId(elfName);
|
||||
|
||||
std::string windowTitle = "PS2-Recomp | ";
|
||||
const char* gameName = getGameName(normalizedId);
|
||||
std::string windowTitle = "PS2-Recomp | ";
|
||||
const char *gameName = getGameName(normalizedId);
|
||||
|
||||
if (gameName)
|
||||
{
|
||||
windowTitle += std::string(gameName) + " | " + folderName;
|
||||
}
|
||||
else
|
||||
{
|
||||
windowTitle += folderName;
|
||||
}
|
||||
#if !defined(PLATFORM_VITA)
|
||||
if (gameName)
|
||||
{
|
||||
windowTitle += std::string(gameName) + " | " + elfName;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
windowTitle += elfName;
|
||||
}
|
||||
|
||||
PS2Runtime runtime;
|
||||
if (!runtime.initialize(windowTitle.c_str()))
|
||||
{
|
||||
std::cerr << "Failed to initialize PS2 runtime" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
PS2Runtime runtime;
|
||||
if (!runtime.initialize(windowTitle.c_str()))
|
||||
{
|
||||
std::cerr << "Failed to initialize PS2 runtime" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
registerAllFunctions(runtime);
|
||||
registerAllFunctions(runtime);
|
||||
|
||||
if (!runtime.loadELF(elfPath))
|
||||
{
|
||||
std::cerr << "Failed to load ELF file: " << elfPath << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if (!runtime.loadELF(filePathStr))
|
||||
{
|
||||
std::cerr << "Failed to load ELF file: " << filePathStr << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
runtime.run();
|
||||
runtime.run();
|
||||
|
||||
#ifdef _DEBUG
|
||||
ps2_log::print_saved_location();
|
||||
ps2_log::print_saved_location();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
std::cout.flush();
|
||||
std::cerr.flush();
|
||||
std::_Exit(0);
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
std::cerr << "[main] fatal exception: " << e.what() << std::endl;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << "[main] fatal exception: unknown" << std::endl;
|
||||
}
|
||||
|
||||
std::cout.flush();
|
||||
std::cerr.flush();
|
||||
std::_Exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user