diff --git a/include/functions.h b/include/functions.h index 71fbadb473..20dabac388 100644 --- a/include/functions.h +++ b/include/functions.h @@ -445,7 +445,7 @@ s32 __osSiRawWriteIo(u32 devAddr, u32 data); u32 __osSpGetStatus(void); void __osSpSetStatus(u32 value); void osCreateViManager(OSPri pri); -void viMgrMain(OSDevMgr* iParm1); +// void viMgrMain(OSDevMgr* iParm1); __OSViContext* __osViGetCurrentContext(void); void osWritebackDCacheAll(void); OSThread* __osGetCurrFaultedThread(void); diff --git a/include/os.h b/include/os.h index e9a5da37dc..568cc17942 100644 --- a/include/os.h +++ b/include/os.h @@ -8,6 +8,25 @@ #define OS_READ 0 #define OS_WRITE 1 +/* + * I/O message types + */ +#define OS_MESG_TYPE_BASE 10 +#define OS_MESG_TYPE_LOOPBACK (OS_MESG_TYPE_BASE+0) +#define OS_MESG_TYPE_DMAREAD (OS_MESG_TYPE_BASE+1) +#define OS_MESG_TYPE_DMAWRITE (OS_MESG_TYPE_BASE+2) +#define OS_MESG_TYPE_VRETRACE (OS_MESG_TYPE_BASE+3) +#define OS_MESG_TYPE_COUNTER (OS_MESG_TYPE_BASE+4) +#define OS_MESG_TYPE_EDMAREAD (OS_MESG_TYPE_BASE+5) +#define OS_MESG_TYPE_EDMAWRITE (OS_MESG_TYPE_BASE+6) + +/* + * I/O message priority + */ +#define OS_MESG_PRI_NORMAL 0 +#define OS_MESG_PRI_HIGH 1 + + typedef u32 OSIntMask; typedef u32 OSPageMask; diff --git a/include/osint.h b/include/osint.h index 71781ab6da..fa74a82eb6 100644 --- a/include/osint.h +++ b/include/osint.h @@ -20,4 +20,7 @@ typedef struct { /* 0x4 */ OSPri priority; } __OSThreadTail; +extern __osHwInt __osHwIntTable[]; +extern __OSEventState __osEventStateTab[]; + #endif diff --git a/include/variables.h b/include/variables.h index 66f4ecc887..281996873f 100644 --- a/include/variables.h +++ b/include/variables.h @@ -88,8 +88,8 @@ extern __OSViContext* __osViNext; extern OSViMode osViModeFpalLan1; // extern u8 ldigs[]; // extern u8 udigs[]; -extern OSDevMgr __osViDevMgr; -extern UNK_TYPE4 __additional_scanline; +// extern OSDevMgr __osViDevMgr; +extern u32 __additional_scanline; // extern UNK_TYPE1 D_80098180; extern char bootThreadName[]; extern char idleThreadName[]; @@ -352,9 +352,9 @@ extern OSPiHandle CartRomHandle; extern OSThread viThread; extern u8 viThreadStack[0x1000]; extern OSMesgQueue viEventQueue; -extern OSMesg viEventBuf[5]; -extern OSIoMesg viRetraceMsg; -extern OSIoMesg viCounterMsg; +// extern OSMesg viEventBuf[5]; +// extern OSIoMesg viRetraceMsg; +// extern OSIoMesg viCounterMsg; extern u16 viRetrace; extern DmaEntry dmadata[1568]; // extern UNK_TYPE1 D_80186028; diff --git a/spec b/spec index 27555435aa..d619034f3d 100644 --- a/spec +++ b/spec @@ -225,8 +225,6 @@ beginseg include "build/src/libultra/io/spsetstat.o" pad_text include "build/src/libultra/io/vimgr.o" - include "build/data/boot/vimgr.data.o" - include "build/data/boot/vimgr.bss.o" include "build/src/libultra/io/vigetcurrcontext.o" include "build/asm/boot/writebackdcacheall.text.o" include "build/src/libultra/os/getcurrfaultthread.o" diff --git a/src/libultra/io/vimgr.c b/src/libultra/io/vimgr.c index ecbb9b37cc..07babf3517 100644 --- a/src/libultra/io/vimgr.c +++ b/src/libultra/io/vimgr.c @@ -1,5 +1,107 @@ #include "global.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/non_matchings/boot/vimgr/osCreateViManager.s") +OSThread viThread; +u8 viThreadStack[0x1000]; +OSMesgQueue viEventQueue; +OSMesg viEventBuf[6]; +OSIoMesg viRetraceMsg; +OSIoMesg viCounterMsg; +OSMgrArgs __osViDevMgr = { 0 }; +u32 __additional_scanline = 0; -#pragma GLOBAL_ASM("asm/non_matchings/boot/vimgr/viMgrMain.s") +void viMgrMain(void*); + +void osCreateViManager(OSPri pri) { + u32 prevInt; + OSPri newPri; + OSPri currentPri; + + if (!__osViDevMgr.initialized) { + __osTimerServicesInit(); + __additional_scanline = 0; + osCreateMesgQueue(&viEventQueue, viEventBuf, ARRAY_COUNT(viEventBuf) - 1); + viRetraceMsg.hdr.type = OS_MESG_TYPE_VRETRACE; + viRetraceMsg.hdr.pri = OS_MESG_PRI_NORMAL; + viRetraceMsg.hdr.retQueue = NULL; + viCounterMsg.hdr.type = OS_MESG_TYPE_COUNTER; + viCounterMsg.hdr.pri = OS_MESG_PRI_NORMAL; + viCounterMsg.hdr.retQueue = NULL; + osSetEventMesg(OS_EVENT_VI, &viEventQueue, &viRetraceMsg); + osSetEventMesg(OS_EVENT_COUNTER, &viEventQueue, &viCounterMsg); + newPri = -1; + currentPri = osGetThreadPri(NULL); + if (currentPri < pri) { + newPri = currentPri; + osSetThreadPri(NULL, pri); + } + + prevInt = __osDisableInt(); + __osViDevMgr.initialized = true; + __osViDevMgr.mgrThread = &viThread; + __osViDevMgr.cmdQueue = &viEventQueue; + __osViDevMgr.eventQueue = &viEventQueue; + __osViDevMgr.accessQueue = NULL; + __osViDevMgr.piDmaCallback = NULL; + __osViDevMgr.epiDmaCallback = NULL; + + osCreateThread(&viThread, 0, &viMgrMain, &__osViDevMgr, viThreadStack + sizeof(viThreadStack), pri); + __osViInit(); + osStartThread(&viThread); + __osRestoreInt(prevInt); + if (newPri != -1) { + osSetThreadPri(NULL, newPri); + } + } +} + +void viMgrMain(void* vargs) { + OSMgrArgs* args; + static u16 viRetrace; + u32 addTime; + OSIoMesg* mesg; + u32 temp = 0; // always 0 + + mesg = NULL; + viRetrace = __osViGetCurrentContext()->retraceCount; + if (viRetrace == 0) { + viRetrace = 1; + } + + args = (OSMgrArgs*)vargs; + + while (true) { + osRecvMesg(args->eventQueue, (OSMesg)&mesg, OS_MESG_BLOCK); + switch (mesg->hdr.type) { + case OS_MESG_TYPE_VRETRACE: + __osViSwapContext(); + viRetrace--; + if (!viRetrace) { + __OSViContext* ctx = __osViGetCurrentContext(); + if (ctx->mq) { + osSendMesg(ctx->mq, ctx->msg, OS_MESG_NOBLOCK); + } + viRetrace = ctx->retraceCount; + } + + __osViIntrCount++; + + // block optimized out since temp is always 0, + // but it changes register allocation and ordering for __osCurrentTime + if (temp != 0) { + addTime = osGetCount(); + __osCurrentTime = addTime; + temp = 0; + } + + addTime = __osBaseCounter; + __osBaseCounter = osGetCount(); + addTime = __osBaseCounter - addTime; + __osCurrentTime = __osCurrentTime + addTime; + break; + case OS_MESG_TYPE_COUNTER: + __osTimerInterrupt(); + break; + } + } +} diff --git a/src/libultra/voice/voicecontrolgain.c b/src/libultra/voice/voicecontrolgain.c index 9dc541cc5c..d7ec8ef69b 100644 --- a/src/libultra/voice/voicecontrolgain.c +++ b/src/libultra/voice/voicecontrolgain.c @@ -1,3 +1,5 @@ #include "global.h" +u8 D_80098180[] = { 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0 }; + #pragma GLOBAL_ASM("asm/non_matchings/boot/voicecontrolgain/osVoiceControlGain.s") diff --git a/tools/disasm/files.txt b/tools/disasm/files.txt index 3f921e7395..8dc09cca4a 100644 --- a/tools/disasm/files.txt +++ b/tools/disasm/files.txt @@ -284,6 +284,7 @@ 0x800980E0 : "guS2DInitBg", 0x80098130 : "xldtob", 0x80098160 : "vimgr", + 0x80098180 : "voicecontrolgain", # .rodata section 0x80098190 : "boot_main",