feat: implement hofs and vofs on io bus

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-02-16 04:29:04 -04:00
parent d275a4890f
commit 034f2e8d1d
2 changed files with 17 additions and 5 deletions

View File

@ -142,6 +142,14 @@ pub fn read32(bus: *const Bus, addr: u32) u32 {
pub fn write32(bus: *Bus, addr: u32, word: u32) void { pub fn write32(bus: *Bus, addr: u32, word: u32) void {
switch (addr) { switch (addr) {
0x0400_0000 => bus.ppu.dispcnt.raw = @truncate(u16, word), 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_0200 => bus.io.ie.raw = @truncate(u16, word),
0x0400_0208 => bus.io.ime = word & 1 == 1, 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 }), 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) { switch (addr) {
0x0400_0000 => bus.ppu.dispcnt.raw = halfword, 0x0400_0000 => bus.ppu.dispcnt.raw = halfword,
0x0400_0004 => bus.ppu.dispstat.raw = halfword, 0x0400_0004 => bus.ppu.dispstat.raw = halfword,
0x0400_0008 => bus.ppu.bg[0].cnt.raw = halfword, 0x0400_0008...0x0400_000F => bus.ppu.bg[addr & 0x7].cnt.raw = halfword,
0x0400_0010 => bus.ppu.bg[0].hofs.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_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_0200 => bus.io.ie.raw = halfword,
0x0400_0202 => bus.io.irq.raw = halfword, 0x0400_0202 => bus.io.irq.raw = halfword,
0x0400_0208 => bus.io.ime = halfword & 1 == 1, 0x0400_0208 => bus.io.ime = halfword & 1 == 1,

View File

@ -61,8 +61,6 @@ pub const Ppu = struct {
} }
fn drawBackround(self: *Self, comptime n: u3, scanline: u32) void { fn drawBackround(self: *Self, comptime n: u3, scanline: u32) void {
// TODO: Consider Scrolling
// The Current Scanline which will be copied into // The Current Scanline which will be copied into
// the Framebuffer // the Framebuffer
const start = framebuf_pitch * @as(usize, scanline); const start = framebuf_pitch * @as(usize, scanline);
@ -97,7 +95,7 @@ pub const Ppu = struct {
// Grab the Screen Entry from VRAM // Grab the Screen Entry from VRAM
const entry_addr = screen_base + tilemapOffset(size, x, y); 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 // Calculate the Address of the Tile in the designated Charblock
// We also take this opportunity to flip tiles if necessary // We also take this opportunity to flip tiles if necessary