chore(ppu): reimplement fifo pixel merging logic

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-06-02 23:32:20 -05:00
parent cd21c90722
commit 112454aa59
1 changed files with 18 additions and 21 deletions

View File

@ -346,33 +346,30 @@ impl Ppu {
} }
if self.fifo.is_enabled() { if self.fifo.is_enabled() {
use RenderPriority::*;
// Handle Background Pixel and Sprite FIFO // Handle Background Pixel and Sprite FIFO
let bg_enabled = self.control.bg_win_enabled(); let bg_enabled = self.control.bg_win_enabled();
let i0_colour = self.monochrome.bg_palette.i0_colour();
// FIXME: Is this the correct behaviour // FIXME: Is this the correct behaviour
let bg_zero_colour = self.monochrome.bg_palette.i0_colour(); let rgba_opt = self.fifo.back.pop_front().map(|bg_info| {
let bg_shade = if bg_enabled { bg_info.shade } else { i0_colour };
let maybe_rgba = match self.fifo.obj.pop_front() {
self.fifo Some(obj_info) => match (obj_info.shade, obj_info.priority) {
.back (Some(obj_shade), BackgroundAndWindow) => match bg_info.shade {
.pop_front() GrayShade::White => obj_shade.into_rgba(),
.map(|bg_info| match self.fifo.obj.pop_front() { _ => bg_shade.into_rgba(),
Some(obj_info) => match obj_info.shade {
Some(obj_shade) => match obj_info.priority {
RenderPriority::BackgroundAndWindow => match bg_info.shade {
GrayShade::White => obj_shade.into_rgba(),
_ if bg_enabled => bg_info.shade.into_rgba(),
_ => bg_zero_colour.into_rgba(),
},
RenderPriority::Object => obj_shade.into_rgba(),
},
None if bg_enabled => bg_info.shade.into_rgba(),
None => bg_zero_colour.into_rgba(),
}, },
None if bg_enabled => bg_info.shade.into_rgba(), (Some(obj_shade), Object) => obj_shade.into_rgba(),
None => bg_zero_colour.into_rgba(), (None, _) => bg_shade.into_rgba(),
}); },
None => bg_shade.into_rgba(),
}
});
if let Some(rgba) = maybe_rgba.as_ref() { if let Some(rgba) = rgba_opt.as_ref() {
let y = self.pos.line_y as usize; let y = self.pos.line_y as usize;
let x = self.x_pos as usize; let x = self.x_pos as usize;