fix tile rendering
This commit is contained in:
parent
d6b95e6c6c
commit
09b1cb1e57
|
@ -330,6 +330,7 @@ impl CPU {
|
|||
palette,
|
||||
scroll_x,
|
||||
scroll_y,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -345,6 +346,7 @@ impl CPU {
|
|||
palette,
|
||||
pos_x,
|
||||
pos_y,
|
||||
false,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -429,28 +431,39 @@ impl CPU {
|
|||
tilemap: &TilemapArea,
|
||||
tiledata: &TiledataArea,
|
||||
palette: Palette,
|
||||
_offset_x: u8,
|
||||
offset_x: u8,
|
||||
offset_y: u8,
|
||||
wrap: bool,
|
||||
) {
|
||||
let tile_line = (scanline as usize) + (offset_y as usize);
|
||||
let tilemap_row = tile_line / 8;
|
||||
let tile_px = (tile_line) % 8;
|
||||
let tiledata_offset = tile_px * 2;
|
||||
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 tile_line_y = scanline.wrapping_add(offset_y);
|
||||
if (scanline as usize + offset_y as usize) % 0xFF > 0 && !wrap {
|
||||
return;
|
||||
}
|
||||
let tilemap_row = tile_line_y / 8;
|
||||
let tile_px_y = (tile_line_y) % 8;
|
||||
let tiledata_offset = tile_px_y * 2;
|
||||
let row_addr = ((tilemap_row as usize * 32) % 0x400) as u16;
|
||||
for x in 0..WIDTH {
|
||||
let tile_line_x = (x as u8).wrapping_add(offset_x);
|
||||
if ((x + offset_x as usize) / 0xFF) > 0 && !wrap {
|
||||
continue;
|
||||
}
|
||||
|
||||
let tilemap_column = (tile_line_x / 8) as u16;
|
||||
|
||||
let tile_px_x = (tile_line_x % 8) as u8;
|
||||
let tile_addr = tiledata.get_addr(
|
||||
self.memory
|
||||
.get(tilemap.get_addr(row_addr + (tilemap_column))),
|
||||
) + 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 {
|
||||
let lsb = get_bit(lsbs, 7 - px_x);
|
||||
let msb = get_bit(msbs, 7 - px_x);
|
||||
let lsb = get_bit(lsbs, 7 - tile_px_x);
|
||||
let msb = get_bit(msbs, 7 - tile_px_x);
|
||||
let colour = bits_to_mapped_colour(lsb, msb, palette);
|
||||
let x_coord = ((x * 8) + (px_x as u16)) as usize;
|
||||
if x_coord < WIDTH {
|
||||
self.gpu.buffer[(scanline as usize * WIDTH) + x_coord] = colour.to_rgb();
|
||||
}
|
||||
}
|
||||
|
||||
self.gpu.buffer[(scanline as usize * WIDTH) + x] = colour.to_rgb();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue