diff --git a/source/mem/memory.cpp b/source/mem/memory.cpp index 6f826ad99..35154f3ed 100644 --- a/source/mem/memory.cpp +++ b/source/mem/memory.cpp @@ -18,6 +18,16 @@ void MemRemoveNode(sLList *LList,u_short Node); sLList MainRam; int MemNodeCount=0; +#define USE_MEM_GUARDS + +#ifdef USE_MEM_GUARDS +static const unsigned int HEAD_GUARD_FILL_PATTERN =0x3c3c3c3c; +static const unsigned int MEM_FILL_PATTERN =0x3d3d3d3d; +static const unsigned int TAIL_GUARD_FILL_PATTERN =0x3e3e3e3e; +static const unsigned int MEM_GUARD_SIZE=sizeof(int)*2; +#endif /* USE_MEM_GUARDS */ + + /*****************************************************************************/ #ifdef __DEBUG_MEM__ @@ -117,6 +127,8 @@ static FontBank s_debugFont; + + void dumpDebugMem() { if (s_dumpMem) @@ -386,6 +398,9 @@ u32 Len = ((TLen + 3) & 0xfffffffc); int BestNode,FirstNode; Len += 4; //add on 4 to store Addr ! +#ifdef USE_MEM_GUARDS + Len+=(MEM_GUARD_SIZE*2); +#endif /* USE_MEM_GUARDS */ // Find First (and possably only) while (Head != 0xffff && mem->Nodes[ Head ].LenNodes[ Head ].Next; @@ -411,8 +426,30 @@ int BestNode,FirstNode; mem->Nodes[BestNode].Len -= Len; mem->Nodes[BestNode].Addr += Len; if (mem->Nodes[BestNode].Len == 0) MemRemoveNode( mem, BestNode); + + *(u32*)Addr = Len; Addr += 4; + +#ifdef USE_MEM_GUARDS + unsigned int i; + for(i=0;iRamUsed += Len; } @@ -435,9 +472,35 @@ char *Addr = (char*)Address; // If file from Databank, dont try and clear it (simple!!) if (CFileIO::IsFromDataBank(Address)) return; +#ifdef USE_MEM_GUARDS + Addr-=MEM_GUARD_SIZE; +#endif /* USE_MEM_GUARDS */ Addr -= 4; - Len = *(u32*)Addr; + +#ifdef USE_MEM_GUARDS + // Check that the guards are intact + unsigned int i; + unsigned int *guardAddr; + guardAddr=(unsigned int*)(Addr+4); + for(i=0;iRamUsed -= Len; diff --git a/source/paul/paul.cpp b/source/paul/paul.cpp index 623fdc73a..2814dca9a 100644 --- a/source/paul/paul.cpp +++ b/source/paul/paul.cpp @@ -26,6 +26,14 @@ #include "gfx\font.h" #endif +#ifndef __MEMORY_HEADER__ +#include "mem\memory.h" +#endif + +#ifndef __UTILS_HEADER__ +#include "utils\utils.h" +#endif + /* Std Lib ------- */ @@ -49,6 +57,7 @@ Vars ---- */ static FontBank s_fontBank; +char *s_mem[3]; /*---------------------------------------------------------------------- @@ -65,6 +74,7 @@ void CPaulScene::init() PAUL_DBGMSG("this is a message.. 3"); s_fontBank.initialise(&standardFont); + } @@ -106,11 +116,34 @@ void CPaulScene::render() Params: Returns: ---------------------------------------------------------------------- */ +int trashoff=-1; +int trash=false; void CPaulScene::think() { // static int arse=0; // PAUL_DBGMSG("%d\n",arse++); // ASSERT(arse<100); + + int i; + int size[3]; + + for(i=0;i<3;i++) + { + size[i]=32763;//getRndRange(32768); + s_mem[i]=MemAlloc(size[i],"Test"); + } + PAUL_DBGMSG("%d %d %d",size[0],size[1],size[2]); + + if(trash) + { + *(s_mem[0]+trashoff)=123; + trash=false; + } + + for(i=0;i<3;i++) + { + MemFree(s_mem[i]); + } }