Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch 9 #21

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions engine/inc/irx/irx_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#pragma once

#include <tamtypes.h>
#include <map>

namespace Tyra {

Expand All @@ -34,6 +35,8 @@ class IrxLoader {
int applyRpcPatches();
void waitUntilUsbDeviceIsReady();
void delay(int count);
std::string GetIrxErrorDescription(const int ID, const int RET);
std::map<int, std::string>IOPErrors;
};

} // namespace Tyra
122 changes: 104 additions & 18 deletions engine/src/irx/irx_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,92 @@ IrxLoader::IrxLoader() {

IrxLoader::~IrxLoader() {}


std::map<int, std::string>IrxLoader::IOPErrors = {
{-1, "Unknown error"},
{-101, "Illegal intrcode"},
{-102, "CPU ID"},
{-103, "Interrupt disabled"},
{-104, "Found handler"},
{-105, "Handler not found"},
{-150, "No timer"},
{-151, "Illegal timer ID"},
{-152, "Illegal source"},
{-153, "Illegal prescale"},
{-154, "Timer busy"},
{-155, "Timer not setup"},
{-156, "Timer not in use"},
{-160, "Unit used"},
{-161, "Unit not used"},
{-162, "No ROMDIR"},
{-200, "Linker error (missing driver dependency/imports)"},
{-201, "Illegal object"},
{-202, "Unknown Module"},
{-203, "No such file"},
{-204, "File error"},
{-205, "Memory in use"},
{-206, "Already started"},
{-207, "Not started"},
{-208, "Module already stopped"},
{-209, "Cannot stop module"},
{-210, "Module not stopped"},
{-211, "Module not removable"},
{-212, "Library found"},
{-213, "Library not found"},
{-214, "Illegal library"},
{-215, "Library in use"},
{-216, "Already stopping"},
{-217, "Illegal offset"},
{-218, "Illegal position"},
{-219, "Illegal access"},
{-220, "Illegal flag"},
{-400, "NO MEMORY"},
{-401, "Illegal attribute"},
{-402, "Illegal entry"},
{-403, "Illegal priority"},
{-404, "Illegal stack size"},
{-405, "Illegal mode"},
{-406, "Illegal THID"},
{-407, "Unknown THID"},
{-408, "Unknown SEMID"},
{-409, "Unknown EVFID"},
{-410, "Unknown MBXID"},
{-411, "Unknown VPLID"},
{-412, "Unknown FPLID"},
{-413, "Dormant"},
{-414, "Not dormant"},
{-415, "Not suspend"},
{-416, "Not Waiting"},
{-417, "Cannot wait"},
{-418, "KE_RELEASE_WAIT"},
{-419, "KE_SEMA_ZERO"},
{-420, "KE_SEMA_OVF"},
{-421, "KE_EVF_COND"},
{-422, "KE_EVF_MULTI"},
{-423, "KE_EVF_ILPAT"},
{-424, "KE_MBOX_NOMSG"},
{-425, "Wait delete"},
{-426, "Illegal memblock"},
{-427, "Illegal memsize"},
{-428, "Illegal SPAD addr"},
{-429, "SPAD in use"},
{-430, "SPAD not in use"},
{-431, "Illegal type"},
{-432, "Illegal size"},
};

/**
* @brief an equivalent of C standard `strerror()` for the IOP error codes
* @note although this is intended for checking IRX module error status. it can be used to evaluate return values from any operation requested to the IOP. such as module unload request. simply pass the error number to the ID parameter
* @param ID module ID or IOP related return value
* @param RET module return value obtained by the last parameter of `SifExecModuleBuffer`
* @return description of an IOP error or IRX startup error
*/
std::string IrxLoader::GetIrxErrorDescription(const int ID, const int RET = 0) {
if (RET == 1) return "Module willingly requested to be unloaded from IOP";
return IrxLoader::IOPErrors[ID]
}

void IrxLoader::loadAll(const bool& withUsb, const bool& isLoggingToFile) {
if (isLoaded) {
TYRA_LOG("IRX modules already loaded!");
Expand Down Expand Up @@ -100,26 +186,26 @@ int IrxLoader::applyRpcPatches() {
void IrxLoader::loadLibsd(const bool& verbose) {
if (verbose) TYRA_LOG("IRX: Loading libsd...");

int ret;
SifExecModuleBuffer(&libsd_irx, size_libsd_irx, 0, nullptr, &ret);
TYRA_ASSERT(ret >= 0, "Failed to load module: libsd_irx");
int ret, id;
id = SifExecModuleBuffer(&libsd_irx, size_libsd_irx, 0, nullptr, &ret);
TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: libsd_irx", IrxLoader::GetIrxErrorDescription(id, ret));

if (verbose) TYRA_LOG("IRX: Libsd loaded!");
}

void IrxLoader::loadIO(const bool& verbose) {
int ret;
int ret, id;
if (verbose) TYRA_LOG("IRX: Loading iomanX...");

SifExecModuleBuffer(&iomanX_irx, size_iomanX_irx, 0, nullptr, &ret);
TYRA_ASSERT(ret >= 0, "Failed to load module: iomanX_irx");
id = SifExecModuleBuffer(&iomanX_irx, size_iomanX_irx, 0, nullptr, &ret);
TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: iomanX_irx", IrxLoader::GetIrxErrorDescription(id, ret));

if (verbose) TYRA_LOG("IRX: iomanX loaded!");

if (verbose) TYRA_LOG("IRX: Loading fileXio...");

SifExecModuleBuffer(&fileXio_irx, size_fileXio_irx, 0, nullptr, &ret);
TYRA_ASSERT(ret >= 0, "Failed to load module: fileXio_irx");
TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: fileXio_irx", IrxLoader::GetIrxErrorDescription(id, ret));

if (verbose) TYRA_LOG("IRX: fileXio_irx loaded!");

Expand All @@ -128,19 +214,19 @@ void IrxLoader::loadIO(const bool& verbose) {
void IrxLoader::loadUsbModules(const bool& verbose) {
if (verbose) TYRA_LOG("IRX: Loading usb modules...");

int ret;
int ret, id;

SifExecModuleBuffer(&usbd_irx, size_usbd_irx, 0, nullptr, &ret);
TYRA_ASSERT(ret >= 0, "Failed to load module: usbd_irx");
TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: usbd_irx", IrxLoader::GetIrxErrorDescription(id, ret));

SifExecModuleBuffer(&bdm_irx, size_bdm_irx, 0, nullptr, &ret);
TYRA_ASSERT(ret >= 0, "Failed to load module: bdm_irx");
TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: bdm_irx", IrxLoader::GetIrxErrorDescription(id, ret));

SifExecModuleBuffer(&bdmfs_fatfs_irx, size_bdmfs_fatfs_irx, 0, nullptr, &ret);
TYRA_ASSERT(ret >= 0, "Failed to load module: bdmfs_fatfs");
TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: bdmfs_fatfs_irx", IrxLoader::GetIrxErrorDescription(id, ret));

SifExecModuleBuffer(&usbmass_bd_irx, size_usbmass_bd_irx, 0, nullptr, &ret);
TYRA_ASSERT(ret >= 0, "Failed to load module: usbmass");
TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: usbmass_bd_irx", IrxLoader::GetIrxErrorDescription(id, ret));

waitUntilUsbDeviceIsReady();

Expand All @@ -150,29 +236,29 @@ void IrxLoader::loadUsbModules(const bool& verbose) {
void IrxLoader::loadAudsrv(const bool& verbose) {
if (verbose) TYRA_LOG("IRX: Loading audsrv...");

int ret;
int ret, id;
SifExecModuleBuffer(&audsrv_irx, size_audsrv_irx, 0, nullptr, &ret);
TYRA_ASSERT(ret >= 0, "Failed to load module: audsrv_irx");
TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: audsrv_irx", IrxLoader::GetIrxErrorDescription(id, ret));

if (verbose) TYRA_LOG("IRX: Audsrv loaded!");
}

void IrxLoader::loadSio2man(const bool& verbose) {
if (verbose) TYRA_LOG("IRX: Loading sio2man...");

int ret;
int ret, id;
SifExecModuleBuffer(&sio2man_irx, size_sio2man_irx, 0, nullptr, &ret);
TYRA_ASSERT(ret >= 0, "Failed to load module: sio2man_irx");
TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: sio2man_irx", IrxLoader::GetIrxErrorDescription(id, ret));

if (verbose) TYRA_LOG("IRX: Sio2man loaded!");
}

void IrxLoader::loadPadman(const bool& verbose) {
if (verbose) TYRA_LOG("IRX: Loading padman...");

int ret;
int ret, id;
SifExecModuleBuffer(&padman_irx, size_padman_irx, 0, nullptr, &ret);
TYRA_ASSERT(ret >= 0, "Failed to load module: padman_irx");
TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: padman_irx", IrxLoader::GetIrxErrorDescription(id, ret));

if (verbose) TYRA_LOG("IRX: Padman loaded!");
}
Expand Down
Loading