diff --git a/lib/asm/non_matchings/osViMgr_0D2590/viMgrMain.s b/lib/asm/non_matchings/osViMgr_0D2590/viMgrMain.s index 0e57bb23..477d87aa 100644 --- a/lib/asm/non_matchings/osViMgr_0D2590/viMgrMain.s +++ b/lib/asm/non_matchings/osViMgr_0D2590/viMgrMain.s @@ -13,13 +13,13 @@ glabel viMgrMain /* 0D2734 800D1B34 0C035820 */ jal __osViGetCurrentContext /* 0D2738 800D1B38 AFA00044 */ sw $zero, 0x44($sp) /* 0D273C 800D1B3C 94430002 */ lhu $v1, 2($v0) -/* 0D2740 800D1B40 3C018013 */ lui $at, %hi(D_8012D190) # $at, 0x8013 +/* 0D2740 800D1B40 3C018013 */ lui $at, %hi(retrace) # $at, 0x8013 /* 0D2744 800D1B44 2416000E */ li $s6, 14 /* 0D2748 800D1B48 14600004 */ bnez $v1, .L800D1B5C -/* 0D274C 800D1B4C A423D190 */ sh $v1, %lo(D_8012D190)($at) +/* 0D274C 800D1B4C A423D190 */ sh $v1, %lo(retrace)($at) /* 0D2750 800D1B50 24030001 */ li $v1, 1 -/* 0D2754 800D1B54 3C018013 */ lui $at, %hi(D_8012D190) # $at, 0x8013 -/* 0D2758 800D1B58 A423D190 */ sh $v1, %lo(D_8012D190)($at) +/* 0D2754 800D1B54 3C018013 */ lui $at, %hi(retrace) # $at, 0x8013 +/* 0D2758 800D1B58 A423D190 */ sh $v1, %lo(retrace)($at) .L800D1B5C: /* 0D275C 800D1B5C 3C138013 */ lui $s3, %hi(__osViIntrCount) # $s3, 0x8013 /* 0D2760 800D1B60 3C128013 */ lui $s2, %hi(__osBaseCounter) # $s2, 0x8013 @@ -46,13 +46,13 @@ glabel viMgrMain .L800D1BAC: /* 0D27AC 800D1BAC 0C035824 */ jal __osViSwapContext /* 0D27B0 800D1BB0 00000000 */ nop -/* 0D27B4 800D1BB4 3C038013 */ lui $v1, %hi(D_8012D190) # $v1, 0x8013 -/* 0D27B8 800D1BB8 9463D190 */ lhu $v1, %lo(D_8012D190)($v1) -/* 0D27BC 800D1BBC 3C018013 */ lui $at, %hi(D_8012D190) # $at, 0x8013 +/* 0D27B4 800D1BB4 3C038013 */ lui $v1, %hi(retrace) # $v1, 0x8013 +/* 0D27B8 800D1BB8 9463D190 */ lhu $v1, %lo(retrace)($v1) +/* 0D27BC 800D1BBC 3C018013 */ lui $at, %hi(retrace) # $at, 0x8013 /* 0D27C0 800D1BC0 2463FFFF */ addiu $v1, $v1, -1 /* 0D27C4 800D1BC4 306FFFFF */ andi $t7, $v1, 0xffff /* 0D27C8 800D1BC8 15E0000E */ bnez $t7, .L800D1C04 -/* 0D27CC 800D1BCC A42FD190 */ sh $t7, %lo(D_8012D190)($at) +/* 0D27CC 800D1BCC A42FD190 */ sh $t7, %lo(retrace)($at) /* 0D27D0 800D1BD0 0C035820 */ jal __osViGetCurrentContext /* 0D27D4 800D1BD4 00000000 */ nop /* 0D27D8 800D1BD8 8C580010 */ lw $t8, 0x10($v0) @@ -65,8 +65,8 @@ glabel viMgrMain /* 0D27F4 800D1BF4 8C450014 */ lw $a1, 0x14($v0) /* 0D27F8 800D1BF8 96030002 */ lhu $v1, 2($s0) .L800D1BFC: -/* 0D27FC 800D1BFC 3C018013 */ lui $at, %hi(D_8012D190) # $at, 0x8013 -/* 0D2800 800D1C00 A423D190 */ sh $v1, %lo(D_8012D190)($at) +/* 0D27FC 800D1BFC 3C018013 */ lui $at, %hi(retrace) # $at, 0x8013 +/* 0D2800 800D1C00 A423D190 */ sh $v1, %lo(retrace)($at) .L800D1C04: /* 0D2804 800D1C04 8E790000 */ lw $t9, ($s3) /* 0D2808 800D1C08 8E500000 */ lw $s0, ($s2) diff --git a/lib/src/os/osTimer.c b/lib/src/os/osTimer.c index 1621c041..9a9f2bea 100644 --- a/lib/src/os/osTimer.c +++ b/lib/src/os/osTimer.c @@ -16,7 +16,8 @@ extern u32 __osTimerCounter; OSTime __osInsertTimer(OSTimer *t); #ifdef NON_MATCHING -//Seems to be a mistmatch based on where __osCurrentTime is defined and set. +//Seems to be a mistmatch based on where __osCurrentTime is defined. +//Scratch proving that: https://decomp.me/scratch/OB3iP void __osTimerServicesInit(void) { __osCurrentTime = 0; @@ -32,8 +33,10 @@ void __osTimerServicesInit(void) #else GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osTimerServicesInit.s") #endif + void __osSetTimerIntr(OSTime tim); void __osSetCompare(u32); + void __osTimerInterrupt(void) { OSTimer *t; u32 count; diff --git a/lib/src/os/osViBlack.c b/lib/src/os/osViBlack.c index f0599ff7..e070a865 100644 --- a/lib/src/os/osViBlack.c +++ b/lib/src/os/osViBlack.c @@ -2,15 +2,14 @@ /* RAM_POS: 0x800D1D10 */ #include "libultra_internal.h" +#include "viint.h" -extern OSViContext *__osViNext; -// TODO: name magic constants void osViBlack(u8 active) { register u32 int_disabled = __osDisableInt(); if (active) { - __osViNext->unk00 |= 0x20; + __osViNext->state |= VI_STATE_BLACK; } else { - __osViNext->unk00 &= ~0x20; + __osViNext->state &= ~VI_STATE_BLACK; } __osRestoreInt(int_disabled); } diff --git a/lib/src/os/osViMgr.c b/lib/src/os/osViMgr.c index a394acb4..32540ae7 100644 --- a/lib/src/os/osViMgr.c +++ b/lib/src/os/osViMgr.c @@ -4,7 +4,7 @@ #include "types.h" #include "macros.h" #include "libultra_internal.h" - +#include "viint.h" extern OSTime __osCurrentTime; extern u32 __osBaseCounter; @@ -54,7 +54,7 @@ void osCreateViManager(OSPri pri) { __osViDevMgr.acsQueue = NULL; __osViDevMgr.dma = NULL; __osViDevMgr.edma = NULL; - osCreateThread(&viThread, 0, viMgrMain, &__osViDevMgr, &viThreadStack[OS_VIM_STACKSIZE], pri); //TODO give 0x8012C130 a proper symbol + osCreateThread(&viThread, 0, viMgrMain, &__osViDevMgr, &viThreadStack[OS_VIM_STACKSIZE], pri); __osViInit(); osStartThread(&viThread); __osRestoreInt(savedMask); @@ -63,4 +63,59 @@ void osCreateViManager(OSPri pri) { } } } + +#ifdef NON_MATCHING +void __osTimerInterrupt(void); +//Fails due to how retrace is declared. Not sure how to fix it. +void viMgrMain(void *arg) { + static u16 retrace; + __OSViContext *vc; + OSDevMgr *dm; + OSIoMesg *mesg; + s32 first; + u32 count; + + mesg = NULL; + first = FALSE; + vc = __osViGetCurrentContext(); + retrace = vc->retraceCount; + + if (retrace == 0) + retrace = 1; + + dm = (OSDevMgr *)arg; + + while (TRUE) { + osRecvMesg(dm->evtQueue, &mesg, OS_MESG_BLOCK); + switch (mesg->hdr.type) { + case OS_MESG_TYPE_VRETRACE: + __osViSwapContext(); + retrace--; + if (retrace == 0) { + vc = __osViGetCurrentContext(); + if (vc->msgq != NULL) { + osSendMesg(vc->msgq, vc->msg, OS_MESG_NOBLOCK); + } + retrace = vc->retraceCount; + } + __osViIntrCount++; + if (first) { + count = osGetCount(); + __osCurrentTime = count; + first = FALSE; + } + count = __osBaseCounter; + __osBaseCounter = osGetCount(); + count = __osBaseCounter - count; + __osCurrentTime = __osCurrentTime + count; + break; + + case OS_MESG_TYPE_COUNTER: + __osTimerInterrupt(); + break; + } + } +} +#else GLOBAL_ASM("lib/asm/non_matchings/osViMgr_0D2590/viMgrMain.s") +#endif \ No newline at end of file diff --git a/lib/src/os/osViSwapBuffer.c b/lib/src/os/osViSwapBuffer.c index f208cd62..7311c45b 100644 --- a/lib/src/os/osViSwapBuffer.c +++ b/lib/src/os/osViSwapBuffer.c @@ -2,12 +2,11 @@ /* RAM_POS: 0x800D2420 */ #include "libultra_internal.h" - -extern OSViContext *__osViNext; +#include "viint.h" void osViSwapBuffer(void *frameBufPtr) { u32 saveMask = __osDisableInt(); - __osViNext->buffer = frameBufPtr; - __osViNext->unk00 |= 0x10; + __osViNext->framep = frameBufPtr; + __osViNext->state |= VI_STATE_10; __osRestoreInt(saveMask); } diff --git a/lib/src/unknown_0CE200.c b/lib/src/unknown_0CE200.c index 3affb12e..1abaa3a1 100644 --- a/lib/src/unknown_0CE200.c +++ b/lib/src/unknown_0CE200.c @@ -21,9 +21,11 @@ s32 viEventQueue[6]; s32 viEventBuf[6]; s32 viRetraceMsg[6]; s32 viCounterMsg[6]; -s32 D_8012D190[4]; +u16 retrace; //Used in viMgrMain, but it's supposed to be static in that function +u16 D_8012D192; +s32 D_8012D194[2]; s32 D_8012D1A0[16]; -s32 D_8012D1E0[2]; +s32 D_8012D1E0[2]; s32 piAccessQueue[6]; OSTimer D_8012D200; OSTime __osCurrentTime;