From b54c4ba83eb4bb53d07425bf1a5c13450dcea140 Mon Sep 17 00:00:00 2001 From: Ziemas Date: Fri, 26 Jan 2024 14:40:10 +0100 Subject: [PATCH] wip --- game/overlord/jak3/basefile.h | 4 +- game/overlord/jak3/basefilesystem.h | 7 +--- game/overlord/jak3/iso.cpp | 64 +++++++++++++++++++++++++++++ game/overlord/jak3/iso.h | 24 +++++++++++ game/overlord/jak3/iso_structs.h | 7 +--- game/overlord/jak3/overlord.h | 12 ++++-- game/overlord/jak3/pagemanager.h | 5 +-- game/overlord/jak3/ramdisk.cpp | 33 +++++++++++++++ game/overlord/jak3/ramdisk.h | 9 ++++ game/overlord/jak3/sbank.h | 5 +-- game/overlord/jak3/srpc.cpp | 54 ++++++++++++++++++++++++ game/overlord/jak3/srpc.h | 10 +++++ game/overlord/jak3/ssound.h | 39 ++++++++++++++++++ game/overlord/jak3/start.cpp | 52 +++++++++++++++++++++++ game/sce/iop.cpp | 6 +++ game/sce/iop.h | 1 + 16 files changed, 306 insertions(+), 26 deletions(-) create mode 100644 game/overlord/jak3/iso.cpp create mode 100644 game/overlord/jak3/iso.h create mode 100644 game/overlord/jak3/ramdisk.h create mode 100644 game/overlord/jak3/srpc.cpp create mode 100644 game/overlord/jak3/srpc.h create mode 100644 game/overlord/jak3/ssound.h diff --git a/game/overlord/jak3/basefile.h b/game/overlord/jak3/basefile.h index 6d6a2fe6c34..da71cfaa4eb 100644 --- a/game/overlord/jak3/basefile.h +++ b/game/overlord/jak3/basefile.h @@ -1,5 +1,4 @@ -#ifndef BASEFILE_H_ -#define BASEFILE_H_ +#pragma once #include "game/overlord/jak3/iso_structs.h" #include "game/overlord/jak3/overlord.h" @@ -18,4 +17,3 @@ class CBaseFile { }; } // namespace jak3 -#endif // BASEFILE_H_ diff --git a/game/overlord/jak3/basefilesystem.h b/game/overlord/jak3/basefilesystem.h index 2803428231f..18100f66e08 100644 --- a/game/overlord/jak3/basefilesystem.h +++ b/game/overlord/jak3/basefilesystem.h @@ -1,12 +1,11 @@ -#ifndef BASEFILESYSTEM_H_ -#define BASEFILESYSTEM_H_ +#pragma once #include "game/overlord/jak3/iso_structs.h" namespace jak3 { class CBaseFileSystem { public: - virtual void Init() = 0; + virtual int Init() = 0; virtual void PollDrive() = 0; virtual const ISOFileDef* Find(const char* name) = 0; virtual const ISOFileDef* FindIN(const char* name) = 0; @@ -16,5 +15,3 @@ class CBaseFileSystem { virtual VagDirEntryJak3* FindVagFile(const char* name) = 0; }; } // namespace jak3 - -#endif // BASEFILESYSTEM_H_ diff --git a/game/overlord/jak3/iso.cpp b/game/overlord/jak3/iso.cpp new file mode 100644 index 00000000000..ab9790d1f09 --- /dev/null +++ b/game/overlord/jak3/iso.cpp @@ -0,0 +1,64 @@ +#include "iso.h" + +#include + +#include "game/overlord/jak3/basefilesystem.h" + +namespace jak3 { +using namespace iop; + +static int s_nISOInitFlag; +static ISO_LoadDGO s_LoadDGO; +int s_nSyncMbx; +CBaseFileSystem* g_pFileSystem; +MsgPacket s_MsgPacket_NotOnStackSync[2]; + +/* COMPLETE */ +void InitDriver() { + if (g_pFileSystem->Init() == 0) { + s_nISOInitFlag = 0; + } + + SendMbx(s_nSyncMbx, &s_MsgPacket_NotOnStackSync[0]); +} + +/* TODO unfinished */ +static int LookMbx() { + MsgPacket* pkt; + + int ret = PollMbx(&pkt, s_nSyncMbx); + if (ret != KE_MBOX_NOMSG) { + // FIXME + } + + return ret != KE_MBOX_NOMSG; +} + +/* COMPLETE */ +static void WaitMbx(int mbx) { + MsgPacket* pkt; + ReceiveMbx(&pkt, mbx); +} + +/* TODO unfinished */ +int InitISOFS(const char* fs_mode, const char* loading_sceeen) { + ThreadParam thp; + MbxParam mbx; + + memset(&s_LoadDGO, 0, sizeof(s_LoadDGO)); + s_nISOInitFlag = 1; + + return s_nISOInitFlag; +} + +/* COMPLETE */ +const ISOFileDef* FindISOFile(char* name) { + return g_pFileSystem->Find(name); +} + +/* COMPLETE */ +s32 GetISOFileLength(const ISOFileDef* fd) { + return g_pFileSystem->GetLength(fd); +} + +} // namespace jak3 diff --git a/game/overlord/jak3/iso.h b/game/overlord/jak3/iso.h new file mode 100644 index 00000000000..7ce81b4d004 --- /dev/null +++ b/game/overlord/jak3/iso.h @@ -0,0 +1,24 @@ +#pragma once + +#include "game/sce/iop.h" + +namespace jak3 { + +struct ISOBuffer { + void AdjustDataLength(int); + void AdvanceCurrentData(int); +}; + +struct ISO_Hdr { + iop::MsgPacket msg; + + void SetActive(); + void SetUnk1(); + void SetUnk2(); +}; + +struct ISO_Msg : ISO_Hdr {}; + +struct ISO_LoadDGO : ISO_Msg {}; + +} // namespace jak3 diff --git a/game/overlord/jak3/iso_structs.h b/game/overlord/jak3/iso_structs.h index 7af569aa763..8e3b997c286 100644 --- a/game/overlord/jak3/iso_structs.h +++ b/game/overlord/jak3/iso_structs.h @@ -1,5 +1,4 @@ -#ifndef ISO_STRUCTS_H_ -#define ISO_STRUCTS_H_ +#pragma once #include "common/common_types.h" @@ -29,9 +28,5 @@ struct VagDirJak3 { struct VagDirEntry {}; -struct ISOBuffer {}; - struct ISOFileDef {}; } // namespace jak3 - -#endif // ISO_STRUCTS_H_ diff --git a/game/overlord/jak3/overlord.h b/game/overlord/jak3/overlord.h index 8fae9fe51f2..15261e4a636 100644 --- a/game/overlord/jak3/overlord.h +++ b/game/overlord/jak3/overlord.h @@ -1,9 +1,15 @@ -#ifndef OVERLORD_H_ -#define OVERLORD_H_ +#pragma once #include +#include "common/common_types.h" + namespace jak3 { + +struct Vec3 { + s32 x, y, z; +}; + enum class EIsoStatus { Unk }; int start_overlord_wrapper(int argc, const char* const* argv, bool* signal); @@ -14,5 +20,3 @@ void InitSound(); int VBlank_Initialize(); } // namespace jak3 - -#endif diff --git a/game/overlord/jak3/pagemanager.h b/game/overlord/jak3/pagemanager.h index 6c5e5283d1b..8ac7cc5a2df 100644 --- a/game/overlord/jak3/pagemanager.h +++ b/game/overlord/jak3/pagemanager.h @@ -1,5 +1,4 @@ -#ifndef PAGEMANAGER_H_ -#define PAGEMANAGER_H_ +#pragma once #include "common/common_types.h" @@ -40,5 +39,3 @@ class CPageManager { }; } // namespace jak3 - -#endif // PAGEMANAGER_H_ diff --git a/game/overlord/jak3/ramdisk.cpp b/game/overlord/jak3/ramdisk.cpp index e69de29bb2d..43a960253e9 100644 --- a/game/overlord/jak3/ramdisk.cpp +++ b/game/overlord/jak3/ramdisk.cpp @@ -0,0 +1,33 @@ +#include "ramdisk.h" + +#include "common/log/log.h" + +#include "game/sce/iop.h" + +namespace jak3 { +using namespace iop; + +static u8 gRamDisk_RPCBUF[40]; + +static void* RPC_Ramdisk(u32 fno, void* data, int size) { + lg::error("RPC_RAMDISK UNIMPLEMENTED"); + return nullptr; +} + +void InitRamdisk() {} + +u32 Thread_Server() { + sceSifQueueData dq; + sceSifServeData serve; + + CpuDisableIntr(); + sceSifInitRpc(0); + sceSifSetRpcQueue(&dq, GetThreadId()); + sceSifRegisterRpc(&serve, 0xfab2, RPC_Ramdisk, gRamDisk_RPCBUF, nullptr, nullptr, &dq); + CpuEnableIntr(); + sceSifRpcLoop(&dq); + + return 0; +} + +} // namespace jak3 diff --git a/game/overlord/jak3/ramdisk.h b/game/overlord/jak3/ramdisk.h new file mode 100644 index 00000000000..f081874264e --- /dev/null +++ b/game/overlord/jak3/ramdisk.h @@ -0,0 +1,9 @@ +#pragma once + +#include "common/common_types.h" + +namespace jak3 { + +u32 Thread_Server(); + +} diff --git a/game/overlord/jak3/sbank.h b/game/overlord/jak3/sbank.h index 310f890ef34..69a41942380 100644 --- a/game/overlord/jak3/sbank.h +++ b/game/overlord/jak3/sbank.h @@ -1,5 +1,4 @@ -#ifndef SBANK_H_ -#define SBANK_H_ +#pragma once #include "common/common_types.h" @@ -18,5 +17,3 @@ struct SoundBankInfo { }; void InitBanks(); } // namespace jak3 - -#endif // SBANK_H_ diff --git a/game/overlord/jak3/srpc.cpp b/game/overlord/jak3/srpc.cpp new file mode 100644 index 00000000000..caf82f752ba --- /dev/null +++ b/game/overlord/jak3/srpc.cpp @@ -0,0 +1,54 @@ +#include "srpc.h" + +#include "common/log/log.h" + +#include "game/sce/iop.h" + +namespace jak3 { +using namespace iop; + +constexpr int SRPC_MESSAGE_SIZE = 0x50; +constexpr int SRPC_MESSAGE_COUNT = 128; + +static u8 s_anSRPC_PlayerBuf[SRPC_MESSAGE_SIZE * SRPC_MESSAGE_COUNT]; +static u8 s_anSRPC_LoaderBuf[SRPC_MESSAGE_SIZE]; + +static void* RPC_Player(u32 fno, void* data, int size) { + lg::error("RPC_PLAYER UNIMPLEMENTED"); + return nullptr; +} + +static void* RPC_Loader(u32 fno, void* data, int size) { + lg::error("RPC_LOADER UNIMPLEMENTED"); + return nullptr; +} + +u32 Thread_Player() { + sceSifQueueData dq; + sceSifServeData serve; + + CpuDisableIntr(); + sceSifInitRpc(0); + sceSifSetRpcQueue(&dq, GetThreadId()); + sceSifRegisterRpc(&serve, 0xfab0, RPC_Player, s_anSRPC_PlayerBuf, nullptr, nullptr, &dq); + CpuEnableIntr(); + sceSifRpcLoop(&dq); + + return 0; +} + +u32 Thread_Loader() { + sceSifQueueData dq; + sceSifServeData serve; + + CpuDisableIntr(); + sceSifInitRpc(0); + sceSifSetRpcQueue(&dq, GetThreadId()); + sceSifRegisterRpc(&serve, 0xfab1, RPC_Loader, s_anSRPC_LoaderBuf, nullptr, nullptr, &dq); + CpuEnableIntr(); + sceSifRpcLoop(&dq); + + return 0; +} + +} // namespace jak3 diff --git a/game/overlord/jak3/srpc.h b/game/overlord/jak3/srpc.h new file mode 100644 index 00000000000..03f20fa86f5 --- /dev/null +++ b/game/overlord/jak3/srpc.h @@ -0,0 +1,10 @@ +#pragma once + +#include "common/common_types.h" + +namespace jak3 { + +u32 Thread_Player(); +u32 Thread_Loader(); + +} diff --git a/game/overlord/jak3/ssound.h b/game/overlord/jak3/ssound.h new file mode 100644 index 00000000000..0fc21dad01b --- /dev/null +++ b/game/overlord/jak3/ssound.h @@ -0,0 +1,39 @@ +#pragma once + +#include "common/common_types.h" + +#include "game/overlord/jak3/overlord.h" + +namespace jak3 { + +struct Curve { + s32 p1; + s32 p2; + s32 p3; + s32 p4; +}; + +struct SoundPlayParams { + u16 mask; + s16 pitch_mod; + s16 bend; + s16 fo_min; + s16 fo_max; + s8 fo_curve; + s8 priority; + s32 volume; + Vec3 trans; + u8 group; + u8 reg[3]; +}; + +struct SoundInfo { + char name[16]; + s32 id; + u32 sound_handle; + s32 auto_volume; + s32 auto_time; + SoundPlayParams params; +}; + +} // namespace jak3 diff --git a/game/overlord/jak3/start.cpp b/game/overlord/jak3/start.cpp index f53da86a3e8..4b1695b6d2b 100644 --- a/game/overlord/jak3/start.cpp +++ b/game/overlord/jak3/start.cpp @@ -2,13 +2,19 @@ #include #include "overlord.h" +#include "ramdisk.h" #include "sbank.h" +#include "game/overlord/jak3/srpc.h" #include "game/sce/iop.h" namespace jak3 { using namespace iop; +int g_nServerThreadID; +int g_nPlayerThreadID; +int g_nLoaderThreadID; + int start_overlord(int argc, const char* const* argp) { ThreadParam thp; @@ -31,6 +37,52 @@ int start_overlord(int argc, const char* const* argp) { InitSound(); VBlank_Initialize(); + thp.attr = TH_C; + thp.option = 0; + thp.entry = Thread_Server; + thp.stackSize = 0x800; + thp.initPriority = 59; + g_nServerThreadID = CreateThread(&thp); + if (g_nServerThreadID < 0) { + Panic(); + return 1; + } + + thp.attr = TH_C; + thp.option = 0; + thp.entry = Thread_Player; + thp.stackSize = 0xb00; + thp.initPriority = 54; + g_nPlayerThreadID = CreateThread(&thp); + if (g_nPlayerThreadID < 0) { + Panic(); + return 1; + } + + thp.attr = TH_C; + thp.option = 0; + thp.entry = Thread_Loader; + thp.stackSize = 0x900; + thp.initPriority = 58; + g_nLoaderThreadID = CreateThread(&thp); + if (g_nPlayerThreadID < 0) { + Panic(); + return 1; + } + + //CDvdDriver::Initialize(&g_DvdDriver); + InitISOFS(argp[1], argp[2]); + + StartThread(g_nServerThreadID, 0); + StartThread(g_nPlayerThreadID, 0); + StartThread(g_nLoaderThreadID, 0); + + printf("======== overlrd2.irx post-startup ========\n"); + // printf(" mem size: %lu\n", QueryMemSize()); + // printf("total mem free: %lu\n", QueryTotalFreeMemSize()); + // printf(" max mem free: %lu\n", QueryMaxFreeMemSize()); + // printf(" used: %lu\n", QueryMemSize() - QueryTotalFreeMemSize()); + return 0; } diff --git a/game/sce/iop.cpp b/game/sce/iop.cpp index fff38a8f145..15a5f94d279 100644 --- a/game/sce/iop.cpp +++ b/game/sce/iop.cpp @@ -193,6 +193,12 @@ s32 SendMbx(s32 mbxid, void* sendmsg) { return iop->kernel.SendMbx(mbxid, sendmsg); } +s32 ReceiveMbx(MsgPacket** recvmsg, int mbxid) { + ASSERT(false); + // TODO + return 0; +} + s32 PollMbx(MsgPacket** recvmsg, int mbxid) { return iop->kernel.PollMbx((void**)recvmsg, mbxid); } diff --git a/game/sce/iop.h b/game/sce/iop.h index 165e8f70744..b7426765665 100644 --- a/game/sce/iop.h +++ b/game/sce/iop.h @@ -131,6 +131,7 @@ int sceCdDiskReady(int mode); u32 sceSifSetDma(sceSifDmaData* sdd, int len); s32 SendMbx(int mbxid, void* sendmsg); +s32 ReceiveMbx(MsgPacket** recvmsg, int mbxid); s32 PollMbx(MsgPacket** recvmsg, int mbxid); s32 PeekMbx(s32 mbx); s32 CreateMbx(MbxParam* param);