Decompile memaGetLongestFree

This commit is contained in:
Ryan Dwyer 2021-10-30 10:03:11 +10:00
parent ccd4bbbccc
commit d348dcb22b
4 changed files with 44 additions and 54 deletions

View File

@ -9681,7 +9681,7 @@ glabel func0f15dc58
/* f15dcdc: 10000004 */ b .L0f15dcf0
/* f15dce0: afad02f4 */ sw $t5,0x2f4($sp)
.L0f15dce4:
/* f15dce4: 0c004b37 */ jal func00012cdc
/* f15dce4: 0c004b37 */ jal memaGetLongestFree
/* f15dce8: afa402f8 */ sw $a0,0x2f8($sp)
/* f15dcec: afa202f4 */ sw $v0,0x2f4($sp)
.L0f15dcf0:
@ -10250,7 +10250,7 @@ glabel func0f15dc58
/* f158488: 10000004 */ beqz $zero,.NB0f15849c
/* f15848c: afad02f4 */ sw $t5,0x2f4($sp)
.NB0f158490:
/* f158490: 0c004d4e */ jal func00012cdc
/* f158490: 0c004d4e */ jal memaGetLongestFree
/* f158494: 00000000 */ sll $zero,$zero,0x0
/* f158498: afa202f4 */ sw $v0,0x2f4($sp)
.NB0f15849c:
@ -10832,7 +10832,7 @@ void func0f15e538(void)
void func0f15e5b8(s32 size, u32 arg1)
{
s32 limit = func00012cdc();
s32 limit = memaGetLongestFree();
s32 bestroom;
s32 bestvalue;
s32 count = 0;
@ -10851,10 +10851,10 @@ void func0f15e5b8(s32 size, u32 arg1)
if (bestroom != 0) {
func0f15e474(bestroom);
func000127b8();
memaDefrag();
}
limit = func00012cdc();
limit = memaGetLongestFree();
count++;
if (count == 30) {
@ -10867,9 +10867,9 @@ void func0f15e5b8(s32 size, u32 arg1)
#endif
{
func0f15e474(i);
func000127b8();
memaDefrag();
if (func00012cdc() >= size) {
if (memaGetLongestFree() >= size) {
return;
}
}
@ -10905,7 +10905,7 @@ void func0f15e728(void)
if (count < 2 && var800a4bf2 == g_Rooms[i].unk02) {
func0f15e474(i);
#if VERSION >= VERSION_NTSC_1_0
func000127b8();
memaDefrag();
#endif
count++;
}

View File

@ -4,16 +4,16 @@
#include "data.h"
#include "types.h"
void func000127b8(void);
void memaDefrag(void);
u32 func00012800(void);
u32 func00012914(void);
void memaInit(void);
void memaHeapInit(void *ptr, u32 arg1);
void memPrintInfoIfEnabled(void);
void memaPrint(void);
void *memaAlloc(u32 size);
u32 func00012c3c(void);
void func00012cb4(void *arg0, s32 arg1);
s32 func00012cdc(void);
s32 memaGetLongestFree(void);
u32 func00012d48(void);
#endif

View File

@ -68,7 +68,7 @@ bool memaDefragPass(struct memaheap *heap)
return merged;
}
void func000127b8(void)
void memaDefrag(void)
{
while (memaDefragPass(&g_MemaHeap));
}
@ -288,10 +288,8 @@ void memaHeapInit(void *heapaddr, u32 heapsize)
* The ETER (permanent) pool has 0 free space because it's shrunk to fit once
* the permanent allocations are done during startup. This pool fits entirely
* in onboard memory, so the expansion size is 0.
*
* mema means audio memory. Unsure what LF is.
*/
void memPrintInfoIfEnabled(void)
void memaPrint(void)
{
s32 onboard;
s32 expansion;
@ -364,7 +362,7 @@ void memPrintInfoIfEnabled(void)
dhudPrintString("mema:");
line++;
sprintf(buffer, "LF: %d", func00012cdc());
sprintf(buffer, "LF: %d", memaGetLongestFree());
dhudSetPos(31, line);
dhudPrintString(buffer);
line++;
@ -736,41 +734,33 @@ glabel func00012cb4
/* 12cd8: 00000000 */ nop
);
GLOBAL_ASM(
glabel func00012cdc
/* 12cdc: 27bdffe0 */ addiu $sp,$sp,-32
/* 12ce0: afbf0014 */ sw $ra,0x14($sp)
/* 12ce4: 0c0049ee */ jal func000127b8
/* 12ce8: afa00018 */ sw $zero,0x18($sp)
/* 12cec: 3c0e800a */ lui $t6,%hi(g_MemaHeap+0xc)
/* 12cf0: 8dce9484 */ lw $t6,%lo(g_MemaHeap+0xc)($t6)
/* 12cf4: 2405ffff */ addiu $a1,$zero,-1
/* 12cf8: 3c02800a */ lui $v0,%hi(g_MemaHeap+0xc)
/* 12cfc: 8fa40018 */ lw $a0,0x18($sp)
/* 12d00: 10ae000a */ beq $a1,$t6,.L00012d2c
/* 12d04: 24429484 */ addiu $v0,$v0,%lo(g_MemaHeap+0xc)
/* 12d08: 8c430004 */ lw $v1,0x4($v0)
.L00012d0c:
/* 12d0c: 0083082b */ sltu $at,$a0,$v1
/* 12d10: 50200003 */ beqzl $at,.L00012d20
/* 12d14: 8c4f0008 */ lw $t7,0x8($v0)
/* 12d18: 00602025 */ or $a0,$v1,$zero
/* 12d1c: 8c4f0008 */ lw $t7,0x8($v0)
.L00012d20:
/* 12d20: 24420008 */ addiu $v0,$v0,0x8
/* 12d24: 54affff9 */ bnel $a1,$t7,.L00012d0c
/* 12d28: 8c430004 */ lw $v1,0x4($v0)
.L00012d2c:
/* 12d2c: 10800003 */ beqz $a0,.L00012d3c
/* 12d30: 8fbf0014 */ lw $ra,0x14($sp)
/* 12d34: 10000002 */ b .L00012d40
/* 12d38: 00801025 */ or $v0,$a0,$zero
.L00012d3c:
/* 12d3c: 00001025 */ or $v0,$zero,$zero
.L00012d40:
/* 12d40: 03e00008 */ jr $ra
/* 12d44: 27bd0020 */ addiu $sp,$sp,0x20
);
/**
* Find and return the largest amount of contiguous free space in the pool.
* ie. the biggest allocation that mema can currently make.
*/
s32 memaGetLongestFree(void)
{
struct memaspace *curr;
s32 biggest = 0;
memaDefrag();
curr = &g_MemaHeap.spaces[1];
while (curr->addr != -1) {
if (curr->size > biggest) {
biggest = curr->size;
}
curr++;
}
if (biggest) {
return biggest;
}
return 0;
}
GLOBAL_ASM(
glabel func00012d48

View File

@ -2665,7 +2665,7 @@ void mainTick(void)
rdpCreateTask(gdlstart, gdl, 0, &msg);
g_MainNumGfxTasks++;
memPrintInfoIfEnabled();
memaPrint();
func0f16cf94();
profileSetMarker(PROFILE_MAINTICK_END);
}
@ -3042,7 +3042,7 @@ glabel mainTick
/* ee50: 2442f2ec */ addiu $v0,$v0,-3348
/* ee54: 8c4e0000 */ lw $t6,0x0($v0)
/* ee58: 25c90001 */ addiu $t1,$t6,0x1
/* ee5c: 0c004c0a */ jal memPrintInfoIfEnabled
/* ee5c: 0c004c0a */ jal memaPrint
/* ee60: ac490000 */ sw $t1,0x0($v0)
/* ee64: 0fc59f51 */ jal func0f16cf94
/* ee68: 00000000 */ sll $zero,$zero,0x0
@ -3162,7 +3162,7 @@ u32 var8005f690nb[] = {
//
// rdpCreateTask(gdlstart, gdl, 0, &msg);
// g_MainNumGfxTasks++;
// memPrintInfoIfEnabled();
// memaPrint();
// func0f16cf94();
// profileSetMarker(PROFILE_MAINTICK_END);
// }