diff --git a/CHANGES b/CHANGES index ab86dde0a..04a1e713f 100644 --- a/CHANGES +++ b/CHANGES @@ -11,6 +11,7 @@ Emulation fixes: - GB Audio: Fix channels 1/2 staying muted if restarted after long silence - GB Audio: Fix channel 1 restarting if sweep applies after stop (fixes mgba.io/i/2965) - GB I/O: Read back proper SVBK value after writing 0 (fixes mgba.io/i/2921) + - GB I/O: Fix STAT writing IRQ trigger conditions (fixes mgba.io/i/2501) - GB Serialize: Add missing Pocket Cam state to savestates - GB SIO: Disabling SIO should cancel pending transfers (fixes mgba.io/i/2537) - GB Video: Implement DMG-style sprite ordering diff --git a/src/gb/video.c b/src/gb/video.c index 3991b0d7e..37c1e3650 100644 --- a/src/gb/video.c +++ b/src/gb/video.c @@ -770,7 +770,10 @@ void GBVideoWriteSTAT(struct GBVideo* video, GBRegisterSTAT value) { if (!GBRegisterLCDCIsEnable(video->p->memory.io[GB_REG_LCDC]) || video->p->model >= GB_MODEL_CGB) { return; } - if (!_statIRQAsserted(oldStat) && video->mode < 3) { + // Writing to STAT on a DMG selects all STAT IRQ types for one cycle. + // However, the signal that the mode 2 IRQ relies on is only high for + // one cycle, which we don't handle yet. TODO: Handle it. + if (!_statIRQAsserted(oldStat) && (video->mode < 2 || GBRegisterSTATIsLYC(video->stat))) { // TODO: variable for the IRQ line value? video->p->memory.io[GB_REG_IF] |= (1 << GB_IRQ_LCDSTAT); GBUpdateIRQs(video->p);