tile window colour
This commit is contained in:
parent
8c574fc47e
commit
be11c6a596
|
@ -305,8 +305,14 @@ where
|
||||||
self.scanline = 0;
|
self.scanline = 0;
|
||||||
self.window_lc = 0;
|
self.window_lc = 0;
|
||||||
self.has_window_been_enabled = false;
|
self.has_window_been_enabled = false;
|
||||||
|
let is_cgb_mode = self.is_cgb_mode();
|
||||||
if let Some(tile_window) = &mut self.tile_window {
|
if let Some(tile_window) = &mut self.tile_window {
|
||||||
tile_window.draw_sprite_window(self.bg_palette, &self.vram);
|
tile_window.draw_sprite_window(
|
||||||
|
self.bg_palette,
|
||||||
|
&self.vram,
|
||||||
|
is_cgb_mode,
|
||||||
|
self.cgb_data.as_ref().map(|v| v.palettes.bg),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,8 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
types::{ColourInner, Vram},
|
cgb::CgbPalette,
|
||||||
|
types::{BgAttributes, ColourInner, Vram, VramBank},
|
||||||
Colour,
|
Colour,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,7 +34,13 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn draw_sprite_window(&mut self, palette: Palette, memory: &Vram) {
|
pub(super) fn draw_sprite_window(
|
||||||
|
&mut self,
|
||||||
|
palette: Palette,
|
||||||
|
memory: &Vram,
|
||||||
|
is_cgb_mode: bool,
|
||||||
|
cgb_data: Option<CgbPalette>,
|
||||||
|
) {
|
||||||
for tile_y in 0..16 {
|
for tile_y in 0..16 {
|
||||||
self.draw_row(
|
self.draw_row(
|
||||||
tile_y,
|
tile_y,
|
||||||
|
@ -41,6 +48,8 @@ where
|
||||||
TiledataArea::D8000,
|
TiledataArea::D8000,
|
||||||
palette,
|
palette,
|
||||||
memory,
|
memory,
|
||||||
|
is_cgb_mode,
|
||||||
|
cgb_data,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for tile_y in 0..8 {
|
for tile_y in 0..8 {
|
||||||
|
@ -50,12 +59,15 @@ where
|
||||||
TiledataArea::D9000,
|
TiledataArea::D9000,
|
||||||
palette,
|
palette,
|
||||||
memory,
|
memory,
|
||||||
|
is_cgb_mode,
|
||||||
|
cgb_data,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.sprite_renderer.display(&self.sprite_buffer);
|
self.sprite_renderer.display(&self.sprite_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn draw_row(
|
fn draw_row(
|
||||||
&mut self,
|
&mut self,
|
||||||
tile_y: u8,
|
tile_y: u8,
|
||||||
|
@ -63,13 +75,29 @@ where
|
||||||
area: TiledataArea,
|
area: TiledataArea,
|
||||||
palette: Palette,
|
palette: Palette,
|
||||||
memory: &Vram,
|
memory: &Vram,
|
||||||
|
is_cgb_mode: bool,
|
||||||
|
cgb_data: Option<CgbPalette>,
|
||||||
) {
|
) {
|
||||||
for tile_x in 0..16 {
|
for tile_x in 0..16 {
|
||||||
let tile_num = (tile_y * 16) + tile_x;
|
let tile_num = (tile_y * 16) + tile_x;
|
||||||
let data_begin = area.get_addr(tile_num);
|
let data_begin = area.get_addr(tile_num);
|
||||||
|
let attributes = if is_cgb_mode {
|
||||||
|
memory
|
||||||
|
.get_with_bank(data_begin, VramBank::Bank1)
|
||||||
|
.map_or(BgAttributes::default(), BgAttributes::from_byte)
|
||||||
|
} else {
|
||||||
|
BgAttributes::default()
|
||||||
|
};
|
||||||
for px_y in 0..8_u16 {
|
for px_y in 0..8_u16 {
|
||||||
let lsbs = memory.get((data_begin + (px_y * 2)).unwrap());
|
let lsbs = memory
|
||||||
let msbs = memory.get((data_begin + (1 + (px_y * 2))).unwrap());
|
.get_with_bank((data_begin + (px_y * 2)).unwrap(), attributes.tile_bank)
|
||||||
|
.unwrap();
|
||||||
|
let msbs = memory
|
||||||
|
.get_with_bank(
|
||||||
|
(data_begin + (1 + (px_y * 2))).unwrap(),
|
||||||
|
attributes.tile_bank,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
for px_x in 0..8 {
|
for px_x in 0..8 {
|
||||||
let real_px_y = (display_y * 8) + px_y as usize;
|
let real_px_y = (display_y * 8) + px_y as usize;
|
||||||
let real_px_x = (tile_x as usize * 8) + px_x as usize;
|
let real_px_x = (tile_x as usize * 8) + px_x as usize;
|
||||||
|
@ -77,8 +105,10 @@ where
|
||||||
let msb = get_bit(msbs, 7 - px_x);
|
let msb = get_bit(msbs, 7 - px_x);
|
||||||
let colour = palette.map_bits(lsb, msb);
|
let colour = palette.map_bits(lsb, msb);
|
||||||
|
|
||||||
self.sprite_buffer[real_px_x + (real_px_y * TILE_WINDOW_WIDTH)] =
|
self.sprite_buffer[real_px_x + (real_px_y * TILE_WINDOW_WIDTH)] = colour
|
||||||
colour.0.rgb_bytes(None).into();
|
.0
|
||||||
|
.rgb_bytes(cgb_data.map(|v| (v, attributes.palette)))
|
||||||
|
.into();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue