Play-/Source/iop/Iop_Heaplib.cpp
Jean-Philip Desjardins 30568a057d
Some checks failed
Build macOS / build_macos (push) Has been cancelled
Build Android / build_android (apk) (push) Has been cancelled
Build Android / build_android (libretro) (push) Has been cancelled
Build Linux ARM32 / build_linux_arm32 (push) Has been cancelled
Build Linux ARM64 / build_linux_arm64 (push) Has been cancelled
Build Windows Psf / build_windows_psf (off, x86_64, Visual Studio 16 2019, installer64.nsi, x64) (push) Has been cancelled
Build Windows Psf / build_windows_psf (on, x86_64, Visual Studio 16 2019, installer64.nsi, x64) (push) Has been cancelled
Build Windows / build_windows (x86_32, Visual Studio 16 2019, installer32.nsi, win32_msvc2019, Win32) (push) Has been cancelled
Build Windows / build_windows (x86_64, Visual Studio 16 2019, installer64.nsi, win64_msvc2019_64, x64) (push) Has been cancelled
Check Format / run_clangformat (push) Has been cancelled
Build iOS / build_ios (push) Has been cancelled
Build JavaScript / build_js (push) Has been cancelled
Build Linux / build_linux (push) Has been cancelled
Use app_config module.
2025-03-11 16:18:58 -04:00

91 lines
2.1 KiB
C++

#include "Iop_Heaplib.h"
#include "Log.h"
using namespace Iop;
#define LOG_NAME ("iop_heaplib")
#define HEAP_PTR 0x12121212
#define FUNCTION_CREATEHEAP "CreateHeap"
#define FUNCTION_ALLOCHEAPMEMORY "AllocHeapMemory"
#define FUNCTION_FREEHEAPMEMORY "FreeHeapMemory"
CHeaplib::CHeaplib(CSysmem& sysMem)
: m_sysMem(sysMem)
{
}
std::string CHeaplib::GetId() const
{
return "heaplib";
}
std::string CHeaplib::GetFunctionName(unsigned int functionId) const
{
switch(functionId)
{
case 4:
return FUNCTION_CREATEHEAP;
break;
case 6:
return FUNCTION_ALLOCHEAPMEMORY;
break;
case 7:
return FUNCTION_FREEHEAPMEMORY;
break;
default:
return "unknown";
break;
}
}
void CHeaplib::Invoke(CMIPS& context, unsigned int functionId)
{
switch(functionId)
{
case 4:
context.m_State.nGPR[CMIPS::V0].nD0 = CreateHeap(
context.m_State.nGPR[CMIPS::A0].nV0,
context.m_State.nGPR[CMIPS::A1].nV0);
break;
case 6:
context.m_State.nGPR[CMIPS::V0].nD0 = AllocHeapMemory(
context.m_State.nGPR[CMIPS::A0].nV0,
context.m_State.nGPR[CMIPS::A1].nV0);
break;
case 7:
context.m_State.nGPR[CMIPS::V0].nD0 = FreeHeapMemory(
context.m_State.nGPR[CMIPS::A0].nV0,
context.m_State.nGPR[CMIPS::A1].nV0);
break;
default:
CLog::GetInstance().Warn(LOG_NAME, "Unknown function called (%d).\r\n",
functionId);
break;
}
}
int32 CHeaplib::CreateHeap(uint32 heapSize, uint32 flags)
{
CLog::GetInstance().Print(LOG_NAME, FUNCTION_CREATEHEAP "(heapSize = 0x%08X, flags = %d);\r\n",
heapSize, flags);
return HEAP_PTR;
}
int32 CHeaplib::AllocHeapMemory(uint32 heapPtr, uint32 size)
{
CLog::GetInstance().Print(LOG_NAME, FUNCTION_ALLOCHEAPMEMORY "(heapPtr = 0x%08X, size = 0x%08X);\r\n",
heapPtr, size);
assert(heapPtr == HEAP_PTR);
return m_sysMem.AllocateMemory(size, 0, 0);
}
int32 CHeaplib::FreeHeapMemory(uint32 heapPtr, uint32 allocPtr)
{
CLog::GetInstance().Print(LOG_NAME, FUNCTION_FREEHEAPMEMORY "(heapPtr = 0x%08X, allocPtr = 0x%08X);\r\n",
heapPtr, allocPtr);
assert(heapPtr == HEAP_PTR);
m_sysMem.FreeMemory(allocPtr);
return 0;
}