chore: rewrite read/write methods for remainig Bus devices
This commit is contained in:
@@ -26,23 +26,15 @@ pub fn deinit(self: Self) void {
|
||||
if (self.buf) |buf| self.alloc.free(buf);
|
||||
}
|
||||
|
||||
pub fn get32(self: *const Self, idx: usize) u32 {
|
||||
if (self.buf) |buf|
|
||||
return (@as(u32, buf[idx + 3]) << 24) | (@as(u32, buf[idx + 2]) << 16) | (@as(u32, buf[idx + 1]) << 8) | (@as(u32, buf[idx]));
|
||||
pub fn read(self: *const Self, comptime T: type, addr: usize) T {
|
||||
if (self.buf) |buf| {
|
||||
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])),
|
||||
u16 => (@as(u16, buf[addr + 1]) << 8) | @as(u16, buf[addr]),
|
||||
u8 => buf[addr],
|
||||
else => @compileError("BIOS: Unsupported read width"),
|
||||
};
|
||||
}
|
||||
|
||||
std.debug.panic("[CPU/BIOS:32] ZBA tried to read from 0x{X:0>8} but no BIOS was provided.", .{idx});
|
||||
}
|
||||
|
||||
pub fn get16(self: *const Self, idx: usize) u16 {
|
||||
if (self.buf) |buf|
|
||||
return (@as(u16, buf[idx + 1]) << 8) | @as(u16, buf[idx]);
|
||||
|
||||
std.debug.panic("[CPU/BIOS:16] ZBA tried to read from 0x{X:0>8} but no BIOS was provided.", .{idx});
|
||||
}
|
||||
|
||||
pub fn get8(self: *const Self, idx: usize) u8 {
|
||||
if (self.buf) |buf|
|
||||
return buf[idx];
|
||||
|
||||
std.debug.panic("[CPU/BIOS:8] ZBA tried to read from 0x{X:0>8} but no BIOS was provided.", .{idx});
|
||||
std.debug.panic("[BIOS] ZBA tried to read {} from 0x{X:0>8} but not BIOS was present", .{ T, addr });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user