diff --git a/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp b/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp index 16562072b..4b6b5ca53 100644 --- a/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp +++ b/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp @@ -94,7 +94,7 @@ void R4300iOp::ExecuteOps(uint32_t Cycles) int32_t & NextTimer = *g_NextTimer; bool CheckTimer = false; bool updateInstructionMemory = true; - m_InstructionRegion = -1; + m_InstructionRegion = (uint64_t)-1; while (!Done && Cycles > 0) { diff --git a/Source/Project64-core/N64System/Recompiler/CodeBlock.cpp b/Source/Project64-core/N64System/Recompiler/CodeBlock.cpp index f800a1796..054b66523 100644 --- a/Source/Project64-core/N64System/Recompiler/CodeBlock.cpp +++ b/Source/Project64-core/N64System/Recompiler/CodeBlock.cpp @@ -894,6 +894,11 @@ bool CCodeBlock::Compile() uint32_t CCodeBlock::Finilize(CRecompMemory & RecompMem) { + size_t codeSize = m_CodeHolder.codeSize(); + if (!RecompMem.CheckRecompMem(codeSize)) + { + return 0; + } m_CompiledLocation = RecompMem.RecompPos(); m_CodeHolder.relocateToBase((uint64_t)m_CompiledLocation); if (CDebugSettings::bRecordRecompilerAsm()) @@ -914,11 +919,6 @@ uint32_t CCodeBlock::Finilize(CRecompMemory & RecompMem) Log("====== Recompiled code ======"); m_CodeLog += CodeLog; } - size_t codeSize = m_CodeHolder.codeSize(); - if (!RecompMem.CheckRecompMem(codeSize)) - { - return 0; - } m_CodeHolder.copyFlattenedData(m_CompiledLocation, codeSize, asmjit::CopySectionFlags::kPadSectionBuffer); m_Recompiler.RecompPos() += codeSize; diff --git a/Source/Project64-core/N64System/Recompiler/Recompiler.cpp b/Source/Project64-core/N64System/Recompiler/Recompiler.cpp index eee6317e4..036e1c9f7 100644 --- a/Source/Project64-core/N64System/Recompiler/Recompiler.cpp +++ b/Source/Project64-core/N64System/Recompiler/Recompiler.cpp @@ -85,14 +85,14 @@ void CRecompiler::RecompilerMain_VirtualTable() m_System.m_PipelineStage = PIPELINE_STAGE_NORMAL; if (!m_MMU.ValidVaddr((uint32_t)PC)) { - g_Notify->DisplayError(stdstr_f("Failed to translate PC to a PAddr: %X\n\nEmulation stopped", PC).c_str()); + g_Notify->DisplayError(stdstr_f("Failed to translate PC to a PAddr: %X\n\nEmulation stopped", (uint32_t)PC).c_str()); return; } continue; } - PCCompiledFunc_TABLE & table = FunctionTable()[PC >> 0xC]; - uint32_t TableEntry = (PC & 0xFFF) >> 2; + PCCompiledFunc_TABLE & table = FunctionTable()[(uint32_t)PC >> 0xC]; + uint32_t TableEntry = ((uint32_t)PC & 0xFFF) >> 2; if (table) { CCompiledFunc * info = table[TableEntry]; diff --git a/Source/Project64-core/N64System/Recompiler/RecompilerMemory.cpp b/Source/Project64-core/N64System/Recompiler/RecompilerMemory.cpp index 59dbbd46b..15b3712b3 100644 --- a/Source/Project64-core/N64System/Recompiler/RecompilerMemory.cpp +++ b/Source/Project64-core/N64System/Recompiler/RecompilerMemory.cpp @@ -63,6 +63,11 @@ bool CRecompMemory::CheckRecompMem(uint32_t BlockSize) if (m_RecompSize == MaxCompileBufferSize) { g_Recompiler->ResetRecompCode(true); + Size = (uint32_t)((uint8_t *)m_RecompPos - (uint8_t *)m_RecompCode); + if ((Size + BlockSize) < m_RecompSize) + { + return true; + } return false; } if (BlockSize > IncreaseCompileBufferSize)