Compare commits
No commits in common. "aa6f3c7a92230c42d72a6013fef0b06cdb90c4da" and "166bc6fc6dd6f39da10aa13b3d82579ba9996558" have entirely different histories.
aa6f3c7a92
...
166bc6fc6d
|
@ -50,47 +50,23 @@ 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 {
|
||||
var address = cpu.r[rb];
|
||||
const end_address = cpu.r[rb] + 4 * countRlist(opcode);
|
||||
const base = cpu.r[rb];
|
||||
|
||||
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 address: u32 = base;
|
||||
|
||||
var i: usize = 0;
|
||||
while (i < 8) : (i += 1) {
|
||||
if (opcode >> i & 1 == 1) {
|
||||
if ((opcode >> @truncate(u3, 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;
|
||||
}
|
||||
}
|
||||
|
||||
if (L and opcode >> rb & 1 != 1) cpu.r[rb] = address;
|
||||
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,14 +44,8 @@ pub fn format78(comptime op: u2, comptime T: bool) InstrFn {
|
|||
cpu.r[rd] = std.math.rotr(u32, @as(u32, value), 8 * (address & 1));
|
||||
},
|
||||
0b11 => {
|
||||
// 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));
|
||||
// LDSH
|
||||
cpu.r[rd] = u32SignExtend(16, @as(u32, bus.read16(address & 0xFFFF_FFFE)));
|
||||
},
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue