summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Runtime/GCN_mem_alloc.c38
1 files changed, 38 insertions, 0 deletions
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 <dolphin/types.h>
+#include <os.h>
+
+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);
+}