From 4326ae7a0addc034b3b5d82eab3ee824746f2b6d Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Sun, 18 Dec 2022 08:59:19 -0400 Subject: [PATCH] fix: resolve broken affine bg in mario kart --- src/core/ppu.zig | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/ppu.zig b/src/core/ppu.zig index e1855b5..29a475f 100644 --- a/src/core/ppu.zig +++ b/src/core/ppu.zig @@ -521,10 +521,10 @@ pub const Ppu = struct { aff_x += self.aff_bg[n - 2].pa; aff_y += self.aff_bg[n - 2].pc; - const x = @bitCast(u32, ix); - const y = @bitCast(u32, iy); + const _x = @truncate(u9, @bitCast(u32, ix)); + const _y = @truncate(u8, @bitCast(u32, iy)); - const win_bounds = self.windowBounds(@truncate(u9, x), @truncate(u8, y)); + const win_bounds = self.windowBounds(_x, _y); if (!shouldDrawBackground(self, n, win_bounds, i)) continue; if (self.bg[n].cnt.display_overflow.read()) { @@ -532,6 +532,9 @@ pub const Ppu = struct { iy = if (iy > px_height) @rem(iy, px_height) else if (iy < 0) px_height + @rem(iy, px_height) else iy; } else if (ix > px_width or iy > px_height or ix < 0 or iy < 0) continue; + const x = @bitCast(u32, ix); + const y = @bitCast(u32, iy); + const tile_id: u32 = self.vram.read(u8, screen_base + ((y / 8) * @bitCast(u32, tile_width) + (x / 8))); const row = y & 7; const col = x & 7;