fix: resolve decoding mixup in THUMB format 8 instructions
This commit is contained in:
parent
b569a32170
commit
d8bd6da563
|
@ -28,26 +28,28 @@ pub fn format78(comptime op: u2, comptime T: bool) InstrFn {
|
||||||
const address = cpu.r[rb] + cpu.r[ro];
|
const address = cpu.r[rb] + cpu.r[ro];
|
||||||
|
|
||||||
if (T) {
|
if (T) {
|
||||||
|
// Format 8
|
||||||
switch (op) {
|
switch (op) {
|
||||||
0b00 => {
|
0b00 => {
|
||||||
// STRH
|
// STRH
|
||||||
bus.write16(address & 0xFFFF_FFFE, @truncate(u16, cpu.r[rd]));
|
bus.write16(address & 0xFFFF_FFFE, @truncate(u16, cpu.r[rd]));
|
||||||
},
|
},
|
||||||
0b01 => {
|
0b01 => {
|
||||||
|
// LDSB
|
||||||
|
cpu.r[rd] = u32SignExtend(8, @as(u32, bus.read8(address)));
|
||||||
|
},
|
||||||
|
0b10 => {
|
||||||
// LDRH
|
// LDRH
|
||||||
const value = bus.read16(address & 0xFFFF_FFFE);
|
const value = bus.read16(address & 0xFFFF_FFFE);
|
||||||
cpu.r[rd] = std.math.rotr(u32, @as(u32, value), 8 * (address & 1));
|
cpu.r[rd] = std.math.rotr(u32, @as(u32, value), 8 * (address & 1));
|
||||||
},
|
},
|
||||||
0b10 => {
|
|
||||||
// LDSB
|
|
||||||
cpu.r[rd] = u32SignExtend(8, @as(u32, bus.read8(address)));
|
|
||||||
},
|
|
||||||
0b11 => {
|
0b11 => {
|
||||||
// LDSH
|
// LDSH
|
||||||
cpu.r[rd] = u32SignExtend(16, @as(u32, bus.read16(address & 0xFFFF_FFFE)));
|
cpu.r[rd] = u32SignExtend(16, @as(u32, bus.read16(address & 0xFFFF_FFFE)));
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Format 7
|
||||||
switch (op) {
|
switch (op) {
|
||||||
0b00 => {
|
0b00 => {
|
||||||
// STR
|
// STR
|
||||||
|
|
Loading…
Reference in New Issue