From dda79ce3456d01e2acefc2b4b1006f5306adc3a2 Mon Sep 17 00:00:00 2001 From: zilmar Date: Tue, 10 Nov 2015 07:22:51 +1100 Subject: [PATCH] [Project64] get Recompiler Memory.cpp to use standard types --- .../Recompiler/Recompiler Memory.cpp | 41 +++++++++---------- .../N64 System/Recompiler/Recompiler Memory.h | 13 +++--- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/Source/Project64/N64 System/Recompiler/Recompiler Memory.cpp b/Source/Project64/N64 System/Recompiler/Recompiler Memory.cpp index b119c6449..be4b9040a 100644 --- a/Source/Project64/N64 System/Recompiler/Recompiler Memory.cpp +++ b/Source/Project64/N64 System/Recompiler/Recompiler Memory.cpp @@ -11,8 +11,8 @@ #include "stdafx.h" CRecompMemory::CRecompMemory() : - m_RecompCode(NULL), - m_RecompSize(0) +m_RecompCode(NULL), +m_RecompSize(0) { m_RecompPos = NULL; } @@ -21,7 +21,7 @@ CRecompMemory::~CRecompMemory() { if (m_RecompCode) { - VirtualFree( m_RecompCode, 0 , MEM_RELEASE); + VirtualFree(m_RecompCode, 0, MEM_RELEASE); m_RecompCode = NULL; } m_RecompPos = NULL; @@ -29,25 +29,25 @@ CRecompMemory::~CRecompMemory() bool CRecompMemory::AllocateMemory() { - BYTE * RecompCodeBase = (BYTE *)VirtualAlloc( NULL, MaxCompileBufferSize + 4, MEM_RESERVE|MEM_TOP_DOWN, PAGE_EXECUTE_READWRITE); + BYTE * RecompCodeBase = (BYTE *)VirtualAlloc(NULL, MaxCompileBufferSize + 4, MEM_RESERVE | MEM_TOP_DOWN, PAGE_EXECUTE_READWRITE); if (RecompCodeBase == NULL) { - WriteTrace(TraceError,__FUNCTION__ ": failed to allocate RecompCodeBase"); + WriteTrace(TraceError, __FUNCTION__ ": failed to allocate RecompCodeBase"); g_Notify->DisplayError(MSG_MEM_ALLOC_ERROR); return false; } - m_RecompCode = (BYTE *)VirtualAlloc( RecompCodeBase, InitialCompileBufferSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE); + m_RecompCode = (BYTE *)VirtualAlloc(RecompCodeBase, InitialCompileBufferSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE); if (m_RecompCode == NULL) { - WriteTrace(TraceError,__FUNCTION__ ": failed to commit initial buffer"); - VirtualFree( RecompCodeBase, 0 , MEM_RELEASE); + WriteTrace(TraceError, __FUNCTION__ ": failed to commit initial buffer"); + VirtualFree(RecompCodeBase, 0, MEM_RELEASE); g_Notify->DisplayError(MSG_MEM_ALLOC_ERROR); return false; } m_RecompSize = InitialCompileBufferSize; m_RecompPos = m_RecompCode; - memset(m_RecompCode,0,InitialCompileBufferSize); + memset(m_RecompCode, 0, InitialCompileBufferSize); return true; } @@ -58,19 +58,18 @@ void CRecompMemory::CheckRecompMem() { return; } - if (m_RecompSize == MaxCompileBufferSize) - { - g_Recompiler->ResetRecompCode(true); - return; - } - LPVOID MemAddr = VirtualAlloc( m_RecompCode + m_RecompSize , IncreaseCompileBufferSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE); - if (MemAddr == NULL) + if (m_RecompSize == MaxCompileBufferSize) { - WriteTrace(TraceError,__FUNCTION__ ": failed to increase buffer"); + g_Recompiler->ResetRecompCode(true); + return; + } + LPVOID MemAddr = VirtualAlloc(m_RecompCode + m_RecompSize, IncreaseCompileBufferSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE); + if (MemAddr == NULL) + { + WriteTrace(TraceError, __FUNCTION__ ": failed to increase buffer"); g_Notify->FatalError(MSG_MEM_ALLOC_ERROR); } m_RecompSize += IncreaseCompileBufferSize; - } void CRecompMemory::Reset() @@ -84,9 +83,9 @@ void CRecompMemory::ShowMemUsed() DWORD MB = Size / 0x100000; Size -= MB * 0x100000; DWORD KB = Size / 1024; - Size -= KB * 1024; + Size -= KB * 1024; DWORD TotalAvaliable = m_RecompSize / 0x100000; - - g_Notify->DisplayMessage(0,stdstr_f("Memory used: %d mb %-3d kb %-3d bytes Total Available: %d mb",MB,KB,Size, TotalAvaliable).ToUTF16().c_str()); + + g_Notify->DisplayMessage(0, stdstr_f("Memory used: %d mb %-3d kb %-3d bytes Total Available: %d mb", MB, KB, Size, TotalAvaliable).ToUTF16().c_str()); } diff --git a/Source/Project64/N64 System/Recompiler/Recompiler Memory.h b/Source/Project64/N64 System/Recompiler/Recompiler Memory.h index 17a9024c8..092a248c1 100644 --- a/Source/Project64/N64 System/Recompiler/Recompiler Memory.h +++ b/Source/Project64/N64 System/Recompiler/Recompiler Memory.h @@ -22,13 +22,16 @@ protected: void Reset(); void ShowMemUsed(); - BYTE* RecompPos() const { return m_RecompPos; } + uint8_t* RecompPos() const { return m_RecompPos; } private: - BYTE * m_RecompCode; - DWORD m_RecompSize; + CRecompMemory(const CRecompMemory&); // Disable copy constructor + CRecompMemory& operator=(const CRecompMemory&); // Disable assignment - enum { MaxCompileBufferSize = 0x03C00000 }; - enum { InitialCompileBufferSize = 0x00500000 }; + uint8_t * m_RecompCode; + uint32_t m_RecompSize; + + enum { MaxCompileBufferSize = 0x03C00000 }; + enum { InitialCompileBufferSize = 0x00500000 }; enum { IncreaseCompileBufferSize = 0x00100000 }; };