This commit is contained in:
parent
260b8ab85e
commit
4e57518409
2 changed files with 97 additions and 1 deletions
|
@ -18,6 +18,16 @@ void MemRemoveNode(sLList *LList,u_short Node);
|
||||||
sLList MainRam;
|
sLList MainRam;
|
||||||
int MemNodeCount=0;
|
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__
|
#ifdef __DEBUG_MEM__
|
||||||
|
@ -117,6 +127,8 @@ static FontBank s_debugFont;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void dumpDebugMem()
|
void dumpDebugMem()
|
||||||
{
|
{
|
||||||
if (s_dumpMem)
|
if (s_dumpMem)
|
||||||
|
@ -386,6 +398,9 @@ u32 Len = ((TLen + 3) & 0xfffffffc);
|
||||||
int BestNode,FirstNode;
|
int BestNode,FirstNode;
|
||||||
|
|
||||||
Len += 4; //add on 4 to store Addr !
|
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)
|
// Find First (and possably only)
|
||||||
while (Head != 0xffff && mem->Nodes[ Head ].Len<Len) Head = mem->Nodes[ Head ].Next;
|
while (Head != 0xffff && mem->Nodes[ Head ].Len<Len) Head = mem->Nodes[ Head ].Next;
|
||||||
|
@ -411,8 +426,30 @@ int BestNode,FirstNode;
|
||||||
mem->Nodes[BestNode].Len -= Len;
|
mem->Nodes[BestNode].Len -= Len;
|
||||||
mem->Nodes[BestNode].Addr += Len;
|
mem->Nodes[BestNode].Addr += Len;
|
||||||
if (mem->Nodes[BestNode].Len == 0) MemRemoveNode( mem, BestNode);
|
if (mem->Nodes[BestNode].Len == 0) MemRemoveNode( mem, BestNode);
|
||||||
|
|
||||||
|
|
||||||
*(u32*)Addr = Len;
|
*(u32*)Addr = Len;
|
||||||
Addr += 4;
|
Addr += 4;
|
||||||
|
|
||||||
|
#ifdef USE_MEM_GUARDS
|
||||||
|
unsigned int i;
|
||||||
|
for(i=0;i<MEM_GUARD_SIZE;i+=sizeof(int))
|
||||||
|
{
|
||||||
|
*(int*)(Addr+i)=HEAD_GUARD_FILL_PATTERN;
|
||||||
|
}
|
||||||
|
Addr+=MEM_GUARD_SIZE;
|
||||||
|
|
||||||
|
for(i=0;i<((TLen+3)&0xfffffffc);i+=sizeof(int))
|
||||||
|
{
|
||||||
|
*(int*)(Addr+i)=MEM_FILL_PATTERN;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0;i<MEM_GUARD_SIZE;i+=sizeof(int))
|
||||||
|
{
|
||||||
|
*(int*)(Addr+((TLen+3)&0xfffffffc)+i)=TAIL_GUARD_FILL_PATTERN;
|
||||||
|
}
|
||||||
|
#endif /* USE_MEM_GUARDS */
|
||||||
|
|
||||||
mem->RamUsed += Len;
|
mem->RamUsed += Len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,10 +472,36 @@ char *Addr = (char*)Address;
|
||||||
|
|
||||||
// If file from Databank, dont try and clear it (simple!!)
|
// If file from Databank, dont try and clear it (simple!!)
|
||||||
if (CFileIO::IsFromDataBank(Address)) return;
|
if (CFileIO::IsFromDataBank(Address)) return;
|
||||||
|
#ifdef USE_MEM_GUARDS
|
||||||
|
Addr-=MEM_GUARD_SIZE;
|
||||||
|
#endif /* USE_MEM_GUARDS */
|
||||||
Addr -= 4;
|
Addr -= 4;
|
||||||
|
|
||||||
Len = *(u32*)Addr;
|
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;i<MEM_GUARD_SIZE;i+=sizeof(unsigned int),guardAddr++)
|
||||||
|
{
|
||||||
|
if(*guardAddr!=HEAD_GUARD_FILL_PATTERN)
|
||||||
|
{
|
||||||
|
ASSERT(!"Memory guard trashed (head)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
guardAddr=(unsigned int*)(Addr+Len-MEM_GUARD_SIZE);
|
||||||
|
for(i=0;i<MEM_GUARD_SIZE;i+=sizeof(unsigned int),guardAddr++)
|
||||||
|
{
|
||||||
|
if(*guardAddr!=TAIL_GUARD_FILL_PATTERN)
|
||||||
|
{
|
||||||
|
ASSERT(!"Memory guard trashed (tail)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* USE_MEM_GUARDS */
|
||||||
|
|
||||||
mem->RamUsed -= Len;
|
mem->RamUsed -= Len;
|
||||||
|
|
||||||
node = &mem->Nodes[ Head ];
|
node = &mem->Nodes[ Head ];
|
||||||
|
|
|
@ -26,6 +26,14 @@
|
||||||
#include "gfx\font.h"
|
#include "gfx\font.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef __MEMORY_HEADER__
|
||||||
|
#include "mem\memory.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __UTILS_HEADER__
|
||||||
|
#include "utils\utils.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Std Lib
|
/* Std Lib
|
||||||
------- */
|
------- */
|
||||||
|
@ -49,6 +57,7 @@
|
||||||
Vars
|
Vars
|
||||||
---- */
|
---- */
|
||||||
static FontBank s_fontBank;
|
static FontBank s_fontBank;
|
||||||
|
char *s_mem[3];
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------
|
/*----------------------------------------------------------------------
|
||||||
|
@ -65,6 +74,7 @@ void CPaulScene::init()
|
||||||
PAUL_DBGMSG("this is a message.. 3");
|
PAUL_DBGMSG("this is a message.. 3");
|
||||||
|
|
||||||
s_fontBank.initialise(&standardFont);
|
s_fontBank.initialise(&standardFont);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,11 +116,34 @@ void CPaulScene::render()
|
||||||
Params:
|
Params:
|
||||||
Returns:
|
Returns:
|
||||||
---------------------------------------------------------------------- */
|
---------------------------------------------------------------------- */
|
||||||
|
int trashoff=-1;
|
||||||
|
int trash=false;
|
||||||
void CPaulScene::think()
|
void CPaulScene::think()
|
||||||
{
|
{
|
||||||
// static int arse=0;
|
// static int arse=0;
|
||||||
// PAUL_DBGMSG("%d\n",arse++);
|
// PAUL_DBGMSG("%d\n",arse++);
|
||||||
// ASSERT(arse<100);
|
// 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]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue