From 705fb6d91579ca6661869ff14a58f7b4145c4104 Mon Sep 17 00:00:00 2001 From: Matthew <25674682+spazzylemons@users.noreply.github.com> Date: Wed, 3 Apr 2024 13:25:07 -0400 Subject: [PATCH] Match func_8009A374 (#592) * Match func_8009A374 * Clean up func_8009A478 --- .../code_80091750/func_8009A374.s | 73 ----------- src/code_80091750.c | 115 +++++++++--------- 2 files changed, 56 insertions(+), 132 deletions(-) delete mode 100644 asm/non_matchings/code_80091750/func_8009A374.s diff --git a/asm/non_matchings/code_80091750/func_8009A374.s b/asm/non_matchings/code_80091750/func_8009A374.s deleted file mode 100644 index eed400d062..0000000000 --- a/asm/non_matchings/code_80091750/func_8009A374.s +++ /dev/null @@ -1,73 +0,0 @@ -glabel func_8009A374 -/* 09AF74 8009A374 27BDFFD8 */ addiu $sp, $sp, -0x28 -/* 09AF78 8009A378 AFBF0014 */ sw $ra, 0x14($sp) -/* 09AF7C 8009A37C 0C026455 */ jal segmented_to_virtual_dupe_2 -/* 09AF80 8009A380 00000000 */ nop -/* 09AF84 8009A384 3C048019 */ lui $a0, %hi(D_8018DEE0) # $a0, 0x8019 -/* 09AF88 8009A388 2484DEE0 */ addiu $a0, %lo(D_8018DEE0) # addiu $a0, $a0, -0x2120 -/* 09AF8C 8009A38C 8C8E000C */ lw $t6, 0xc($a0) -/* 09AF90 8009A390 00403025 */ move $a2, $v0 -/* 09AF94 8009A394 00002825 */ move $a1, $zero -/* 09AF98 8009A398 11C0000C */ beqz $t6, .L8009A3CC -/* 09AF9C 8009A39C 2419FFFF */ li $t9, -1 -/* 09AFA0 8009A3A0 3C038019 */ lui $v1, %hi(D_8018DEE0) # $v1, 0x8019 -/* 09AFA4 8009A3A4 2463DEE0 */ addiu $v1, %lo(D_8018DEE0) # addiu $v1, $v1, -0x2120 -/* 09AFA8 8009A3A8 24A50001 */ addiu $a1, $a1, 1 -.L8009A3AC: -/* 09AFAC 8009A3AC 28A10010 */ slti $at, $a1, 0x10 -/* 09AFB0 8009A3B0 14200003 */ bnez $at, .L8009A3C0 -/* 09AFB4 8009A3B4 24630018 */ addiu $v1, $v1, 0x18 -.L8009A3B8: -/* 09AFB8 8009A3B8 1000FFFF */ b .L8009A3B8 -/* 09AFBC 8009A3BC 00000000 */ nop -.L8009A3C0: -/* 09AFC0 8009A3C0 8C6F000C */ lw $t7, 0xc($v1) -/* 09AFC4 8009A3C4 55E0FFF9 */ bnel $t7, $zero, .L8009A3AC -/* 09AFC8 8009A3C8 24A50001 */ addiu $a1, $a1, 1 -.L8009A3CC: -/* 09AFCC 8009A3CC 0005C080 */ sll $t8, $a1, 2 -/* 09AFD0 8009A3D0 0305C023 */ subu $t8, $t8, $a1 -/* 09AFD4 8009A3D4 0018C0C0 */ sll $t8, $t8, 3 -/* 09AFD8 8009A3D8 00981821 */ addu $v1, $a0, $t8 -/* 09AFDC 8009A3DC 3C088000 */ lui $t0, 0x8000 -/* 09AFE0 8009A3E0 AC620000 */ sw $v0, ($v1) -/* 09AFE4 8009A3E4 AC790004 */ sw $t9, 4($v1) -/* 09AFE8 8009A3E8 AC600008 */ sw $zero, 8($v1) -/* 09AFEC 8009A3EC AC68000C */ sw $t0, 0xc($v1) -/* 09AFF0 8009A3F0 3C098019 */ lui $t1, %hi(gNumD_8018E118Entries) # $t1, 0x8019 -/* 09AFF4 8009A3F4 8D29E758 */ lw $t1, %lo(gNumD_8018E118Entries)($t1) -/* 09AFF8 8009A3F8 AC690010 */ sw $t1, 0x10($v1) -/* 09AFFC 8009A3FC 8C4A0000 */ lw $t2, ($v0) -/* 09B000 8009A400 5140000A */ beql $t2, $zero, .L8009A42C -/* 09B004 8009A404 8CC40008 */ lw $a0, 8($a2) -/* 09B008 8009A408 8CC40000 */ lw $a0, ($a2) -/* 09B00C 8009A40C AFA60028 */ sw $a2, 0x28($sp) -/* 09B010 8009A410 AFA50024 */ sw $a1, 0x24($sp) -/* 09B014 8009A414 0C0265A7 */ jal func_8009969C -/* 09B018 8009A418 AFA3001C */ sw $v1, 0x1c($sp) -/* 09B01C 8009A41C 8FA3001C */ lw $v1, 0x1c($sp) -/* 09B020 8009A420 8FA50024 */ lw $a1, 0x24($sp) -/* 09B024 8009A424 8FA60028 */ lw $a2, 0x28($sp) -/* 09B028 8009A428 8CC40008 */ lw $a0, 8($a2) -.L8009A42C: -/* 09B02C 8009A42C 50800008 */ beql $a0, $zero, .L8009A450 -/* 09B030 8009A430 8CC40000 */ lw $a0, ($a2) -/* 09B034 8009A434 AFA3001C */ sw $v1, 0x1c($sp) -/* 09B038 8009A438 0C0265A7 */ jal func_8009969C -/* 09B03C 8009A43C AFA50024 */ sw $a1, 0x24($sp) -/* 09B040 8009A440 8FA3001C */ lw $v1, 0x1c($sp) -/* 09B044 8009A444 10000007 */ b .L8009A464 -/* 09B048 8009A448 8FA50024 */ lw $a1, 0x24($sp) -/* 09B04C 8009A44C 8CC40000 */ lw $a0, ($a2) -.L8009A450: -/* 09B050 8009A450 AFA50024 */ sw $a1, 0x24($sp) -/* 09B054 8009A454 0C0265A7 */ jal func_8009969C -/* 09B058 8009A458 AFA3001C */ sw $v1, 0x1c($sp) -/* 09B05C 8009A45C 8FA3001C */ lw $v1, 0x1c($sp) -/* 09B060 8009A460 8FA50024 */ lw $a1, 0x24($sp) -.L8009A464: -/* 09B064 8009A464 8FBF0014 */ lw $ra, 0x14($sp) -/* 09B068 8009A468 AC600014 */ sw $zero, 0x14($v1) -/* 09B06C 8009A46C 27BD0028 */ addiu $sp, $sp, 0x28 -/* 09B070 8009A470 03E00008 */ jr $ra -/* 09B074 8009A474 00A01025 */ move $v0, $a1 diff --git a/src/code_80091750.c b/src/code_80091750.c index 3710418132..9a149cf496 100644 --- a/src/code_80091750.c +++ b/src/code_80091750.c @@ -4647,73 +4647,70 @@ void func_8009A344(void) { } } -#ifdef NON_MATCHING -// https://decomp.me/scratch/BRs75 -// Too much stuff on the stack, but removing the padding -// causes some stack offsets to be wrong :/ -s32 func_8009A374(MkAnimation *arg0) { - s32 stackPadding0; - MkAnimation *temp_v0; - s32 var_a1; - struct_8018DEE0_entry *temp_v1; +s32 func_8009A374(MkAnimation *anim) { + s32 i; + struct_8018DEE0_entry *entry; - temp_v0 = segmented_to_virtual_dupe_2(arg0); - var_a1 = 0; - while (D_8018DEE0[var_a1].visible != 0) { - var_a1++; - if (var_a1 >= 0x10) { - while(TRUE); - } - } - temp_v1 = &D_8018DEE0[var_a1]; - temp_v1->textureSequence = temp_v0; - temp_v1->sequenceIndex = -1; - temp_v1->frameCountDown = 0; - temp_v1->visible = 0x80000000; - temp_v1->D_8018E118_index = gNumD_8018E118Entries; - if (temp_v0->mk64Texture != NULL) { - func_8009969C(temp_v0->mk64Texture); - } - if ((temp_v0 + 1)->mk64Texture != NULL) { - func_8009969C((temp_v0 + 1)->mk64Texture); + anim = segmented_to_virtual_dupe_2(anim); + i = 0; + while (D_8018DEE0[i].visible) { + i++; + if (i >= 0x10) { + // No more space. + while (1); + } + } + + entry = &D_8018DEE0[i]; + entry->textureSequence = anim; + entry->sequenceIndex = -1; + entry->frameCountDown = 0; + entry->visible = 0x80000000; + entry->D_8018E118_index = gNumD_8018E118Entries; + + if (anim[0].mk64Texture) { + func_8009969C(anim[0].mk64Texture); + } + if (anim[1].mk64Texture) { + func_8009969C(anim[1].mk64Texture); } else { - func_8009969C(temp_v0->mk64Texture); + func_8009969C(anim[0].mk64Texture); } - temp_v1->unk14 = 0; - return var_a1; + + entry->unk14 = 0; + return i; } -#else -GLOBAL_ASM("asm/non_matchings/code_80091750/func_8009A374.s") -#endif -s32 func_8009A478(MkAnimation *arg0, s32 arg1) { - s32 var_a1; - MkAnimation *temp_v0; +s32 func_8009A478(MkAnimation* anim, s32 arg1) { + s32 i; + struct_8018DEE0_entry* entry; - temp_v0 = segmented_to_virtual_dupe_2(arg0); - var_a1 = 0; - while (D_8018DEE0[var_a1].visible != 0) { - var_a1++; - if (var_a1 >= 0x10) { - while(TRUE); - } - } - D_8018DEE0[var_a1].textureSequence = temp_v0; - D_8018DEE0[var_a1].sequenceIndex = -1; - D_8018DEE0[var_a1].frameCountDown = 0; - D_8018DEE0[var_a1].visible = 0x80000000; - D_8018DEE0[var_a1].D_8018E118_index = gNumD_8018E118Entries; - if (temp_v0->mk64Texture != NULL) { - func_80099958(temp_v0->mk64Texture, arg1, 0); - } - if ((temp_v0 + 1)->mk64Texture != NULL) { - func_80099958((temp_v0 + 1)->mk64Texture, arg1, 1); + anim = segmented_to_virtual_dupe_2(anim); + i = 0; + while (D_8018DEE0[i].visible) { + i++; + if (i >= 0x10) { + // No more space. + while(1); + } + } + + entry = &D_8018DEE0[i]; + entry->textureSequence = anim; + entry->sequenceIndex = -1; + entry->frameCountDown = 0; + entry->visible = 0x80000000; + entry->D_8018E118_index = gNumD_8018E118Entries; + if (anim[0].mk64Texture) { + func_80099958(anim[0].mk64Texture, arg1, 0); + } + if (anim[1].mk64Texture) { + func_80099958(anim[1].mk64Texture, arg1, 1); } else { - func_80099958(temp_v0->mk64Texture, arg1, 1); + func_80099958(anim[0].mk64Texture, arg1, 1); } - // ????????????????????? - D_8018DEE0[var_a1].unk14 = (temp_v0->mk64Texture != ((void *) 0)) * 0; - return var_a1; + entry->unk14 = 0; + return i; } void func_8009A594(s32 arg0, s32 arg1, MkAnimation *arg2) {