irx, nullptr, threading patch
This commit is contained in:
@@ -48,7 +48,7 @@ void AudioSong::init() {
|
||||
void AudioSong::load(const char* t_path) {
|
||||
if (songLoaded) unloadSong();
|
||||
wav = fopen(t_path, "rb");
|
||||
TYRA_ASSERT(wav != NULL, "Failed to open wav file!");
|
||||
TYRA_ASSERT(wav != nullptr, "Failed to open wav file!");
|
||||
rewindSongToStart();
|
||||
songLoaded = true;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ void AudioSong::unloadSong() {
|
||||
|
||||
/** Fseek on wav. */
|
||||
void AudioSong::rewindSongToStart() {
|
||||
if (wav != NULL) fseek(wav, 0x30, SEEK_SET);
|
||||
if (wav != nullptr) fseek(wav, 0x30, SEEK_SET);
|
||||
chunkReadStatus = 0;
|
||||
songFinished = false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
# _____ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licensed under Apache License 2.0
|
||||
# Wellington Carvalho <wellcoj@gmail.com>
|
||||
*/
|
||||
|
||||
#include "debug/debug.hpp"
|
||||
|
||||
std::unique_ptr<std::ofstream> TyraDebug::logFile;
|
||||
|
||||
std::ofstream* TyraDebug::getLogFile() {
|
||||
if (logFile) {
|
||||
return logFile.get();
|
||||
} else {
|
||||
logFile = std::make_unique<std::ofstream>();
|
||||
logFile->open(Tyra::FileUtils::fromCwd("log.txt"),
|
||||
std::ofstream::out | std::ofstream::app);
|
||||
return logFile.get();
|
||||
}
|
||||
|
||||
} // namespace Tyra
|
||||
+14
-7
@@ -12,13 +12,11 @@
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
Engine::Engine() {
|
||||
srand(time(nullptr));
|
||||
renderer.init();
|
||||
banner.show(&renderer);
|
||||
irx.loadDefaultDrivers();
|
||||
audio.init();
|
||||
pad.init();
|
||||
Engine::Engine() { initAll(false); }
|
||||
|
||||
Engine::Engine(const EngineOptions& options) {
|
||||
info.writeLogsToFile = options.writeLogsToFile;
|
||||
initAll(options.loadUsbDriver);
|
||||
}
|
||||
|
||||
Engine::~Engine() {}
|
||||
@@ -37,4 +35,13 @@ void Engine::realLoop() {
|
||||
info.update();
|
||||
}
|
||||
|
||||
void Engine::initAll(const bool& loadUsbDriver) {
|
||||
srand(time(nullptr));
|
||||
irx.loadAll(loadUsbDriver, info.writeLogsToFile);
|
||||
renderer.init();
|
||||
banner.show(&renderer);
|
||||
audio.init();
|
||||
pad.init();
|
||||
}
|
||||
|
||||
} // namespace Tyra
|
||||
|
||||
@@ -34,11 +34,11 @@ void FileUtils::setPathInfo(const char* path) {
|
||||
strcpy(this->elfPath, path);
|
||||
|
||||
ptr = strrchr(this->elfPath, '/');
|
||||
if (ptr == NULL) {
|
||||
if (ptr == nullptr) {
|
||||
ptr = strrchr(this->elfPath, '\\');
|
||||
if (ptr == NULL) {
|
||||
if (ptr == nullptr) {
|
||||
ptr = strrchr(this->elfPath, ':');
|
||||
if (ptr == NULL) {
|
||||
if (ptr == nullptr) {
|
||||
TYRA_TRAP("Did not find path! PATH: ", path);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-10
@@ -14,6 +14,8 @@
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
bool Info::writeLogsToFile = false;
|
||||
|
||||
Info::Info() {
|
||||
fps = 0;
|
||||
fpsDelayer = 0;
|
||||
@@ -48,21 +50,21 @@ void* Info::allocateLargestFreeRAMBlock(size_t* Size) {
|
||||
|
||||
s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);
|
||||
|
||||
while (s0 && (p = malloc(s0)) == NULL) s0 >>= 1;
|
||||
while (s0 && (p = malloc(s0)) == nullptr) s0 >>= 1;
|
||||
|
||||
if (p) free(p);
|
||||
|
||||
s1 = s0 >> 1;
|
||||
|
||||
while (s1) {
|
||||
if ((p = malloc(s0 + s1)) != NULL) {
|
||||
if ((p = malloc(s0 + s1)) != nullptr) {
|
||||
s0 += s1;
|
||||
free(p);
|
||||
}
|
||||
s1 >>= 1;
|
||||
}
|
||||
|
||||
while (s0 && (p = malloc(s0)) == NULL) s0 ^= s0 & -s0;
|
||||
while (s0 && (p = malloc(s0)) == nullptr) s0 ^= s0 & -s0;
|
||||
|
||||
*Size = s0;
|
||||
return p;
|
||||
@@ -70,30 +72,30 @@ void* Info::allocateLargestFreeRAMBlock(size_t* Size) {
|
||||
|
||||
size_t Info::getFreeRAMSize() {
|
||||
size_t total = 0;
|
||||
void* pFirst = NULL;
|
||||
void* pLast = NULL;
|
||||
void* pFirst = nullptr;
|
||||
void* pLast = nullptr;
|
||||
|
||||
for (;;) {
|
||||
size_t largest;
|
||||
void* p = allocateLargestFreeRAMBlock(&largest);
|
||||
|
||||
if (largest < sizeof(void*)) {
|
||||
if (p != NULL) free(p);
|
||||
if (p != nullptr) free(p);
|
||||
break;
|
||||
}
|
||||
|
||||
*(void**)p = NULL;
|
||||
*(void**)p = nullptr;
|
||||
|
||||
total += largest;
|
||||
|
||||
if (pFirst == NULL) pFirst = p;
|
||||
if (pFirst == nullptr) pFirst = p;
|
||||
|
||||
if (pLast != NULL) *(void**)pLast = p;
|
||||
if (pLast != nullptr) *(void**)pLast = p;
|
||||
|
||||
pLast = p;
|
||||
}
|
||||
|
||||
while (pFirst != NULL) {
|
||||
while (pFirst != nullptr) {
|
||||
void* p = *(void**)pFirst;
|
||||
free(pFirst);
|
||||
pFirst = p;
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
$PS2SDK/iop/irx/audsrv.irx
|
||||
audsrv_irx
|
||||
@@ -16,8 +16,23 @@
|
||||
#include <kernel.h>
|
||||
#include <sifrpc.h>
|
||||
#include <sbv_patches.h>
|
||||
#include <iopcontrol.h>
|
||||
#include "file/file_utils.hpp"
|
||||
|
||||
// external IRX modules
|
||||
|
||||
extern u8 sio2man_irx[];
|
||||
extern int size_sio2man_irx;
|
||||
|
||||
extern u8 padman_irx[];
|
||||
extern int size_padman_irx;
|
||||
|
||||
extern u8 audsrv_irx[];
|
||||
extern int size_audsrv_irx;
|
||||
|
||||
extern u8 libsd_irx[];
|
||||
extern int size_libsd_irx;
|
||||
|
||||
extern u8 bdm_irx[];
|
||||
extern int size_bdm_irx;
|
||||
|
||||
@@ -32,19 +47,41 @@ extern int size_usbmass_bd_irx;
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
bool IrxLoader::isLoaded = false;
|
||||
|
||||
IrxLoader::IrxLoader() {
|
||||
SifInitRpc(0);
|
||||
|
||||
while (!SifIopReset("", 0)) {
|
||||
};
|
||||
while (!SifIopSync()) {
|
||||
};
|
||||
|
||||
SifInitRpc(0);
|
||||
|
||||
this->applyRpcPatches();
|
||||
}
|
||||
|
||||
IrxLoader::~IrxLoader() {}
|
||||
|
||||
void IrxLoader::loadDefaultDrivers() {
|
||||
this->loadAudio();
|
||||
this->loadPad();
|
||||
}
|
||||
void IrxLoader::loadAll(const bool& withUsb, const bool& isLoggingToFile) {
|
||||
if (isLoaded) {
|
||||
TYRA_LOG("IRX modules already loaded!");
|
||||
return;
|
||||
}
|
||||
|
||||
void IrxLoader::loadUSBDriver() { this->loadUsb(); }
|
||||
loadSio2man(!isLoggingToFile);
|
||||
loadPadman(!isLoggingToFile);
|
||||
loadLibsd(!isLoggingToFile);
|
||||
|
||||
if (withUsb) {
|
||||
loadUsbModules(!isLoggingToFile);
|
||||
}
|
||||
|
||||
loadAudsrv(true);
|
||||
|
||||
isLoaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Apply the SBV LMB patch to allow modules to be loaded from a buffer in
|
||||
@@ -53,7 +90,6 @@ void IrxLoader::loadUSBDriver() { this->loadUsb(); }
|
||||
*/
|
||||
int IrxLoader::applyRpcPatches() {
|
||||
int ret;
|
||||
TYRA_LOG("Applying SBV Patches");
|
||||
|
||||
ret = sbv_patch_enable_lmb();
|
||||
TYRA_ASSERT(ret >= 0,
|
||||
@@ -67,65 +103,69 @@ int IrxLoader::applyRpcPatches() {
|
||||
ret = sbv_patch_fileio();
|
||||
TYRA_ASSERT(ret >= 0, "Failed to load Applying SBV Patches sbv_patch_fileio");
|
||||
|
||||
TYRA_LOG("SBV Patches applyed ");
|
||||
return ret;
|
||||
}
|
||||
|
||||
int IrxLoader::loadUsb() {
|
||||
void IrxLoader::loadLibsd(const bool& verbose) {
|
||||
if (verbose) TYRA_LOG("IRX: Loading libsd...");
|
||||
|
||||
int ret;
|
||||
TYRA_LOG("Loading USB modules");
|
||||
SifExecModuleBuffer(&libsd_irx, size_libsd_irx, 0, nullptr, &ret);
|
||||
TYRA_ASSERT(ret >= 0, "Failed to load module: libsd_irx");
|
||||
|
||||
// Load Block Device Manager (BDM)
|
||||
SifExecModuleBuffer(&bdm_irx, size_bdm_irx, 0, NULL, &ret);
|
||||
TYRA_ASSERT(ret >= 0, "Failed to load module: usbhdfsd");
|
||||
|
||||
// Load FATFS (mass:) driver
|
||||
SifExecModuleBuffer(&bdmfs_fatfs_irx, size_bdmfs_fatfs_irx, 0, NULL, &ret);
|
||||
TYRA_ASSERT(ret >= 0, "Failed to load module: usbd");
|
||||
|
||||
// Load USB Block Device drivers
|
||||
SifExecModuleBuffer(&usbd_irx, size_usbd_irx, 0, NULL, &ret);
|
||||
TYRA_ASSERT(ret >= 0, "Failed to load module: usbd");
|
||||
|
||||
SifExecModuleBuffer(&usbmass_bd_irx, size_usbmass_bd_irx, 0, NULL, &ret);
|
||||
TYRA_ASSERT(ret >= 0, "Failed to load module: usbhdfsd");
|
||||
|
||||
this->waitUntilUsbDeviceIsReady();
|
||||
|
||||
TYRA_LOG("USB/MASS modules loaded!");
|
||||
|
||||
return ret;
|
||||
if (verbose) TYRA_LOG("IRX: Libsd loaded!");
|
||||
}
|
||||
|
||||
int IrxLoader::loadAudio() {
|
||||
void IrxLoader::loadUsbModules(const bool& verbose) {
|
||||
if (verbose) TYRA_LOG("IRX: Loading usb modules...");
|
||||
|
||||
int ret;
|
||||
|
||||
TYRA_LOG("Modules loading started (LIBSD, AUDSRV)");
|
||||
ret = SifLoadModule("rom0:LIBSD", 0, NULL);
|
||||
TYRA_ASSERT(ret != -203, "LIBSD loading failed!");
|
||||
SifExecModuleBuffer(&usbd_irx, size_usbd_irx, 0, nullptr, &ret);
|
||||
TYRA_ASSERT(ret >= 0, "Failed to load module: usbd_irx");
|
||||
|
||||
ret = SifLoadModule("host:audsrv.irx", 0, NULL);
|
||||
TYRA_ASSERT(ret != -203, "audsrv.irx loading failed!");
|
||||
TYRA_LOG("Audio modules loaded");
|
||||
SifExecModuleBuffer(&bdm_irx, size_bdm_irx, 0, nullptr, &ret);
|
||||
TYRA_ASSERT(ret >= 0, "Failed to load module: bdm_irx");
|
||||
|
||||
return ret;
|
||||
SifExecModuleBuffer(&bdmfs_fatfs_irx, size_bdmfs_fatfs_irx, 0, nullptr, &ret);
|
||||
TYRA_ASSERT(ret >= 0, "Failed to load module: bdmfs_fatfs");
|
||||
|
||||
SifExecModuleBuffer(&usbmass_bd_irx, size_usbmass_bd_irx, 0, nullptr, &ret);
|
||||
TYRA_ASSERT(ret >= 0, "Failed to load module: usbmass");
|
||||
|
||||
waitUntilUsbDeviceIsReady();
|
||||
|
||||
if (verbose) TYRA_LOG("IRX: Usb modules loaded!");
|
||||
}
|
||||
|
||||
int IrxLoader::loadPad() {
|
||||
void IrxLoader::loadAudsrv(const bool& verbose) {
|
||||
if (verbose) TYRA_LOG("IRX: Loading audsrv...");
|
||||
|
||||
int ret;
|
||||
SifExecModuleBuffer(&audsrv_irx, size_audsrv_irx, 0, nullptr, &ret);
|
||||
TYRA_ASSERT(ret >= 0, "Failed to load module: audsrv_irx");
|
||||
|
||||
TYRA_LOG("PAD Modules loading started (SIO2MAN, PADMAN)");
|
||||
if (verbose) TYRA_LOG("IRX: Audsrv loaded!");
|
||||
}
|
||||
|
||||
ret = SifLoadModule("rom0:SIO2MAN", 0, NULL);
|
||||
TYRA_ASSERT(ret >= 0,
|
||||
"SifLoadModule (SIO2MAN) failed! Returned value: ", ret);
|
||||
void IrxLoader::loadSio2man(const bool& verbose) {
|
||||
if (verbose) TYRA_LOG("IRX: Loading sio2man...");
|
||||
|
||||
ret = SifLoadModule("rom0:PADMAN", 0, NULL);
|
||||
TYRA_ASSERT(ret >= 0, "SifLoadModule (PADMAN) failed! Returned value: ", ret);
|
||||
int ret;
|
||||
SifExecModuleBuffer(&sio2man_irx, size_sio2man_irx, 0, nullptr, &ret);
|
||||
TYRA_ASSERT(ret >= 0, "Failed to load module: sio2man_irx");
|
||||
|
||||
TYRA_LOG("Pad modules loaded!");
|
||||
if (verbose) TYRA_LOG("IRX: Sio2man loaded!");
|
||||
}
|
||||
|
||||
return ret;
|
||||
void IrxLoader::loadPadman(const bool& verbose) {
|
||||
if (verbose) TYRA_LOG("IRX: Loading padman...");
|
||||
|
||||
int ret;
|
||||
SifExecModuleBuffer(&padman_irx, size_padman_irx, 0, nullptr, &ret);
|
||||
TYRA_ASSERT(ret >= 0, "Failed to load module: padman_irx");
|
||||
|
||||
if (verbose) TYRA_LOG("IRX: Padman loaded!");
|
||||
}
|
||||
|
||||
void IrxLoader::delay(int count) {
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
$PS2SDK/iop/irx/libsd.irx
|
||||
libsd_irx
|
||||
@@ -0,0 +1,2 @@
|
||||
$PS2SDK/iop/irx/padman.irx
|
||||
padman_irx
|
||||
@@ -0,0 +1,2 @@
|
||||
$PS2SDK/iop/irx/sio2man.irx
|
||||
sio2man_irx
|
||||
@@ -95,7 +95,7 @@ MeshBuilderData* MD2Loader::load(const char* fullpath,
|
||||
auto filename = getFilenameFromPath(path);
|
||||
|
||||
FILE* file = fopen(fullpath, "rb");
|
||||
TYRA_ASSERT(file != NULL, "Failed to load: ", filename);
|
||||
TYRA_ASSERT(file != nullptr, "Failed to load: ", filename);
|
||||
md2_t header;
|
||||
|
||||
fread(reinterpret_cast<char*>(&header), sizeof(md2_t), 1, file);
|
||||
|
||||
@@ -55,7 +55,7 @@ void DynPipRenderer::init(RendererCore* t_core,
|
||||
rendererCore = t_core;
|
||||
programsRepo = t_programRepo;
|
||||
|
||||
dma_channel_initialize(DMA_CHANNEL_VIF1, NULL, 0);
|
||||
dma_channel_initialize(DMA_CHANNEL_VIF1, nullptr, 0);
|
||||
|
||||
setProgramsCache();
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ BlockizerProgramsManager::BlockizerProgramsManager() {
|
||||
context = 0;
|
||||
vu1BlockData = BlockNotUploaded;
|
||||
|
||||
dma_channel_initialize(DMA_CHANNEL_VIF1, NULL, 0);
|
||||
dma_channel_initialize(DMA_CHANNEL_VIF1, nullptr, 0);
|
||||
|
||||
setProgramsCache();
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// #define TYRA_RENDERER_VERBOSE_LOG 1
|
||||
|
||||
#ifdef TYRA_RENDERER_VERBOSE_LOG
|
||||
#define Verbose(...) Debug::writeLines("VRB: ", ##__VA_ARGS__, "\n")
|
||||
#define Verbose(...) TyraDebug::writeLines("VRB: ", ##__VA_ARGS__, "\n")
|
||||
#else
|
||||
#define Verbose(...) ((void)0)
|
||||
#endif
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
// #define TYRA_QBUFF_RENDERER_VERBOSE_LOG 1
|
||||
|
||||
#ifdef TYRA_QBUFF_RENDERER_VERBOSE_LOG
|
||||
#define Verbose(...) Debug::writeLines("VRB: ", ##__VA_ARGS__, "\n")
|
||||
#define Verbose(...) TyraDebug::writeLines("VRB: ", ##__VA_ARGS__, "\n")
|
||||
#else
|
||||
#define Verbose(...) ((void)0)
|
||||
#endif
|
||||
@@ -98,7 +98,7 @@ void StaPipQBufferRenderer::init(RendererCore* t_core, prim_t* t_prim,
|
||||
prim = t_prim;
|
||||
lod = t_lod;
|
||||
|
||||
dma_channel_initialize(DMA_CHANNEL_VIF1, NULL, 0);
|
||||
dma_channel_initialize(DMA_CHANNEL_VIF1, nullptr, 0);
|
||||
|
||||
setProgramsCache();
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ void RendererCoreGS::init(RendererSettings* t_settings) {
|
||||
}
|
||||
|
||||
void RendererCoreGS::initChannels() {
|
||||
dma_channel_initialize(DMA_CHANNEL_GIF, NULL, 0);
|
||||
dma_channel_initialize(DMA_CHANNEL_GIF, nullptr, 0);
|
||||
}
|
||||
|
||||
void RendererCoreGS::allocateBuffers() {
|
||||
|
||||
@@ -31,7 +31,7 @@ Path3::~Path3() {
|
||||
void Path3::init(RendererSettings* t_settings) {
|
||||
settings = t_settings;
|
||||
|
||||
dma_channel_initialize(DMA_CHANNEL_GIF, NULL, 0);
|
||||
dma_channel_initialize(DMA_CHANNEL_GIF, nullptr, 0);
|
||||
|
||||
TYRA_LOG("Path3 initialized");
|
||||
}
|
||||
|
||||
@@ -19,12 +19,27 @@ void Color::copy(Color* out, const float* in) {
|
||||
}
|
||||
|
||||
void Color::operator=(const Color& v) { copy(this, v); }
|
||||
|
||||
void Color::operator+=(const float& v) {
|
||||
r += v;
|
||||
g += v;
|
||||
b += v;
|
||||
a += v;
|
||||
}
|
||||
void Color::operator-=(const float& v) {
|
||||
r -= v;
|
||||
g -= v;
|
||||
b -= v;
|
||||
a -= v;
|
||||
}
|
||||
|
||||
void Color::operator*=(const float& v) {
|
||||
r *= v;
|
||||
g *= v;
|
||||
b *= v;
|
||||
a *= v;
|
||||
}
|
||||
|
||||
void Color::operator/=(const float& v) {
|
||||
r /= v;
|
||||
g /= v;
|
||||
|
||||
Reference in New Issue
Block a user