1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-14 13:30:47 +00:00
oot/src/code/code_800FC620.c

201 lines
5.1 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
};
2020-03-22 21:19:43 +00:00
s32 Overlay_Load(u32 vRomStart, u32 vRomEnd, void* vRamStart, void* vRamEnd, void* allocatedVRamAddr) {
s32 pad;
2020-03-17 04:31:30 +00:00
u32 end;
u32 bssSize;
2020-03-22 21:19:43 +00:00
OverlayRelocationSection* ovl;
2020-03-17 04:31:30 +00:00
u32 relocCnt;
u32 ovlOffset;
u32 size;
2020-03-22 21:19:43 +00:00
if (gOverlayLogSeverity >= 3) {
2020-03-17 04:31:30 +00:00
// Start loading dynamic link function
osSyncPrintf("\nダイナミックリンクファンクションのロードを開始します\n");
}
2020-03-22 21:19:43 +00:00
if (gOverlayLogSeverity >= 3) {
2020-03-17 04:31:30 +00:00
size = vRomEnd - vRomStart;
2020-03-22 21:19:43 +00:00
// DMA transfer of TEXT, DATA, RODATA + rel (%08x-%08x)
osSyncPrintf("TEXT,DATA,RODATA+relを転送します(%08x-%08x)\n", allocatedVRamAddr,
(u32)allocatedVRamAddr + size);
2020-03-17 04:31:30 +00:00
}
size = vRomEnd - vRomStart;
end = (u32)allocatedVRamAddr + size;
DmaMgr_SendRequest0((u32)allocatedVRamAddr, vRomStart, size);
ovlOffset = ((s32*)end)[-1];
ovl = (OverlayRelocationSection*)((u32)end - ovlOffset);
2020-03-22 21:19:43 +00:00
if (gOverlayLogSeverity >= 3) {
osSyncPrintf("TEXT(%08x), DATA(%08x), RODATA(%08x), BSS(%08x)\n", ovl->textSize, ovl->dataSize, ovl->rodataSize,
ovl->bssSize);
2020-03-17 04:31:30 +00:00
}
2020-03-22 21:19:43 +00:00
if (gOverlayLogSeverity >= 3) {
2020-03-17 04:31:30 +00:00
// Relocate
osSyncPrintf("リロケーションします\n");
}
Overlay_Relocate(allocatedVRamAddr, ovl, vRamStart);
2020-03-17 04:31:30 +00:00
bssSize = ovl->bssSize;
2020-03-22 21:19:43 +00:00
if (bssSize != 0) {
if (gOverlayLogSeverity >= 3) {
2020-03-17 04:31:30 +00:00
// Clear BSS area (% 08x-% 08x)
osSyncPrintf("BSS領域をクリアします(%08x-%08x)\n", end, end + ovl->bssSize);
}
size = ovl->bssSize;
bssSize = size;
bzero((void*)end, bssSize);
relocCnt = ovl->nRelocations;
}
size = (u32)&ovl->relocations[ovl->nRelocations] - (u32)ovl;
2020-03-22 21:19:43 +00:00
if (gOverlayLogSeverity >= 3) {
2020-03-17 04:31:30 +00:00
// Clear REL area (%08x-%08x)
osSyncPrintf("REL領域をクリアします(%08x-%08x)\n", ovl, (u32)ovl + size);
}
bzero(ovl, size);
size = (u32)vRamEnd - (u32)vRamStart;
osWritebackDCache(allocatedVRamAddr, size);
osInvalICache(allocatedVRamAddr, size);
2020-03-22 21:19:43 +00:00
if (gOverlayLogSeverity >= 3) {
2020-03-17 04:31:30 +00:00
// Finish loading dynamic link function
osSyncPrintf("ダイナミックリンクファンクションのロードを終了します\n\n");
}
return size;
}
// 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);
}
// possible 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
s32 masked_arg2;
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;
masked_arg2 = (s32)(blkSize & ~0);
pos = (u32)end + (nBlk * blkSize);
2020-03-22 21:19:43 +00:00
if (masked_arg2) {}
2020-03-17 04:31:30 +00:00
2020-03-22 21:19:43 +00:00
while (pos > end) {
2020-03-17 04:31:30 +00:00
do {
pos -= masked_arg2;
arg3((void*)pos, 2);
} while (0);
}
2020-03-22 21:19:43 +00:00
if (!masked_arg2) {}
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;
2020-03-17 04:31:30 +00:00
u32 nextOffset;
2020-03-22 21:19:43 +00:00
InitFunc* prev;
2020-03-17 04:31:30 +00:00
initFunc = (InitFunc*)&sInitFuncs;
nextOffset = initFunc->nextOffset;
prev = NULL;
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
}