1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-02 15:55:59 +00:00
oot/src/code/code_800FC620.c

118 lines
2.7 KiB
C
Raw Normal View History

#include "global.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
char sNew[] = { 'n', 'e', 'w' };
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) {
if (size == 0) {
2020-03-17 04:31:30 +00:00
size = 1;
}
return __osMallocDebug(&gSystemArena, size, sNew, 0);
}
// possibly some kind of delete() function
2020-03-22 21:19:43 +00:00
void func_800FC83C(void* ptr) {
if (ptr != NULL) {
2020-03-17 04:31:30 +00:00
__osFree(&gSystemArena, ptr);
}
}
2020-03-22 21:19:43 +00:00
void func_800FC868(void* blk, u32 nBlk, u32 blkSize, arg3_800FC868 arg3) {
2020-03-17 04:31:30 +00:00
u32 pos;
2020-03-22 21:19:43 +00:00
for (pos = (u32)blk; pos < (u32)blk + (nBlk * blkSize); pos = (u32)pos + (blkSize & ~0)) {
2020-03-17 04:31:30 +00:00
arg3((void*)pos);
}
}
2020-03-22 21:19:43 +00:00
void func_800FC8D8(void* blk, u32 nBlk, s32 blkSize, arg3_800FC8D8 arg3) {
2020-03-17 04:31:30 +00:00
u32 pos;
2020-03-22 21:19:43 +00:00
for (pos = (u32)blk; pos < (u32)blk + (nBlk * blkSize); pos = (u32)pos + (blkSize & ~0)) {
2020-03-17 04:31:30 +00:00
arg3((void*)pos, 2);
}
}
2020-03-22 21:19:43 +00:00
void* func_800FC948(void* blk, u32 nBlk, u32 blkSize, arg3_800FC948 arg3) {
2020-03-17 04:31:30 +00:00
u32 pos;
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);
}
}
return blk;
}
2020-03-22 21:19:43 +00:00
void func_800FCA18(void* blk, u32 nBlk, u32 blkSize, arg3_800FCA18 arg3, s32 arg4) {
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
2020-03-22 21:19:43 +00:00
if (blk == 0) {
2020-03-17 04:31:30 +00:00
return;
}
2020-03-22 21:19:43 +00:00
if (arg3 != 0) {
2020-03-17 04:31:30 +00:00
end = (u32)blk;
pos = (u32)end + (nBlk * blkSize);
2020-03-22 21:19:43 +00:00
while (pos > end) {
pos -= (s32)(blkSize & ~0);
arg3((void*)pos, 2);
2020-03-17 04:31:30 +00:00
}
}
2020-03-22 21:19:43 +00:00
if (arg4 != 0) {
2020-03-17 04:31:30 +00:00
func_800FC83C(blk);
}
}
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) {
2020-03-17 04:31:30 +00:00
(*initFunc->func)();
}
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) {
2020-03-17 04:31:30 +00:00
SystemArena_Init(start, size);
func_800FCB34();
2020-03-22 21:19:43 +00:00
}