implement QueryTotalFreeMemSize()

This commit is contained in:
Ian Brown 2019-01-15 21:31:17 +00:00
parent 20113e02d2
commit 0c24165d92
2 changed files with 28 additions and 0 deletions

View File

@ -11,6 +11,7 @@ using namespace Iop;
#define FUNCTION_PRINTF "printf"
#define FUNCTION_QUERYMEMSIZE "QueryMemSize"
#define FUNCTION_QUERYMAXFREEMEMSIZE "QueryMaxFreeMemSize"
#define FUNCTION_QUERYTOTALFREEMEMSIZE "QueryTotalFreeMemSize"
#define MIN_BLOCK_SIZE 0x100
@ -59,6 +60,9 @@ std::string CSysmem::GetFunctionName(unsigned int functionId) const
case 7:
return FUNCTION_QUERYMAXFREEMEMSIZE;
break;
case 8:
return FUNCTION_QUERYTOTALFREEMEMSIZE;
break;
case 14:
return FUNCTION_PRINTF;
break;
@ -88,6 +92,9 @@ void CSysmem::Invoke(CMIPS& context, unsigned int functionId)
case 7:
context.m_State.nGPR[CMIPS::V0].nD0 = QueryMaxFreeMemSize();
break;
case 8:
context.m_State.nGPR[CMIPS::V0].nD0 = QueryTotalFreeMemSize();
break;
case 14:
m_stdio.__printf(context);
break;
@ -124,6 +131,9 @@ bool CSysmem::Invoke(uint32 method, uint32* args, uint32 argsSize, uint32* ret,
case 0x07:
ret[0] = QueryMaxFreeMemSize();
break;
case 0x08:
ret[0] = QueryTotalFreeMemSize();
break;
default:
CLog::GetInstance().Print(LOG_NAME, "Unknown method invoked (0x%08X).\r\n", method);
break;
@ -131,6 +141,23 @@ bool CSysmem::Invoke(uint32 method, uint32* args, uint32 argsSize, uint32* ret,
return true;
}
uint32 CSysmem::QueryTotalFreeMemSize()
{
uint32 totalSize = 0;
uint32 begin = 0;
auto nextBlockId = &m_headBlockId;
auto nextBlock = m_blocks[*nextBlockId];
while(nextBlock != nullptr)
{
uint32 end = nextBlock->address;
totalSize += (end - begin);
begin = nextBlock->address + nextBlock->size;
nextBlockId = &nextBlock->nextBlockId;
nextBlock = m_blocks[*nextBlockId];
}
return totalSize;
}
uint32 CSysmem::QueryMaxFreeMemSize()
{
uint32 maxSize = 0;

View File

@ -39,6 +39,7 @@ namespace Iop
uint32 SifFreeMemory(uint32);
uint32 QueryMaxFreeMemSize();
uint32 QueryTotalFreeMemSize();
uint8* m_iopRam = nullptr;
BlockListType& m_blocks;