From 5c612c27bc34a838987dea940f9049ffbcdfd06b Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Wed, 8 Feb 2023 10:09:24 +1100 Subject: [PATCH] fix addr handling for tilemaps --- src/processor/gpu.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/processor/gpu.rs b/src/processor/gpu.rs index ce74229..fbccd70 100644 --- a/src/processor/gpu.rs +++ b/src/processor/gpu.rs @@ -22,10 +22,10 @@ enum TilemapArea { } impl TilemapArea { - fn get_offset(&self) -> u16 { + fn get_addr(&self, addr: u16) -> u16 { match self { - TilemapArea::T9800 => 0x9800, - TilemapArea::T9C00 => 0x9C00, + TilemapArea::T9800 => 0x9800 + addr, + TilemapArea::T9C00 => 0x9C00 + addr, } } } @@ -400,10 +400,10 @@ impl CPU { let tilemap_row = tile_line / 8; let tile_px = (tile_line) % 8; let tiledata_offset = tile_px * 2; - let row_addr = (tilemap_row * 32) as u16 + tilemap.get_offset(); - for x in 0..32 { - let tile_addr = - tiledata.get_addr(self.memory.get(row_addr + x)) + tiledata_offset as u16; + let row_addr = ((tilemap_row * 32) % 0x400) as u16; + for x in 0..32_u16 { + let tile_addr = tiledata.get_addr(self.memory.get(tilemap.get_addr(row_addr + x))) + + tiledata_offset as u16; let lsbs = self.memory.get(tile_addr); let msbs = self.memory.get(tile_addr + 1); for px_x in 0..8 {