Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

fix interpreter bug that occassionally led to getting stuck in irq

Layle4474775191ef
diff --git a/crates/gekko/src/cpu/interpreter/branch.rs b/crates/gekko/src/cpu/interpreter/branch.rs
index c9b6bd5..e2a03c1 100644
--- a/crates/gekko/src/cpu/interpreter/branch.rs
+++ b/crates/gekko/src/cpu/interpreter/branch.rs
@@ -1,6 +1,9 @@
use crate::cpu::condition::BranchControl;
pub fn branch<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {
+ // Read LR before potentially overwriting LR with CIA+4 (matters for blrl/bctrl)
+ let old_lr = ctx.cpu.spr.lr;
+
if instr.lk() {
ctx.cpu.spr.lr = ctx.cpu.cia.wrapping_add(4);
}
@@ -34,7 +37,7 @@ pub fn branch<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::s
}
match OP {
- crate::cpu::lut::OP_BCLRX => ctx.cpu.nia = ctx.cpu.spr.lr,
+ crate::cpu::lut::OP_BCLRX => ctx.cpu.nia = old_lr,
crate::cpu::lut::OP_BCX => {
ctx.cpu.nia = if instr.aa() {
instr.bd() as u32