chore: remove awful ptr casts in backup.zig and bios.zig

This commit is contained in:
2022-05-27 20:24:09 -03:00
parent d4bc1f2cd0
commit 517ed7a835
5 changed files with 13 additions and 23 deletions

View File

@@ -31,11 +31,10 @@ pub fn deinit(self: Self) void {
if (self.buf) |buf| self.alloc.free(buf);
}
pub fn checkedRead(self: *const Self, comptime T: type, r15: u32, addr: u32) T {
pub fn checkedRead(self: *Self, comptime T: type, r15: u32, addr: u32) T {
if (r15 < Self.size) {
// FIXME: Just give up on *const Self on bus reads, Rekai
const this = @intToPtr(*Self, @ptrToInt(self));
this.addr_latch = addr;
self.addr_latch = addr;
return self.read(T, addr);
}

View File

@@ -65,7 +65,7 @@ pub fn deinit(self: Self) void {
self.backup.deinit();
}
pub fn read(self: *const Self, comptime T: type, address: u32) T {
pub fn read(self: *Self, comptime T: type, address: u32) T {
const addr = address & 0x1FF_FFFF;
if (self.backup.kind == .Eeprom) {

View File

@@ -333,20 +333,8 @@ const Eeprom = struct {
};
}
pub fn read(self: *const Self) u1 {
// Here I throw away the const qualifier which is bad and dumb but here's why.
// This is one of the few (as of when I write this, **only**) places that mutate
// some value upon access. Before this I've been able to have all read-related functions
// present a *const Self parameter with no issues.
//
// I don't think it's worth throwing away all the good that *const Self brings across the entire
// memory bus because reading from the EEPROM increments an internal counter which isn't even
// visible to neither the cartridge nor any other component of the emulator.
//
// By throwing away const, we can increment self.read_proc.i which has a range of 0 -> 67. This is
// a small enough scope (and a well defined one at that) so that this transgression isn't the worst, I think.
const self_mut = @intToPtr(*Self, @ptrToInt(self));
return self_mut.reader.read();
pub fn read(self: *Self) u1 {
return self.reader.read();
}
pub fn write(self: *Self, word_count: u16, buf: *[]u8, bit: u1) void {