From ff6d2517be1c1be1a59ef741a07eb94ce1c2a11c Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:12:43 -0300 Subject: [PATCH] fix: resolve out-of-bounds error with 8bpp tall / horizontal sprites Boot ROM is now enabled by default as well --- src/main.zig | 2 +- src/ppu.zig | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main.zig b/src/main.zig index 1102d92..bc5aaac 100644 --- a/src/main.zig +++ b/src/main.zig @@ -84,7 +84,7 @@ pub fn main() anyerror!void { defer cpu.deinit(); cpu.bus.attach(&cpu); - cpu.fastBoot(); + // cpu.fastBoot(); // Initialize SDL Audio const audio_dev = initAudio(&cpu.bus.apu); diff --git a/src/ppu.zig b/src/ppu.zig index 96cca86..1238dd9 100644 --- a/src/ppu.zig +++ b/src/ppu.zig @@ -187,14 +187,11 @@ pub const Ppu = struct { // When calcualting the inital address, the first entry is always 0x20 * tile_id, even if it is 8bpp const tile_base = char_base + (0x20 * @as(u32, tile_id)) + (tile_row_offset * row) + if (is_8bpp) col else col / 2; - // TODO: Understand more - var tile_offset = (tile_x / 8) * tile_len; - if (self.dispcnt.obj_mapping.read()) { - tile_offset += (tile_y / 8) * tile_len * (sprite.width / 8); // 1D Mapping - } else { - tile_offset += (tile_y / 8) * tile_len * 0x20; // 2D Mapping - } + // TODO: Finish that 2D Sprites Test ROM + const offset_base = (tile_x / 8) * tile_len; + const offset_offset = (tile_y / 8) * tile_len * if (self.dispcnt.obj_mapping.read()) sprite.width / 8 else if (is_8bpp) @as(u32, 0x10) else 0x20; + const tile_offset = offset_base + offset_offset; const tile = self.vram.buf[tile_base + tile_offset]; const pal_id: u16 = if (!is_8bpp) blk: {