feat: implement BG Scrolling Registers

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-02-13 04:04:10 -04:00
parent b238a3e8f3
commit ec25a9aae4
2 changed files with 38 additions and 1 deletions

View File

@ -17,6 +17,24 @@ pub const Io = struct {
bg2cnt: BackgroundControl, bg2cnt: BackgroundControl,
/// Read / Write /// Read / Write
bg3cnt: BackgroundControl, 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 /// Read / Write
ime: bool, ime: bool,
ie: InterruptEnable, ie: InterruptEnable,
@ -34,6 +52,14 @@ pub const Io = struct {
.bg1cnt = .{ .raw = 0x0000 }, .bg1cnt = .{ .raw = 0x0000 },
.bg2cnt = .{ .raw = 0x0000 }, .bg2cnt = .{ .raw = 0x0000 },
.bg3cnt = .{ .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, .ime = false,
.ie = .{ .raw = 0x0000 }, .ie = .{ .raw = 0x0000 },
.irq = .{ .raw = 0x0000 }, .irq = .{ .raw = 0x0000 },
@ -78,6 +104,8 @@ pub const Io = struct {
0x0400_0000 => self.dispcnt.raw = halfword, 0x0400_0000 => self.dispcnt.raw = halfword,
0x0400_0004 => self.dispstat.raw = halfword, 0x0400_0004 => self.dispstat.raw = halfword,
0x0400_0008 => self.bg0cnt.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_0200 => self.ie.raw = halfword,
0x0400_0202 => self.irq.raw = halfword, 0x0400_0202 => self.irq.raw = halfword,
0x0400_0208 => self.ime = halfword & 1 == 1, 0x0400_0208 => self.ime = halfword & 1 == 1,
@ -181,6 +209,11 @@ const BackgroundControl = extern union {
raw: u16, raw: u16,
}; };
const BackgroundOffset = extern union {
offset: Bitfield(u16, 0, 9),
raw: u16,
};
const InterruptRequest = extern union { const InterruptRequest = extern union {
vblank: Bit(u16, 0), vblank: Bit(u16, 0),
hblank: Bit(u16, 1), hblank: Bit(u16, 1),

View File

@ -47,6 +47,10 @@ pub const Ppu = struct {
const scanline = io.vcount.scanline.read(); const scanline = io.vcount.scanline.read();
switch (bg_mode) { switch (bg_mode) {
0x0 => {
// Mode 0
},
0x3 => { 0x3 => {
const start = framebuf_pitch * @as(usize, scanline); const start = framebuf_pitch * @as(usize, scanline);
const end = start + framebuf_pitch; const end = start + framebuf_pitch;
@ -70,7 +74,7 @@ pub const Ppu = struct {
self.framebuf[buf_start + j] = self.palette.buf[id]; 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}),
} }
} }
}; };