Files
jak-project/game/overlord/jakx/overlord.cpp
T
Tyler Wilding d3cc739e43 jakx: Commit existing work from other PRs (#4112)
This attempts to get into master whatever work was done in this PR /
it's earlier PR https://github.com/open-goal/jak-project/pull/3965

I don't want this work to be lost / floating around in massive PRs.

However the changes are:
- switch to ntsc_v1 instead of PAL as the development target, as we have
done for all other games
- remove most of the copied-from-jak2/3 changes as they need to be
confirmed during the decompilation process not just assumed
- avoids committing any changes to `game/kernel/common` as it was not
clear to me if these were changes made in jak x's kernel that were not
properly broken out into it's own functions. We don't want to
accidentally introduce bugs into jak1-3's kernel code.
- in other words, if the change in the kernel only happens in jak x...it
should likely be specific to jak x's kernel, not common.

---------

Co-authored-by: VodBox <dillon@vodbox.io>
Co-authored-by: yodah <greenboyyodah@gmail.com>
2025-12-31 21:08:44 -05:00

151 lines
3.9 KiB
C++

#include "overlord.h"
#include "common/log/log.h"
#include "game/overlord/jakx/dvd_driver.h"
#include "game/overlord/jakx/init.h"
#include "game/overlord/jakx/iso.h"
#include "game/overlord/jakx/ramdisk.h"
#include "game/overlord/jakx/sbank.h"
#include "game/overlord/jakx/srpc.h"
#include "game/overlord/jakx/ssound.h"
#include "game/overlord/jakx/vblank_handler.h"
#include "game/sce/iop.h"
namespace jakx {
using namespace iop;
int g_nServerThreadID = 0;
int g_nPlayerThreadID = 0;
int g_nLoaderThreadID = 0;
void jakx_overlord_init_globals_overlord() {
g_nServerThreadID = 0;
g_nPlayerThreadID = 0;
g_nLoaderThreadID = 0;
}
namespace {
/*!
* Start up overlord threads. After this returns, the overlord is initialized and
* ready to run. (this might have been in start.cpp in the original, but this is close enough)
*/
int start_overlord() {
// Initialize SIF to communicate with the EE. Does nothing in port
if (!sceSifCheckInit()) {
sceSifInit();
}
// Initialize RPC to EE
sceSifInitRpc(0);
lg::info("======== overlrd2.irx startup ========");
// Removed some prints related to IOP memory size
// C++ ctors ran here. In the port, we've added these "init_globals" function that
// take care of resetting all the global/static variables and constructing C++ objects.
// do_global_ctors();
jakx_overlord_init_globals_all();
InitBanks();
InitSound();
VBlank_Initialize();
// RPC thread to load data from game files to the game memory.
ThreadParam thread_param;
thread_param.initPriority = 0x3b;
thread_param.stackSize = 0x800;
thread_param.entry = LoadToEE_RPC_Thread;
thread_param.attr = TH_C;
thread_param.option = 0;
strcpy(thread_param.name, "load_to_ee");
g_nServerThreadID = CreateThread(&thread_param);
if (g_nServerThreadID <= 0) {
return 1;
}
// thread to respond to sound play RPC's
thread_param.entry = Thread_Player;
thread_param.initPriority = 0x36;
thread_param.stackSize = 0xb00;
thread_param.attr = TH_C;
thread_param.option = 0;
strcpy(thread_param.name, "player");
g_nPlayerThreadID = CreateThread(&thread_param);
if (g_nPlayerThreadID <= 0) {
return 1;
}
// thread to respond to sound load RPC's
thread_param.attr = TH_C;
thread_param.entry = Thread_Loader;
thread_param.initPriority = 0x3a;
thread_param.stackSize = 0x900;
thread_param.option = 0;
strcpy(thread_param.name, "loader");
g_nLoaderThreadID = CreateThread(&thread_param);
if (g_nLoaderThreadID <= 0) {
return 1;
}
// Initialize the dvd driver that will be used to implement the "ISO FS" system
get_driver()->Initialize();
// then, initialize ISO FS itself
InitISOFS();
// start up RPC threads!
StartThread(g_nServerThreadID, 0);
StartThread(g_nPlayerThreadID, 0);
StartThread(g_nLoaderThreadID, 0);
lg::info("[overlord2] Threads started");
return 0;
}
bool* init_complete;
/*!
* Wrapper of start_overlord that can be run as an IOP thread. Sets init_complete flag to true.
* This is a bit of hack to transition from the normal and sane game code to the world of IOP
* threading.
*/
u32 call_start() {
start_overlord();
*init_complete = true;
// TODO: figure out how to quit this thread.
while (true) {
SleepThread();
}
return 0;
}
} // namespace
int start_overlord_wrapper(bool* signal) {
ThreadParam param = {};
init_complete = signal;
param.attr = TH_C;
param.initPriority = 0;
param.stackSize = 0x800;
param.option = 0;
strcpy(param.name, "start"); // added for debug
param.entry = call_start;
auto start_thread = CreateThread(&param);
StartThread(start_thread, 0);
return 0;
}
/*!
* Copy null-terminated string to destination buffer with the given size.
* If the string doesn't fit, it will be truncated and null terminated.
*/
char* strncpyz(char* dst, const char* src, size_t n) {
if (n) {
strncpy(dst, src, n);
dst[n - 1] = 0;
}
return dst;
}
} // namespace jakx