tile window improvements
This commit is contained in:
parent
f1e5960484
commit
3b853408f7
1 changed files with 17 additions and 34 deletions
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
connect::Renderer,
|
connect::Renderer,
|
||||||
processor::memory::mmio::gpu::{Palette, TiledataArea, TILE_WINDOW_HEIGHT, TILE_WINDOW_WIDTH},
|
processor::memory::mmio::gpu::{Palette, TILE_WINDOW_HEIGHT, TILE_WINDOW_WIDTH},
|
||||||
util::get_bit,
|
util::get_bit,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -61,25 +61,8 @@ where
|
||||||
current_width * TILE_WINDOW_HEIGHT
|
current_width * TILE_WINDOW_HEIGHT
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
for tile_y in 0..16 {
|
for (tile_y, data_begin) in (0x8000..0xA000).step_by(0x10 * 16).enumerate() {
|
||||||
self.draw_row(
|
self.draw_row(tile_y, data_begin, palette, memory, is_cgb_mode);
|
||||||
tile_y,
|
|
||||||
tile_y as usize,
|
|
||||||
TiledataArea::D8000,
|
|
||||||
palette,
|
|
||||||
memory,
|
|
||||||
is_cgb_mode,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
for tile_y in 0..8 {
|
|
||||||
self.draw_row(
|
|
||||||
tile_y,
|
|
||||||
(tile_y as usize) + 16,
|
|
||||||
TiledataArea::D9000,
|
|
||||||
palette,
|
|
||||||
memory,
|
|
||||||
is_cgb_mode,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.sprite_renderer.display(&self.sprite_buffer);
|
self.sprite_renderer.display(&self.sprite_buffer);
|
||||||
|
@ -87,9 +70,8 @@ where
|
||||||
|
|
||||||
fn draw_row(
|
fn draw_row(
|
||||||
&mut self,
|
&mut self,
|
||||||
tile_y: u8,
|
|
||||||
display_y: usize,
|
display_y: usize,
|
||||||
area: TiledataArea,
|
data_begin: u16,
|
||||||
palette: Palette,
|
palette: Palette,
|
||||||
memory: &Vram,
|
memory: &Vram,
|
||||||
is_cgb_mode: bool,
|
is_cgb_mode: bool,
|
||||||
|
@ -100,9 +82,8 @@ where
|
||||||
TILE_WINDOW_WIDTH
|
TILE_WINDOW_WIDTH
|
||||||
};
|
};
|
||||||
self.draw_row_from_bank(
|
self.draw_row_from_bank(
|
||||||
tile_y,
|
|
||||||
display_y,
|
display_y,
|
||||||
area,
|
data_begin,
|
||||||
palette,
|
palette,
|
||||||
memory,
|
memory,
|
||||||
is_cgb_mode,
|
is_cgb_mode,
|
||||||
|
@ -112,9 +93,8 @@ where
|
||||||
);
|
);
|
||||||
if is_cgb_mode {
|
if is_cgb_mode {
|
||||||
self.draw_row_from_bank(
|
self.draw_row_from_bank(
|
||||||
tile_y,
|
|
||||||
display_y,
|
display_y,
|
||||||
area,
|
data_begin,
|
||||||
palette,
|
palette,
|
||||||
memory,
|
memory,
|
||||||
is_cgb_mode,
|
is_cgb_mode,
|
||||||
|
@ -128,9 +108,8 @@ where
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn draw_row_from_bank(
|
fn draw_row_from_bank(
|
||||||
&mut self,
|
&mut self,
|
||||||
tile_y: u8,
|
|
||||||
display_y: usize,
|
display_y: usize,
|
||||||
area: TiledataArea,
|
data_begin: u16,
|
||||||
palette: Palette,
|
palette: Palette,
|
||||||
memory: &Vram,
|
memory: &Vram,
|
||||||
is_cgb_mode: bool,
|
is_cgb_mode: bool,
|
||||||
|
@ -139,20 +118,22 @@ where
|
||||||
line_width: usize,
|
line_width: usize,
|
||||||
) {
|
) {
|
||||||
for tile_x 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);
|
|
||||||
let attributes = BgAttributes {
|
let attributes = BgAttributes {
|
||||||
tile_bank: bank,
|
tile_bank: bank,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
let data_begin = data_begin + ((tile_x * 16) as u16);
|
||||||
|
|
||||||
for px_y in 0..8_u16 {
|
for px_y in 0..8_u16 {
|
||||||
let lsbs = memory
|
let lsbs = memory
|
||||||
.get_with_bank((data_begin + (px_y * 2)).unwrap(), attributes.tile_bank)
|
.get_with_bank(
|
||||||
|
(data_begin + (px_y * 2)).try_into().unwrap(),
|
||||||
|
attributes.tile_bank,
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let msbs = memory
|
let msbs = memory
|
||||||
.get_with_bank(
|
.get_with_bank(
|
||||||
(data_begin + (1 + (px_y * 2))).unwrap(),
|
(data_begin + (1 + (px_y * 2))).try_into().unwrap(),
|
||||||
attributes.tile_bank,
|
attributes.tile_bank,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -167,8 +148,10 @@ where
|
||||||
palette.map_bits(lsb, msb).0
|
palette.map_bits(lsb, msb).0
|
||||||
};
|
};
|
||||||
|
|
||||||
self.sprite_buffer[offset + real_px_x + (real_px_y * line_width)] =
|
let addr = offset + real_px_x + (real_px_y * line_width);
|
||||||
colour.rgb_bytes(None, is_cgb_mode).into();
|
if addr < self.sprite_buffer.len() {
|
||||||
|
self.sprite_buffer[addr] = colour.rgb_bytes(None, is_cgb_mode).into();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue