From 5cf5f655ef926e20ceb384ee37c13b46ef71e7f1 Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Thu, 7 Oct 2021 11:36:02 -0400 Subject: [PATCH] Nearly have __scHandleRSP --- ...dleRetrace.s => __scHandleRetrace_Maybe.s} | 2 +- lib/asm/non_matchings/sched/__scMain.s | 2 +- lib/src/mips1/sc/sched.c | 54 ++++++++++++++++++- lib/src/mips1/sc/sched.h | 31 ++++++++++- 4 files changed, 83 insertions(+), 6 deletions(-) rename lib/asm/non_matchings/sched/{__scHandleRetrace.s => __scHandleRetrace_Maybe.s} (99%) diff --git a/lib/asm/non_matchings/sched/__scHandleRetrace.s b/lib/asm/non_matchings/sched/__scHandleRetrace_Maybe.s similarity index 99% rename from lib/asm/non_matchings/sched/__scHandleRetrace.s rename to lib/asm/non_matchings/sched/__scHandleRetrace_Maybe.s index 66380241..2027258b 100644 --- a/lib/asm/non_matchings/sched/__scHandleRetrace.s +++ b/lib/asm/non_matchings/sched/__scHandleRetrace_Maybe.s @@ -1,4 +1,4 @@ -glabel __scHandleRetrace +glabel __scHandleRetrace_Maybe /* 07A418 80079818 27BDFFB8 */ addiu $sp, $sp, -0x48 /* 07A41C 8007981C AFBF001C */ sw $ra, 0x1c($sp) /* 07A420 80079820 AFB10018 */ sw $s1, 0x18($sp) diff --git a/lib/asm/non_matchings/sched/__scMain.s b/lib/asm/non_matchings/sched/__scMain.s index 94f79fe5..d958a642 100644 --- a/lib/asm/non_matchings/sched/__scMain.s +++ b/lib/asm/non_matchings/sched/__scMain.s @@ -40,7 +40,7 @@ glabel __scMain /* 07A240 80079640 10000020 */ b .L800796C4 /* 07A244 80079644 8FA50064 */ lw $a1, 0x64($sp) .L80079648: -/* 07A248 80079648 0C01E606 */ jal __scHandleRetrace +/* 07A248 80079648 0C01E606 */ jal __scHandleRetrace_Maybe /* 07A24C 8007964C 02402025 */ move $a0, $s2 /* 07A250 80079650 1000FFEC */ b .L80079604 /* 07A254 80079654 02602025 */ move $a0, $s3 diff --git a/lib/src/mips1/sc/sched.c b/lib/src/mips1/sc/sched.c index e8f6cf06..84f1c948 100644 --- a/lib/src/mips1/sc/sched.c +++ b/lib/src/mips1/sc/sched.c @@ -56,7 +56,7 @@ s32 D_80126110; s32 D_80126114; OSTime gYieldTime; s32 D_80126120; -s32 D_80126124; +u32 D_80126124; s32 D_80126128[18]; /*******************************/ @@ -179,8 +179,58 @@ void dummy_80079808() { void dummy_80079810() { } -GLOBAL_ASM("lib/asm/non_matchings/sched/__scHandleRetrace.s") +GLOBAL_ASM("lib/asm/non_matchings/sched/__scHandleRetrace_Maybe.s") + +#ifdef NON_MATCHING +void __scHandleRSP(OSSched *sc) { + OSScTask *t, *sp = 0, *dp = 0; + s32 state; + s32 temp_hi; + + t = sc->curRSPTask; + sc->curRSPTask = NULL; + + if (t->list.t.type == M_AUDTASK) { + D_80126124 = osGetCount(); + D_800DE74C = (f32) (((f32) (D_80126124 - D_80126120) * 60.0f) / 468750.0f); + D_800DE744 = (f32) (D_800DE744 + D_800DE74C); + if (D_800DE740 < D_800DE74C) { + D_800DE740 = D_800DE74C; + } + temp_hi = (s32) D_800DE750 % 1000; + if ((temp_hi == 1) || (temp_hi == 2)) { + D_800DE748 = (f32) (D_800DE744 / 500.0f); + D_800DE744 = 0.0f; + D_800DE740 = 0.0f; + } + } + + if ((t->state & OS_SC_YIELD)) { + if (osSpTaskYielded(&t->list)) { + t->state |= OS_SC_YIELDED; + if ((t->flags & OS_SC_TYPE_MASK) == OS_SC_XBUS) { + /* push the task back on the list */ + t->next = sc->gfxListHead; + sc->gfxListHead = t; + if (sc->gfxListTail == 0) + sc->gfxListTail = t; + } + } else { + t->state &= ~OS_SC_NEEDS_RSP; + } + if ((t->flags & OS_SC_TYPE_MASK) != OS_SC_XBUS){} + } else { + t->state &= ~OS_SC_NEEDS_RSP; + __scTaskComplete(sc, t); + } + + state = ((sc->curRSPTask == 0) << 1) | (sc->curRDPTask == 0); + if ( (__scSchedule (sc, &sp, &dp, state)) != state) + __scExec(sc, sp, dp); +} +#else GLOBAL_ASM("lib/asm/non_matchings/sched/__scHandleRSP.s") +#endif void __scHandleRDP(OSSched *sc) { OSScTask *t, *sp = 0, *dp = 0; diff --git a/lib/src/mips1/sc/sched.h b/lib/src/mips1/sc/sched.h index 7e84b88a..8eb4ff7e 100644 --- a/lib/src/mips1/sc/sched.h +++ b/lib/src/mips1/sc/sched.h @@ -9,7 +9,35 @@ #define OS_SC_PRE_NMI_MSG 4 #define OS_SC_MAX_MESGS 8 -#define OS_SC_YIELD 0x10 +/* + * OSScTask state + */ +#define OS_SC_DP 0x0001 /* set if still needs dp */ +#define OS_SC_SP 0x0002 /* set if still needs sp */ +#define OS_SC_YIELD 0x0010 /* set if yield requested */ +#define OS_SC_YIELDED 0x0020 /* set if yield completed */ + +/* + * OSScTask->flags type identifier + */ +#define OS_SC_XBUS (OS_SC_SP | OS_SC_DP) +#define OS_SC_DRAM (OS_SC_SP | OS_SC_DP | OS_SC_DRAM_DLIST) +#define OS_SC_DP_XBUS (OS_SC_SP) +#define OS_SC_DP_DRAM (OS_SC_SP | OS_SC_DRAM_DLIST) +#define OS_SC_SP_XBUS (OS_SC_DP) +#define OS_SC_SP_DRAM (OS_SC_DP | OS_SC_DRAM_DLIST) +/* + * OSScTask flags: + */ +#define OS_SC_NEEDS_RDP 0x0001 /* uses the RDP */ +#define OS_SC_NEEDS_RSP 0x0002 /* uses the RSP */ +#define OS_SC_DRAM_DLIST 0x0004 /* SP & DP communicate through DRAM */ +#define OS_SC_PARALLEL_TASK 0x0010 /* must be first gfx task on list */ +#define OS_SC_LAST_TASK 0x0020 /* last task in queue for frame */ +#define OS_SC_SWAPBUFFER 0x0040 /* swapbuffers when gfx task done */ + +#define OS_SC_RCP_MASK 0x0003 /* mask for needs bits */ +#define OS_SC_TYPE_MASK 0x0007 /* complete type mask */ typedef struct { short type; @@ -31,7 +59,6 @@ typedef struct OSScTask_s { #endif /* FINALROM library used with */ } OSScTask; /* non FINALROM code */ - typedef struct SCClient_s { u8 unk0; struct SCClient_s *next; /* next client in the list */