2010-06-04 06:25:07 +00:00
|
|
|
#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>
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
CFunctionMap::CFunctionMap() :
|
2021-04-14 05:34:15 +00:00
|
|
|
m_JumpTable(nullptr),
|
|
|
|
m_FunctionTable(nullptr)
|
2010-05-25 09:15:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CFunctionMap::~CFunctionMap()
|
|
|
|
{
|
2015-11-09 20:07:54 +00:00
|
|
|
CleanBuffers();
|
2010-05-25 09:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CFunctionMap::AllocateMemory()
|
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceRecompiler, TraceDebug, "Start");
|
2021-04-12 11:35:39 +00:00
|
|
|
if (LookUpMode() == FuncFind_VirtualLookup && m_FunctionTable == nullptr)
|
2015-11-09 20:07:54 +00:00
|
|
|
{
|
2017-01-03 05:38:44 +00:00
|
|
|
m_FunctionTable = new PCCompiledFunc_TABLE[0x100000];
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_FunctionTable == nullptr)
|
2015-11-09 20:07:54 +00:00
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceRecompiler, TraceError, "Failed to allocate function table");
|
2015-11-09 20:07:54 +00:00
|
|
|
g_Notify->FatalError(MSG_MEM_ALLOC_ERROR);
|
|
|
|
return false;
|
|
|
|
}
|
2016-01-13 21:38:54 +00:00
|
|
|
memset(m_FunctionTable, 0, 0x100000 * sizeof(PCCompiledFunc_TABLE));
|
2015-11-09 20:07:54 +00:00
|
|
|
}
|
2021-04-12 11:35:39 +00:00
|
|
|
if (LookUpMode() == FuncFind_PhysicalLookup && m_JumpTable == nullptr)
|
2015-11-09 20:07:54 +00:00
|
|
|
{
|
2017-01-03 05:38:44 +00:00
|
|
|
m_JumpTable = new PCCompiledFunc[RdramSize() >> 2];
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_JumpTable == nullptr)
|
2015-11-09 20:07:54 +00:00
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceRecompiler, TraceError, "Failed to allocate jump table");
|
2015-11-09 20:07:54 +00:00
|
|
|
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));
|
2015-11-09 20:07:54 +00:00
|
|
|
}
|
2016-09-26 11:10:11 +00:00
|
|
|
WriteTrace(TraceRecompiler, TraceDebug, "Done");
|
2015-11-09 20:07:54 +00:00
|
|
|
return true;
|
2010-05-25 09:15:19 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CFunctionMap::CleanBuffers()
|
2010-06-12 02:02:06 +00:00
|
|
|
{
|
2015-11-09 20:07:54 +00:00
|
|
|
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)
|
2015-11-09 20:07:54 +00:00
|
|
|
{
|
|
|
|
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;
|
2015-11-09 20:07:54 +00:00
|
|
|
}
|
|
|
|
if (m_JumpTable)
|
|
|
|
{
|
|
|
|
delete[] m_JumpTable;
|
2021-04-12 11:35:39 +00:00
|
|
|
m_JumpTable = nullptr;
|
2015-11-09 20:07:54 +00:00
|
|
|
}
|
2010-06-12 02:02:06 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 20:07:54 +00:00
|
|
|
void CFunctionMap::Reset(bool bAllocate)
|
2010-06-12 02:02:06 +00:00
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(TraceRecompiler, TraceDebug, "Start (bAllocate: %s)", bAllocate ? "true" : "false");
|
2015-11-09 20:07:54 +00:00
|
|
|
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");
|
2015-12-14 10:51:33 +00:00
|
|
|
}
|