feat: implement LDR STR

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-10-21 05:11:44 -03:00
parent 6c6d7d463d
commit 1991bd8525
4 changed files with 24 additions and 6 deletions

View File

@ -16,8 +16,13 @@ pub const Bus = struct {
return self.pak.readWord(addr); return self.pak.readWord(addr);
} }
pub fn writeWord(_: *@This(), _: u32, _: u32) void { pub fn writeWord(self: *@This(), addr: u32, word: u32) void {
std.debug.panic("TODO: Implement Bus#writeWord", .{}); // 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 { 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 { pub inline fn step(self: *@This()) u64 {
const opcode = self.fetch(); 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); 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); cpu.r[rd] = bus.readByte(address);
} else { } else {
// LDR // 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 { } else {
if (B) { if (B) {
@ -37,7 +39,11 @@ pub fn comptimeSingleDataTransfer(comptime I: bool, comptime P: bool, comptime U
bus.writeByte(address, src); bus.writeByte(address, src);
} else { } else {
// STR // 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])); 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 { pub fn readHalfWord(self: *const @This(), addr: u32) u16 {
return (@as(u16, self.buf[addr + 1]) << 8) | @as(u16, self.buf[addr]); return (@as(u16, self.buf[addr + 1]) << 8) | @as(u16, self.buf[addr]);
} }