chore: log error on open bus in page 0x00 and 0x01

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-04-09 18:01:17 -03:00
parent 76789aa8bc
commit 5da84aff36
1 changed files with 5 additions and 0 deletions

View File

@ -29,6 +29,11 @@ pub fn deinit(self: Self) void {
pub fn read(self: *const Self, comptime T: type, addr: usize) T { pub fn read(self: *const Self, comptime T: type, addr: usize) T {
if (self.buf) |buf| { if (self.buf) |buf| {
if (addr > buf.len) {
log.err("Tried to read {} from {X:0>8} (open bus)", .{ T, addr });
return 0;
}
return switch (T) { return switch (T) {
u32 => (@as(u32, buf[addr + 3]) << 24) | (@as(u32, buf[addr + 2]) << 16) | (@as(u32, buf[addr + 1]) << 8) | (@as(u32, buf[addr])), u32 => (@as(u32, buf[addr + 3]) << 24) | (@as(u32, buf[addr + 2]) << 16) | (@as(u32, buf[addr + 1]) << 8) | (@as(u32, buf[addr])),
u16 => (@as(u16, buf[addr + 1]) << 8) | @as(u16, buf[addr]), u16 => (@as(u16, buf[addr + 1]) << 8) | @as(u16, buf[addr]),