From 4e9d88fab9dedbd41948fd9f02aab49e47864820 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 22 Oct 2022 20:03:56 +1000 Subject: [PATCH] Print unused memory to HUD --- src/game/lv.c | 15 +++++++++++++++ src/lib/mema.c | 3 +++ src/lib/memp.c | 8 ++++++++ 3 files changed, 26 insertions(+) diff --git a/src/game/lv.c b/src/game/lv.c index 4c048d23d..f06397e94 100644 --- a/src/game/lv.c +++ b/src/game/lv.c @@ -87,6 +87,8 @@ #include "lib/lib_06440.h" #include "lib/lib_317f0.h" #include "lib/main.h" +#include "lib/mema.h" +#include "lib/memp.h" #include "lib/mtx.h" #include "lib/music.h" #include "lib/rng.h" @@ -953,6 +955,8 @@ void lvFindThreats(void) u8 g_LvShowRates = 0; u8 g_LvAntialias = 1; u8 g_LvRateIndex = 59; +u8 g_LvOom = 0; +u32 g_LvOomSize = 0; u8 g_LvFrameRates[60]; void lvRecordRate(void) @@ -1067,6 +1071,17 @@ Gfx *lvPrintRateText(Gfx *gdl) x = 10; sprintf(buffer, "Antialias %s\n", g_LvAntialias ? "on" : "off"); gdl = textRender(gdl, &x, &y, buffer, g_CharsHandelGothicXs, g_FontHandelGothicXs, 0x00ff00a0, 0x000000a0, viGetWidth(), viGetHeight(), 0, 0); + + sprintf(buffer, "mema free %d KB\n", memaGetLongestFree() / 1024); + gdl = textRender(gdl, &x, &y, buffer, g_CharsHandelGothicXs, g_FontHandelGothicXs, 0x00ff00a0, 0x000000a0, viGetWidth(), viGetHeight(), 0, 0); + + sprintf(buffer, "memp free %d KB\n", mempGetStageFree() / 1024); + gdl = textRender(gdl, &x, &y, buffer, g_CharsHandelGothicXs, g_FontHandelGothicXs, 0x00ff00a0, 0x000000a0, viGetWidth(), viGetHeight(), 0, 0); + + if (g_LvOom) { + sprintf(buffer, "mem%c OOM %x\n", g_LvOom, g_LvOomSize); + gdl = textRender(gdl, &x, &y, buffer, g_CharsHandelGothicXs, g_FontHandelGothicXs, 0xff0000a0, 0x000000a0, viGetWidth(), viGetHeight(), 0, 0); + } } return gdl; diff --git a/src/lib/mema.c b/src/lib/mema.c index 5242f084f..0b347d749 100644 --- a/src/lib/mema.c +++ b/src/lib/mema.c @@ -620,6 +620,8 @@ glabel memaAlloc ); #endif #else +extern u8 g_LvOom; + void *memaAlloc(u32 size) { u32 addr; @@ -682,6 +684,7 @@ void *memaAlloc(u32 size) } if (curr->addr == 0xffffffff) { + g_LvOom = 'a'; return NULL; } } diff --git a/src/lib/memp.c b/src/lib/memp.c index ed8fe9428..d36bdb725 100644 --- a/src/lib/memp.c +++ b/src/lib/memp.c @@ -171,6 +171,9 @@ void *mempAllocFromBank(struct memorypool *pool, u32 size, u8 poolnum) return (void *)allocation; } +extern u8 g_LvOom; +extern u32 g_LvOomSize; + void *mempAlloc(u32 len, u8 pool) { void *allocation = mempAllocFromBank(g_MempOnboardPools, len, pool); @@ -185,6 +188,11 @@ void *mempAlloc(u32 len, u8 pool) return allocation; } + if (pool != MEMPOOL_8 && pool != MEMPOOL_7 && len) { + g_LvOom = 'p'; + g_LvOomSize = len; + } + #if VERSION < VERSION_NTSC_1_0 if (pool != MEMPOOL_8 && pool != MEMPOOL_7 && len) { char buffer[80];