From 778e04e645c4797c1826eb7d6cba0a37463f3b48 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Thu, 3 Jun 2021 02:16:03 -0500 Subject: [PATCH] feat(ppu): account for OBJ ENABLE bit in LCDC --- src/ppu.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/ppu.rs b/src/ppu.rs index c2f80e6..2fae0aa 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -373,6 +373,7 @@ impl Ppu { // Handle Background Pixel and Sprite FIFO let bg_enabled = self.control.bg_win_enabled(); + let obj_enabled = self.control.obj_enabled(); let i0_colour = self.monochrome.bg_palette.i0_colour(); // FIXME: Is this the correct behaviour @@ -380,14 +381,20 @@ impl Ppu { let bg_shade = if bg_enabled { bg_info.shade } else { i0_colour }; match self.fifo.obj.pop_front() { - Some(obj_info) => match (obj_info.shade, obj_info.priority) { - (Some(obj_shade), BackgroundAndWindow) => match bg_info.shade { - GrayShade::White => obj_shade.into_rgba(), - _ => bg_shade.into_rgba(), - }, - (Some(obj_shade), Object) => obj_shade.into_rgba(), - (None, _) => bg_shade.into_rgba(), - }, + Some(obj_info) => { + if obj_enabled { + match (obj_info.shade, obj_info.priority) { + (Some(obj_shade), BackgroundAndWindow) => match bg_info.shade { + GrayShade::White => obj_shade.into_rgba(), + _ => bg_shade.into_rgba(), + }, + (Some(obj_shade), Object) => obj_shade.into_rgba(), + (None, _) => bg_shade.into_rgba(), + } + } else { + bg_shade.into_rgba() + } + } None => bg_shade.into_rgba(), } });