fix(bus): restrict Game ROM and VRAM to a 16-bit bus

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-01-04 03:01:37 -06:00
parent ed9c1413b1
commit 8b9a80b279
3 changed files with 4 additions and 7 deletions

View File

@ -98,7 +98,6 @@ pub const Bus = struct {
pub fn write16(self: *@This(), addr: u32, halfword: u16) void {
// TODO: write16 can write to GamePak Flash
switch (addr) {
// General Internal Memory
0x0200_0000...0x0203_FFFF => std.debug.panic("[Bus:16] write 0x{X:} to 0x{X:} in IWRAM", .{ halfword, addr }),

View File

@ -23,7 +23,7 @@ pub const GamePak = struct {
}
pub inline fn get32(self: *const @This(), idx: usize) u32 {
return (@as(u32, self.buf[idx + 3]) << 24) | (@as(u32, self.buf[idx + 2]) << 16) | (@as(u32, self.buf[idx + 1]) << 8) | (@as(u32, self.buf[idx]));
return (@as(u32, self.get16(idx + 2)) << 16) | @as(u32, self.get16(idx));
}
pub inline fn get16(self: *const @This(), idx: usize) u16 {

View File

@ -32,14 +32,12 @@ const Vram = struct {
}
pub inline fn get32(self: *const @This(), idx: usize) u32 {
return (@as(u32, self.buf[idx + 3]) << 24) | (@as(u32, self.buf[idx + 2]) << 16) | (@as(u32, self.buf[idx + 1]) << 8) | (@as(u32, self.buf[idx]));
return (@as(u32, self.get16(idx + 2)) << 16) | @as(u32, self.get16(idx));
}
pub inline fn set32(self: *@This(), idx: usize, word: u32) void {
self.buf[idx + 3] = @truncate(u8, word >> 24);
self.buf[idx + 2] = @truncate(u8, word >> 16);
self.buf[idx + 1] = @truncate(u8, word >> 8);
self.buf[idx] = @truncate(u8, word);
self.set16(idx + 2, @truncate(u16, word >> 16));
self.set16(idx, @truncate(u16, word));
}
pub inline fn get16(self: *const @This(), idx: usize) u16 {