From 47af523921dab40e68259f7e58bc535474630b5a Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 16 Nov 2017 01:50:38 -0500 Subject: clear bg_pixel when it is not rendering --- src/ppu.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/ppu.rs b/src/ppu.rs index c5b4aec..54dbc0b 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -488,9 +488,10 @@ impl<'a> PPU<'a> { self.cycle = cycle + 1; return false; } + let rendering = self.get_show_bg() || self.get_show_sp(); let visible_line = self.scanline < 240; let pre_line = self.scanline == 261; - if (pre_line || visible_line) && (self.get_show_bg() || self.get_show_sp()) { + if (pre_line || visible_line) && rendering { if pre_line && 279 < cycle && cycle < 305 { self.reset_y(); } else { @@ -534,14 +535,17 @@ impl<'a> PPU<'a> { self.bg_pixel = 0; } } - } else if self.scanline == 241 && cycle == 1 { - if !self.early_read { - self.ppustatus |= PPU::FLAG_VBLANK; + } else { + if !rendering { self.bg_pixel = 0 } + if self.scanline == 241 && cycle == 1 { + if !self.early_read { + self.ppustatus |= PPU::FLAG_VBLANK; + } + self.scr.render(); + self.cycle += 1; + self.early_read = false; + return !self.early_read && self.get_flag_nmi(); /* trigger cpu's NMI */ } - self.scr.render(); - self.cycle += 1; - self.early_read = false; - return !self.early_read && self.get_flag_nmi(); /* trigger cpu's NMI */ } self.cycle += 1; if self.cycle > 340 { -- cgit v1.2.3-70-g09d2