fix: reimpl debug reads w/out throwing away *const Self

This commit is contained in:
2022-08-07 05:11:29 -05:00
parent 5a18b1dcc7
commit 739db99c83
6 changed files with 155 additions and 76 deletions

View File

@@ -31,17 +31,22 @@ pub fn deinit(self: Self) void {
if (self.buf) |buf| self.alloc.free(buf);
}
pub fn checkedRead(self: *Self, comptime T: type, r15: u32, addr: u32) T {
pub fn read(self: *Self, comptime T: type, r15: u32, addr: u32) T {
if (r15 < Self.size) {
self.addr_latch = addr;
return self.read(T, addr);
return self.uncheckedRead(T, addr);
}
log.debug("Rejected read since r15=0x{X:0>8}", .{r15});
return @truncate(T, self.read(T, self.addr_latch + 8));
return @truncate(T, self.uncheckedRead(T, self.addr_latch + 8));
}
fn read(self: *const Self, comptime T: type, addr: u32) T {
pub fn dbgRead(self: *const Self, comptime T: type, r15: u32, addr: u32) T {
if (r15 < Self.size) return self.uncheckedRead(T, addr);
return @truncate(T, self.uncheckedRead(T, self.addr_latch + 8));
}
fn uncheckedRead(self: *const Self, comptime T: type, addr: u32) T {
if (self.buf) |buf| {
return switch (T) {
u32, u16, u8 => std.mem.readIntSliceLittle(T, buf[addr..][0..@sizeOf(T)]),