From 45354a149b134ad745224818d8394bb2a4e7410b Mon Sep 17 00:00:00 2001 From: Tyler McGavran Date: Mon, 18 Apr 2022 10:04:46 -0400 Subject: [PATCH] Mostly match a few functions in memory.c (#178) * Match a few functions in memory.c Signed-off-by: Taggerung --- asm/non_matchings/memory/func_802ABD10.s | 13 ----- asm/non_matchings/memory/func_802ABD40.s | 16 ------ asm/non_matchings/memory/func_802ABD7C.s | 16 ------ asm/non_matchings/memory/func_802ABDB8.s | 16 ------ asm/non_matchings/memory/func_802ABDF4.s | 16 ------ asm/non_matchings/memory/func_802ABE30.s | 34 ------------ include/variables.h | 2 +- src/memory.c | 69 +++++++----------------- src/memory.h | 6 +++ 9 files changed, 27 insertions(+), 161 deletions(-) delete mode 100644 asm/non_matchings/memory/func_802ABD10.s delete mode 100644 asm/non_matchings/memory/func_802ABD40.s delete mode 100644 asm/non_matchings/memory/func_802ABD7C.s delete mode 100644 asm/non_matchings/memory/func_802ABDB8.s delete mode 100644 asm/non_matchings/memory/func_802ABDF4.s delete mode 100644 asm/non_matchings/memory/func_802ABE30.s diff --git a/asm/non_matchings/memory/func_802ABD10.s b/asm/non_matchings/memory/func_802ABD10.s deleted file mode 100644 index 9623a1e1d..000000000 --- a/asm/non_matchings/memory/func_802ABD10.s +++ /dev/null @@ -1,13 +0,0 @@ -glabel func_802ABD10 -/* 115320 802ABD10 308EFFFF */ andi $t6, $a0, 0xffff -/* 115324 802ABD14 000E7880 */ sll $t7, $t6, 2 -/* 115328 802ABD18 01EE7823 */ subu $t7, $t7, $t6 -/* 11532C 802ABD1C 3C188016 */ lui $t8, %hi(D_8015F580) # $t8, 0x8016 -/* 115330 802ABD20 8F18F580 */ lw $t8, %lo(D_8015F580)($t8) -/* 115334 802ABD24 000F7880 */ sll $t7, $t7, 2 -/* 115338 802ABD28 01EE7823 */ subu $t7, $t7, $t6 -/* 11533C 802ABD2C 000F7880 */ sll $t7, $t7, 2 -/* 115340 802ABD30 AFA40000 */ sw $a0, ($sp) -/* 115344 802ABD34 01F81821 */ addu $v1, $t7, $t8 -/* 115348 802ABD38 03E00008 */ jr $ra -/* 11534C 802ABD3C 80620003 */ lb $v0, 3($v1) diff --git a/asm/non_matchings/memory/func_802ABD40.s b/asm/non_matchings/memory/func_802ABD40.s deleted file mode 100644 index 464df3c3a..000000000 --- a/asm/non_matchings/memory/func_802ABD40.s +++ /dev/null @@ -1,16 +0,0 @@ -glabel func_802ABD40 -/* 115350 802ABD40 308EFFFF */ andi $t6, $a0, 0xffff -/* 115354 802ABD44 000E7880 */ sll $t7, $t6, 2 -/* 115358 802ABD48 01EE7823 */ subu $t7, $t7, $t6 -/* 11535C 802ABD4C 3C188016 */ lui $t8, %hi(D_8015F580) # $t8, 0x8016 -/* 115360 802ABD50 8F18F580 */ lw $t8, %lo(D_8015F580)($t8) -/* 115364 802ABD54 000F7880 */ sll $t7, $t7, 2 -/* 115368 802ABD58 01EE7823 */ subu $t7, $t7, $t6 -/* 11536C 802ABD5C 000F7880 */ sll $t7, $t7, 2 -/* 115370 802ABD60 AFA40000 */ sw $a0, ($sp) -/* 115374 802ABD64 01F81821 */ addu $v1, $t7, $t8 -/* 115378 802ABD68 94620000 */ lhu $v0, ($v1) -/* 11537C 802ABD6C 305900FF */ andi $t9, $v0, 0xff -/* 115380 802ABD70 00194400 */ sll $t0, $t9, 0x10 -/* 115384 802ABD74 03E00008 */ jr $ra -/* 115388 802ABD78 00081403 */ sra $v0, $t0, 0x10 diff --git a/asm/non_matchings/memory/func_802ABD7C.s b/asm/non_matchings/memory/func_802ABD7C.s deleted file mode 100644 index b712dbe7f..000000000 --- a/asm/non_matchings/memory/func_802ABD7C.s +++ /dev/null @@ -1,16 +0,0 @@ -glabel func_802ABD7C -/* 11538C 802ABD7C 308EFFFF */ andi $t6, $a0, 0xffff -/* 115390 802ABD80 000E7880 */ sll $t7, $t6, 2 -/* 115394 802ABD84 01EE7823 */ subu $t7, $t7, $t6 -/* 115398 802ABD88 3C188016 */ lui $t8, %hi(D_8015F580) # $t8, 0x8016 -/* 11539C 802ABD8C 8F18F580 */ lw $t8, %lo(D_8015F580)($t8) -/* 1153A0 802ABD90 000F7880 */ sll $t7, $t7, 2 -/* 1153A4 802ABD94 01EE7823 */ subu $t7, $t7, $t6 -/* 1153A8 802ABD98 000F7880 */ sll $t7, $t7, 2 -/* 1153AC 802ABD9C AFA40000 */ sw $a0, ($sp) -/* 1153B0 802ABDA0 01F81821 */ addu $v1, $t7, $t8 -/* 1153B4 802ABDA4 94620000 */ lhu $v0, ($v1) -/* 1153B8 802ABDA8 30591000 */ andi $t9, $v0, 0x1000 -/* 1153BC 802ABDAC 00194400 */ sll $t0, $t9, 0x10 -/* 1153C0 802ABDB0 03E00008 */ jr $ra -/* 1153C4 802ABDB4 00081403 */ sra $v0, $t0, 0x10 diff --git a/asm/non_matchings/memory/func_802ABDB8.s b/asm/non_matchings/memory/func_802ABDB8.s deleted file mode 100644 index 5b138787d..000000000 --- a/asm/non_matchings/memory/func_802ABDB8.s +++ /dev/null @@ -1,16 +0,0 @@ -glabel func_802ABDB8 -/* 1153C8 802ABDB8 308EFFFF */ andi $t6, $a0, 0xffff -/* 1153CC 802ABDBC 000E7880 */ sll $t7, $t6, 2 -/* 1153D0 802ABDC0 01EE7823 */ subu $t7, $t7, $t6 -/* 1153D4 802ABDC4 3C188016 */ lui $t8, %hi(D_8015F580) # $t8, 0x8016 -/* 1153D8 802ABDC8 8F18F580 */ lw $t8, %lo(D_8015F580)($t8) -/* 1153DC 802ABDCC 000F7880 */ sll $t7, $t7, 2 -/* 1153E0 802ABDD0 01EE7823 */ subu $t7, $t7, $t6 -/* 1153E4 802ABDD4 000F7880 */ sll $t7, $t7, 2 -/* 1153E8 802ABDD8 AFA40000 */ sw $a0, ($sp) -/* 1153EC 802ABDDC 01F81821 */ addu $v1, $t7, $t8 -/* 1153F0 802ABDE0 94620000 */ lhu $v0, ($v1) -/* 1153F4 802ABDE4 30590400 */ andi $t9, $v0, 0x400 -/* 1153F8 802ABDE8 00194400 */ sll $t0, $t9, 0x10 -/* 1153FC 802ABDEC 03E00008 */ jr $ra -/* 115400 802ABDF0 00081403 */ sra $v0, $t0, 0x10 diff --git a/asm/non_matchings/memory/func_802ABDF4.s b/asm/non_matchings/memory/func_802ABDF4.s deleted file mode 100644 index 6cd3f164c..000000000 --- a/asm/non_matchings/memory/func_802ABDF4.s +++ /dev/null @@ -1,16 +0,0 @@ -glabel func_802ABDF4 -/* 115404 802ABDF4 308EFFFF */ andi $t6, $a0, 0xffff -/* 115408 802ABDF8 000E7880 */ sll $t7, $t6, 2 -/* 11540C 802ABDFC 01EE7823 */ subu $t7, $t7, $t6 -/* 115410 802ABE00 3C188016 */ lui $t8, %hi(D_8015F580) # $t8, 0x8016 -/* 115414 802ABE04 8F18F580 */ lw $t8, %lo(D_8015F580)($t8) -/* 115418 802ABE08 000F7880 */ sll $t7, $t7, 2 -/* 11541C 802ABE0C 01EE7823 */ subu $t7, $t7, $t6 -/* 115420 802ABE10 000F7880 */ sll $t7, $t7, 2 -/* 115424 802ABE14 AFA40000 */ sw $a0, ($sp) -/* 115428 802ABE18 01F81821 */ addu $v1, $t7, $t8 -/* 11542C 802ABE1C 94620000 */ lhu $v0, ($v1) -/* 115430 802ABE20 30590800 */ andi $t9, $v0, 0x800 -/* 115434 802ABE24 00194400 */ sll $t0, $t9, 0x10 -/* 115438 802ABE28 03E00008 */ jr $ra -/* 11543C 802ABE2C 00081403 */ sra $v0, $t0, 0x10 diff --git a/asm/non_matchings/memory/func_802ABE30.s b/asm/non_matchings/memory/func_802ABE30.s deleted file mode 100644 index 77d3ada8f..000000000 --- a/asm/non_matchings/memory/func_802ABE30.s +++ /dev/null @@ -1,34 +0,0 @@ -glabel func_802ABE30 -/* 115440 802ABE30 30EEFFFF */ andi $t6, $a3, 0xffff -/* 115444 802ABE34 000E7880 */ sll $t7, $t6, 2 -/* 115448 802ABE38 01EE7823 */ subu $t7, $t7, $t6 -/* 11544C 802ABE3C 3C188016 */ lui $t8, %hi(D_8015F580) # $t8, 0x8016 -/* 115450 802ABE40 8F18F580 */ lw $t8, %lo(D_8015F580)($t8) -/* 115454 802ABE44 000F7880 */ sll $t7, $t7, 2 -/* 115458 802ABE48 01EE7823 */ subu $t7, $t7, $t6 -/* 11545C 802ABE4C 000F7880 */ sll $t7, $t7, 2 -/* 115460 802ABE50 AFA60008 */ sw $a2, 8($sp) -/* 115464 802ABE54 AFA7000C */ sw $a3, 0xc($sp) -/* 115468 802ABE58 01F81021 */ addu $v0, $t7, $t8 -/* 11546C 802ABE5C C4420020 */ lwc1 $f2, 0x20($v0) -/* 115470 802ABE60 44802000 */ mtc1 $zero, $f4 -/* 115474 802ABE64 C7A80008 */ lwc1 $f8, 8($sp) -/* 115478 802ABE68 46022032 */ c.eq.s $f4, $f2 -/* 11547C 802ABE6C 00000000 */ nop -/* 115480 802ABE70 45020004 */ bc1fl .L802ABE84 -/* 115484 802ABE74 C4460024 */ lwc1 $f6, 0x24($v0) -/* 115488 802ABE78 03E00008 */ jr $ra -/* 11548C 802ABE7C 46007006 */ mov.s $f0, $f14 - -/* 115490 802ABE80 C4460024 */ lwc1 $f6, 0x24($v0) -.L802ABE84: -/* 115494 802ABE84 C450001C */ lwc1 $f16, 0x1c($v0) -/* 115498 802ABE88 46083282 */ mul.s $f10, $f6, $f8 -/* 11549C 802ABE8C C4460028 */ lwc1 $f6, 0x28($v0) -/* 1154A0 802ABE90 460C8482 */ mul.s $f18, $f16, $f12 -/* 1154A4 802ABE94 46001407 */ neg.s $f16, $f2 -/* 1154A8 802ABE98 460A9100 */ add.s $f4, $f18, $f10 -/* 1154AC 802ABE9C 46062200 */ add.s $f8, $f4, $f6 -/* 1154B0 802ABEA0 46104003 */ div.s $f0, $f8, $f16 -/* 1154B4 802ABEA4 03E00008 */ jr $ra -/* 1154B8 802ABEA8 00000000 */ nop diff --git a/include/variables.h b/include/variables.h index a0de621ad..dcdae9e49 100644 --- a/include/variables.h +++ b/include/variables.h @@ -101,7 +101,7 @@ extern struct_D_802BFB80 D_802BFB80[][8]; extern struct GfxPool *gGfxPool; // D_8014EF40 -extern mk64_surface_map_ram (*D_8015F580)[]; // Pointer to a list of surface_map entries +extern mk64_surface_map_ram *D_8015F580; // This is techinally a pointer to an array, but declaring it as such create regalloc issues elsewhere extern u16 D_8015F588; // Number of entires in D_8015F580 extern Vec3f D_80165070[]; diff --git a/src/memory.c b/src/memory.c index 8358bbc3d..96b174178 100644 --- a/src/memory.c +++ b/src/memory.c @@ -9,6 +9,7 @@ //#include "game_init.h" #include "main.h" #include "memory.h" +#include "variables.h" //#include "segment_symbols.h" //#include "segments.h" @@ -44,7 +45,6 @@ extern s32 gPrevMainThreadTask; extern Gfx *gDisplayListHead; extern u32 D_8015F724; extern u32 gHeapEndPtr; -extern u32 gIsMirrorMode; extern struct D_80150158 gD_80150158[]; @@ -2445,67 +2445,38 @@ block_10: GLOBAL_ASM("asm/non_matchings/memory/func_802ABB04.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -s8 func_802ABD10(s32 arg0) { - return (((arg0 & 0xFFFF) * 0x2C) + D_8015F580)->unk3; +s8 func_802ABD10(u16 arg0) { + mk64_surface_map_ram *tile = &D_8015F580[arg0]; + return tile->surfaceType; } -#else -GLOBAL_ASM("asm/non_matchings/memory/func_802ABD10.s") -#endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -s16 func_802ABD40(s32 arg0) { - return *(((arg0 & 0xFFFF) * 0x2C) + D_8015F580) & 0xFF; +s16 func_802ABD40(u16 arg0) { + mk64_surface_map_ram *tile = &D_8015F580[arg0]; + return tile->flags & 0xFF; } -#else -GLOBAL_ASM("asm/non_matchings/memory/func_802ABD40.s") -#endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -s16 func_802ABD7C(s32 arg0) { - return *(((arg0 & 0xFFFF) * 0x2C) + D_8015F580) & 0x1000; +s16 func_802ABD7C(u16 arg0) { + mk64_surface_map_ram *tile = &D_8015F580[arg0]; + return tile->flags & 0x1000; } -#else -GLOBAL_ASM("asm/non_matchings/memory/func_802ABD7C.s") -#endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -s16 func_802ABDB8(s32 arg0) { - return *(((arg0 & 0xFFFF) * 0x2C) + D_8015F580) & 0x400; +s16 func_802ABDB8(u16 arg0) { + mk64_surface_map_ram *tile = &D_8015F580[arg0]; + return tile->flags & 0x400; } -#else -GLOBAL_ASM("asm/non_matchings/memory/func_802ABDB8.s") -#endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -s16 func_802ABDF4(s32 arg0) { - return *(((arg0 & 0xFFFF) * 0x2C) + D_8015F580) & 0x800; +s16 func_802ABDF4(u16 arg0) { + mk64_surface_map_ram *tile = &D_8015F580[arg0]; + return tile->flags & 0x800; } -#else -GLOBAL_ASM("asm/non_matchings/memory/func_802ABDF4.s") -#endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 792017ad9d422c2467bd42686f383a5c41f41c75 -f32 func_802ABE30(f32 arg0, f32 arg1, f32 arg2, s32 arg3) { - f32 temp_f2; - mk64_surface_map_ram *temp_v0; - - temp_v0 = &(*D_8015F580)[arg3 & 0xFFFF]; - temp_f2 = temp_v0->gravity; - if (temp_f2 == 0.0f) { +f32 func_802ABE30(f32 arg0, f32 arg1, f32 arg2, u16 arg3) { + mk64_surface_map_ram *tile = &D_8015F580[arg3]; + if (tile->gravity == 0.0f) { return arg1; } - return ((temp_v0->height * arg0) + (temp_v0->rotation * arg2) + temp_v0->height2) / -temp_f2; + return ((tile->height * arg0) + (tile->rotation * arg2) + tile->height2) / -tile->gravity; } -#else -GLOBAL_ASM("asm/non_matchings/memory/func_802ABE30.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 diff --git a/src/memory.h b/src/memory.h index bac6864ba..0738fec11 100644 --- a/src/memory.h +++ b/src/memory.h @@ -11,6 +11,12 @@ s32 func_802A7B70(s32 segment); uintptr_t set_segment_base_addr(s32 segment, void *addr); void *get_segment_base_addr(s32 segment); s32 lookup_item(u32 segment); +s8 func_802ABD10(u16); +s16 func_802ABD40(u16); +s16 func_802ABD7C(u16); +s16 func_802ABDB8(u16); +s16 func_802ABDF4(u16); +f32 func_802ABE30(f32, f32, f32, u16); struct AllocOnlyPool { s32 totalSpace;