ogrebattle64/src/_ob_icy_coast.c

87 lines
2.2 KiB
C

#include "common.h"
#include "nu/nusys.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, &MQ_800BE030, 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, &MQ_800BE030, OSMESG_800BE048, sizeof(OSMESG_800BE048) / sizeof(OSMesg));
PTR_CART_ROM_HANDLE = osCartRomInit();
}
/* 1A380 80089F80 */
void romCopy_512(void *src, void *dst, u32 len) {
OSIoMesg dmaIoMesgBuf;
OSMesgQueue dmaMessageQ;
OSMesg dummyMesg;
u32 readlength;
osCreateMesgQueue(&dmaMessageQ, &dummyMesg, 1);
dmaIoMesgBuf.hdr.pri = 0;
dmaIoMesgBuf.hdr.retQueue = &dmaMessageQ;
osInvalDCache(dst, len);
while (len != 0) {
readlength = len;
if (readlength > MAX_BYTES_TO_READ) {
readlength = MAX_BYTES_TO_READ;
}
dmaIoMesgBuf.devAddr = (u32)src;
dmaIoMesgBuf.dramAddr = dst;
dmaIoMesgBuf.size = readlength;
// Start the DMA transfer
osEPiStartDma(PTR_CART_ROM_HANDLE, &dmaIoMesgBuf, 0);
// Wait for the DMA transfer to complete
osRecvMesg(&dmaMessageQ, &dummyMesg, 1);
src += readlength;
dst += readlength;
len -= readlength;
}
}
INCLUDE_ASM(const s32, "_ob_icy_coast", func_8008A040);