fix(cpu): handle edge case in LDRSH

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-02-05 17:12:25 -04:00
parent 166bc6fc6d
commit 0a22730479
1 changed files with 8 additions and 2 deletions

View File

@ -44,8 +44,14 @@ pub fn format78(comptime op: u2, comptime T: bool) InstrFn {
cpu.r[rd] = std.math.rotr(u32, @as(u32, value), 8 * (address & 1));
},
0b11 => {
// LDSH
cpu.r[rd] = u32SignExtend(16, @as(u32, bus.read16(address & 0xFFFF_FFFE)));
// LDRSH
const value = if (address & 1 == 1) blk: {
break :blk u32SignExtend(8, bus.read8(address));
} else blk: {
break :blk u32SignExtend(16, bus.read16(address));
};
cpu.r[rd] = std.math.rotr(u32, value, 8 * (address & 1));
},
}
} else {