From d297cca81c62efd9f3a34c2f89b51342f68f319b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com> Date: Sat, 29 Apr 2023 17:59:42 +0100 Subject: [PATCH] fix: tile data update --- src/ppu.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/ppu.rs b/src/ppu.rs index 7dd6b5b7..81012027 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -917,19 +917,18 @@ impl Ppu { fn update_bg_map_attrs(&mut self, addr: u16, value: u8) { let bg_map = addr > 0x9bff; let tile_index = if bg_map { addr - 0x9c00 } else { addr - 0x9800 }; - let tile_data = TileData { - palette: (value & 0x03 == 0x03) as u8, - vram_bank: (value & 0x08) >> 4, - xflip: value & 0x20 == 0x20, - yflip: value & 0x40 == 0x40, - priority: value & 0x80 == 0x80, - }; let mut bg_map_attrs = if bg_map { self.bg_map_attrs_1 } else { self.bg_map_attrs_0 }; - bg_map_attrs[tile_index as usize] = tile_data; + let tile_data = bg_map_attrs[tile_index as usize].borrow_mut(); + tile_data.palette = (value & 0x03 == 0x03) as u8; + tile_data.vram_bank = (value & 0x08) >> 4; + tile_data.vram_bank = (value & 0x08) >> 4; + tile_data.xflip = value & 0x20 == 0x20; + tile_data.yflip = value & 0x40 == 0x40; + tile_data.priority = value & 0x80 == 0x80; } pub fn registers(&self) -> PpuRegisters { -- GitLab