From dfd0d064de0b7b9136f57376f03c74a8f566ff45 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:12:19 -0300 Subject: [PATCH] feat: implement BG Scrolling Registers --- src/bus/io.zig | 33 +++++++++++++++++++++++++++++++++ src/ppu.zig | 6 +++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/bus/io.zig b/src/bus/io.zig index 66561ec..134fedb 100644 --- a/src/bus/io.zig +++ b/src/bus/io.zig @@ -17,6 +17,24 @@ pub const Io = struct { bg2cnt: BackgroundControl, /// Read / Write bg3cnt: BackgroundControl, + + /// Write Only + bg0hofs: BackgroundOffset, + /// Write Only + bg0vofs: BackgroundOffset, + /// Write Only + bg1hofs: BackgroundOffset, + /// Write Only + bg1vofs: BackgroundOffset, + /// Write Only + bg2hofs: BackgroundOffset, + /// Write Only + bg2vofs: BackgroundOffset, + /// Write Only + bg3hofs: BackgroundOffset, + /// Write Only + bg3vofs: BackgroundOffset, + /// Read / Write ime: bool, ie: InterruptEnable, @@ -34,6 +52,14 @@ pub const Io = struct { .bg1cnt = .{ .raw = 0x0000 }, .bg2cnt = .{ .raw = 0x0000 }, .bg3cnt = .{ .raw = 0x0000 }, + .bg0hofs = .{ .raw = 0x0000 }, + .bg0vofs = .{ .raw = 0x0000 }, + .bg1hofs = .{ .raw = 0x0000 }, + .bg1vofs = .{ .raw = 0x0000 }, + .bg2hofs = .{ .raw = 0x0000 }, + .bg2vofs = .{ .raw = 0x0000 }, + .bg3hofs = .{ .raw = 0x0000 }, + .bg3vofs = .{ .raw = 0x0000 }, .ime = false, .ie = .{ .raw = 0x0000 }, .irq = .{ .raw = 0x0000 }, @@ -78,6 +104,8 @@ pub const Io = struct { 0x0400_0000 => self.dispcnt.raw = halfword, 0x0400_0004 => self.dispstat.raw = halfword, 0x0400_0008 => self.bg0cnt.raw = halfword, + 0x0400_0010 => self.bg0hofs.raw = halfword, + 0x0400_0012 => self.bg0vofs.raw = halfword, 0x0400_0200 => self.ie.raw = halfword, 0x0400_0202 => self.irq.raw = halfword, 0x0400_0208 => self.ime = halfword & 1 == 1, @@ -181,6 +209,11 @@ const BackgroundControl = extern union { raw: u16, }; +const BackgroundOffset = extern union { + offset: Bitfield(u16, 0, 9), + raw: u16, +}; + const InterruptRequest = extern union { vblank: Bit(u16, 0), hblank: Bit(u16, 1), diff --git a/src/ppu.zig b/src/ppu.zig index c89d00f..dbc555e 100644 --- a/src/ppu.zig +++ b/src/ppu.zig @@ -47,6 +47,10 @@ pub const Ppu = struct { const scanline = io.vcount.scanline.read(); switch (bg_mode) { + 0x0 => { + // Mode 0 + + }, 0x3 => { const start = framebuf_pitch * @as(usize, scanline); const end = start + framebuf_pitch; @@ -70,7 +74,7 @@ pub const Ppu = struct { self.framebuf[buf_start + j] = self.palette.buf[id]; } }, - else => {}, // std.debug.panic("[PPU] TODO: Implement BG Mode {}", .{bg_mode}), + else => std.debug.panic("[PPU] TODO: Implement BG Mode {}", .{bg_mode}), } } };