project64/Source/Project64-core/N64System/Recompiler/FunctionMap.cpp

77 lines
2.2 KiB
C++
Raw Normal View History

#include "stdafx.h"
2022-10-10 00:22:17 +00:00
#include <Project64-core/N64System/N64System.h>
2021-04-14 05:34:15 +00:00
#include <Project64-core/N64System/Recompiler/FunctionMap.h>
2015-12-06 09:59:58 +00:00
#include <Project64-core/N64System/SystemGlobals.h>
CFunctionMap::CFunctionMap() :
2021-04-14 05:34:15 +00:00
m_JumpTable(nullptr),
m_FunctionTable(nullptr)
{
}
CFunctionMap::~CFunctionMap()
{
CleanBuffers();
}
bool CFunctionMap::AllocateMemory()
{
WriteTrace(TraceRecompiler, TraceDebug, "Start");
2021-04-12 11:35:39 +00:00
if (LookUpMode() == FuncFind_VirtualLookup && m_FunctionTable == nullptr)
{
m_FunctionTable = new PCCompiledFunc_TABLE[0x100000];
2021-04-12 11:35:39 +00:00
if (m_FunctionTable == nullptr)
{
WriteTrace(TraceRecompiler, TraceError, "Failed to allocate function table");
g_Notify->FatalError(MSG_MEM_ALLOC_ERROR);
return false;
}
memset(m_FunctionTable, 0, 0x100000 * sizeof(PCCompiledFunc_TABLE));
}
2021-04-12 11:35:39 +00:00
if (LookUpMode() == FuncFind_PhysicalLookup && m_JumpTable == nullptr)
{
m_JumpTable = new PCCompiledFunc[RdramSize() >> 2];
2021-04-12 11:35:39 +00:00
if (m_JumpTable == nullptr)
{
WriteTrace(TraceRecompiler, TraceError, "Failed to allocate jump table");
g_Notify->FatalError(MSG_MEM_ALLOC_ERROR);
return false;
}
2016-09-26 11:10:11 +00:00
memset(m_JumpTable, 0, (RdramSize() >> 2) * sizeof(PCCompiledFunc));
}
2016-09-26 11:10:11 +00:00
WriteTrace(TraceRecompiler, TraceDebug, "Done");
return true;
}
void CFunctionMap::CleanBuffers()
{
if (m_FunctionTable)
{
for (int i = 0, n = 0x100000; i < n; i++)
{
2021-04-12 11:35:39 +00:00
if (m_FunctionTable[i] != nullptr)
{
delete m_FunctionTable[i];
}
}
2016-09-26 11:10:11 +00:00
delete[] m_FunctionTable;
2021-04-12 11:35:39 +00:00
m_FunctionTable = nullptr;
}
if (m_JumpTable)
{
delete[] m_JumpTable;
2021-04-12 11:35:39 +00:00
m_JumpTable = nullptr;
}
}
void CFunctionMap::Reset(bool bAllocate)
{
WriteTrace(TraceRecompiler, TraceDebug, "Start (bAllocate: %s)", bAllocate ? "true" : "false");
CleanBuffers();
if (bAllocate && (g_System->LookUpMode() == FuncFind_VirtualLookup || g_System->LookUpMode() == FuncFind_PhysicalLookup))
{
AllocateMemory();
}
2016-09-26 11:10:11 +00:00
WriteTrace(TraceRecompiler, TraceDebug, "Done");
}