From b0f31ab0f746a459cc8f6051f2181171083a2941 Mon Sep 17 00:00:00 2001 From: Maide Date: Mon, 12 Aug 2024 01:56:15 +0100 Subject: [PATCH] 6BC0 --- include/macros.h | 1 + include/variables.h | 8 ++ src/6BC0.c | 200 +++++++++++++++++++++++++++++++++--- src/6BC0.h | 26 ++++- src/dp_intro.c | 4 +- src/fragments/6/fragment6.c | 1 + src/libleo/leodiskinit.c | 2 +- src/main.c | 1 + src/stage_loader.c | 8 +- yamls/us/rom.yaml | 3 +- 10 files changed, 231 insertions(+), 23 deletions(-) diff --git a/include/macros.h b/include/macros.h index 5feab756..9ce74973 100644 --- a/include/macros.h +++ b/include/macros.h @@ -35,5 +35,6 @@ #define ALIGN4(val) (((val) + 0x3) & ~0x3) #define ALIGN8(val) (((val) + 0x7) & ~0x7) #define ALIGN16(val) (((val) + 0xF) & ~0xF) +#define ALIGN64(val) (((val) + 0x3F) & ~0x3F) #endif diff --git a/include/variables.h b/include/variables.h index c4d7dcac..03956b93 100644 --- a/include/variables.h +++ b/include/variables.h @@ -79,4 +79,12 @@ extern unk_func_80007444* D_800A7464; extern Gfx* D_800A74B0; +typedef struct unk_D_800A7440 { + /* 0x00 */ s16 x1; + /* 0x02 */ s16 y1; + /* 0x04 */ s16 x2; + /* 0x06 */ s16 y2; +} unk_D_800A7440; // size >= 0x8 +extern unk_D_800A7440 D_800A7440; + #endif diff --git a/src/6BC0.c b/src/6BC0.c index 27ad9ce8..67374e86 100644 --- a/src/6BC0.c +++ b/src/6BC0.c @@ -1,28 +1,202 @@ #include "global.h" #include "6BC0.h" +#include "memory.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/6BC0/func_80005FC0.s") +static unk_D_80068BB0* D_80068BB0 = NULL; -#pragma GLOBAL_ASM("asm/us/nonmatchings/6BC0/func_80006030.s") +unk_D_800A7440* func_80005FC0(unk_D_800A7440* arg0, s16 x1, s16 y1, s16 x2, s16 y2) { + if (x2 >= x1) { + arg0->x1 = x1; + arg0->y1 = x2; + } else { + arg0->x1 = x2; + arg0->y1 = x1; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/6BC0/func_800060E0.s") + if (y2 >= y1) { + arg0->x2 = y2; + arg0->y2 = y1; + } else { + arg0->y2 = y2; + arg0->x2 = y1; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/6BC0/func_80006200.s") + return arg0; +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/6BC0/func_800062E4.s") +s32 func_80006030(unk_D_800A7440* arg0) { + s32 ret = 0; -#pragma GLOBAL_ASM("asm/us/nonmatchings/6BC0/func_80006314.s") + if (D_80068BB0 != NULL) { + if (arg0->x1 < D_800A7440.x1) { + arg0->x1 = D_800A7440.x1; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/6BC0/func_80006414.s") + if (D_800A7440.y1 < arg0->y1) { + arg0->y1 = D_800A7440.y1; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/6BC0/func_80006450.s") + if (arg0->y2 < D_800A7440.y2) { + arg0->y2 = D_800A7440.y2; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/6BC0/func_8000648C.s") + if (D_800A7440.x2 < arg0->x2) { + arg0->x2 = D_800A7440.x2; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/6BC0/func_80006498.s") + ret = arg0->y1 >= arg0->x1 && arg0->x2 >= arg0->y2; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/6BC0/func_800065B4.s") + return ret; +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/6BC0/func_800067E4.s") +void func_800060E0(Gfx** gfx_p, s16 x, s16 y, s16 width, s16 height) { + if (D_80068BB0 != NULL) { + Gfx* gfx = *gfx_p; -#pragma GLOBAL_ASM("asm/us/nonmatchings/6BC0/func_8000699C.s") + gDPPipeSync(gfx++); + gDPSetScissorFrac(gfx++, G_SC_NON_INTERLACE, (x * 4.0f), (y * 4.0f), (x + width) * 4.0f, (y + height) * 4.0f); + + *gfx_p = gfx; + + func_80005FC0(&D_800A7440, x, y, x + width - 1, y + height - 1); + } +} + +void func_80006200(Gfx** gfx_p) { + if (D_80068BB0 != NULL) { + Gfx* gfx = *gfx_p; + + gDPPipeSync(gfx++); + gDPSetScissorFrac(gfx++, G_SC_NON_INTERLACE, D_800A7440.x1 * 4.0f, D_800A7440.y2 * 4.0f, + (D_800A7440.y1 + 1) * 4.0f, (D_800A7440.x2 + 1) * 4.0f); + + *gfx_p = gfx; + } +} + +void func_800062E4(unk_D_80068BB0* arg0, s32 fmt, s32 size, s32 width, s32 height, u32 img_p) { + arg0->fmt = fmt; + arg0->size = size; + arg0->width = width; + arg0->height = height; + arg0->img_p = (u8*)ALIGN64(img_p); + arg0->depth_p = NULL; +} + +unk_D_80068BB0* func_80006314(s32 fmt, s32 size, s32 width, s32 height, s32 side) { + unk_D_80068BB0* sp34; + s32 size_bytes; + s32 num_pixels = width * height; + + switch (size) { + case IMAGE_SIZE_BITS_4b: + size_bytes = (num_pixels + 1) / 2; + break; + + case IMAGE_SIZE_BITS_8b: + size_bytes = num_pixels; + break; + + case IMAGE_SIZE_BITS_16b: + size_bytes = num_pixels * 2; + break; + + case IMAGE_SIZE_BITS_32b: + size_bytes = num_pixels * 4; + break; + } + + sp34 = main_pool_alloc(size_bytes + sizeof(unk_D_80068BB0), side); + if (sp34 != NULL) { + // image data follows the header struct + func_800062E4(sp34, fmt, size, width, height, sp34->unk_10); + } + + return sp34; +} + +void func_80006414(unk_D_80068BB0* img, unk_D_80068BB0* depth) { + if ((depth->size == IMAGE_SIZE_BITS_16b) && (img->width == depth->width) && (img->height == depth->height)) { + img->depth_p = depth; + } +} + +void func_80006450(void) { + D_80068BB0 = NULL; + func_80005FC0(&D_800A7440, 0, 0, 0, 0); +} + +unk_D_80068BB0* func_8000648C(void) { + return D_80068BB0; +} + +void func_80006498(Gfx** gfx_p, unk_D_80068BB0* arg1) { + Gfx* gfx = *gfx_p; + + gDPPipeSync(gfx++); + + if (arg1->depth_p != NULL) { + gDPSetDepthSource(gfx++, G_ZS_PIXEL); + gDPSetDepthImage(gfx++, (u32)arg1->depth_p->img_p & 0x1FFFFFFF); + } + + gDPSetColorImage(gfx++, arg1->fmt, arg1->size, arg1->width, (u32)arg1->img_p & 0x1FFFFFFF); + + D_80068BB0 = arg1; + func_800060E0(&gfx, 0, 0, arg1->width, arg1->height); + + *gfx_p = gfx; +} + +void func_800065B4(Gfx** gfx_p, s32 arg1, s32 arg2, s32 arg3, s32 arg4, u16 fill_colour) { + if (D_80068BB0 != NULL) { + Gfx* gfx = *gfx_p; + + gDPPipeSync(gfx++); + gDPSetRenderMode(gfx++, G_RM_OPA_SURF, G_RM_OPA_SURF2); + gDPSetCycleType(gfx++, G_CYC_FILL); + + if (D_80068BB0->depth_p) { + unk_D_80068BB0* depth = D_80068BB0->depth_p; + + gDPSetColorImage(gfx++, depth->fmt, depth->size, depth->width, (u32)depth->img_p & 0x1FFFFFFF); + gDPSetFillColor(gfx++, 0xFFFCFFFC); + gDPFillRectangle(gfx++, arg1, arg2, (arg1 + arg3) - 1, (arg2 + arg4) - 1); + gDPPipeSync(gfx++); + gDPSetColorImage(gfx++, D_80068BB0->fmt, D_80068BB0->size, D_80068BB0->width, + (u32)D_80068BB0->img_p & 0x1FFFFFFF); + } + + gDPPipeSync(gfx++); + gDPSetFillColor(gfx++, (fill_colour << 0x10) | fill_colour); + gDPFillRectangle(gfx++, arg1, arg2, (arg1 + arg3) - 1, (arg2 + arg4) - 1); + + *gfx_p = gfx; + } +} + +void func_800067E4(Gfx** gfx_p, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { + if (D_80068BB0 != NULL && D_80068BB0->depth_p != NULL) { + Gfx* gfx = *gfx_p; + unk_D_80068BB0* depth = D_80068BB0->depth_p; + + gDPPipeSync(gfx++); + gDPSetRenderMode(gfx++, G_RM_OPA_SURF, G_RM_OPA_SURF2); + gDPSetCycleType(gfx++, G_CYC_FILL); + gDPSetColorImage(gfx++, depth->fmt, depth->size, depth->width, (u32)depth->img_p & 0x1FFFFFFF); + + gDPSetFillColor(gfx++, 0xFFFCFFFC); + gDPFillRectangle(gfx++, arg1, arg2, (arg1 + arg3) - 1, (arg2 + arg4) - 1); + + gDPPipeSync(gfx++); + gDPSetColorImage(gfx++, D_80068BB0->fmt, D_80068BB0->size, D_80068BB0->width, + (u32)D_80068BB0->img_p & 0x1FFFFFFF); + + *gfx_p = gfx; + } +} + +void func_8000699C(Gfx** gfx_p, u16 fill_colour) { + func_800065B4(gfx_p, 0, 0, D_80068BB0->width, D_80068BB0->height, (fill_colour << 0x10) | fill_colour); +} diff --git a/src/6BC0.h b/src/6BC0.h index d997b67a..c4dc6aa8 100644 --- a/src/6BC0.h +++ b/src/6BC0.h @@ -3,11 +3,29 @@ #include "global.h" -void func_800060E0(Gfx**, s32, s32, s16, s16); -void* func_80006314(s32, s32, s32, s32, s32); -void func_80006414(void*, void*); +// image size in bits +typedef enum IMAGE_SIZE_BITS { + IMAGE_SIZE_BITS_4b, + IMAGE_SIZE_BITS_8b, + IMAGE_SIZE_BITS_16b, + IMAGE_SIZE_BITS_32b, +} IMAGE_SIZE_BITS; + +typedef struct unk_D_80068BB0 { + /* 0x00 */ u16 fmt; + /* 0x02 */ u16 size; + /* 0x04 */ u16 width; + /* 0x06 */ u16 height; + /* 0x08 */ u8* img_p; + /* 0x0C */ struct unk_D_80068BB0* depth_p; + /* 0x10 */ char unk_10[0x40]; +} unk_D_80068BB0; // size = 0x50 + +void func_800060E0(Gfx**, s16, s16, s16, s16); +unk_D_80068BB0* func_80006314(s32 fmt, s32 size, s32 width, s32 height, s32 side); +void func_80006414(unk_D_80068BB0*, unk_D_80068BB0*); void func_80006450(void); -void func_80006498(Gfx**, void*); +void func_80006498(Gfx**, unk_D_80068BB0*); void func_800067E4(Gfx**, s32, s32, s32, s32); diff --git a/src/dp_intro.c b/src/dp_intro.c index d6e52838..52f23390 100644 --- a/src/dp_intro.c +++ b/src/dp_intro.c @@ -2,8 +2,10 @@ #include #include "global.h" #include "dp_intro.h" +#include "6BC0.h" #include "crash_screen.h" #include "profiler.h" +#include "memory.h" // dp_intro.c @@ -266,7 +268,7 @@ void func_800019C8(void) { osCreateMesgQueue(&D_800846A4, &D_80084688, 1); D_80083CA0.unkA88 = 0; D_80083CA0.unkA8A = 0; - D_80084680[0] = func_80006314(0, 2, 0x280, 1, 1); + D_80084680[0] = func_80006314(0, IMAGE_SIZE_BITS_16b, 0x280, 1, MEMORY_POOL_RIGHT); func_80001AD4(1); func_80003B30(&D_80084760, 0xB0000B70, 0xB0000C70, 0); } diff --git a/src/fragments/6/fragment6.c b/src/fragments/6/fragment6.c index 06a51536..b20c5319 100644 --- a/src/fragments/6/fragment6.c +++ b/src/fragments/6/fragment6.c @@ -483,6 +483,7 @@ void func_86000020(void) { } } #else +void func_86000020(void); #pragma GLOBAL_ASM("asm/us/nonmatchings/fragments/6/fragment6/func_86000020.s") #endif diff --git a/src/libleo/leodiskinit.c b/src/libleo/leodiskinit.c index 7a479bde..6b6b1799 100644 --- a/src/libleo/leodiskinit.c +++ b/src/libleo/leodiskinit.c @@ -19,7 +19,7 @@ OSPiHandle* osLeoDiskInit(void) { __LeoDiskHandle.speed = 0; bzero(&__LeoDiskHandle.transferInfo, sizeof(__OSTranxInfo)); - + saveMask = __osDisableInt(); __LeoDiskHandle.next = __osPiTable; __osPiTable = &__LeoDiskHandle; diff --git a/src/main.c b/src/main.c index 508985dc..978e50c5 100644 --- a/src/main.c +++ b/src/main.c @@ -3,6 +3,7 @@ #include "crash_screen.h" #include "rsp.h" #include "reset.h" +#include "util.h" extern void func_8002B330(); // thread 6 function diff --git a/src/stage_loader.c b/src/stage_loader.c index 82161020..683b6359 100644 --- a/src/stage_loader.c +++ b/src/stage_loader.c @@ -395,7 +395,7 @@ void func_80007304(void) { } unk_func_80007444* func_80007444(s8 arg0, s8 arg1, s8 arg2, s8 arg3, s8 arg4, s32 arg5) { - unk_func_80007444* temp_v0 = main_pool_alloc(0x24, 0); + unk_func_80007444* temp_v0 = main_pool_alloc(sizeof(unk_func_80007444), 0); if (temp_v0 != NULL) { if (arg0 == 1) { @@ -425,11 +425,13 @@ unk_func_80007444* func_80007444(s8 arg0, s8 arg1, s8 arg2, s8 arg3, s8 arg4, s3 s32 i; for (i = 0; i < temp_v0->unk_0E; i++) { - temp_v0->unk_18[i] = func_80006314(0, 2, temp_v0->unk_00, temp_v0->unk_02, 1); + temp_v0->unk_18[i] = + func_80006314(0, IMAGE_SIZE_BITS_16b, temp_v0->unk_00, temp_v0->unk_02, MEMORY_POOL_RIGHT); } if (temp_v0->unk_0F == 1) { - void* temp_s3 = func_80006314(0, 2, temp_v0->unk_00, temp_v0->unk_02, 0); + void* temp_s3 = + func_80006314(0, IMAGE_SIZE_BITS_16b, temp_v0->unk_00, temp_v0->unk_02, MEMORY_POOL_LEFT); for (i = 0; i < temp_v0->unk_0E; i++) { func_80006414(temp_v0->unk_18[i], temp_s3); diff --git a/yamls/us/rom.yaml b/yamls/us/rom.yaml index 2ee1f1f3..d43603b9 100644 --- a/yamls/us/rom.yaml +++ b/yamls/us/rom.yaml @@ -33,7 +33,7 @@ - [0x60A0, c, reset] # soft reset effect - [0x6430, c, controller] # controller code - [0x6A40, c] - - [0x6BC0, c] # + - [0x6BC0, c, 6BC0] # - [0x75F0, c, stage_loader] # stage loader - [0x8EB0, c] # empty file/padding? - [0x8EC0, c, crash_screen] # crash handler @@ -323,6 +323,7 @@ # .data is somewhere in here - [0x69790, .data, util] - [0x697A0, bin, rom_data_697A0] + - [0x697B0, .data, 6BC0] - [0x697C0, .data, stage_loader] - [0x6A1B0, .data, crash_screen] - [0x6A3B0, .data, profiler]