From 73dc3560a5e62f40718367d91709fcd7e1c5eb85 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 31 Mar 2018 13:18:02 +0300 Subject: [PATCH] Mode 0 interrupts do not occur in the glitched mode 0 of the first line 0. The extra OAM interrupt bug also affects DMG. --- Core/display.c | 6 ++++-- Core/gb.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Core/display.c b/Core/display.c index cb3c090b..7d0be765 100644 --- a/Core/display.c +++ b/Core/display.c @@ -245,7 +245,7 @@ void GB_STAT_update(GB_gameboy_t *gb) } switch (gb->io_registers[GB_IO_STAT] & 3) { - case 0: gb->stat_interrupt_line = (gb->io_registers[GB_IO_STAT] & 8); break; + case 0: gb->stat_interrupt_line = (gb->io_registers[GB_IO_STAT] & 8) && !gb->is_first_line_mode2; break; case 1: gb->stat_interrupt_line = gb->io_registers[GB_IO_STAT] & 0x10; break; case 2: gb->stat_interrupt_line = gb->io_registers[GB_IO_STAT] & 0x20; break; } @@ -431,6 +431,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) } /* Handle the very first line 0 */ + gb->is_first_line_mode2 = true; gb->current_line = 0; gb->ly_for_comparison = 0; gb->io_registers[GB_IO_STAT] &= ~3; @@ -448,6 +449,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) gb->vram_read_blocked = !gb->is_cgb; gb->oam_write_blocked = true; gb->vram_write_blocked = !gb->is_cgb; + gb->is_first_line_mode2 = false; GB_STAT_update(gb); gb->cycles_for_line += 2; @@ -727,7 +729,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) if (!gb->is_cgb) { gb->ly_for_comparison = -1; } - if (gb->is_cgb && gb->current_line == LINES) { + if (gb->current_line == LINES) { gb->io_registers[GB_IO_STAT] &= ~3; gb->io_registers[GB_IO_STAT] |= 2; GB_STAT_update(gb); diff --git a/Core/gb.h b/Core/gb.h index 897dfb90..599b6b9b 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -429,6 +429,7 @@ struct GB_gameboy_internal_s { uint8_t oam_search_index; uint8_t accessed_oam_row; uint8_t extra_penalty_for_sprite_at_0; + bool is_first_line_mode2; ); /* Unsaved data. This includes all pointers, as well as everything that shouldn't be on a save state */