From dacb9c71e87f9c0900de72af11ad887293decebf Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Thu, 29 Jun 2023 23:12:08 -0500 Subject: [PATCH] feat: implement debug i/o in Bus Interface --- src/lib.zig | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/lib.zig b/src/lib.zig index cd73a37..f5ce9c7 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -45,6 +45,14 @@ pub const Bus = struct { write16: *const fn (ptr: *anyopaque, address: u32, value: u16) void, write32: *const fn (ptr: *anyopaque, address: u32, value: u32) void, + dbg_read8: *const fn (ptr: *anyopaque, address: u32) u8, + dbg_read16: *const fn (ptr: *anyopaque, address: u32) u16, + dbg_read32: *const fn (ptr: *anyopaque, address: u32) u32, + + dbg_write8: *const fn (ptr: *anyopaque, address: u32, value: u8) void, + dbg_write16: *const fn (ptr: *anyopaque, address: u32, value: u16) void, + dbg_write32: *const fn (ptr: *anyopaque, address: u32, value: u32) void, + reset: *const fn (ptr: *anyopaque) void, }; @@ -89,6 +97,36 @@ pub const Bus = struct { self.write(u32, address, value); } + fn dbgRead8(ptr: *anyopaque, address: u32) u8 { + const self = @ptrCast(P, @alignCast(alignment, ptr)); + return self.dbgRead(u8, address); + } + + fn dbgRead16(ptr: *anyopaque, address: u32) u16 { + const self = @ptrCast(P, @alignCast(alignment, ptr)); + return self.dbgRead(u16, address); + } + + fn dbgRead32(ptr: *anyopaque, address: u32) u32 { + const self = @ptrCast(P, @alignCast(alignment, ptr)); + return self.dbgRead(u32, address); + } + + fn dbgWrite8(ptr: *anyopaque, address: u32, value: u8) void { + const self = @ptrCast(P, @alignCast(alignment, ptr)); + self.dbgWrite(u8, address, value); + } + + fn dbgWrite16(ptr: *anyopaque, address: u32, value: u16) void { + const self = @ptrCast(P, @alignCast(alignment, ptr)); + self.dbgWrite(u16, address, value); + } + + fn dbgWrite32(ptr: *anyopaque, address: u32, value: u32) void { + const self = @ptrCast(P, @alignCast(alignment, ptr)); + self.dbgWrite(u32, address, value); + } + fn reset(ptr: *anyopaque) void { const self = @ptrCast(P, @alignCast(alignment, ptr)); self.reset(); @@ -106,6 +144,14 @@ pub const Bus = struct { .write16 = impl.write16, .write32 = impl.write32, + .dbg_read8 = impl.dbgRead8, + .dbg_read16 = impl.dbgRead16, + .dbg_read32 = impl.dbgRead32, + + .dbg_write8 = impl.dbgWrite8, + .dbg_write16 = impl.dbgWrite16, + .dbg_write32 = impl.dbgWrite32, + .reset = impl.reset, }, };