Compare commits

..

17 Commits

Author SHA1 Message Date
gijs f03558ef48 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`
2023-10-21 17:33:47 +02:00
gijs a5a10f03cd Rename `_ob_grumpy_island.c` to `nugfxthread.c` and move it to `nu` folder 2023-10-21 17:25:30 +02:00
gijs 6499c2fe8f Rename `__start_copy_global_controller_data` to `nuContDataClose` and `__end_copy_global_controller_data` to `nuContDataOpen` 2023-10-20 21:20:36 +02:00
gijs 92fd0c2213 Rename `func_8008B1D0` to `nuSiCallBackRemove` 2023-10-20 21:17:55 +02:00
gijs 1fa7c6930f Rename `func_8008A334` to `nuContMgrRemove` 2023-10-20 21:15:53 +02:00
gijs 6290ea1045 Clean up `nuContMgrInit` 2023-10-20 19:53:46 +02:00
gijs 5ce4b39095 Rename `obStackMain` to `nuContNum` 2023-10-20 19:53:24 +02:00
gijs 84c9518b4c Rename `__GLOBAL_CONT_STATUS` to `nuContStatus` 2023-10-20 19:49:28 +02:00
gijs 118c79854c Rename `D_800A9FF8` to `nuContCallBack` 2023-10-20 19:47:12 +02:00
gijs c1974f2e83 Rename `OSMESG_800BE194` to `nuContDataMutexBuf` 2023-10-20 19:43:59 +02:00
gijs 7bd8d54843 Rename `MQ_800E9BF0` to `nuContDataMutexQ` 2023-10-20 19:42:55 +02:00
gijs d1d3e1eb1c Rename `OSMESG_800BE190` to `nuContWaitMesgBuf` 2023-10-20 19:41:59 +02:00
gijs 2a951738a0 Rename `MQ_800C4A00` to `nuContWaitMesgQ` 2023-10-20 19:41:07 +02:00
gijs bc821ded12 Rename `func_8008B130` to `nuSiCallBackAdd` 2023-10-20 19:39:45 +02:00
gijs 9fcec8adfd Rename `func_8008A5D0` to `nuContDataUnLock` 2023-10-20 19:37:39 +02:00
gijs 7ff45c1495 Rename `func_8008A260` to `nuContMgrInit` 2023-10-20 19:36:46 +02:00
gijs eb3f05151b Rename `func_8008A640` to `nuContQueryRead` 2023-10-20 19:35:44 +02:00
15 changed files with 160 additions and 163 deletions

View File

@ -137,12 +137,8 @@ extern OSPiHandle* CART_HANDLE;
extern OSMesgQueue MQ_800E7988;
extern s32 D_800C4B30;
extern OSMesgQueue MQ_800E9BF0;
extern u8 D_800A9FF8;
extern OSContStatus __GLOBAL_CONT_STATUS[MAXCONTROLLERS];
extern void (*D_800A9FE0)(s16);
extern OSMesgQueue MQ_800C4A00;
extern OSContPad __GLOBAL_CONTROLLER_DATA[MAXCONTROLLERS];
extern OSContPad __GLOBAL_CONTROLLER_DATA_COPY[MAXCONTROLLERS];
@ -167,9 +163,6 @@ extern void __calls_osViBlack(bool black);
extern void __osViSwapBuffer_3(void** buffers);
extern void __start_copy_global_controller_data(void);
extern void __end_copy_global_controller_data(void);
extern s32 __read_controller(OSContPad* data, u32 flags);
extern s32 __real_read_controller(void);
extern s32 __calls_read_controller_0(s16* arg0);
@ -177,11 +170,7 @@ extern s32 __calls_read_controller_0(s16* arg0);
extern void func_8008A354();
extern void func_8008A37C();
extern void func_8008B130(u8*);
extern void func_8008B1D0(u8*);
extern void func_8008350C();
extern void func_8008B1D0(u8*);
extern void __set_vi_mode(s32);

View File

@ -687,6 +687,9 @@ extern OSContPad nuContData[];
extern u32 nuContNum; /* Number of controllers connected */
extern u32 nuContDataLockKey; /* Lock Controller data. */
extern OSMesgQueue nuContWaitMesgQ; /* Wait for Controller read */
extern OSMesg nuContWaitMesgBuf;
extern OSMesgQueue nuContDataMutexQ;
extern OSMesg nuContDataMutexBuf;
extern OSPfs nuContPfs[];
extern NUCallBackList nuContCallBack;
extern u16 nuContPakCompanyCode; /* Company code */

View File

@ -31,6 +31,13 @@ nuStackIdle = 0x800B17A0;
nuPiCartHandle = 0x800E7A20;
nuPiMgrMesgQ = 0x800BE030;
nuPiMesgBuf = 0x800BE048;
nuContWaitMesgQ = 0x800C4A00;
nuContWaitMesgBuf = 0x800BE190;
nuContDataMutexQ = 0x800E9BF0;
nuContDataMutexBuf = 0x800BE194;
nuContCallBack = 0x800A9FF8;
nuContStatus = 0x800C4B38; // size:0x10 type:u32
nuContNum = 0x800C6D60;
nuBoot = 0x8007F880;
nuScCreateScheduler = 0x80088C50; // rom:0x19050
@ -68,6 +75,14 @@ nuSiMgrStop = 0x80089D5C;
nuSiMgrRestart = 0x80089D7C;
nuIdle = 0x8007F8E4;
nuPiReadRom = 0x80089F80;
nuContQueryRead = 0x8008A640;
nuContMgrInit = 0x8008A260;
nuContDataUnLock = 0x8008A5D0;
nuSiCallBackAdd = 0x8008B130;
nuContMgrRemove = 0x8008A334;
nuSiCallBackRemove = 0x8008B1D0;
nuContDataClose = 0x8008A354;
nuContDataOpen = 0x8008A37C;
obCurrentTime = 0x800C47D0;
@ -762,7 +777,6 @@ __MENU_INDEX = 0x801BA94C;
__GLOBAL_WITH__inc_menu_timer = 0x8018FB20;
__GLOBAL_CONT_STATUS = 0x800C4B38; // size:0x10 type:u32
__set_fp_8008A660 = 0x8008A660;
@ -911,16 +925,12 @@ __MUS_MEM_800B1868 = 0x800B1868;
MQ_SWAP_BUFFER = 0x800E9BA8;
MQ_800E7988 = 0x800E7988;
MQ_800C4A00 = 0x800C4A00;
MQ_800E9BF0 = 0x800E9BF0;
MQ_800C35A0 = 0x800C35A0;
MQ_800AF320 = 0x800AF320;
MQ_800B1880 = 0x800B1880;
MQ_800E79C8 = 0x800E79C8;
MQ_800C49E8 = 0x800C49E8;
OSMESG_800BE190 = 0x800BE190;
OSMESG_800BE194 = 0x800BE194;
OSMESG_800B1870 = 0x800B1870;
OSMESG_800B17D0 = 0x800B17D0;
OSMESG_800B17E0 = 0x800B17E0;
@ -982,8 +992,6 @@ __GLOBAL_CONTROLLER_DATA_COPY = 0x0800AEE78; // size:0x18
__calls_copy_controller_data = 0x8007297C;
__copy_global_controller_data = 0x8008A600;
__start_copy_global_controller_data = 0x8008A354;
__end_copy_global_controller_data = 0x8008A37C;
__read_controller = 0x8008A3A4;
__calls_read_controller_0 = 0x8008A47C;
__calls_read_controller_1 = 0x8008A508;
@ -1007,7 +1015,6 @@ __virtual_mem_alloc = 0x80070F30;
obMain = 0x80071EB0;
obThreadMain = 0x800AF5F0;
obStackMain = 0x800C6D60;
entry = 0x80070C00;

View File

@ -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"]
@ -139,7 +141,7 @@ segments:
- [0x1B320, asm]
- [0x1B360, asm]
- [0x1B3A0, c, "_ob_electric_zephyr"]
- [0x1B3E0, c, "_ob_grumpy_island"]
- [0x1B3E0, c, "nu/nugfxthread"]
- [0x1B510, c, "_ob_painful_roll"]
- [0x1B530, asm]
- [0x1B650, asm]

View File

@ -3,13 +3,13 @@
#include "nu/nusys.h"
void __copy_global_controller_data(OSContPad* arg0) {
__start_copy_global_controller_data();
nuContDataClose();
bcopy(&__GLOBAL_CONTROLLER_DATA, arg0, 0x18);
__end_copy_global_controller_data();
nuContDataOpen();
}
void func_8008A640(void) {
nuSiSendMesg(0x103, 0);
void nuContQueryRead(void) {
nuSiSendMesg(NU_CONT_QUERY_MSG, NULL);
}
void __set_fp_8008A660(void(*arg0)(s16)) {

View File

@ -1,12 +1,14 @@
#include "common.h"
#include "nu/nusys.h"
void func_8008A6A0(void) {
func_8008B130(&D_800AA040);
nuSiCallBackAdd(&D_800AA040);
}
void func_8008A6C0(void) {
func_8008B1D0(&D_800AA040);
nuSiCallBackRemove(&D_800AA040);
}
INCLUDE_ASM(const s32, "_ob_dull_silver", func_8008A6E0);

View File

@ -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);

View File

@ -2,55 +2,47 @@
#include "nu/nusys.h"
void func_8008A5D0();
void func_8008A640();
extern OSMesg OSMESG_800BE190;
extern OSMesg OSMESG_800BE194;
extern u32 obStackMain;
/* 1A660 8008A260 */
u8 func_8008A260(void) {
s32 var_a0;
s32 var_a1;
s32 var_v1;
u8 nuContMgrInit(void) {
s32 i;
u8 pattern;
u8 bitmask;
func_8008A5D0();
osCreateMesgQueue(&MQ_800C4A00, &OSMESG_800BE190, 1);
osCreateMesgQueue(&MQ_800E9BF0, &OSMESG_800BE194, 1);
func_8008B130(&D_800A9FF8);
func_8008A640();
nuContDataUnLock();
osCreateMesgQueue(&nuContWaitMesgQ, &nuContWaitMesgBuf, 1);
osCreateMesgQueue(&nuContDataMutexQ, &nuContDataMutexBuf, 1);
nuSiCallBackAdd(&nuContCallBack);
nuContQueryRead();
var_a0 = 1;
var_a1 = 0;
var_v1 = 0;
obStackMain = 0;
for(; var_v1 < MAXCONTROLLERS; var_v1++) {
if (__GLOBAL_CONT_STATUS[var_v1].errno == 0) {
if ((__GLOBAL_CONT_STATUS[var_v1].type & CONT_TYPE_MASK) == CONT_TYPE_NORMAL) {
var_a1 |= var_a0;
obStackMain += 1;
}
var_a0 *= 2;
}
nuContNum = 0;
bitmask = 1;
pattern = 0;
for (i = 0; i < NU_CONT_MAXCONTROLLERS; i++) {
if (nuContStatus[i].errno != 0) {
continue;
}
return var_a1;
if ((nuContStatus[i].type & CONT_TYPE_MASK) == CONT_TYPE_NORMAL) {
nuContNum++;
pattern |= bitmask;
}
bitmask <<= 1;
}
return pattern;
}
void func_8008A334(void) {
func_8008B1D0(&D_800A9FF8);
void nuContMgrRemove(void) {
nuSiCallBackRemove(&nuContCallBack);
}
void __start_copy_global_controller_data(void) {
osSendMesg(&MQ_800E9BF0, NULL, OS_MESG_BLOCK);
void nuContDataClose(void) {
osSendMesg(&nuContDataMutexQ, NULL, OS_MESG_BLOCK);
}
void __end_copy_global_controller_data(void) {
osRecvMesg(&MQ_800E9BF0, NULL, OS_MESG_BLOCK);
void nuContDataOpen(void) {
osRecvMesg(&nuContDataMutexQ, NULL, OS_MESG_BLOCK);
}
s32 __read_controller(OSContPad* data, u32 flags) {
@ -77,7 +69,7 @@ s32 __real_read_controller(void) {
var_v0 = osContStartQuery(&nuSiMesgQ);
if (var_v0 == 0) {
osRecvMesg(&nuSiMesgQ, NULL, OS_MESG_BLOCK);
osContGetQuery(__GLOBAL_CONT_STATUS);
osContGetQuery(nuContStatus);
return 0;
} else {
return var_v0;
@ -87,12 +79,12 @@ s32 __real_read_controller(void) {
s32 __calls_read_controller_0(s16* arg0) {
if (D_800C4B30 == 0) {
osRecvMesg(&MQ_800C4A00, NULL, 0);
osRecvMesg(&nuContWaitMesgQ, NULL, 0);
__read_controller(__GLOBAL_CONTROLLER_DATA, 1);
if (D_800A9FE0 != NULL) {
D_800A9FE0(*arg0);
}
osSendMesg(&MQ_800C4A00, NULL, 0);
osSendMesg(&nuContWaitMesgQ, NULL, 0);
}
return 0;
}
@ -109,7 +101,7 @@ void __calls_read_controller_1(Arg___calls_read_controller_1* arg) {
s32 __calls_read_controller_2(s16* arg0) {
s32 var_v0;
osRecvMesg(&MQ_800C4A00, NULL, 0);
osRecvMesg(&nuContWaitMesgQ, NULL, 0);
var_v0 = __read_controller(__GLOBAL_CONTROLLER_DATA, 0);
if (var_v0 == 0) {
if (D_800A9FE0 != NULL) {

View File

@ -8,7 +8,7 @@ void func_8008A5A0(void) {
osSetIntMask(temp_v0);
}
void func_8008A5D0(void) {
void nuContDataUnLock(void) {
s32 temp_v0;
temp_v0 = osSetIntMask(OS_IM_NONE);

View File

@ -5,8 +5,6 @@
extern OSThread nuThreadIdle;
extern u64 nuStackIdle[];
extern u8 obStackMain[];
void nuIdle(void* arg);
void nuBoot(void) {
@ -23,7 +21,7 @@ void nuIdle(void* arg) {
osViSetSpecialFeatures(OS_VI_DIVOT_ON | OS_VI_DITHER_FILTER_ON | OS_VI_GAMMA_OFF | OS_VI_GAMMA_DITHER_OFF);
osCreateThread(&obThreadMain, NU_MAIN_THREAD_ID, obMain, NULL, obStackMain, NU_MAIN_THREAD_PRI);
osCreateThread(&obThreadMain, NU_MAIN_THREAD_ID, obMain, NULL, &nuContNum, NU_MAIN_THREAD_PRI);
osStartThread(&obThreadMain);
osSetThreadPri(&nuThreadIdle, NU_IDLE_THREAD_PRI);

View File

@ -32,7 +32,6 @@ void func_800749C0(s32); /* extern */
void func_800764E0(); /* extern */
void func_80079380(); /* extern */
void func_8008A040(); /* extern */
s8 func_8008A260(); /* extern */
void func_8009DAEC(); /* extern */
void func_800E9CEC(); /* extern */
void func_800EA714(); /* extern */

8
src/nu/nupiinit.c Normal file
View File

@ -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();
}

37
src/nu/nupireadrom.c Normal file
View File

@ -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);

48
src/nu/nusimgr.c Normal file
View File

@ -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);