feat: implement LDR STR

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-12-29 17:16:32 -06:00
parent 7cc3f40a85
commit c660ca8922
4 changed files with 24 additions and 6 deletions

View File

@ -16,8 +16,13 @@ pub const Bus = struct {
return self.pak.readWord(addr);
}
pub fn writeWord(_: *@This(), _: u32, _: u32) void {
std.debug.panic("TODO: Implement Bus#writeWord", .{});
pub fn writeWord(self: *@This(), addr: u32, word: u32) void {
// TODO: Actually implement the memory mmap
if (addr >= self.pak.buf.len) {
return;
}
self.pak.writeWord(addr, word);
}
pub fn readHalfWord(self: *const @This(), addr: u32) u16 {

View File

@ -27,8 +27,8 @@ pub const ARM7TDMI = struct {
pub inline fn step(self: *@This()) u64 {
const opcode = self.fetch();
// Debug
std.debug.print("R15: 0x{X:}\n", .{opcode});
std.debug.print("R15: 0x{X:}\n", .{opcode}); // Debug
ARM_LUT[armIdx(opcode)](self, self.bus, opcode);

View File

@ -24,7 +24,9 @@ pub fn comptimeSingleDataTransfer(comptime I: bool, comptime P: bool, comptime U
cpu.r[rd] = bus.readByte(address);
} else {
// LDR
std.debug.panic("Implement LDR", .{});
// FIXME: Unsure about how I calculate the boundary offset
cpu.r[rd] = std.math.rotl(u32, bus.readWord(address), address % 4);
}
} else {
if (B) {
@ -37,7 +39,11 @@ pub fn comptimeSingleDataTransfer(comptime I: bool, comptime P: bool, comptime U
bus.writeByte(address, src);
} else {
// STR
std.debug.panic("Implement STR", .{});
// FIXME: Is this right?
const src = cpu.r[rd];
const aligned_addr = address - (address % 4);
bus.writeWord(aligned_addr, src);
}
}

View File

@ -20,6 +20,13 @@ pub const GamePak = struct {
return (@as(u32, self.buf[addr + 3]) << 24) | (@as(u32, self.buf[addr + 2]) << 16) | (@as(u32, self.buf[addr + 1]) << 8) | (@as(u32, self.buf[addr]));
}
pub fn writeWord(self: *const @This(), addr: u32, word: u32) void {
self.buf[addr + 3] = @truncate(u8, word >> 24);
self.buf[addr + 2] = @truncate(u8, word >> 16);
self.buf[addr + 1] = @truncate(u8, word >> 8);
self.buf[addr] = @truncate(u8, word);
}
pub fn readHalfWord(self: *const @This(), addr: u32) u16 {
return (@as(u16, self.buf[addr + 1]) << 8) | @as(u16, self.buf[addr]);
}