From 051a7bce318da32811cead4c97495f77fc712627 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 4 Feb 2020 20:53:59 +1000 Subject: [PATCH] Decompile propAllocate --- src/game/game_014f10.c | 2 +- src/game/game_015280.c | 4 +- src/game/game_0601b0.c | 108 +++++++++++++-------------------- src/game/game_066310.c | 16 ++--- src/game/game_097a50.c | 2 +- src/game/game_0b28d0.c | 2 +- src/include/game/game_0601b0.h | 2 +- src/include/gvars/gvars.h | 5 +- src/include/types.h | 2 +- 9 files changed, 61 insertions(+), 82 deletions(-) diff --git a/src/game/game_014f10.c b/src/game/game_014f10.c index 1c27647f4..aea28020b 100644 --- a/src/game/game_014f10.c +++ b/src/game/game_014f10.c @@ -50,7 +50,7 @@ glabel func0f014f10 /* f014f98: 8d44001c */ lw $a0,0x1c($t2) /* f014f9c: 8e2b0000 */ lw $t3,0x0($s1) /* f014fa0: 01706021 */ addu $t4,$t3,$s0 -/* f014fa4: 0fc1810e */ jal func0f060438 +/* f014fa4: 0fc1810e */ jal propFree /* f014fa8: 8d84001c */ lw $a0,0x1c($t4) /* f014fac: 3c038006 */ lui $v1,0x8006 /* f014fb0: 8c63298c */ lw $v1,0x298c($v1) diff --git a/src/game/game_015280.c b/src/game/game_015280.c index 762755923..ea7193422 100644 --- a/src/game/game_015280.c +++ b/src/game/game_015280.c @@ -40,7 +40,7 @@ glabel func0f015280 /* f0152e8: 8d040000 */ lw $a0,0x0($t0) /* f0152ec: 8e290000 */ lw $t1,0x0($s1) /* f0152f0: 01305021 */ addu $t2,$t1,$s0 -/* f0152f4: 0fc1810e */ jal func0f060438 +/* f0152f4: 0fc1810e */ jal propFree /* f0152f8: 8d440000 */ lw $a0,0x0($t2) /* f0152fc: 8e2b0000 */ lw $t3,0x0($s1) /* f015300: 01706021 */ addu $t4,$t3,$s0 @@ -90,7 +90,7 @@ glabel func0f015330 /* f015394: 8d040000 */ lw $a0,0x0($t0) /* f015398: 8e290000 */ lw $t1,0x0($s1) /* f01539c: 01305021 */ addu $t2,$t1,$s0 -/* f0153a0: 0fc1810e */ jal func0f060438 +/* f0153a0: 0fc1810e */ jal propFree /* f0153a4: 8d440000 */ lw $a0,0x0($t2) /* f0153a8: 8e2b0000 */ lw $t3,0x0($s1) /* f0153ac: 3c02800a */ lui $v0,0x800a diff --git a/src/game/game_0601b0.c b/src/game/game_0601b0.c index 5367bcd85..e63237d7b 100644 --- a/src/game/game_0601b0.c +++ b/src/game/game_0601b0.c @@ -318,69 +318,47 @@ glabel func0f060300 /* f060354: 00000000 */ sll $zero,$zero,0x0 ); -GLOBAL_ASM( -glabel propAllocate -/* f060358: 3c04800a */ lui $a0,%hi(g_Vars) -/* f06035c: 24849fc0 */ addiu $a0,$a0,%lo(g_Vars) -/* f060360: 8c820344 */ lw $v0,0x344($a0) -/* f060364: 10400031 */ beqz $v0,.L0f06042c -/* f060368: 00401825 */ or $v1,$v0,$zero -/* f06036c: 8c4e0020 */ lw $t6,0x20($v0) -/* f060370: 240fffff */ addiu $t7,$zero,-1 -/* f060374: 24190002 */ addiu $t9,$zero,0x2 -/* f060378: ac8e0344 */ sw $t6,0x344($a0) -/* f06037c: ac400020 */ sw $zero,0x20($v0) -/* f060380: ac400024 */ sw $zero,0x24($v0) -/* f060384: ac400018 */ sw $zero,0x18($v0) -/* f060388: ac40001c */ sw $zero,0x1c($v0) -/* f06038c: a0400001 */ sb $zero,0x1($v0) -/* f060390: a4400002 */ sh $zero,0x2($v0) -/* f060394: a44f0028 */ sh $t7,0x28($v0) -/* f060398: ac400004 */ sw $zero,0x4($v0) -/* f06039c: 90980359 */ lbu $t8,0x359($a0) -/* f0603a0: 9048003f */ lbu $t0,0x3f($v0) -/* f0603a4: a040003e */ sb $zero,0x3e($v0) -/* f0603a8: a058003d */ sb $t8,0x3d($v0) -/* f0603ac: 350a0080 */ ori $t2,$t0,0x80 -/* f0603b0: 9048003d */ lbu $t0,0x3d($v0) -/* f0603b4: 314c00df */ andi $t4,$t2,0xdf -/* f0603b8: a04a003f */ sb $t2,0x3f($v0) -/* f0603bc: 318e00ef */ andi $t6,$t4,0xef -/* f0603c0: a04c003f */ sb $t4,0x3f($v0) -/* f0603c4: 000848c0 */ sll $t1,$t0,0x3 -/* f0603c8: a04e003f */ sb $t6,0x3f($v0) -/* f0603cc: 31cf00bf */ andi $t7,$t6,0xbf -/* f0603d0: 3418ffff */ dli $t8,0xffff -/* f0603d4: 01284823 */ subu $t1,$t1,$t0 -/* f0603d8: a04f003f */ sb $t7,0x3f($v0) -/* f0603dc: a4580038 */ sh $t8,0x38($v0) -/* f0603e0: a440003a */ sh $zero,0x3a($v0) -/* f0603e4: a059003c */ sb $t9,0x3c($v0) -/* f0603e8: ac400040 */ sw $zero,0x40($v0) -/* f0603ec: ac400044 */ sw $zero,0x44($v0) -/* f0603f0: 00094880 */ sll $t1,$t1,0x2 -/* f0603f4: 00891021 */ addu $v0,$a0,$t1 -/* f0603f8: 944a0360 */ lhu $t2,0x360($v0) -/* f0603fc: 254b0001 */ addiu $t3,$t2,0x1 -/* f060400: a44b0360 */ sh $t3,0x360($v0) -/* f060404: 908c0359 */ lbu $t4,0x359($a0) -/* f060408: 908f0358 */ lbu $t7,0x358($a0) -/* f06040c: 258d0001 */ addiu $t5,$t4,0x1 -/* f060410: 31ae00ff */ andi $t6,$t5,0xff -/* f060414: 01cf082a */ slt $at,$t6,$t7 -/* f060418: 14200002 */ bnez $at,.L0f060424 -/* f06041c: a08d0359 */ sb $t5,0x359($a0) -/* f060420: a0800359 */ sb $zero,0x359($a0) -.L0f060424: -/* f060424: 03e00008 */ jr $ra -/* f060428: 00601025 */ or $v0,$v1,$zero -.L0f06042c: -/* f06042c: 00001025 */ or $v0,$zero,$zero -/* f060430: 03e00008 */ jr $ra -/* f060434: 00000000 */ sll $zero,$zero,0x0 -); +struct prop *propAllocate(void) +{ + struct prop *prop = g_Vars.freeprops; -void func0f060438(struct prop *prop) + if (g_Vars.freeprops) { + g_Vars.freeprops = g_Vars.freeprops->next; + + prop->next = NULL; + prop->prev = NULL; + prop->parent = NULL; + prop->child = NULL; + prop->flags = 0; + prop->timetoregen = 0; + prop->rooms[0] = -1; + prop->chr = NULL; + prop->propstateindex = g_Vars.nextpropstateindex; + prop->unk3e = 0; + prop->unk3f_00 = 1; + prop->unk3f_02 = 0; + prop->unk3f_03 = 0; + prop->unk3f_01 = 0; + prop->unk38 = 0xffff; + prop->unk3a = 0; + prop->unk3c = 2; + prop->unk40 = 0; + prop->unk44 = 0; + g_Vars.propstates[prop->propstateindex].propcount++; + + g_Vars.nextpropstateindex++; + + if (g_Vars.nextpropstateindex >= g_Vars.numpropstateindexes) { + g_Vars.nextpropstateindex = 0; + } + + return prop; + } + + return NULL; +} + +void propFree(struct prop *prop) { if (prop->type == PROPTYPE_CHR) { g_Vars.propstates[prop->propstateindex].chrpropcount--; @@ -388,11 +366,11 @@ void func0f060438(struct prop *prop) g_Vars.propstates[prop->propstateindex].propcount--; } - prop->next = g_Vars.unk000344; + prop->next = g_Vars.freeprops; prop->prev = NULL; prop->chr = NULL; prop->rooms[0] = -1; - g_Vars.unk000344 = prop; + g_Vars.freeprops = prop; } GLOBAL_ASM( @@ -3162,7 +3140,7 @@ glabel func0f062b64 /* f062c18: 02002025 */ or $a0,$s0,$zero /* f062c1c: 0fc180c0 */ jal func0f060300 /* f062c20: 02002025 */ or $a0,$s0,$zero -/* f062c24: 0fc1810e */ jal func0f060438 +/* f062c24: 0fc1810e */ jal propFree /* f062c28: 02002025 */ or $a0,$s0,$zero /* f062c2c: 1000001f */ beqz $zero,.L0f062cac /* f062c30: 8fbf001c */ lw $ra,0x1c($sp) diff --git a/src/game/game_066310.c b/src/game/game_066310.c index 91a2cc099..76d128672 100644 --- a/src/game/game_066310.c +++ b/src/game/game_066310.c @@ -6086,7 +6086,7 @@ glabel func0f06a1ec .L0f06a418: /* f06a418: 10c00004 */ beqz $a2,.L0f06a42c /* f06a41c: 00000000 */ sll $zero,$zero,0x0 -/* f06a420: 0fc1810e */ jal func0f060438 +/* f06a420: 0fc1810e */ jal propFree /* f06a424: 00c02025 */ or $a0,$a2,$zero /* f06a428: 00003025 */ or $a2,$zero,$zero .L0f06a42c: @@ -7155,7 +7155,7 @@ glabel setupParseObject /* f06b314: 8e240014 */ lw $a0,0x14($s1) /* f06b318: 0fc180c0 */ jal func0f060300 /* f06b31c: 8e240014 */ lw $a0,0x14($s1) -/* f06b320: 0fc1810e */ jal func0f060438 +/* f06b320: 0fc1810e */ jal propFree /* f06b324: 8e240014 */ lw $a0,0x14($s1) /* f06b328: 8e380014 */ lw $t8,0x14($s1) .L0f06b32c: @@ -41463,7 +41463,7 @@ glabel chrTryEquipHat .L0f089f4c: /* f089f4c: 12000004 */ beqz $s0,.L0f089f60 /* f089f50: 00000000 */ sll $zero,$zero,0x0 -/* f089f54: 0fc1810e */ jal func0f060438 +/* f089f54: 0fc1810e */ jal propFree /* f089f58: 02002025 */ or $a0,$s0,$zero /* f089f5c: 00008025 */ or $s0,$zero,$zero .L0f089f60: @@ -42818,7 +42818,7 @@ glabel func0f08b108 /* f08b194: 8fa50024 */ lw $a1,0x24($sp) /* f08b198: 54400016 */ bnezl $v0,.L0f08b1f4 /* f08b19c: 8fbf001c */ lw $ra,0x1c($sp) -/* f08b1a0: 0fc1810e */ jal func0f060438 +/* f08b1a0: 0fc1810e */ jal propFree /* f08b1a4: 02202025 */ or $a0,$s1,$zero /* f08b1a8: 00008825 */ or $s1,$zero,$zero /* f08b1ac: ae000014 */ sw $zero,0x14($s0) @@ -42829,7 +42829,7 @@ glabel func0f08b108 .L0f08b1c0: /* f08b1c0: 50400006 */ beqzl $v0,.L0f08b1dc /* f08b1c4: 8e040018 */ lw $a0,0x18($s0) -/* f08b1c8: 0fc1810e */ jal func0f060438 +/* f08b1c8: 0fc1810e */ jal propFree /* f08b1cc: 02202025 */ or $a0,$s1,$zero /* f08b1d0: 00008825 */ or $s1,$zero,$zero /* f08b1d4: ae000014 */ sw $zero,0x14($s0) @@ -43143,7 +43143,7 @@ glabel func0f08b27c .L0f08b630: /* f08b630: 51200004 */ beqzl $t1,.L0f08b644 /* f08b634: 00008025 */ or $s0,$zero,$zero -/* f08b638: 0fc1810e */ jal func0f060438 +/* f08b638: 0fc1810e */ jal propFree /* f08b63c: 01202025 */ or $a0,$t1,$zero /* f08b640: 00008025 */ or $s0,$zero,$zero .L0f08b644: @@ -43296,7 +43296,7 @@ glabel func0f08b658 .L0f08b858: /* f08b858: 52200004 */ beqzl $s1,.L0f08b86c /* f08b85c: 8fbf001c */ lw $ra,0x1c($sp) -/* f08b860: 0fc1810e */ jal func0f060438 +/* f08b860: 0fc1810e */ jal propFree /* f08b864: 02202025 */ or $a0,$s1,$zero .L0f08b868: /* f08b868: 8fbf001c */ lw $ra,0x1c($sp) @@ -43461,7 +43461,7 @@ glabel func0f08b8e8 .L0f08ba90: /* f08ba90: 12400004 */ beqz $s2,.L0f08baa4 /* f08ba94: 00000000 */ sll $zero,$zero,0x0 -/* f08ba98: 0fc1810e */ jal func0f060438 +/* f08ba98: 0fc1810e */ jal propFree /* f08ba9c: 02402025 */ or $a0,$s2,$zero /* f08baa0: 00009025 */ or $s2,$zero,$zero .L0f08baa4: diff --git a/src/game/game_097a50.c b/src/game/game_097a50.c index 8a7602958..ab65a2e82 100644 --- a/src/game/game_097a50.c +++ b/src/game/game_097a50.c @@ -10522,7 +10522,7 @@ glabel func0f09fa84 /* f0a0350: a6080062 */ sh $t0,0x62($s0) /* f0a0354: 50800004 */ beqzl $a0,.L0f0a0368 /* f0a0358: 8e060018 */ lw $a2,0x18($s0) -/* f0a035c: 0fc1810e */ jal func0f060438 +/* f0a035c: 0fc1810e */ jal propFree /* f0a0360: 00000000 */ sll $zero,$zero,0x0 /* f0a0364: 8e060018 */ lw $a2,0x18($s0) .L0f0a0368: diff --git a/src/game/game_0b28d0.c b/src/game/game_0b28d0.c index 11128d968..b1be51c66 100644 --- a/src/game/game_0b28d0.c +++ b/src/game/game_0b28d0.c @@ -6502,7 +6502,7 @@ glabel func0f0b7c60 /* f0b7fe8: 8fa40044 */ lw $a0,0x44($sp) /* f0b7fec: 0fc180c0 */ jal func0f060300 /* f0b7ff0: 8fa40044 */ lw $a0,0x44($sp) -/* f0b7ff4: 0fc1810e */ jal func0f060438 +/* f0b7ff4: 0fc1810e */ jal propFree /* f0b7ff8: 8fa40044 */ lw $a0,0x44($sp) /* f0b7ffc: 10000006 */ beqz $zero,.L0f0b8018 /* f0b8000: 24020001 */ addiu $v0,$zero,0x1 diff --git a/src/include/game/game_0601b0.h b/src/include/game/game_0601b0.h index 8f4a18068..b195833af 100644 --- a/src/include/game/game_0601b0.h +++ b/src/include/game/game_0601b0.h @@ -7,7 +7,7 @@ u32 func0f0601b0(void); void propHide(struct prop *prop); u32 func0f060300(struct prop *prop); struct prop *propAllocate(void); -void func0f060438(struct prop *prop); +void propFree(struct prop *prop); void func0f0604bc(struct prop *prop); u32 func0f060538(void); void func0f0605c4(struct prop *prop); diff --git a/src/include/gvars/gvars.h b/src/include/gvars/gvars.h index acd69cbd7..5e43c353f 100644 --- a/src/include/gvars/gvars.h +++ b/src/include/gvars/gvars.h @@ -90,12 +90,13 @@ struct g_vars { /*000338*/ struct prop *props; /*00033c*/ struct prop *unk00033c; /*000340*/ struct prop *unk000340; - /*000344*/ struct prop *unk000344; + /*000344*/ struct prop *freeprops; /*000348*/ struct prop *unk000348; /*00034c*/ u32 unk00034c; /*000350*/ u32 unk000350; /*000354*/ struct prop *unk000354; - /*000358*/ u32 unk000358; + /*000358*/ u8 numpropstateindexes; + /*000359*/ u8 nextpropstateindex; /*00035c*/ u32 unk00035c; /*000360*/ struct propstate propstates[2]; /*000398*/ u32 unk000398; diff --git a/src/include/types.h b/src/include/types.h index 8bd80e6b5..cb70f02bf 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -52,7 +52,7 @@ struct prop { /*0x20*/ struct prop *next; /*0x24*/ struct prop *prev; /*0x28*/ s16 rooms[8]; - /*0x38*/ s16 unk38; + /*0x38*/ u16 unk38; /*0x3a*/ s16 unk3a; /*0x3c*/ u8 unk3c; /*0x3d*/ u8 propstateindex;