diff --git a/libpsx/src/memory.c b/libpsx/src/memory.c index 9b18556..1d0e6de 100644 --- a/libpsx/src/memory.c +++ b/libpsx/src/memory.c @@ -12,6 +12,7 @@ extern int __bss_start[]; extern int __bss_end[]; static unsigned int first_free_page; +static int init; // 1K granularity and "pages", so more allocations which are small can be done @@ -22,7 +23,7 @@ static unsigned int alloc_size[2048]; // 0x80000000 - 0x8000FFFF RAM used by the BIOS // 0x80010000 - 0x801FFFFF Program memory -void malloc_setup() +static void malloc_setup() { int x; @@ -53,6 +54,14 @@ void malloc_setup() void *malloc(size_t size) { + if (!init) + { + // Setup memory allocation functions + malloc_setup(); + dprintf("Finished setting up memory allocation functions.\n"); + init = 1; + } + dprintf("malloc(%d)\n", size); int x, y; diff --git a/libpsx/src/memory.h b/libpsx/src/memory.h deleted file mode 100644 index 39985b2..0000000 --- a/libpsx/src/memory.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _PSXSDK_MEMORY_H -#define _PSXSDK_MEMORY_H - -void malloc_setup(); - -#endif \ No newline at end of file diff --git a/libpsx/src/setup.c b/libpsx/src/setup.c index d77f062..1a28685 100644 --- a/libpsx/src/setup.c +++ b/libpsx/src/setup.c @@ -1,6 +1,5 @@ #include #include -#include "memory.h" extern int __bss_start[]; extern int __bss_end[]; @@ -38,11 +37,6 @@ void psxsdk_setup() *((unsigned char*)x) = 0; dprintf("BSS space cleared.\n"); - -// Setup memory allocation functions - malloc_setup(); - - dprintf("Finished setting up memory allocation functions.\n"); // Call static constructors call_ctors();