alHeapAlloc

This commit is contained in:
Ethan Roseman 2020-12-01 18:23:26 -05:00
parent 7851aac54e
commit d39d5837c3
4 changed files with 18 additions and 29 deletions

View File

@ -1,23 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel alHeapAlloc
/* 33390 80057F90 0080382D */ daddu $a3, $a0, $zero
/* 33394 80057F94 00A60018 */ mult $a1, $a2
/* 33398 80057F98 2402FFF0 */ addiu $v0, $zero, -0x10
/* 3339C 80057F9C 8CE50004 */ lw $a1, 4($a3)
/* 333A0 80057FA0 8CE40008 */ lw $a0, 8($a3)
/* 333A4 80057FA4 00004012 */ mflo $t0
/* 333A8 80057FA8 2503000F */ addiu $v1, $t0, 0xf
/* 333AC 80057FAC 00621824 */ and $v1, $v1, $v0
/* 333B0 80057FB0 8CE20000 */ lw $v0, ($a3)
/* 333B4 80057FB4 00A31821 */ addu $v1, $a1, $v1
/* 333B8 80057FB8 00441021 */ addu $v0, $v0, $a0
/* 333BC 80057FBC 0043102B */ sltu $v0, $v0, $v1
/* 333C0 80057FC0 14400003 */ bnez $v0, .L80057FD0
/* 333C4 80057FC4 0000302D */ daddu $a2, $zero, $zero
/* 333C8 80057FC8 00A0302D */ daddu $a2, $a1, $zero
/* 333CC 80057FCC ACE30004 */ sw $v1, 4($a3)
.L80057FD0:
/* 333D0 80057FD0 03E00008 */ jr $ra
/* 333D4 80057FD4 00C0102D */ daddu $v0, $a2, $zero

View File

@ -10,6 +10,8 @@
#define INCLUDE_ASM(TYPE, FOLDER, NAME, ARGS...)
#endif
#define ALIGN16(val) (((val) + 0xF) & ~0xF)
#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))
#define ARRAY_COUNTU(arr) (u32)(sizeof(arr) / sizeof(arr[0]))

View File

@ -3,8 +3,6 @@
#include "common.h"
#undef alHeapAlloc
typedef struct UnkAl1 {
/* 0x00 */ s16 unk_00;
/* 0x02 */ char unk_02[2];
@ -271,6 +269,8 @@ s32 al_CopyFileTableEntry(u16 arg0, s32 arg1, s32* arg2);
void al_LoadPER(UnkAl19E0*, s32*);
void al_LoadPRG(UnkAl19E0*, s32*);
void al_DmaCopy(s32*, s32*, s32);
s32* alHeapAlloc(ALHeap*, s32, s32);
#undef alHeapAlloc
void* alHeapAlloc(ALHeap *heap, s32 arg1, s32 size);
#endif

View File

@ -1,7 +1,8 @@
#include "common.h"
#include "audio.h"
// TODO: rodata
extern s32 D_80078DB0;
extern u16 D_80078DB4;
INCLUDE_ASM(s32, "code_303c0_len_3e10", al_LoadBKHeaders);
@ -224,8 +225,17 @@ INCLUDE_ASM(s32, "code_303c0_len_3e10", func_80057ED0);
INCLUDE_ASM(s32, "code_303c0_len_3e10", func_80057F20);
#undef alHeapAlloc
INCLUDE_ASM(void, "code_303c0_len_3e10", alHeapAlloc, u8* file, s32 line, ALHeap* hp, s32 num, s32 size);
void* alHeapAlloc(ALHeap *heap, s32 arg1, s32 size) {
void* ret = NULL;
u8* prevCur = heap->cur;
u8* newCur = &prevCur[ALIGN16(arg1 * size)];
if (&heap->base[heap->len] >= newCur) {
ret = prevCur;
heap->cur = newCur;
}
return ret;
}
INCLUDE_ASM(s32, "code_303c0_len_3e10", func_80057FD8);