52 lines
1.7 KiB
Rust
52 lines
1.7 KiB
Rust
use crate::{
|
|
processor::{
|
|
get_bit,
|
|
gpu::{
|
|
bits_to_mapped_colour, scale_buffer, Palette, TiledataArea, TILE_WINDOW_EDGE_LENGTH,
|
|
TILE_WINDOW_EDGE_LENGTH_SCALED,
|
|
},
|
|
CPU,
|
|
},
|
|
FACTOR,
|
|
};
|
|
|
|
impl CPU {
|
|
pub(super) fn draw_sprite_window(&mut self, area: TiledataArea, palette: Palette) {
|
|
for tile_y in 0..16 {
|
|
for tile_x in 0..16 {
|
|
let tile_num = (tile_y * 16) + tile_x;
|
|
let data_begin = area.get_addr(tile_num);
|
|
for px_y in 0..8 {
|
|
let lsbs = self.memory.get((px_y * 2) + data_begin);
|
|
let msbs = self.memory.get((px_y * 2) + data_begin + 1);
|
|
for px_x in 0..8 {
|
|
let real_px_y = (tile_y as usize * 8) + px_y as usize;
|
|
let real_px_x = (tile_x as usize * 8) + px_x as usize;
|
|
let lsb = get_bit(lsbs, 7 - px_x);
|
|
let msb = get_bit(msbs, 7 - px_x);
|
|
let colour = bits_to_mapped_colour(lsb, msb, palette);
|
|
|
|
self.gpu.sprite_buffer[real_px_x + (real_px_y * TILE_WINDOW_EDGE_LENGTH)] =
|
|
colour.to_rgb();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
self.gpu.sprite_buffer_scaled = scale_buffer(
|
|
&self.gpu.sprite_buffer,
|
|
TILE_WINDOW_EDGE_LENGTH,
|
|
TILE_WINDOW_EDGE_LENGTH,
|
|
FACTOR,
|
|
);
|
|
self.gpu
|
|
.sprite_window
|
|
.update_with_buffer(
|
|
&self.gpu.sprite_buffer_scaled,
|
|
TILE_WINDOW_EDGE_LENGTH_SCALED,
|
|
TILE_WINDOW_EDGE_LENGTH_SCALED,
|
|
)
|
|
.unwrap();
|
|
}
|
|
}
|