From f03558ef4827d41aba48c629d42b03172f8e5248 Mon Sep 17 00:00:00 2001 From: gijs Date: Sat, 21 Oct 2023 17:33:47 +0200 Subject: [PATCH] Rename a couple files and split them into their own Rename `_ob_icy_coast.c` to `nusimgr.c` Add decompiled `nuPiInit` to `nupiinit.c` Add decompiled `nuPiReadRom` to `nupireadrom.c` --- splat.yaml | 4 +- src/_ob_icy_coast.c | 88 -------------------------------------------- src/nu/nupiinit.c | 8 ++++ src/nu/nupireadrom.c | 37 +++++++++++++++++++ src/nu/nusimgr.c | 48 ++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 89 deletions(-) delete mode 100644 src/_ob_icy_coast.c create mode 100644 src/nu/nupiinit.c create mode 100644 src/nu/nupireadrom.c create mode 100644 src/nu/nusimgr.c diff --git a/splat.yaml b/splat.yaml index 36e6973..d9070d7 100644 --- a/splat.yaml +++ b/splat.yaml @@ -121,7 +121,9 @@ segments: - [0x19EB0, c, "nu/nugfxsetcfb"] - [0x19FC0, c, "nu/nugfxdisplayoff"] - [0x1A050, c, "nu/nugfxdisplayon"] - - [0x1A060, c, "_ob_icy_coast"] + - [0x1A060, c, "nu/nusimgr"] + - [0x1A340, c, "nu/nupiinit"] + - [0x1A380, c, "nu/nupireadrom"] - [0x1A4F0, c, "rom_copy"] - [0x1A5B0, c, "nu/nugfxinit"] - [0x1A660, c, "_ob_prized_reading"] diff --git a/src/_ob_icy_coast.c b/src/_ob_icy_coast.c deleted file mode 100644 index 7a8d57c..0000000 --- a/src/_ob_icy_coast.c +++ /dev/null @@ -1,88 +0,0 @@ -#include "common.h" - -#include "nu/nusys.h" -#include "os_pi.h" - -void nuSiMgrThread(void* arg); - -/* 1A060 80089C60 */ -u8 nuSiMgrInit(void) { - u8 pattern; - OSContStatus status[NU_CONT_MAXCONTROLLERS]; - - osCreateMesgQueue(&nuSiMesgQ, nuSiMesgBuf, NU_SC_MAX_MESGS); - osSetEventMesg(OS_EVENT_SI, &nuSiMesgQ, NULL); - - osContInit(&nuSiMesgQ, &pattern, status); - - osCreateThread(&siMgrThread, 5, nuSiMgrThread, NULL, &nuPiMgrMesgQ, NU_SI_THREAD_PRI); - osStartThread(&siMgrThread); - - return pattern; -} - -s32 nuSiSendMesg(NUScMsg mesg, void* dataPtr) { - OSMesgQueue rtnMesgQ; - NUSiCommonMesg siCommonMesg; - OSMesg sp38; // maybe this is part of the struct? - - siCommonMesg.mesg = mesg; - siCommonMesg.dataPtr = dataPtr; - siCommonMesg.rtnMesgQ = &rtnMesgQ; - - osCreateMesgQueue(&rtnMesgQ, &sp38, 1); - osSendMesg(&MQ_800E7988, &siCommonMesg, OS_MESG_BLOCK); - osRecvMesg(&rtnMesgQ, NULL, OS_MESG_BLOCK); - - return siCommonMesg.error; -} - -void nuSiMgrStop(void) { - nuSiSendMesg(NU_SI_STOP_MGR_MSG, NULL); -} - -void nuSiMgrRestart(void) { - osStartThread(&siMgrThread); -} - -INCLUDE_ASM(const s32, "_ob_icy_coast", nuSiMgrThread); - -void nuPiInit(void) { - osCreatePiManager(OS_PRIORITY_PIMGR, &nuPiMgrMesgQ, nuPiMesgBuf, NU_PI_MESG_NUM); - nuPiCartHandle = osCartRomInit(); -} - -/* 1A380 80089F80 */ -void nuPiReadRom(void *src, void *dst, u32 size) { - OSIoMesg ioMesg; - OSMesg mesg; - OSMesgQueue queue; - u32 mesgSize; - - osCreateMesgQueue(&queue, &mesg, 1); - - ioMesg.hdr.pri = 0; - ioMesg.hdr.retQueue = &queue; - osInvalDCache(dst, size); - while (size != 0) { - mesgSize = size; - if (mesgSize > MAX_BYTES_TO_READ) { - mesgSize = MAX_BYTES_TO_READ; - } - - ioMesg.devAddr = (u32)src; - ioMesg.dramAddr = dst; - ioMesg.size = mesgSize; - // Start the DMA transfer - osEPiStartDma(nuPiCartHandle, &ioMesg, OS_READ); - // Wait for the DMA transfer to complete - osRecvMesg(&queue, &mesg, OS_MESG_BLOCK); - - src += mesgSize; - dst += mesgSize; - size -= mesgSize; - } -} - - -INCLUDE_ASM(const s32, "_ob_icy_coast", func_8008A040); diff --git a/src/nu/nupiinit.c b/src/nu/nupiinit.c new file mode 100644 index 0000000..0e0ac0b --- /dev/null +++ b/src/nu/nupiinit.c @@ -0,0 +1,8 @@ +#include "common.h" + +#include "nu/nusys.h" + +void nuPiInit(void) { + osCreatePiManager(OS_PRIORITY_PIMGR, &nuPiMgrMesgQ, nuPiMesgBuf, NU_PI_MESG_NUM); + nuPiCartHandle = osCartRomInit(); +} \ No newline at end of file diff --git a/src/nu/nupireadrom.c b/src/nu/nupireadrom.c new file mode 100644 index 0000000..03a86af --- /dev/null +++ b/src/nu/nupireadrom.c @@ -0,0 +1,37 @@ +#include "common.h" + +#include "nu/nusys.h" + +/* 1A380 80089F80 */ +void nuPiReadRom(void *src, void *dst, u32 size) { + OSIoMesg ioMesg; + OSMesg mesg; + OSMesgQueue queue; + u32 mesgSize; + + osCreateMesgQueue(&queue, &mesg, 1); + + ioMesg.hdr.pri = 0; + ioMesg.hdr.retQueue = &queue; + osInvalDCache(dst, size); + while (size != 0) { + mesgSize = size; + if (mesgSize > MAX_BYTES_TO_READ) { + mesgSize = MAX_BYTES_TO_READ; + } + + ioMesg.devAddr = (u32)src; + ioMesg.dramAddr = dst; + ioMesg.size = mesgSize; + // Start the DMA transfer + osEPiStartDma(nuPiCartHandle, &ioMesg, OS_READ); + // Wait for the DMA transfer to complete + osRecvMesg(&queue, &mesg, OS_MESG_BLOCK); + + src += mesgSize; + dst += mesgSize; + size -= mesgSize; + } +} + +INCLUDE_ASM(const s32, "nu/nupireadrom", func_8008A040); diff --git a/src/nu/nusimgr.c b/src/nu/nusimgr.c new file mode 100644 index 0000000..8d0391d --- /dev/null +++ b/src/nu/nusimgr.c @@ -0,0 +1,48 @@ +#include "common.h" + +#include "nu/nusys.h" +#include "os_pi.h" + +void nuSiMgrThread(void* arg); + +/* 1A060 80089C60 */ +u8 nuSiMgrInit(void) { + u8 pattern; + OSContStatus status[NU_CONT_MAXCONTROLLERS]; + + osCreateMesgQueue(&nuSiMesgQ, nuSiMesgBuf, NU_SC_MAX_MESGS); + osSetEventMesg(OS_EVENT_SI, &nuSiMesgQ, NULL); + + osContInit(&nuSiMesgQ, &pattern, status); + + osCreateThread(&siMgrThread, 5, nuSiMgrThread, NULL, &nuPiMgrMesgQ, NU_SI_THREAD_PRI); + osStartThread(&siMgrThread); + + return pattern; +} + +s32 nuSiSendMesg(NUScMsg mesg, void* dataPtr) { + OSMesgQueue rtnMesgQ; + NUSiCommonMesg siCommonMesg; + OSMesg sp38; + + siCommonMesg.mesg = mesg; + siCommonMesg.dataPtr = dataPtr; + siCommonMesg.rtnMesgQ = &rtnMesgQ; + + osCreateMesgQueue(&rtnMesgQ, &sp38, 1); + osSendMesg(&MQ_800E7988, &siCommonMesg, OS_MESG_BLOCK); + osRecvMesg(&rtnMesgQ, NULL, OS_MESG_BLOCK); + + return siCommonMesg.error; +} + +void nuSiMgrStop(void) { + nuSiSendMesg(NU_SI_STOP_MGR_MSG, NULL); +} + +void nuSiMgrRestart(void) { + osStartThread(&siMgrThread); +} + +INCLUDE_ASM(const s32, "nu/nusimgr", nuSiMgrThread); \ No newline at end of file