Compare commits
3 Commits
166bc6fc6d
...
aa6f3c7a92
Author | SHA1 | Date |
---|---|---|
Rekai Nyangadzayi Musuka | aa6f3c7a92 | |
Rekai Nyangadzayi Musuka | 3ae24d6977 | |
Rekai Nyangadzayi Musuka | 0a22730479 |
|
@ -50,23 +50,47 @@ pub fn format14(comptime L: bool, comptime R: bool) InstrFn {
|
|||
pub fn format15(comptime L: bool, comptime rb: u3) InstrFn {
|
||||
return struct {
|
||||
fn inner(cpu: *Arm7tdmi, bus: *Bus, opcode: u16) void {
|
||||
const base = cpu.r[rb];
|
||||
var address = cpu.r[rb];
|
||||
const end_address = cpu.r[rb] + 4 * countRlist(opcode);
|
||||
|
||||
var address: u32 = base;
|
||||
if (opcode & 0xFF == 0) {
|
||||
if (L) cpu.r[15] = bus.read32(address) else bus.write32(address, cpu.r[15] + 4); // TODO: Why is this r[15] + 4?
|
||||
cpu.r[rb] += 0x40;
|
||||
return;
|
||||
}
|
||||
|
||||
var i: u4 = 0;
|
||||
var first_write = true;
|
||||
|
||||
var i: usize = 0;
|
||||
while (i < 8) : (i += 1) {
|
||||
if ((opcode >> @truncate(u3, i)) & 1 == 1) {
|
||||
if (opcode >> i & 1 == 1) {
|
||||
if (L) {
|
||||
cpu.r[i] = bus.read32(address);
|
||||
} else {
|
||||
bus.write32(address, cpu.r[i]);
|
||||
}
|
||||
|
||||
if (!L and first_write) {
|
||||
cpu.r[rb] = end_address;
|
||||
first_write = false;
|
||||
}
|
||||
|
||||
address += 4;
|
||||
}
|
||||
}
|
||||
|
||||
cpu.r[rb] = address;
|
||||
if (L and opcode >> rb & 1 != 1) cpu.r[rb] = address;
|
||||
}
|
||||
}.inner;
|
||||
}
|
||||
|
||||
inline fn countRlist(opcode: u16) u32 {
|
||||
var count: u32 = 0;
|
||||
|
||||
comptime var i: u4 = 0;
|
||||
inline while (i < 8) : (i += 1) {
|
||||
if (opcode >> (7 - i) & 1 == 1) count += 1;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue