From 20725b8fc23c682ccfc03c03ceca4714b4a3b81b Mon Sep 17 00:00:00 2001 From: farisawan-2000 Date: Tue, 11 Aug 2020 02:36:39 -0400 Subject: [PATCH] some decomp --- asm/non_matchings/ovl0/ovl0_4/func_80018920.s | 2 +- asm/non_matchings/ovl0/ovl0_4/func_80018948.s | 2 +- include/types.h | 15 +++++-- kirby.us.ld | 2 +- src/ovl0/ovl0_4.c | 37 ++++++++--------- src/ovl2/ovl2_8.c | 40 +++++-------------- src/ovl6/ovl6.c | 28 ++++--------- 7 files changed, 49 insertions(+), 77 deletions(-) diff --git a/asm/non_matchings/ovl0/ovl0_4/func_80018920.s b/asm/non_matchings/ovl0/ovl0_4/func_80018920.s index 3992ba33..7184a907 100644 --- a/asm/non_matchings/ovl0/ovl0_4/func_80018920.s +++ b/asm/non_matchings/ovl0/ovl0_4/func_80018920.s @@ -1,4 +1,4 @@ -glabel inv_sinf +glabel cscf /* 019520 80018920 27BDFFE8 */ addiu $sp, $sp, -0x18 /* 019524 80018924 AFBF0014 */ sw $ra, 0x14($sp) /* 019528 80018928 0C00B5B8 */ jal sinf diff --git a/asm/non_matchings/ovl0/ovl0_4/func_80018948.s b/asm/non_matchings/ovl0/ovl0_4/func_80018948.s index 676c02c2..f185c086 100644 --- a/asm/non_matchings/ovl0/ovl0_4/func_80018948.s +++ b/asm/non_matchings/ovl0/ovl0_4/func_80018948.s @@ -1,4 +1,4 @@ -glabel inv_cosf +glabel secf /* 019548 80018948 27BDFFE8 */ addiu $sp, $sp, -0x18 /* 01954C 8001894C AFBF0014 */ sw $ra, 0x14($sp) /* 019550 80018950 0C00D604 */ jal cosf diff --git a/include/types.h b/include/types.h index 1a62dc5f..adc494ef 100644 --- a/include/types.h +++ b/include/types.h @@ -96,14 +96,20 @@ struct KirbyState { u8 unk9; u8 unkA; u8 unkB; - u32 powerupState; // 0xC + s8 powerupState; // 0xC + u8 unkD; + u8 unkE; + u8 unkF; u32 unk10; u8 unk14; u8 unk15; u8 unk16; u8 unk17; - u32 unk18; - u32 floatTimer; + u8 unk18; + u8 unk19; + u8 unk1A; + u8 unk1B; + u32 floatTimer; // 0x1C s32 turnDirection; // 0x20 u32 unk24; u32 unk28; @@ -124,7 +130,8 @@ struct KirbyState { u32 unk60; u16 unk64; u16 unk66; - u32 unk68; + u16 unk68; + u16 unk6A; u32 unk6C; u32 unk70; u32 unk74; diff --git a/kirby.us.ld b/kirby.us.ld index e1225e11..295d72c4 100644 --- a/kirby.us.ld +++ b/kirby.us.ld @@ -48,10 +48,10 @@ SECTIONS BUILD_DIR/src/ovl0/ovl0_8.o(.text); BUILD_DIR/asm/ovl0/ovl0_9.o(.text); BUILD_DIR/asm/ovl0/exception.o(.text); + /*libreultra/build/2.0I/libultra_rom.a:__osDequeueThread.o(.text);*/ BUILD_DIR/asm/ovl0/ovl0_afterException.o(.text); BUILD_DIR/asm/ovl0/lib/osViGetCurrentFramebuffer.o(.text); BUILD_DIR/asm/ovl0/lib/__osSPSetPc.o(.text); - /*libreultra/build/2.0I/libultra.a:*(.text);*/ BUILD_DIR/data/kirby.039DF0.o(.data); } END_SEG(ovl0) diff --git a/src/ovl0/ovl0_4.c b/src/ovl0/ovl0_4.c index 061d39e9..3da22a9d 100644 --- a/src/ovl0/ovl0_4.c +++ b/src/ovl0/ovl0_4.c @@ -8,7 +8,7 @@ extern u8 D_8003DF20[]; extern s32 D_8003DF10, D_8003DF14, D_8003DF18, D_8003DF1C; extern s32 D_8004AB9C; -extern Gfx *gDisplayListHead, *gDisplayListHead2, *gDisplayListHead3, *gDisplayListHead4; +extern Gfx *gDisplayListHeads[4]; void func_80010B20(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { D_8003DF10 = arg0; @@ -249,7 +249,7 @@ void func_80010EF8(s32 arg0, void *arg1, s32 arg2) { temp_f14 = arg1->unk20 - D_8004A7C8->unk3C->unk40; sp44 = temp_f16; sp40 = temp_f14; - temp_f0 = sqrtf((temp_f16 * temp_f16) + (temp_f14 * temp_f14), temp_f14); + temp_f0 = sqrtf((temp_f16 * temp_f16) + (temp_f14 * temp_f14)); temp_cond = temp_f0 == 0.0f; sp50 = 0.0f; sp6C = 0.0f; @@ -324,7 +324,7 @@ void func_8001103C(s32 arg0, void *arg1, s32 arg2) { temp_f16 = arg1->unk24 - D_8004A7C8->unk3C->unk44; sp44 = temp_f14; sp40 = temp_f16; - temp_f0 = sqrtf((temp_f14 * temp_f14) + (temp_f16 * temp_f16), temp_f14); + temp_f0 = sqrtf((temp_f14 * temp_f14) + (temp_f16 * temp_f16)); temp_cond = temp_f0 == 0.0f; sp60 = 0.0f; sp4C = 0.0f; @@ -4299,8 +4299,9 @@ f32 tanf(f32 x) { return sinf(x) / cosf(x); } +extern f32 D_80040C38, D_80040C3C; +extern f32 D_80040C20, D_80040C24, D_80040C28, D_80040C2C, D_80040C30, D_80040C34; #ifdef MIPS_TO_C -//generated by mips_to_c commit e0e006e8858ba357d1dcb4dc64f038b7df278aa6 f32 func_800185E4(f32 arg0) { f32 temp_f0; f32 temp_f2; @@ -4323,16 +4324,12 @@ f32 func_800185E4(f32 arg0) { } temp_f0 = phi_f12 * phi_f12; temp_f2 = ((temp_f0 / ((temp_f0 / ((temp_f0 / ((temp_f0 / ((temp_f0 / ((temp_f0 / D_80040C20) + D_80040C24)) + D_80040C28)) + D_80040C2C)) + D_80040C30)) + D_80040C34)) + 1.0f) * phi_f12; - if (phi_v0 == 0) { - return temp_f2; + switch (phi_v0) { + case 0: return temp_f2; + case 1: return D_80040C38 - temp_f2; + case 2: return D_80040C3C - temp_f2; + default: return temp_f0; } - if (phi_v0 == 1) { - return D_80040C38 - temp_f2; - } - if (phi_v0 != 2) { - return temp_f0; - } - return D_80040C3C - temp_f2; } #else GLOBAL_ASM("asm/non_matchings/ovl0/ovl0_4/func_800185E4.s") @@ -4380,7 +4377,7 @@ GLOBAL_ASM("asm/non_matchings/ovl0/ovl0_4/func_8001870C.s") extern f32 D_80040000; extern f32 D_80040C48, D_80040C4C, D_80040C50, D_80040C54; -extern f32 func_800185E4(f32 a, f32 b); +extern f32 func_800185E4(f32 a); extern f32 sqrtf(f32 a); f32 func_8001880C(f32 arg0) { f32 temp_f10; @@ -4392,7 +4389,7 @@ f32 func_8001880C(f32 arg0) { return D_80040C54; } temp_f10 = arg0 * arg0; - return func_800185E4(arg0 / sqrtf(1.0f - temp_f10), arg0); + return func_800185E4(arg0 / sqrtf(1.0f - temp_f10)); } extern f32 D_80040C64; @@ -4409,18 +4406,18 @@ f32 func_80018890(f32 arg0) { return D_80040C60; } temp_f10 = arg0 * arg0; - return D_80040C64 - func_800185E4(arg0 / sqrtf(1.0f - temp_f10), arg0); + return D_80040C64 - func_800185E4(arg0 / sqrtf(1.0f - temp_f10)); } -f32 inv_sinf(f32 y) { - return 1.0f / sinf(y); +f32 cscf(f32 x) { + return 1.0f / sinf(x); } -f32 inv_cosf(f32 x) { +f32 secf(f32 x) { return 1.0f / cosf(x); } -f32 inv_tanf(f32 x) { +f32 cotf(f32 x) { return 1.0f / tanf(x); } diff --git a/src/ovl2/ovl2_8.c b/src/ovl2/ovl2_8.c index 5cb37c12..8c3cf88e 100644 --- a/src/ovl2/ovl2_8.c +++ b/src/ovl2/ovl2_8.c @@ -1636,44 +1636,26 @@ f32 func_8011E438(void) { GLOBAL_ASM("asm/non_matchings/ovl2_8/func_8011E438.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 09d006c9da5d6bbcd31ac6ca5c9165c1a8533a83 -void *func_8011E4E4(s8 arg0) { - gKirbyState.unk17 = (u8)1; - gKirbyState.unk18 = (u8)1; - gKirbyState.unkC = arg0; - gKirbyState.unk68 = (s16) (u8)1; - return &gKirbyState; +void func_8011E4E4(u32 arg0) { + gKirbyState.unk17 = 1; + gKirbyState.unk18 = 1; + gKirbyState.powerupState = arg0; + gKirbyState.unk68 = 1; } -#else -GLOBAL_ASM("asm/non_matchings/ovl2_8/func_8011E4E4.s") -#endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 09d006c9da5d6bbcd31ac6ca5c9165c1a8533a83 -void *func_8011E504(void) { - gKirbyState.unk17 = (u8)0; - gKirbyState.unk18 = (u8)0; - gKirbyState.unkC = (u8)0; +void func_8011E504(void) { + gKirbyState.unk17 = 0; + gKirbyState.unk18 = 0; + gKirbyState.powerupState = 0; gKirbyState.unk24 = 0; - gKirbyState.unk68 = (u16)0; - return &gKirbyState; + gKirbyState.unk68 = 0; } -#else -GLOBAL_ASM("asm/non_matchings/ovl2_8/func_8011E504.s") -#endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 09d006c9da5d6bbcd31ac6ca5c9165c1a8533a83 -void *func_8011E524(void) { +void func_8011E524(void) { if (gKirbyState.unk16C == 0) { gKirbyState.unk16C = 1; } - return &gKirbyState; } -#else -GLOBAL_ASM("asm/non_matchings/ovl2_8/func_8011E524.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit 09d006c9da5d6bbcd31ac6ca5c9165c1a8533a83 diff --git a/src/ovl6/ovl6.c b/src/ovl6/ovl6.c index d330072a..9d871af2 100644 --- a/src/ovl6/ovl6.c +++ b/src/ovl6/ovl6.c @@ -50,21 +50,17 @@ GLOBAL_ASM("asm/non_matchings/ovl6/func_80151138.s") #endif extern Gfx *gDisplayListHeads[4]; -extern void func_8009E8F4_ovl6(u32 a, Gfx **b); +extern void func_8009E8F4_ovl6(s32 hidden, u32 a, Gfx **b); -#ifdef MIPS_TO_C -void *func_80151204(void) { +void *func_80151204(s32 arg0) { gDPPipeSync(gDisplayListHeads[1]++); gDPSetRenderMode(gDisplayListHeads[1]++, G_RM_ZB_CLD_SURF, G_RM_ZB_CLD_SURF2); - func_8009E8F4_ovl6(2, &gDisplayListHeads[1]); + func_8009E8F4_ovl6(arg0, 2, &gDisplayListHeads[1]); gDPPipeSync(gDisplayListHeads[1]++); gDPSetColorDither(gDisplayListHeads[1]++, G_CD_MAGICSQ); gDPSetAlphaDither(gDisplayListHeads[1]++, G_AD_DISABLE); gDPSetRenderMode(gDisplayListHeads[1]++, G_RM_AA_ZB_XLU_SURF, G_RM_AA_ZB_XLU_SURF2); } -#else -GLOBAL_ASM("asm/non_matchings/ovl6/func_80151204.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit e0e006e8858ba357d1dcb4dc64f038b7df278aa6 @@ -226,25 +222,15 @@ void *func_8015150C(void) { GLOBAL_ASM("asm/non_matchings/ovl6/func_8015150C.s") #endif +extern u32 D_8015A670[]; // Lights? +extern u32 *D_8015A56C; // lights? #ifdef MIPS_TO_C -//generated by mips_to_c commit e0e006e8858ba357d1dcb4dc64f038b7df278aa6 void func_8015166C(Gfx *dl) { - void *temp_v0; - void *temp_v0_2; - void *temp_v0_3; - func_8015150C_ovl6(); func_801514A0_ovl6(D_8015A56C, D_8015A670); gMoveWd(dl++, 2, G_MW_MATRIX, 0x00000018); - - temp_v0_2 = *arg0; - *arg0 = (void *) (temp_v0_2 + 8); - temp_v0_2->unk0 = 0xDC08060A; - temp_v0_2->unk4 = (s32) (D_8015A670 + 8); - temp_v0_3 = *arg0; - *arg0 = (void *) (temp_v0_3 + 8); - temp_v0_3->unk0 = 0xDC08090A; - temp_v0_3->unk4 = (s32) D_8015A670; + gSPLight(dl++, D_8015A670[2], 1); + gSPLight(dl++, D_8015A670[2], 2); } #else GLOBAL_ASM("asm/non_matchings/ovl6/func_8015166C.s")