From 1cb054ec67ea7b1e7e9162c1e74bd4ab254efb74 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Tue, 20 Sep 2016 10:44:49 -0700 Subject: [PATCH] GB Video: Setting LYC=LY during mode 2 should trigger an IRQ --- CHANGES | 1 + src/gb/io.c | 4 +++- src/gb/video.c | 10 ++++++++++ src/gb/video.h | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 0c9f725a0..ab16b7e59 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,7 @@ 0.6.0: (Future) Bugfixes: - GB MBC: Fix MBC7 when size is incorrectly specified + - GB Video: Setting LYC=LY during mode 2 should trigger an IRQ Misc: - All: Only update version info if needed diff --git a/src/gb/io.c b/src/gb/io.c index e09a33173..6b799913a 100644 --- a/src/gb/io.c +++ b/src/gb/io.c @@ -341,7 +341,6 @@ void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) { case REG_SB: case REG_TIMA: case REG_TMA: - case REG_LYC: // Handled transparently by the registers break; case REG_TAC: @@ -357,6 +356,9 @@ void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) { value = gb->video.renderer->writeVideoRegister(gb->video.renderer, address, value); GBVideoWriteLCDC(&gb->video, value); break; + case REG_LYC: + GBVideoWriteLYC(&gb->video, value); + break; case REG_DMA: GBMemoryDMA(gb, value << 8); break; diff --git a/src/gb/video.c b/src/gb/video.c index 45031311c..b2b2408e4 100644 --- a/src/gb/video.c +++ b/src/gb/video.c @@ -312,6 +312,16 @@ void GBVideoWriteSTAT(struct GBVideo* video, GBRegisterSTAT value) { } } +void GBVideoWriteLYC(struct GBVideo* video, uint8_t value) { + if (video->mode == 2) { + video->stat = GBRegisterSTATSetLYC(video->stat, value == video->ly); + if (GBRegisterSTATIsLYCIRQ(video->stat) && value == video->ly) { + video->p->memory.io[REG_IF] |= (1 << GB_IRQ_LCDSTAT); + GBUpdateIRQs(video->p); + } + } +} + void GBVideoWritePalette(struct GBVideo* video, uint16_t address, uint8_t value) { static const uint16_t dmgPalette[4] = { 0x7FFF, 0x56B5, 0x294A, 0x0000}; if (video->p->model < GB_MODEL_CGB) { diff --git a/src/gb/video.h b/src/gb/video.h index 05f84c913..b8a3e73d1 100644 --- a/src/gb/video.h +++ b/src/gb/video.h @@ -135,6 +135,7 @@ void GBVideoProcessDots(struct GBVideo* video); void GBVideoWriteLCDC(struct GBVideo* video, GBRegisterLCDC value); void GBVideoWriteSTAT(struct GBVideo* video, GBRegisterSTAT value); +void GBVideoWriteLYC(struct GBVideo* video, uint8_t value); void GBVideoWritePalette(struct GBVideo* video, uint16_t address, uint8_t value); void GBVideoSwitchBank(struct GBVideo* video, uint8_t value);