diff --git a/Source/Project64-core/AppInit.cpp b/Source/Project64-core/AppInit.cpp index c5df07645..36f73cc48 100644 --- a/Source/Project64-core/AppInit.cpp +++ b/Source/Project64-core/AppInit.cpp @@ -234,8 +234,8 @@ bool AppInit(CNotification * Notify, const char * BaseDirectory, int argc, char SetupTrace(); FixDirectories(); -#ifdef _WIN32 CMipsMemoryVM::ReserveMemory(); +#ifdef _WIN32 IncreaseThreadPriority(); #else if (!CMipsMemoryVM::SetupSegvHandler()) diff --git a/Source/Project64-core/N64System/N64Class.h b/Source/Project64-core/N64System/N64Class.h index e14700966..b1b841c52 100644 --- a/Source/Project64-core/N64System/N64Class.h +++ b/Source/Project64-core/N64System/N64Class.h @@ -105,6 +105,8 @@ private: //Recompiler has access to manipulate and call functions friend CSystemTimer; + friend CMipsMemoryVM; + //Used for loading and potentially executing the CPU in its own thread. static void StartEmulationThread(CThread * thread); static bool EmulationStarting(CThread * thread); diff --git a/Source/Project64-core/N64System/N64RomClass.cpp b/Source/Project64-core/N64System/N64RomClass.cpp index 2ba038ad6..15fd5b9ee 100644 --- a/Source/Project64-core/N64System/N64RomClass.cpp +++ b/Source/Project64-core/N64System/N64RomClass.cpp @@ -465,6 +465,8 @@ void CN64Rom::NotificationCB(const char * Status, CN64Rom * /*_this*/) bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly) { + WriteTrace(TraceN64System, TraceDebug, "Start (FileLoc: \"%s\" LoadBootCodeOnly: %s)", FileLoc, LoadBootCodeOnly ? "true" : "false"); + UnallocateRomImage(); m_ErrorMsg = EMPTY_STRING; @@ -482,6 +484,7 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly) { //Pop up a dialog and select file //allocate memory for sub name and copy selected file name to var + WriteTrace(TraceN64System, TraceDebug, "Done (res: false)"); return false; //remove once dialog is done } else @@ -517,6 +520,7 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly) if (!AllocateRomImage(RomFileSize)) { + WriteTrace(TraceN64System, TraceDebug, "Done (res: false)"); return false; } @@ -525,12 +529,14 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly) if (!ZipFile.GetFile(i, m_ROMImage, RomFileSize)) { SetError(MSG_FAIL_IMAGE); + WriteTrace(TraceN64System, TraceDebug, "Done (res: false)"); return false; } if (!IsValidRomImage(m_ROMImage)) { SetError(MSG_FAIL_IMAGE); + WriteTrace(TraceN64System, TraceDebug, "Done (res: false)"); return false; } g_Notify->DisplayMessage(5, MSG_BYTESWAP); @@ -544,6 +550,7 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly) if (!Loaded7zFile) { SetError(MSG_7Z_FILE_NOT_FOUND); + WriteTrace(TraceN64System, TraceDebug, "Done (res: false)"); return false; } } @@ -556,10 +563,12 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly) { if (m_ErrorMsg != EMPTY_STRING) { + WriteTrace(TraceN64System, TraceDebug, "Done (res: false)"); return false; } if (!AllocateAndLoadN64Image(FileLoc, LoadBootCodeOnly)) { + WriteTrace(TraceN64System, TraceDebug, "Done (res: false)"); return false; } } @@ -606,6 +615,7 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly) CalculateRomCrc(); } + WriteTrace(TraceN64System, TraceDebug, "Done (res: true)"); return true; } @@ -759,7 +769,7 @@ void CN64Rom::SaveRomSettingID(bool temp) g_Settings->SaveBool(Game_TempLoaded, temp); g_Settings->SaveString(Game_GameName, m_RomName.c_str()); g_Settings->SaveString(Game_IniKey, m_RomIdent.c_str()); - g_Settings->SaveString(Game_UniqueSaveDir, stdstr_f("%s-%s", m_RomName.c_str(), m_MD5.c_str() ).c_str()); + g_Settings->SaveString(Game_UniqueSaveDir, stdstr_f("%s-%s", m_RomName.c_str(), m_MD5.c_str()).c_str()); switch (GetCountry()) { diff --git a/Source/Project64-core/N64System/Recompiler/FunctionMapClass.cpp b/Source/Project64-core/N64System/Recompiler/FunctionMapClass.cpp index fe8c41dd0..229dbfce1 100644 --- a/Source/Project64-core/N64System/Recompiler/FunctionMapClass.cpp +++ b/Source/Project64-core/N64System/Recompiler/FunctionMapClass.cpp @@ -26,9 +26,10 @@ CFunctionMap::~CFunctionMap() bool CFunctionMap::AllocateMemory() { - if (g_System->LookUpMode() == FuncFind_VirtualLookup && m_FunctionTable == NULL) + WriteTrace(TraceRecompiler, TraceDebug, "start"); + if (LookUpMode() == FuncFind_VirtualLookup && m_FunctionTable == NULL) { - m_FunctionTable = new PCCompiledFunc_TABLE[0x100000]; + m_FunctionTable = new (std::nothrow) PCCompiledFunc_TABLE[0x100000]; if (m_FunctionTable == NULL) { WriteTrace(TraceRecompiler, TraceError, "failed to allocate function table"); @@ -37,17 +38,18 @@ bool CFunctionMap::AllocateMemory() } memset(m_FunctionTable, 0, 0x100000 * sizeof(PCCompiledFunc_TABLE)); } - if (g_System->LookUpMode() == FuncFind_PhysicalLookup && m_JumpTable == NULL) + if (LookUpMode() == FuncFind_PhysicalLookup && m_JumpTable == NULL) { - m_JumpTable = new PCCompiledFunc[g_MMU->RdramSize() >> 2]; + m_JumpTable = new (std::nothrow) PCCompiledFunc[RdramSize() >> 2]; if (m_JumpTable == NULL) { WriteTrace(TraceRecompiler, TraceError, "failed to allocate jump table"); g_Notify->FatalError(MSG_MEM_ALLOC_ERROR); return false; } - memset(m_JumpTable, 0, (g_MMU->RdramSize() >> 2) * sizeof(PCCompiledFunc)); + memset(m_JumpTable, 0, (RdramSize() >> 2) * sizeof(PCCompiledFunc)); } + WriteTrace(TraceRecompiler, TraceDebug, "Done"); return true; } @@ -62,7 +64,7 @@ void CFunctionMap::CleanBuffers() delete m_FunctionTable[i]; } } - delete [] m_FunctionTable; + delete[] m_FunctionTable; m_FunctionTable = NULL; } if (m_JumpTable) @@ -74,9 +76,11 @@ void CFunctionMap::CleanBuffers() void CFunctionMap::Reset(bool bAllocate) { + WriteTrace(TraceRecompiler, TraceDebug, "start (bAllocate: %s)", bAllocate ? "true" : "false"); CleanBuffers(); if (bAllocate && (g_System->LookUpMode() == FuncFind_VirtualLookup || g_System->LookUpMode() == FuncFind_PhysicalLookup)) { AllocateMemory(); } + WriteTrace(TraceRecompiler, TraceDebug, "Done"); } \ No newline at end of file diff --git a/Source/Project64-core/N64System/Recompiler/FunctionMapClass.h b/Source/Project64-core/N64System/Recompiler/FunctionMapClass.h index 61c61bdc4..531031f83 100644 --- a/Source/Project64-core/N64System/Recompiler/FunctionMapClass.h +++ b/Source/Project64-core/N64System/Recompiler/FunctionMapClass.h @@ -11,7 +11,8 @@ #pragma once #include -class CFunctionMap +class CFunctionMap : + private CGameSettings { protected: typedef CCompiledFunc * PCCompiledFunc; diff --git a/Source/Project64-core/N64System/Recompiler/RecompilerClass.cpp b/Source/Project64-core/N64System/Recompiler/RecompilerClass.cpp index 5dddd391d..711cfbb2c 100644 --- a/Source/Project64-core/N64System/Recompiler/RecompilerClass.cpp +++ b/Source/Project64-core/N64System/Recompiler/RecompilerClass.cpp @@ -22,6 +22,7 @@ CRecompiler::CRecompiler(CRegisters & Registers, CProfiling & Profile, bool & En m_EndEmulation(EndEmulation), PROGRAM_COUNTER(Registers.m_PROGRAM_COUNTER) { + CFunctionMap::AllocateMemory(); if (g_MMU != NULL) { ResetMemoryStackPos(); @@ -718,12 +719,15 @@ void CRecompiler::RecompilerMain_Lookup_validate_TLB() void CRecompiler::Reset() { + WriteTrace(TraceRecompiler, TraceDebug, "start"); ResetRecompCode(true); ResetMemoryStackPos(); + WriteTrace(TraceRecompiler, TraceDebug, "Done"); } void CRecompiler::ResetRecompCode(bool bAllocate) { + WriteTrace(TraceRecompiler, TraceDebug, "start"); CRecompMemory::Reset(); CFunctionMap::Reset(bAllocate); @@ -739,6 +743,7 @@ void CRecompiler::ResetRecompCode(bool bAllocate) } } m_Functions.clear(); + WriteTrace(TraceRecompiler, TraceDebug, "Done"); } void CRecompiler::RecompilerMain_ChangeMemory() @@ -1036,18 +1041,21 @@ void CRecompiler::ClearRecompCode_Phys(uint32_t Address, int length, REMOVE_REAS void CRecompiler::ClearRecompCode_Virt(uint32_t Address, int length, REMOVE_REASON Reason) { + uint32_t AddressIndex, WriteStart; + int DataInBlock, DataToWrite, DataLeft; + switch (g_System->LookUpMode()) { case FuncFind_VirtualLookup: + AddressIndex = Address >> 0xC; + WriteStart = (Address & 0xFFC); + length = ((length + 3) & ~0x3); + + DataInBlock = 0x1000 - WriteStart; + DataToWrite = length < DataInBlock ? length : DataInBlock; + DataLeft = length - DataToWrite; + { - uint32_t AddressIndex = Address >> 0xC; - uint32_t WriteStart = (Address & 0xFFC); - length = ((length + 3) & ~0x3); - - int DataInBlock = 0x1000 - WriteStart; - int DataToWrite = length < DataInBlock ? length : DataInBlock; - int DataLeft = length - DataToWrite; - PCCompiledFunc_TABLE & table = FunctionTable()[AddressIndex]; if (table) { diff --git a/Source/Project64-core/Settings/GameSettings.cpp b/Source/Project64-core/Settings/GameSettings.cpp index 65b813d64..bf5f8195d 100644 --- a/Source/Project64-core/Settings/GameSettings.cpp +++ b/Source/Project64-core/Settings/GameSettings.cpp @@ -40,6 +40,7 @@ CPU_TYPE CGameSettings::m_CpuType = CPU_Recompiler; void CGameSettings::RefreshGameSettings() { + WriteTrace(TraceN64System, TraceDebug, "start"); m_bSMM_StoreInstruc = false /*g_Settings->LoadBool(Game_SMM_StoreInstruc)*/; m_bSMM_Protect = g_Settings->LoadBool(Game_SMM_Protect); m_bSMM_ValidFunc = g_Settings->LoadBool(Game_SMM_ValidFunc); @@ -73,6 +74,7 @@ void CGameSettings::RefreshGameSettings() { m_CountPerOp = 2; } + WriteTrace(TraceN64System, TraceDebug, "Done"); } void CGameSettings::SpeedChanged(int SpeedLimit) diff --git a/Source/Project64-core/Settings/SettingType/SettingsType-Application.cpp b/Source/Project64-core/Settings/SettingType/SettingsType-Application.cpp index a5ff9d16e..cd61091bc 100644 --- a/Source/Project64-core/Settings/SettingType/SettingsType-Application.cpp +++ b/Source/Project64-core/Settings/SettingType/SettingsType-Application.cpp @@ -130,7 +130,7 @@ bool CSettingTypeApplication::Load(int /*Index*/, bool & Value) const { bool bRes = false; - uint32_t dwValue; + uint32_t dwValue = 0; bRes = m_SettingsIniFile ? m_SettingsIniFile->GetNumber(SectionName(), m_KeyNameIdex.c_str(), Value, dwValue) : false; if (bRes) {