Compare commits

..

No commits in common. "07343efdf3fb3db2cec176c499f767b81739fd2b" and "034f2e8d1dc82d4065dbc9a44770ea385f9943aa" have entirely different histories.

2 changed files with 17 additions and 40 deletions

View File

@ -142,22 +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 => { 0x0400_0010 => bus.ppu.bg[0].hofs.raw = @truncate(u16, word), // TODO: Don't write out every HOFS / VOFS?
bus.ppu.bg[0].hofs.raw = @truncate(u16, word); 0x0400_0012 => bus.ppu.bg[0].vofs.raw = @truncate(u16, word),
bus.ppu.bg[0].vofs.raw = @truncate(u16, word >> 16); 0x0400_0014 => bus.ppu.bg[1].hofs.raw = @truncate(u16, word),
}, 0x0400_0016 => bus.ppu.bg[1].vofs.raw = @truncate(u16, word),
0x0400_0014 => { 0x0400_0018 => bus.ppu.bg[2].hofs.raw = @truncate(u16, word),
bus.ppu.bg[1].hofs.raw = @truncate(u16, word); 0x0400_001A => bus.ppu.bg[2].vofs.raw = @truncate(u16, word),
bus.ppu.bg[1].vofs.raw = @truncate(u16, word >> 16); 0x0400_001C => bus.ppu.bg[3].hofs.raw = @truncate(u16, word),
}, 0x0400_001E => bus.ppu.bg[3].vofs.raw = @truncate(u16, word),
0x0400_0018 => {
bus.ppu.bg[2].hofs.raw = @truncate(u16, word);
bus.ppu.bg[2].vofs.raw = @truncate(u16, word >> 16);
},
0x0400_001C => {
bus.ppu.bg[3].hofs.raw = @truncate(u16, word);
bus.ppu.bg[3].vofs.raw = @truncate(u16, word >> 16);
},
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 }),

View File

@ -87,15 +87,15 @@ pub const Ppu = struct {
const vofs = self.bg[n].vofs.offset.read(); const vofs = self.bg[n].vofs.offset.read();
const hofs = self.bg[n].hofs.offset.read(); const hofs = self.bg[n].hofs.offset.read();
const y = vofs + scanline; const y = scanline + vofs;
var i: u32 = 0; var i: u32 = 0;
while (i < width) : (i += 1) { while (i < width) : (i += 1) {
const x = hofs + i; const x = i + hofs;
// 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, self.vram.get16(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
@ -112,13 +112,13 @@ pub const Ppu = struct {
// If we're in 8bpp, then the tile value is an index into the palette, // If we're in 8bpp, then the tile value is an index into the palette,
// If we're in 4bpp, we have to account for a pal bank value in the Screen entry // If we're in 4bpp, we have to account for a pal bank value in the Screen entry
// and then we can index the palette // and then we can index the palette
const pal_id = if (!is_8bpp) blk: { const colour = if (!is_8bpp) blk: {
tile = if (col & 1 == 1) tile >> 4 else tile & 0xF; tile = if (col & 1 == 1) tile >> 4 else tile & 0xF;
const pal_bank: u8 = @as(u8, entry.palette_bank.read()) << 4; const pal_bank: u8 = @as(u8, entry.palette_bank.read()) << 4;
break :blk pal_bank | tile; break :blk pal_bank | tile;
} else tile; } else tile;
std.mem.copy(u8, scanline_buf[i * 2 ..][0..2], self.palette.buf[pal_id * 2 ..][0..2]); std.mem.copy(u8, scanline_buf[i * 2 ..][0..2], self.palette.buf[colour * 2 ..][0..2]);
} }
std.mem.copy(u8, self.framebuf[start..][0..framebuf_pitch], &scanline_buf); std.mem.copy(u8, self.framebuf[start..][0..framebuf_pitch], &scanline_buf);
@ -168,26 +168,11 @@ pub const Ppu = struct {
// Current COlumn: (x % PIXEL_COUNT) / 8 // Current COlumn: (x % PIXEL_COUNT) / 8
// Length of 1 row of Screen Entries: 0x40 // Length of 1 row of Screen Entries: 0x40
// Length of 1 Screen Entry: 0x2 is the size of a screen entry // Length of 1 Screen Entry: 0x2 is the size of a screen entry
@setRuntimeSafety(false);
return switch (size) { return switch (size) {
0 => (x % 256 / 8) * 2 + (y % 256 / 8) * 0x40, // 256 x 256 0 => (y % 256 / 8) * 0x40 + (x % 256 / 8) * 2, // 256 x 256
1 => blk: { 1 => (y % 512 / 8) * 0x40 + (x % 256 / 8) * 2, // 512 x 256
// 512 x 256 2 => (y % 256 / 8) * 0x40 + (x % 512 / 8) * 2, // 256 x 512
const offset: u32 = if (x & 0x1FF > 0xFF) 0x800 else 0; 3 => (y % 512 / 8) * 0x40 + (x % 512 / 8) * 2, // 512 x 512
break :blk offset + (x % 256 / 8) * 2 + (y % 256 / 8) * 0x40;
},
2 => blk: {
// 256 x 512
const offset: u32 = if (y & 0x1FF > 0xFF) 0x800 else 0;
break :blk offset + (x % 256 / 8) * 2 + (y % 256 / 8) * 0x40;
},
3 => blk: {
// 512 x 512
const offset: u32 = if (x & 0x1FF > 0xFF) 0x800 else 0;
const offset_2: u32 = if (y & 0x1FF > 0xFF) 0x800 else 0;
break :blk offset + offset_2 + (x % 256 / 8) * 2 + (y % 512 / 8) * 0x40;
},
}; };
} }
}; };