From 034f2e8d1dc82d4065dbc9a44770ea385f9943aa Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Wed, 16 Feb 2022 04:29:04 -0400 Subject: [PATCH] feat: implement hofs and vofs on io bus --- src/bus/io.zig | 18 ++++++++++++++++-- src/ppu.zig | 4 +--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/bus/io.zig b/src/bus/io.zig index 07ed7cc..4bef89c 100644 --- a/src/bus/io.zig +++ b/src/bus/io.zig @@ -142,6 +142,14 @@ pub fn read32(bus: *const Bus, addr: u32) u32 { pub fn write32(bus: *Bus, addr: u32, word: u32) void { switch (addr) { 0x0400_0000 => bus.ppu.dispcnt.raw = @truncate(u16, word), + 0x0400_0010 => bus.ppu.bg[0].hofs.raw = @truncate(u16, word), // TODO: Don't write out every HOFS / VOFS? + 0x0400_0012 => bus.ppu.bg[0].vofs.raw = @truncate(u16, word), + 0x0400_0014 => bus.ppu.bg[1].hofs.raw = @truncate(u16, word), + 0x0400_0016 => bus.ppu.bg[1].vofs.raw = @truncate(u16, word), + 0x0400_0018 => bus.ppu.bg[2].hofs.raw = @truncate(u16, word), + 0x0400_001A => bus.ppu.bg[2].vofs.raw = @truncate(u16, word), + 0x0400_001C => bus.ppu.bg[3].hofs.raw = @truncate(u16, word), + 0x0400_001E => bus.ppu.bg[3].vofs.raw = @truncate(u16, word), 0x0400_0200 => bus.io.ie.raw = @truncate(u16, word), 0x0400_0208 => bus.io.ime = word & 1 == 1, else => std.debug.panic("[I/O:32] tried to write 0x{X:} to 0x{X:}", .{ word, addr }), @@ -164,9 +172,15 @@ pub fn write16(bus: *Bus, addr: u32, halfword: u16) void { switch (addr) { 0x0400_0000 => bus.ppu.dispcnt.raw = halfword, 0x0400_0004 => bus.ppu.dispstat.raw = halfword, - 0x0400_0008 => bus.ppu.bg[0].cnt.raw = halfword, - 0x0400_0010 => bus.ppu.bg[0].hofs.raw = halfword, + 0x0400_0008...0x0400_000F => bus.ppu.bg[addr & 0x7].cnt.raw = halfword, + 0x0400_0010 => bus.ppu.bg[0].hofs.raw = halfword, // TODO: Don't write out every HOFS / VOFS? 0x0400_0012 => bus.ppu.bg[0].vofs.raw = halfword, + 0x0400_0014 => bus.ppu.bg[1].hofs.raw = halfword, + 0x0400_0016 => bus.ppu.bg[1].vofs.raw = halfword, + 0x0400_0018 => bus.ppu.bg[2].hofs.raw = halfword, + 0x0400_001A => bus.ppu.bg[2].vofs.raw = halfword, + 0x0400_001C => bus.ppu.bg[3].hofs.raw = halfword, + 0x0400_001E => bus.ppu.bg[3].vofs.raw = halfword, 0x0400_0200 => bus.io.ie.raw = halfword, 0x0400_0202 => bus.io.irq.raw = halfword, 0x0400_0208 => bus.io.ime = halfword & 1 == 1, diff --git a/src/ppu.zig b/src/ppu.zig index fea7077..f5c8e54 100644 --- a/src/ppu.zig +++ b/src/ppu.zig @@ -61,8 +61,6 @@ pub const Ppu = struct { } fn drawBackround(self: *Self, comptime n: u3, scanline: u32) void { - // TODO: Consider Scrolling - // The Current Scanline which will be copied into // the Framebuffer const start = framebuf_pitch * @as(usize, scanline); @@ -97,7 +95,7 @@ pub const Ppu = struct { // Grab the Screen Entry from VRAM const entry_addr = screen_base + tilemapOffset(size, x, y); - const entry = @bitCast(ScreenEntry, @as(u16, self.vram.buf[entry_addr + 1]) << 8 | @as(u16, self.vram.buf[entry_addr])); + const entry = @bitCast(ScreenEntry, @as(u16, self.vram.get16(entry_addr))); // Calculate the Address of the Tile in the designated Charblock // We also take this opportunity to flip tiles if necessary