2012-12-19 09:30:18 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
|
|
|
* Project 64 - A Nintendo 64 emulator. *
|
|
|
|
* http://www.pj64-emu.com/ *
|
|
|
|
* Copyright (C) 2012 Project64. All rights reserved. *
|
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
2010-06-04 06:25:07 +00:00
|
|
|
#include "stdafx.h"
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
CFunctionMap::CFunctionMap() :
|
2010-06-29 02:11:22 +00:00
|
|
|
m_JumpTable(NULL),
|
2012-10-01 03:49:31 +00:00
|
|
|
m_FunctionTable(NULL)
|
2010-05-25 09:15:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CFunctionMap::~CFunctionMap()
|
|
|
|
{
|
2010-06-12 02:02:06 +00:00
|
|
|
CleanBuffers();
|
2010-05-25 09:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CFunctionMap::AllocateMemory()
|
|
|
|
{
|
2013-01-04 22:47:28 +00:00
|
|
|
if (g_System->LookUpMode() == FuncFind_VirtualLookup && m_FunctionTable == NULL)
|
2010-06-04 06:25:07 +00:00
|
|
|
{
|
2013-01-04 22:47:28 +00:00
|
|
|
m_FunctionTable = (PCCompiledFunc_TABLE *)VirtualAlloc(NULL,0xFFFFF * sizeof(CCompiledFunc *),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE);
|
|
|
|
if (m_FunctionTable == NULL) {
|
|
|
|
WriteTrace(TraceError,__FUNCTION__ ": failed to allocate function table");
|
|
|
|
g_Notify->FatalError(MSG_MEM_ALLOC_ERROR);
|
|
|
|
return false;
|
2010-06-29 02:11:22 +00:00
|
|
|
}
|
2013-01-04 22:47:28 +00:00
|
|
|
memset(m_FunctionTable,0,0xFFFFF * sizeof(CCompiledFunc *));
|
2010-05-25 09:15:19 +00:00
|
|
|
}
|
2013-01-04 22:47:28 +00:00
|
|
|
if (g_System->LookUpMode() == FuncFind_PhysicalLookup && m_JumpTable == NULL)
|
2010-06-07 02:23:58 +00:00
|
|
|
{
|
2012-11-17 01:18:00 +00:00
|
|
|
m_JumpTable = new PCCompiledFunc[g_MMU->RdramSize() >> 2];
|
2013-01-04 22:47:28 +00:00
|
|
|
if (m_JumpTable == NULL)
|
|
|
|
{
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTrace(TraceError,__FUNCTION__ ": failed to allocate jump table");
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify->FatalError(MSG_MEM_ALLOC_ERROR);
|
2010-06-29 02:11:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-17 01:18:00 +00:00
|
|
|
memset(m_JumpTable,0,(g_MMU->RdramSize() >> 2) * sizeof(PCCompiledFunc));
|
2010-06-07 02:23:58 +00:00
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-12 02:02:06 +00:00
|
|
|
void CFunctionMap::CleanBuffers ( void )
|
|
|
|
{
|
|
|
|
if (m_FunctionTable)
|
|
|
|
{
|
|
|
|
for (int i = 0, n = 0x100000; i < n; i++)
|
|
|
|
{
|
|
|
|
if (m_FunctionTable[i] != NULL)
|
|
|
|
{
|
|
|
|
delete m_FunctionTable[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VirtualFree( m_FunctionTable, 0 , MEM_RELEASE);
|
|
|
|
m_FunctionTable = NULL;
|
|
|
|
}
|
2010-06-29 02:11:22 +00:00
|
|
|
if (m_JumpTable)
|
|
|
|
{
|
|
|
|
delete [] m_JumpTable;
|
|
|
|
m_JumpTable = NULL;
|
|
|
|
}
|
2010-06-12 02:02:06 +00:00
|
|
|
}
|
|
|
|
|
2013-01-03 08:51:00 +00:00
|
|
|
void CFunctionMap::Reset ( bool bAllocate )
|
2010-06-12 02:02:06 +00:00
|
|
|
{
|
|
|
|
CleanBuffers();
|
2013-01-04 22:47:28 +00:00
|
|
|
if (bAllocate && (g_System->LookUpMode() == FuncFind_VirtualLookup || g_System->LookUpMode() == FuncFind_PhysicalLookup))
|
2010-06-12 02:02:06 +00:00
|
|
|
{
|
|
|
|
AllocateMemory();
|
|
|
|
}
|
2015-01-31 19:27:27 +00:00
|
|
|
}
|