From ebad7a380b74808e41b022e1c6c53ce863d04d8a Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Wed, 23 Aug 2023 14:35:16 -0700 Subject: [PATCH] GB I/O: Fix STAT writing IRQ trigger conditions (fixes #2501) --- CHANGES | 1 + src/gb/video.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index ce8aa3625..7fb5e9ede 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,7 @@ 0.10.4: (Future) Emulation fixes: - GB Audio: Fix audio envelope timing resetting too often (fixes mgba.io/i/3164) + - GB I/O: Fix STAT writing IRQ trigger conditions (fixes mgba.io/i/2501) - GBA GPIO: Fix gyro read-out start (fixes mgba.io/i/3141) - GBA SIO: Fix MULTI mode SIOCNT bit 7 writes on secondary GBAs (fixes mgba.io/i/3110) Other fixes: 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);