summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--obj_files.mk1
-rw-r--r--src/Runtime/GCN_mem_alloc.c38
2 files changed, 39 insertions, 0 deletions
diff --git a/obj_files.mk b/obj_files.mk
index 085c6ed..baea650 100644
--- a/obj_files.mk
+++ b/obj_files.mk
@@ -10,6 +10,7 @@ O_FILES := $(BUILD_DIR)/src/main.o \
$(BUILD_DIR)/src/Runtime/runtime.o \
$(BUILD_DIR)/src/Runtime/__init_cpp_exceptions.o \
$(BUILD_DIR)/asm/Runtime/ExceptionPPC.o \
+ $(BUILD_DIR)/src/Runtime/GCN_mem_alloc.o \
$(BUILD_DIR)/src/Dolphin/os/__start.o \
$(BUILD_DIR)/src/Dolphin/os/__ppc_eabi_init.o \
$(BUILD_DIR)/src/Dolphin/PPCArch.o \
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);
+}