From 8dddb865cc4fc3e90259f671cb4739f0e4b585c3 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Tue, 17 May 2022 12:16:03 -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: {