2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
2024-09-08 21:47:25 +00:00
|
|
|
#include "libc64/os_malloc.h"
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
typedef void (*arg3_800FC868)(void*);
|
2020-03-22 21:19:43 +00:00
|
|
|
typedef void (*arg3_800FC8D8)(void*, u32);
|
|
|
|
typedef void (*arg3_800FC948)(void*, u32, u32, u32, u32, u32, u32, u32, u32);
|
|
|
|
typedef void (*arg3_800FCA18)(void*, u32);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
typedef struct InitFunc {
|
2020-03-17 04:31:30 +00:00
|
|
|
s32 nextOffset;
|
|
|
|
void (*func)(void);
|
|
|
|
} InitFunc;
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
// .data
|
|
|
|
void* sInitFuncs = NULL;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2024-03-23 16:30:09 +00:00
|
|
|
#if OOT_DEBUG
|
2023-11-12 21:59:52 +00:00
|
|
|
char sNew[] = "new";
|
2024-03-23 16:30:09 +00:00
|
|
|
#else
|
|
|
|
char sNew[] = "";
|
|
|
|
#endif
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2024-09-07 12:10:52 +00:00
|
|
|
#if !PLATFORM_N64
|
2020-03-22 21:19:43 +00:00
|
|
|
char D_80134488[0x18] = {
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x80, 0x00, 0x00,
|
|
|
|
0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
|
2020-03-17 04:31:30 +00:00
|
|
|
};
|
2024-09-07 12:10:52 +00:00
|
|
|
#endif
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
// possibly some kind of new() function
|
2020-03-22 21:19:43 +00:00
|
|
|
void* func_800FC800(u32 size) {
|
2024-09-04 09:10:14 +00:00
|
|
|
DECLARE_INTERRUPT_MASK
|
|
|
|
void* ptr;
|
|
|
|
|
|
|
|
DISABLE_INTERRUPTS();
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (size == 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
size = 1;
|
|
|
|
}
|
|
|
|
|
2024-02-02 04:17:17 +00:00
|
|
|
#if OOT_DEBUG
|
2024-09-04 09:10:14 +00:00
|
|
|
ptr = __osMallocDebug(&gSystemArena, size, sNew, 0);
|
2024-02-02 04:17:17 +00:00
|
|
|
#else
|
2024-09-04 09:10:14 +00:00
|
|
|
ptr = __osMalloc(&gSystemArena, size);
|
2024-02-02 04:17:17 +00:00
|
|
|
#endif
|
2024-09-04 09:10:14 +00:00
|
|
|
|
|
|
|
RESTORE_INTERRUPTS();
|
|
|
|
return ptr;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2022-05-15 14:38:31 +00:00
|
|
|
// possibly some kind of delete() function
|
2020-03-22 21:19:43 +00:00
|
|
|
void func_800FC83C(void* ptr) {
|
2024-09-04 09:10:14 +00:00
|
|
|
DECLARE_INTERRUPT_MASK
|
|
|
|
|
|
|
|
DISABLE_INTERRUPTS();
|
2020-03-22 21:19:43 +00:00
|
|
|
if (ptr != NULL) {
|
2020-03-17 04:31:30 +00:00
|
|
|
__osFree(&gSystemArena, ptr);
|
|
|
|
}
|
2024-09-04 09:10:14 +00:00
|
|
|
RESTORE_INTERRUPTS();
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void func_800FC868(void* blk, u32 nBlk, u32 blkSize, arg3_800FC868 arg3) {
|
2024-09-04 09:10:14 +00:00
|
|
|
DECLARE_INTERRUPT_MASK
|
2020-03-17 04:31:30 +00:00
|
|
|
u32 pos;
|
|
|
|
|
2024-09-04 09:10:14 +00:00
|
|
|
DISABLE_INTERRUPTS();
|
|
|
|
for (pos = ((u32)blk & ~0); pos < (u32)blk + (nBlk * blkSize); pos = (u32)pos + (blkSize & ~0)) {
|
2020-03-17 04:31:30 +00:00
|
|
|
arg3((void*)pos);
|
|
|
|
}
|
2024-09-04 09:10:14 +00:00
|
|
|
RESTORE_INTERRUPTS();
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void func_800FC8D8(void* blk, u32 nBlk, s32 blkSize, arg3_800FC8D8 arg3) {
|
2024-09-04 09:10:14 +00:00
|
|
|
DECLARE_INTERRUPT_MASK
|
2020-03-17 04:31:30 +00:00
|
|
|
u32 pos;
|
|
|
|
|
2024-09-04 09:10:14 +00:00
|
|
|
DISABLE_INTERRUPTS();
|
|
|
|
for (pos = ((u32)blk & ~0); pos < (u32)blk + (nBlk * blkSize); pos = (u32)pos + (blkSize & ~0)) {
|
2020-03-17 04:31:30 +00:00
|
|
|
arg3((void*)pos, 2);
|
|
|
|
}
|
2024-09-04 09:10:14 +00:00
|
|
|
RESTORE_INTERRUPTS();
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void* func_800FC948(void* blk, u32 nBlk, u32 blkSize, arg3_800FC948 arg3) {
|
2024-09-04 09:10:14 +00:00
|
|
|
DECLARE_INTERRUPT_MASK
|
2020-03-17 04:31:30 +00:00
|
|
|
u32 pos;
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2024-09-04 09:10:14 +00:00
|
|
|
DISABLE_INTERRUPTS();
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (blk == NULL) {
|
2020-03-17 04:31:30 +00:00
|
|
|
blk = func_800FC800(nBlk * blkSize);
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (blk != NULL && arg3 != NULL) {
|
2020-03-17 04:31:30 +00:00
|
|
|
pos = (u32)blk;
|
2020-03-22 21:19:43 +00:00
|
|
|
while (pos < (u32)blk + (nBlk * blkSize)) {
|
2020-03-17 04:31:30 +00:00
|
|
|
arg3((void*)pos, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
|
|
pos = (u32)pos + (blkSize & ~0);
|
|
|
|
}
|
|
|
|
}
|
2024-09-04 09:10:14 +00:00
|
|
|
|
|
|
|
RESTORE_INTERRUPTS();
|
2020-03-17 04:31:30 +00:00
|
|
|
return blk;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void func_800FCA18(void* blk, u32 nBlk, u32 blkSize, arg3_800FCA18 arg3, s32 arg4) {
|
2024-09-04 09:10:14 +00:00
|
|
|
DECLARE_INTERRUPT_MASK
|
2020-03-17 04:31:30 +00:00
|
|
|
u32 pos;
|
2020-03-22 21:19:43 +00:00
|
|
|
u32 end;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2024-09-04 09:10:14 +00:00
|
|
|
DISABLE_INTERRUPTS();
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2024-09-04 09:10:14 +00:00
|
|
|
if (blk != NULL) {
|
|
|
|
if (arg3 != NULL) {
|
|
|
|
end = (u32)blk;
|
|
|
|
pos = (u32)end + (nBlk * blkSize);
|
|
|
|
|
|
|
|
while (pos > end) {
|
|
|
|
pos -= (s32)(blkSize & ~0);
|
|
|
|
arg3((void*)pos, 2);
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2024-09-04 09:10:14 +00:00
|
|
|
if (arg4 != 0) {
|
|
|
|
func_800FC83C(blk);
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2024-09-04 09:10:14 +00:00
|
|
|
|
|
|
|
RESTORE_INTERRUPTS();
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void func_800FCB34(void) {
|
2021-02-14 00:49:40 +00:00
|
|
|
InitFunc* initFunc = (InitFunc*)&sInitFuncs;
|
|
|
|
u32 nextOffset = initFunc->nextOffset;
|
|
|
|
InitFunc* prev = NULL;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
while (nextOffset != 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
initFunc = (InitFunc*)((s32)initFunc + nextOffset);
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (initFunc->func != NULL) {
|
2023-11-12 21:59:52 +00:00
|
|
|
initFunc->func();
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nextOffset = initFunc->nextOffset;
|
|
|
|
initFunc->nextOffset = (s32)prev;
|
|
|
|
prev = initFunc;
|
|
|
|
}
|
|
|
|
|
|
|
|
sInitFuncs = prev;
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void SystemHeap_Init(void* start, u32 size) {
|
2024-09-04 09:10:14 +00:00
|
|
|
#if PLATFORM_N64
|
|
|
|
__osMallocInit(&gSystemArena, start, size);
|
|
|
|
#else
|
2020-03-17 04:31:30 +00:00
|
|
|
SystemArena_Init(start, size);
|
2024-09-04 09:10:14 +00:00
|
|
|
#endif
|
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
func_800FCB34();
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|