From 1db5467b0213634cb8b5c2f8de435b3e60b2eb3a Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Wed, 6 Oct 2021 21:42:28 -0400 Subject: [PATCH] Match osSpTaskYielded and clean up an unknown file a little --- lib/src/os/siacs.c | 2 +- lib/src/os/unknown_0D29F0.c | 80 +++++++++++-------------------------- 2 files changed, 25 insertions(+), 57 deletions(-) diff --git a/lib/src/os/siacs.c b/lib/src/os/siacs.c index a499b237..813c45c3 100644 --- a/lib/src/os/siacs.c +++ b/lib/src/os/siacs.c @@ -22,7 +22,7 @@ s32 viCounterMsg[6]; 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]; +OSTask tmp_task; #define PI_Q_BUF_LEN 1 OSMesg piAccessBuf[PI_Q_BUF_LEN]; //Should be static, but this works for now s32 __osPiAccessQueue[6]; diff --git a/lib/src/os/unknown_0D29F0.c b/lib/src/os/unknown_0D29F0.c index bfbaad0b..5e7f4a42 100644 --- a/lib/src/os/unknown_0D29F0.c +++ b/lib/src/os/unknown_0D29F0.c @@ -1,40 +1,32 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D1DF0 */ -#include "types.h" -#include "macros.h" #include "libultra_internal.h" - -typedef struct -{ - /* 0x0 */ f32 factor; - /* 0x4 */ u16 offset; - /* 0x8 */ u32 scale; -} __OSViScale; - -typedef struct -{ - /* 0x0 */ u16 state; - /* 0x2 */ u16 retraceCount; - /* 0x4 */ void *framep; - /* 0x8 */ OSViMode *modep; - /* 0xC */ u32 control; - /* 0x10 */ OSMesgQueue *msgq; - /* 0x14 */ OSMesg msg; - /* 0x18 */ __OSViScale x; - /* 0x24 */ __OSViScale y; -} __OSViContext; +#include "viint.h" __OSViContext vi[2] = {0}; - __OSViContext *__osViCurr = &vi[0]; __OSViContext *__osViNext = &vi[1]; //TODO: This should be defined above osInitialize -#define VI_NTSC_CLOCK 48681812 +#define OS_TASK_YIELDED 0x0001 +#define OS_TASK_DP_WAIT 0x0002 s32 osViClock = VI_NTSC_CLOCK; -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D29F0/osSpTaskYielded.s") +OSYieldResult osSpTaskYielded(OSTask *tp) { + u32 status; + OSYieldResult result; + status = __osSpGetStatus(); + if (status & SP_STATUS_YIELDED) + result = OS_TASK_YIELDED; + else + result = 0; + if (status & SP_STATUS_YIELD) { + tp->t.flags |= result; + tp->t.flags &= ~(OS_TASK_DP_WAIT); + } + return result; +} void *osViGetCurrentFramebuffer(void){ register u32 saveMask; @@ -56,38 +48,15 @@ void *osViGetNextFramebuffer(void){ return framep; } - -//TODO Split into sptask.c and seperate header - -#define OS_TASK_YIELDED 0x0001 - -#define SP_CLR_HALT 0x00001 /* Bit 0: clear halt */ -#define SP_CLR_BROKE 0x00004 /* Bit 2: clear broke */ -#define SP_CLR_SSTEP 0x00020 /* Bit 5: clear sstep */ -#define SP_SET_INTR_BREAK 0x00100 /* Bit 8: set intr on break */ -#define SP_CLR_SIG0 0x00200 /* Bit 9: clear signal 0 */ -#define SP_CLR_SIG1 0x00800 /* Bit 11: clear signal 1 */ -#define SP_CLR_SIG2 0x02000 /* Bit 11: clear signal 1 */ - - - -#define SP_CLR_YIELD SP_CLR_SIG0 -#define SP_CLR_YIELDED SP_CLR_SIG1 -#define SP_CLR_TASKDONE SP_CLR_SIG2 - -#define SP_IMEM_START 0x04001000 /* read/write */ - #define _osVirtualToPhysical(ptr) \ - if (ptr != NULL) \ - { \ + if (ptr != NULL) { \ ptr = (void *)osVirtualToPhysical(ptr); \ } -extern OSTask D_8012D1A0; -OSTask *_VirtualToPhysicalTask(OSTask *intp) -{ +extern OSTask tmp_task; +OSTask *_VirtualToPhysicalTask(OSTask *intp) { OSTask *tp; - tp = &D_8012D1A0; + tp = &tmp_task; bcopy(intp, tp, sizeof(OSTask)); _osVirtualToPhysical(tp->t.ucode); @@ -100,16 +69,15 @@ OSTask *_VirtualToPhysicalTask(OSTask *intp) return tp; } -void osSpTaskLoad(OSTask *intp){ - +void osSpTaskLoad(OSTask *intp) { OSTask *tp; tp = _VirtualToPhysicalTask(intp); - if (tp->t.flags & OS_TASK_YIELDED) - { + if (tp->t.flags & OS_TASK_YIELDED) { tp->t.ucode_data = tp->t.yield_data_ptr; tp->t.ucode_data_size = tp->t.yield_data_size; intp->t.flags &= ~OS_TASK_YIELDED; } + osWritebackDCache(tp, sizeof(OSTask)); __osSpSetStatus(SP_CLR_YIELD | SP_CLR_YIELDED | SP_CLR_TASKDONE | SP_SET_INTR_BREAK); while (__osSpSetPc(SP_IMEM_START) == -1)