Skip to content

Commit fd7bd8e

Browse files
StarlitGhostStarlitGhost
authored andcommitted
[LCD] fix scanline increment and y-flipped sprite alignment
1 parent e5f51e6 commit fd7bd8e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/gameboy/lcd.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,21 @@ impl LCD {
313313

314314
self.scanline_cycle_count = LCD::SCANLINE_CYCLE_TOTAL;
315315
match self.lcd_y {
316-
0..=SCREEN_HEIGHT if self.lcd_y < SCREEN_HEIGHT => self.draw_scanline(),
317-
SCREEN_HEIGHT => ih.set_interrupt(Interrupt::VBlank),
316+
0..=SCREEN_HEIGHT if self.lcd_y < SCREEN_HEIGHT => {
317+
self.draw_scanline();
318+
self.lcd_y += 1;
319+
},
320+
SCREEN_HEIGHT => {
321+
ih.set_interrupt(Interrupt::VBlank);
322+
self.lcd_y += 1;
323+
},
318324
// TODO: pad this out to reduce lag?
319325
// (give the emulated cpu more time than
320326
// the actual hardware cpu would have had
321327
// to process each frame)
322328
LCD::VBLANK_HEIGHT => self.lcd_y = 0,
323-
_ => (),
329+
_ => self.lcd_y += 1,
324330
}
325-
326-
self.lcd_y += 1;
327331
}
328332

329333
pub fn vblank_reached(&mut self) -> bool {
@@ -510,7 +514,7 @@ impl LCD {
510514

511515
// calculate the line within the sprite that the current LCD line intersects
512516
let sprite_line = if sprite.attributes.y_flip() {
513-
y_size - (self.lcd_y + 16 - y_pos)
517+
7 - (self.lcd_y + 16 - y_pos)
514518
} else {
515519
self.lcd_y + 16 - y_pos
516520
};

0 commit comments

Comments
 (0)