From 7925118e5715aa545fe3d9bf0ae2cd924c84b7c4 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Wed, 8 Feb 2023 19:45:25 -0400 Subject: runtime: Add `GCN_mem_alloc.c` --- src/Runtime/GCN_mem_alloc.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/Runtime/GCN_mem_alloc.c (limited to 'src/Runtime') diff --git a/src/Runtime/GCN_mem_alloc.c b/src/Runtime/GCN_mem_alloc.c new file mode 100644 index 0000000..75e4826 --- /dev/null +++ b/src/Runtime/GCN_mem_alloc.c @@ -0,0 +1,38 @@ +// This was taken from the Pikmin 2 decompilation project. +// https://github.com/projectPiki/pikmin2/blob/main/src/Dolphin/Runtime/GCN_mem_alloc.c +#include +#include + +inline static void InitDefaultHeap() +{ + void* arenaLo; + void* arenaHi; + + OSReport("GCN_Mem_Alloc.c : InitDefaultHeap. No Heap Available\n"); + OSReport("Metrowerks CW runtime library initializing default heap\n"); + + arenaLo = OSGetArenaLo(); + arenaHi = OSGetArenaHi(); + + arenaLo = OSInitAlloc(arenaLo, arenaHi, 1); + OSSetArenaLo(arenaLo); + + arenaLo = (void*)OSRoundUp32B(arenaLo); + arenaHi = (void*)OSRoundDown32B(arenaHi); + + OSSetCurrentHeap(OSCreateHeap(arenaLo, arenaHi)); + OSSetArenaLo(arenaLo = arenaHi); +} + +/* + * --INFO-- + * Address: 800C23A8 + * Size: 0000B8 + */ +__declspec(weak) extern void __sys_free(void* ptr) +{ + if (__OSCurrHeap == -1) { + InitDefaultHeap(); + } + OSFreeToHeap(__OSCurrHeap, ptr); +} -- cgit v1.2.3-13-gbd6f