From fd7bd8e755c60c57b5d6db1d2deecac7f705eb90 Mon Sep 17 00:00:00 2001 From: StarlitGhost <36834781+StarlitGhost@users.noreply.github.com> Date: Tue, 5 Nov 2019 03:03:10 +0000 Subject: [PATCH] [LCD] fix scanline increment and y-flipped sprite alignment --- src/gameboy/lcd.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/gameboy/lcd.rs b/src/gameboy/lcd.rs index 53550a2..4165587 100644 --- a/src/gameboy/lcd.rs +++ b/src/gameboy/lcd.rs @@ -313,17 +313,21 @@ impl LCD { self.scanline_cycle_count = LCD::SCANLINE_CYCLE_TOTAL; match self.lcd_y { - 0..=SCREEN_HEIGHT if self.lcd_y < SCREEN_HEIGHT => self.draw_scanline(), - SCREEN_HEIGHT => ih.set_interrupt(Interrupt::VBlank), + 0..=SCREEN_HEIGHT if self.lcd_y < SCREEN_HEIGHT => { + self.draw_scanline(); + self.lcd_y += 1; + }, + SCREEN_HEIGHT => { + ih.set_interrupt(Interrupt::VBlank); + self.lcd_y += 1; + }, // TODO: pad this out to reduce lag? // (give the emulated cpu more time than // the actual hardware cpu would have had // to process each frame) LCD::VBLANK_HEIGHT => self.lcd_y = 0, - _ => (), + _ => self.lcd_y += 1, } - - self.lcd_y += 1; } pub fn vblank_reached(&mut self) -> bool { @@ -510,7 +514,7 @@ impl LCD { // calculate the line within the sprite that the current LCD line intersects let sprite_line = if sprite.attributes.y_flip() { - y_size - (self.lcd_y + 16 - y_pos) + 7 - (self.lcd_y + 16 - y_pos) } else { self.lcd_y + 16 - y_pos };