Pre allocate RDRAM space

This commit is contained in:
zilmar 2012-12-18 21:43:29 +11:00
parent 718239477f
commit d3c946891b
3 changed files with 68 additions and 23 deletions

View File

@ -2,6 +2,9 @@
DWORD RegModValue;
BYTE * CMipsMemoryVM::m_Reserve1 = NULL;
BYTE * CMipsMemoryVM::m_Reserve2 = NULL;
CMipsMemoryVM::CMipsMemoryVM ( CMipsMemory_CallBack * CallBack, bool SavesReadOnly ) :
CPifRam(SavesReadOnly),
@ -56,6 +59,29 @@ void CMipsMemoryVM::Reset( bool /*EraseMemory*/ )
}
}
void CMipsMemoryVM::ReserveMemory ( void )
{
m_Reserve1 = (unsigned char *) VirtualAlloc( NULL, 0x20000000, MEM_RESERVE | MEM_TOP_DOWN, PAGE_READWRITE );
if (g_Settings->LoadBool(Debugger_Enabled))
{
m_Reserve2 = (unsigned char *) VirtualAlloc( NULL, 0x20000000, MEM_RESERVE | MEM_TOP_DOWN, PAGE_READWRITE );
}
}
void CMipsMemoryVM::FreeReservedMemory ( void )
{
if (m_Reserve1)
{
VirtualFree( m_Reserve1, 0 , MEM_RELEASE);
m_Reserve1 = NULL;
}
if (m_Reserve2)
{
VirtualFree( m_Reserve2, 0 , MEM_RELEASE);
m_Reserve2 = NULL;
}
}
BOOL CMipsMemoryVM::Initialize ( void )
{
if (m_RDRAM != NULL)
@ -63,7 +89,9 @@ BOOL CMipsMemoryVM::Initialize ( void )
return true;
}
m_RDRAM = (unsigned char *) VirtualAlloc( NULL, 0x20000000, MEM_RESERVE | MEM_TOP_DOWN, PAGE_READWRITE );
if (m_Reserve1) { m_RDRAM = m_Reserve1; m_Reserve1 = NULL; }
if (m_RDRAM == NULL && m_Reserve2) { m_RDRAM = m_Reserve2; m_Reserve2 = NULL; }
if (m_RDRAM == NULL) { m_RDRAM = (unsigned char *) VirtualAlloc( NULL, 0x20000000, MEM_RESERVE | MEM_TOP_DOWN, PAGE_READWRITE ); }
if( m_RDRAM == NULL )
{
WriteTraceF(TraceError,__FUNCTION__ ": Failed to Reserve RDRAM (Size: 0x%X)",0x20000000);
@ -134,7 +162,14 @@ void CMipsMemoryVM::FreeMemory ( void )
{
if (m_RDRAM)
{
VirtualFree( m_RDRAM, 0 , MEM_RELEASE);
if (VirtualFree( m_RDRAM, 0x20000000,MEM_DECOMMIT) != 0)
{
if (m_Reserve1 == NULL) { m_Reserve1 = m_RDRAM; }
else if (m_Reserve2 == NULL) { m_Reserve2 = m_RDRAM; }
else { VirtualFree( m_RDRAM, 0 , MEM_RELEASE); }
} else {
VirtualFree( m_RDRAM, 0 , MEM_RELEASE);
}
m_RDRAM = NULL;
m_IMEM = NULL;
m_DMEM = NULL;

View File

@ -8,31 +8,13 @@ class CMipsMemoryVM :
private CSram,
private CDMA
{
CMipsMemory_CallBack * const m_CBClass;
//Memory Locations
BYTE * m_RDRAM, * m_DMEM, * m_IMEM;
DWORD m_AllocatedRdramSize;
//Rom Information
bool m_RomMapped;
BYTE * m_Rom;
DWORD m_RomSize;
bool m_RomWrittenTo;
DWORD m_RomWroteValue;
//Current Half line
void UpdateHalfLine ( void );
DWORD m_HalfLine;
DWORD m_TempValue;
//Initilizing and reseting information about the memory system
void FreeMemory ( void );
public:
CMipsMemoryVM ( CMipsMemory_CallBack * CallBack, bool SavesReadOnly );
~CMipsMemoryVM ( void );
static void ReserveMemory ( void );
static void FreeReservedMemory ( void );
BOOL Initialize ( void );
void Reset ( bool EraseMemory );
@ -111,6 +93,10 @@ public:
LPCTSTR LabelName ( DWORD Address ) const;
private:
CMipsMemoryVM(void); // Disable default constructor
CMipsMemoryVM(const CMipsMemoryVM&); // Disable copy constructor
CMipsMemoryVM& operator=(const CMipsMemoryVM&); // Disable assignment
static void RdramChanged ( CMipsMemoryVM * _this );
static void ChangeSpStatus ( void );
static void ChangeMiIntrMask ( void );
@ -125,6 +111,28 @@ private:
void Compile_StoreInstructClean (x86Reg AddressReg, int Length );
CMipsMemory_CallBack * const m_CBClass;
//Memory Locations
static BYTE * m_Reserve1, * m_Reserve2;
BYTE * m_RDRAM, * m_DMEM, * m_IMEM;
DWORD m_AllocatedRdramSize;
//Rom Information
bool m_RomMapped;
BYTE * m_Rom;
DWORD m_RomSize;
bool m_RomWrittenTo;
DWORD m_RomWroteValue;
//Current Half line
void UpdateHalfLine ( void );
DWORD m_HalfLine;
DWORD m_TempValue;
//Initilizing and reseting information about the memory system
void FreeMemory ( void );
mutable char m_strLabelName[100];
//BIG look up table to quickly translate the tlb to real mem address

View File

@ -263,6 +263,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lps
WriteTrace(TraceDebug,__FUNCTION__ ": Application Starting");
FixUPXIssue((BYTE *)hInstance);
CMipsMemoryVM::ReserveMemory();
g_Notify = &Notify();
//Create the plugin container