1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-01-15 12:47:04 +00:00
oot/src/code/code_800FC620.c

159 lines
3.4 KiB
C
Raw Normal View History

#include "global.h"
#include "osMalloc.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
char sNew[] = "new";
2024-03-23 16:30:09 +00:00
#else
char sNew[] = "";
#endif
2020-03-17 04:31:30 +00:00
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
};
// possibly some kind of new() function
2020-03-22 21:19:43 +00:00
void* func_800FC800(u32 size) {
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;
}
#if OOT_DEBUG
ptr = __osMallocDebug(&gSystemArena, size, sNew, 0);
#else
ptr = __osMalloc(&gSystemArena, size);
#endif
RESTORE_INTERRUPTS();
return ptr;
2020-03-17 04:31:30 +00:00
}
// possibly some kind of delete() function
2020-03-22 21:19:43 +00:00
void func_800FC83C(void* ptr) {
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);
}
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) {
DECLARE_INTERRUPT_MASK
2020-03-17 04:31:30 +00:00
u32 pos;
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);
}
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) {
DECLARE_INTERRUPT_MASK
2020-03-17 04:31:30 +00:00
u32 pos;
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);
}
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) {
DECLARE_INTERRUPT_MASK
2020-03-17 04:31:30 +00:00
u32 pos;
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);
}
}
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) {
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
DISABLE_INTERRUPTS();
2020-03-17 04:31:30 +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
}
if (arg4 != 0) {
func_800FC83C(blk);
}
2020-03-17 04:31:30 +00:00
}
RESTORE_INTERRUPTS();
2020-03-17 04:31:30 +00:00
}
2020-03-22 21:19:43 +00:00
void func_800FCB34(void) {
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) {
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) {
#if PLATFORM_N64
__osMallocInit(&gSystemArena, start, size);
#else
2020-03-17 04:31:30 +00:00
SystemArena_Init(start, size);
#endif
2020-03-17 04:31:30 +00:00
func_800FCB34();
2020-03-22 21:19:43 +00:00
}