Skip to content

Commit

Permalink
Add some specialised code path to handle Edge of Reality games.
Browse files Browse the repository at this point in the history
Uses E bit in a branch delay slot.
  • Loading branch information
jpd002 committed Aug 16, 2024
1 parent 71e2a2f commit 1f2a662
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Source/ee/VuBasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ void CVuBasicBlock::CompileRange(CMipsJitter* jitter)
//Disable block linking because targets will be wrong
m_isLinkable = false;

assert(address >= 8);
uint32 branchOpcodeAddr = address - 8;
assert(branchOpcodeAddr >= m_begin);
uint32 branchOpcodeLo = m_context.m_pMemoryMap->GetInstruction(branchOpcodeAddr);
Expand All @@ -336,6 +337,30 @@ void CVuBasicBlock::CompileRange(CMipsJitter* jitter)
arch->CompileInstruction(branchTgtAddress, jitter, &m_context, address - m_begin);
}
}
//Handle some E bit in delay slot situation (Edge of Reality games)
else if((address == (m_end - 4)) && (opcodeHi & VUShared::VU_UPPEROP_BIT_E))
{
//Check if we actually had a conditional branch before
assert(address >= 8);
uint32 branchOpcodeAddr = address - 8;
assert(branchOpcodeAddr >= m_begin);
uint32 branchOpcodeLo = m_context.m_pMemoryMap->GetInstruction(branchOpcodeAddr);
if(IsConditionalBranch(branchOpcodeLo))
{
//So, this is a E bit in a delay slot. If branch is not taken
//we want to execute the instruction in the E bit delay slot.
jitter->PushRel(offsetof(CMIPS, m_State.nDelayedJumpAddr));
jitter->PushCst(MIPS_INVALID_PC);
jitter->BeginIf(Jitter::CONDITION_EQ);
{
//If we haven't taken the jump, execute the instruction after the delay slot
uint32 nextOpcodeAddr = address + 8;
uint32 nextOpcodeLo = m_context.m_pMemoryMap->GetInstruction(nextOpcodeAddr);
arch->CompileInstruction(nextOpcodeAddr, jitter, &m_context, nextOpcodeAddr - m_begin);
}
jitter->EndIf();
}
}

//Sanity check
assert(jitter->IsStackEmpty());
Expand Down

0 comments on commit 1f2a662

Please sign in to comment.