#define INVALID_POINTER NULL // ((void*)INVALID32)
#define STACK_EMPTY(p) (INVALID_POINTER == p)
typedef struct
{
uint8* mpTopPointer;
uint8* mpBottomPointer;
uint8* mpMax;
uint32 mdWidth;
uint32 mdSize;
} TStackCtl, *pTStackCtl;
Bool IsStackEmpty(pTStackCtl pSatckData)
{
if(pSatckData->mpBottomPointer == pSatckData->mpTopPointer)
return TRUE;
else
return FALSE;
}
void PushStackDataEntry(pTStackCtl pSatckData)
{
// If the stack is not full, push the entry.
if(pSatckData->mpMax != pSatckData->mpTopPointer)
{
pSatckData->mpTopPointer += pSatckData->mdWidth;
}
}
void PopStackDataEntry(pTStackCtl pSatckData)
{
// If the stack is not empty, pop the entry.
if(pSatckData->mpBottomPointer != pSatckData->mpTopPointer)
{
pSatckData->mpTopPointer -= pSatckData->mdWidth;
}
}
void* GetStackFreeEntry(pTStackCtl pSatckData)
{
void* p;
// If the stack is full, return invalid pointer.
if(pSatckData->mpMax == pSatckData->mpTopPointer)
{
p = INVALID_POINTER;
}
else
{
p = pSatckData->mpTopPointer;
}
return p;
}
void* GetStackTopEntry(pTStackCtl pSatckData)
{
void* p;
// If the stack is empty, return invalid pointer.
if(pSatckData->mpBottomPointer == pSatckData->mpTopPointer)
{
p = INVALID_POINTER;
}
else
{
p = pSatckData->mpTopPointer - pSatckData->mdWidth;
}
return p;
}
void InitStackEntry(pTStackCtl pSatckData, uint8* pBottomPointer, uint32 dWidth, uint32 dCount)
{
pSatckData->mpTopPointer = pBottomPointer;
pSatckData->mpBottomPointer = pBottomPointer;
pSatckData->mdWidth = dWidth;
pSatckData->mdSize = dCount * dWidth;
pSatckData->mpMax = pBottomPointer + dCount * dWidth;
}