summaryrefslogtreecommitdiff
path: root/src/Runtime
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2023-02-08 19:45:25 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2023-02-08 19:45:25 -0400
commit7925118e5715aa545fe3d9bf0ae2cd924c84b7c4 (patch)
tree7ea721ff4735d83f848e0bba6cf335e9ba63994d /src/Runtime
parent64cc4930531375080e0b92c01fcc1c2432d3aa1d (diff)
runtime: Add `GCN_mem_alloc.c`
Diffstat (limited to 'src/Runtime')
-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);
+}