From f9ff88302f3de521a0f71ffbe8d15d9bfd9d0c8c Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 3 Mar 2019 12:46:46 -0800 Subject: [PATCH] GB Video: Delay LYC STAT check (fixes #1331) --- CHANGES | 1 + src/gb/video.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 4e9653d92..e79ec1691 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,7 @@ Bugfixes: - GBA BIOS: Fix multiboot entry point (fixes Magic Floor) - Qt: More app metadata fixes - Qt: Fix load recent from archive (fixes mgba.io/i/1325) + - GB Video: Delay LYC STAT check (fixes mgba.io/i/1331) Misc: - GBA Savedata: EEPROM performance fixes - GBA Savedata: Automatically map 1Mbit Flash files as 1Mbit Flash diff --git a/src/gb/video.c b/src/gb/video.c index d63460088..8aa978292 100644 --- a/src/gb/video.c +++ b/src/gb/video.c @@ -224,7 +224,6 @@ void _endMode0(struct mTiming* timing, void* context, uint32_t cyclesLate) { ++video->ly; video->p->memory.io[REG_LY] = video->ly; GBRegisterSTAT oldStat = video->stat; - video->stat = GBRegisterSTATSetLYC(video->stat, lyc == video->ly); if (video->ly < GB_VIDEO_VERTICAL_PIXELS) { next = GB_VIDEO_MODE_2_LENGTH; video->mode = 2; @@ -246,6 +245,14 @@ void _endMode0(struct mTiming* timing, void* context, uint32_t cyclesLate) { if (!_statIRQAsserted(video, oldStat) && _statIRQAsserted(video, video->stat)) { video->p->memory.io[REG_IF] |= (1 << GB_IRQ_LCDSTAT); } + + // LYC stat is delayed 1 T-cycle + oldStat = video->stat; + video->stat = GBRegisterSTATSetLYC(video->stat, lyc == video->ly); + if (!_statIRQAsserted(video, oldStat) && _statIRQAsserted(video, video->stat)) { + video->p->memory.io[REG_IF] |= (1 << GB_IRQ_LCDSTAT); + } + GBUpdateIRQs(video->p); video->p->memory.io[REG_STAT] = video->stat; mTimingSchedule(timing, &video->modeEvent, (next << video->p->doubleSpeed) - cyclesLate);