gbc: Implement background priority bit

This commit is contained in:
Kevin Hamacher 2020-02-21 18:39:17 +01:00
parent 1890dd2d3a
commit 515321110b
2 changed files with 10 additions and 2 deletions

View File

@ -491,6 +491,10 @@ impl Display {
} }
} }
if pixel_origin == PixelOrigin::BackgroundPriority {
continue;
}
let x_maybe_flipped: u8 = if sprite.is_x_flipped() { x_o ^ 7 } else { x_o }; let x_maybe_flipped: u8 = if sprite.is_x_flipped() { x_o ^ 7 } else { x_o };
b1 = (tile_line_1 & 1 << (7 - x_o)) > 0; b1 = (tile_line_1 & 1 << (7 - x_o)) > 0;
b2 = (tile_line_2 & 1 << (7 - x_o)) > 0; b2 = (tile_line_2 & 1 << (7 - x_o)) > 0;
@ -599,7 +603,6 @@ impl Display {
let bg_attribs = BgMapAttributes(self.vram1[vram_offset]); let bg_attribs = BgMapAttributes(self.vram1[vram_offset]);
let vram = [&*self.vram0, &*self.vram1][bg_attribs.vram_bank_number()]; let vram = [&*self.vram0, &*self.vram1][bg_attribs.vram_bank_number()];
// TODO: Priority
let tile_offset_y = if bg_attribs.vertical_flip() { let tile_offset_y = if bg_attribs.vertical_flip() {
7 ^ tile_offset_y 7 ^ tile_offset_y
} else { } else {
@ -631,7 +634,11 @@ impl Display {
let c = ((b2 as u8) * 2 + b1 as u8) as usize; let c = ((b2 as u8) * 2 + b1 as u8) as usize;
// let color = self.background_palette.get_color(c); // let color = self.background_palette.get_color(c);
let color = self.background_palette_cgb[bg_attribs.palette_number()].get_color(c); let color = self.background_palette_cgb[bg_attribs.palette_number()].get_color(c);
self.set_pixel(render_x, render_y, color, PixelOrigin::Background(c)); if bg_attribs.has_priority() && (self.control & 1) == 1 {
self.set_pixel(render_x, render_y, color, PixelOrigin::BackgroundPriority);
} else {
self.set_pixel(render_x, render_y, color, PixelOrigin::Background(c));
}
} }
} }

View File

@ -27,6 +27,7 @@ impl BgMapAttributes {
pub enum PixelOrigin { pub enum PixelOrigin {
Empty, Empty,
Background(usize), Background(usize),
BackgroundPriority,
Window, Window,
Sprite, Sprite,
} }