fix addr handling for tilemaps

This commit is contained in:
Alex Janka 2023-02-08 10:09:24 +11:00
parent 0a75b58732
commit 5c612c27bc

View file

@ -22,10 +22,10 @@ enum TilemapArea {
} }
impl TilemapArea { impl TilemapArea {
fn get_offset(&self) -> u16 { fn get_addr(&self, addr: u16) -> u16 {
match self { match self {
TilemapArea::T9800 => 0x9800, TilemapArea::T9800 => 0x9800 + addr,
TilemapArea::T9C00 => 0x9C00, TilemapArea::T9C00 => 0x9C00 + addr,
} }
} }
} }
@ -400,10 +400,10 @@ impl CPU {
let tilemap_row = tile_line / 8; let tilemap_row = tile_line / 8;
let tile_px = (tile_line) % 8; let tile_px = (tile_line) % 8;
let tiledata_offset = tile_px * 2; let tiledata_offset = tile_px * 2;
let row_addr = (tilemap_row * 32) as u16 + tilemap.get_offset(); let row_addr = ((tilemap_row * 32) % 0x400) as u16;
for x in 0..32 { for x in 0..32_u16 {
let tile_addr = let tile_addr = tiledata.get_addr(self.memory.get(tilemap.get_addr(row_addr + x)))
tiledata.get_addr(self.memory.get(row_addr + x)) + tiledata_offset as u16; + tiledata_offset as u16;
let lsbs = self.memory.get(tile_addr); let lsbs = self.memory.get(tile_addr);
let msbs = self.memory.get(tile_addr + 1); let msbs = self.memory.get(tile_addr + 1);
for px_x in 0..8 { for px_x in 0..8 {