chore: use stdlib endian-aware integer read/write functions

This commit is contained in:
2022-06-03 12:18:28 -03:00
parent deff74d804
commit 2dc3864dca
8 changed files with 29 additions and 128 deletions

View File

@@ -44,9 +44,7 @@ pub fn checkedRead(self: *Self, comptime T: type, r15: u32, addr: u32) T {
fn read(self: *const Self, comptime T: type, addr: u32) 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],
u32, u16, u8 => std.mem.readIntSliceLittle(T, buf[addr..][0..@sizeOf(T)]),
else => @compileError("BIOS: Unsupported read width"),
};
}