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-05-25 09:15:19 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
CRecompMemory::CRecompMemory() :
|
2010-05-30 01:54:42 +00:00
|
|
|
m_RecompCode(NULL),
|
2010-05-25 09:15:19 +00:00
|
|
|
m_RecompSize(0)
|
|
|
|
{
|
2010-05-30 01:54:42 +00:00
|
|
|
m_RecompPos = NULL;
|
2010-05-25 09:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CRecompMemory::~CRecompMemory()
|
|
|
|
{
|
|
|
|
if (m_RecompCode)
|
|
|
|
{
|
|
|
|
VirtualFree( m_RecompCode, 0 , MEM_RELEASE);
|
|
|
|
m_RecompCode = NULL;
|
|
|
|
}
|
2010-05-30 01:54:42 +00:00
|
|
|
m_RecompPos = NULL;
|
2010-05-25 09:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CRecompMemory::AllocateMemory()
|
|
|
|
{
|
|
|
|
BYTE * RecompCodeBase = (BYTE *)VirtualAlloc( NULL, MaxCompileBufferSize + 4, MEM_RESERVE|MEM_TOP_DOWN, PAGE_EXECUTE_READWRITE);
|
2010-06-04 06:25:07 +00:00
|
|
|
if (RecompCodeBase==NULL)
|
2010-05-25 09:15:19 +00:00
|
|
|
{
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTrace(TraceError,__FUNCTION__ ": failed to allocate RecompCodeBase");
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify->DisplayError(MSG_MEM_ALLOC_ERROR);
|
2010-05-25 09:15:19 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-06-04 06:25:07 +00:00
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
m_RecompCode = (BYTE *)VirtualAlloc( RecompCodeBase, InitialCompileBufferSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
2010-06-04 06:25:07 +00:00
|
|
|
if (m_RecompCode==NULL)
|
2010-05-25 09:15:19 +00:00
|
|
|
{
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTrace(TraceError,__FUNCTION__ ": failed to commit initial buffer");
|
2010-05-25 09:15:19 +00:00
|
|
|
VirtualFree( RecompCodeBase, 0 , MEM_RELEASE);
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify->DisplayError(MSG_MEM_ALLOC_ERROR);
|
2010-05-25 09:15:19 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
m_RecompSize = InitialCompileBufferSize;
|
2010-05-30 01:54:42 +00:00
|
|
|
m_RecompPos = m_RecompCode;
|
2010-06-12 02:02:06 +00:00
|
|
|
memset(m_RecompCode,0,InitialCompileBufferSize);
|
2010-05-25 09:15:19 +00:00
|
|
|
return true;
|
2010-05-30 01:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CRecompMemory::CheckRecompMem ( void )
|
|
|
|
{
|
2010-10-23 18:53:01 +00:00
|
|
|
DWORD Size = (DWORD)((BYTE *)m_RecompPos - (BYTE *)m_RecompCode);
|
2010-05-30 01:54:42 +00:00
|
|
|
if ((Size + 0x20000) < m_RecompSize)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_RecompSize == MaxCompileBufferSize)
|
|
|
|
{
|
2012-11-17 01:15:55 +00:00
|
|
|
g_Recompiler->ResetRecompCode();
|
2010-05-30 01:54:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
LPVOID MemAddr = VirtualAlloc( m_RecompCode + m_RecompSize , IncreaseCompileBufferSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
|
|
|
if (MemAddr == NULL)
|
|
|
|
{
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTrace(TraceError,__FUNCTION__ ": failed to increase buffer");
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify->FatalError(MSG_MEM_ALLOC_ERROR);
|
2010-05-30 01:54:42 +00:00
|
|
|
}
|
2010-06-22 20:36:28 +00:00
|
|
|
m_RecompSize += IncreaseCompileBufferSize;
|
|
|
|
|
2010-05-30 01:54:42 +00:00
|
|
|
}
|
2010-06-12 02:02:06 +00:00
|
|
|
|
|
|
|
void CRecompMemory::Reset()
|
|
|
|
{
|
|
|
|
m_RecompPos = m_RecompCode;
|
2010-06-16 07:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CRecompMemory::ShowMemUsed()
|
|
|
|
{
|
|
|
|
DWORD Size = m_RecompPos - m_RecompCode;
|
|
|
|
DWORD MB = Size / 0x100000;
|
|
|
|
Size -= MB * 0x100000;
|
|
|
|
DWORD KB = Size / 1024;
|
|
|
|
Size -= KB * 1024;
|
|
|
|
|
|
|
|
DWORD TotalAvaliable = m_RecompSize / 0x100000;
|
|
|
|
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify->DisplayMessage(0,"Memory used: %d mb %-3d kb %-3d bytes Total Available: %d mb",MB,KB,Size, TotalAvaliable);
|
2010-06-12 02:02:06 +00:00
|
|
|
}
|