From 6f8edc5bbc554acb78596393135a7af40d4d3172 Mon Sep 17 00:00:00 2001 From: RevoSucks Date: Fri, 28 Jul 2023 20:11:52 -0400 Subject: [PATCH] decompile C030.c --- Makefile | 2 ++ splat.yaml | 2 +- src/C030.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 src/C030.c diff --git a/Makefile b/Makefile index b77a699..a6872ad 100644 --- a/Makefile +++ b/Makefile @@ -177,6 +177,8 @@ build/src/libultra/io/gbpakpower.c.o: OPTFLAGS += -Wo,-loopunroll,0 build/src/libultra/io/gbpakinit.c.o: OPTFLAGS += -Wo,-loopunroll,0 build/src/libultra/io/gbpakselectbank.c.o: OPTFLAGS += -Wo,-loopunroll,0 +build/src/C030.c.o: OPTFLAGS += -Wo,-loopunroll,0 + # Libultra misc build/src/libultra/gu/scale.c.o: CC := $(CC_OLD) build/src/libultra/gu/scale.c.o: OPTFLAGS := -O3 diff --git a/splat.yaml b/splat.yaml index ce5276d..2388688 100644 --- a/splat.yaml +++ b/splat.yaml @@ -51,7 +51,7 @@ segments: - [0xAF00, asm] # camera code - [0xB130, c, hal_libc] - [0xB230, c, gb_tower] - - [0xC030, asm] # extra sprites loader + - [0xC030, c] # extra sprites loader - [0xC3D0, asm, exception_set] # exception functions - [0xC3F0, asm] # yay0 decoder - [0xC4B0, bin, libleo_bootdisk] # These are libleo's bootdisk and bootstrap files, but diff --git a/src/C030.c b/src/C030.c new file mode 100644 index 0000000..3f732be --- /dev/null +++ b/src/C030.c @@ -0,0 +1,92 @@ +#include "ultra64.h" +#include "ultra64/controller.h" + +extern s32 D_800697E0; +extern u8 D_800A82B0[32]; + +extern OSMesgQueue gSIEventMesgQueue; + +s32 __osContRamWrite(OSMesgQueue *mq, int channel, u16 address, u8 *buffer, int force); +s32 __osContRamRead(OSMesgQueue *mq, int channel, u16 address, u8 *buffer); + +extern s32 osPfsIsPlug(OSMesgQueue *, u8 *); + +extern u8 D_800A82CF; + +// some kind of cycle count sleep function. just like the one in crash_screen.c +void func_8000B430(long ms) { + unsigned long start = (osGetCount()); + unsigned long target = (s32)((ms * 1000LL) * 3000 / 64ULL + start); + + while (osGetCount() < target) { + ; + } +} + +s32 func_8000B4C4(void) { + s32 i; + s32 ret; + u8 sp2F; // sp2F + + if (D_800697E0 == 0) { + u8 *buffer; + osPfsIsPlug(&gSIEventMesgQueue, &sp2F); + if(sp2F & 8) { + Cont_BlockEepromQueue(); + for(buffer = D_800A82B0, i = 0; i < 32; i++) { + buffer[i] = 0xFE; + } + if((__osContRamWrite(&gSIEventMesgQueue, 3, 0x400, buffer, 0) == 2) + && (__osContRamWrite(&gSIEventMesgQueue, 3, 0x400, buffer, 0) != 0)) { + Cont_NoBlockEepromQueue(); + return 0; + } + if((__osContRamRead(&gSIEventMesgQueue, 3, 0x400, buffer) == 0) && (D_800A82CF == 0xFE)) { + Cont_NoBlockEepromQueue(); + return 0; + } + for(buffer = D_800A82B0, i = 0; i < 32; i+=4) { + buffer[i+0] = 0x85; + buffer[i+1] = 0x85; + buffer[i+2] = 0x85; + buffer[i+3] = 0x85; + } + if((__osContRamWrite(&gSIEventMesgQueue, 3, 0x400, buffer, 0) == 2) + && (__osContRamWrite(&gSIEventMesgQueue, 3, 0x400, buffer, 0) != 0)) { + Cont_NoBlockEepromQueue(); + return 0; + } + if((__osContRamRead(&gSIEventMesgQueue, 3, 0x400, buffer) == 0) + && (D_800A82CF == 0x85)) { + Cont_NoBlockEepromQueue(); + D_800697E0 = 1; + return 1; + } + Cont_NoBlockEepromQueue(); + } + return 0; + } + return 1; +} + +u8 func_8000B6B4(void) { + Cont_BlockEepromQueue(); + __osContRamRead(&gSIEventMesgQueue, 3, 0x600, D_800A82B0); + Cont_NoBlockEepromQueue(); + return D_800A82CF; +} + +void func_8000B6FC(u8 arg0) { + u8 *buffer = D_800A82B0; + Cont_BlockEepromQueue(); + __osContRamRead(&gSIEventMesgQueue, 3, 0x600, buffer); + if (D_800A82CF == 8) { + do { + func_8000B430(0x14); + __osContRamRead(&gSIEventMesgQueue, 3, 0x600, buffer); + } while (buffer[0x1F] == 8); + } + D_800A82CF = arg0; + __osContRamWrite(&gSIEventMesgQueue, 3, 0x600, buffer, 1); + Cont_NoBlockEepromQueue(); +}