fix(cpu): handle edge case in LDRSH

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-10-21 05:12:15 -03:00
parent feded4ac25
commit f63ae76931
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 {