fix(cpu): don't ignore 11th bit of THUMB BL offset

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-10-21 05:12:06 -03:00
parent d6ed071bc6
commit 1ac193c506
1 changed files with 2 additions and 2 deletions

View File

@ -9,7 +9,7 @@ pub fn format19(comptime is_low: bool) InstrFn {
return struct { return struct {
fn inner(cpu: *Arm7tdmi, _: *Bus, opcode: u16) void { fn inner(cpu: *Arm7tdmi, _: *Bus, opcode: u16) void {
// BL // BL
const offset = opcode & 0x3FF; const offset = opcode & 0x7FF;
if (is_low) { if (is_low) {
// Instruction 2 // Instruction 2
@ -19,7 +19,7 @@ pub fn format19(comptime is_low: bool) InstrFn {
cpu.r[14] = old_pc | 1; cpu.r[14] = old_pc | 1;
} else { } else {
// Instruction 1 // Instruction 1
cpu.r[14] = (cpu.r[15] + 2) + (u32SignExtend(11, @as(u32, offset)) << 12); cpu.r[14] = (cpu.r[15] + 2) +% (u32SignExtend(11, @as(u32, offset)) << 12);
} }
} }
}.inner; }.inner;