GB Video: Setting LYC=LY during mode 2 should trigger an IRQ
Jeffrey Pfau jeffrey@endrift.com
Tue, 20 Sep 2016 10:44:49 -0700
4 files changed,
15 insertions(+),
1 deletions(-)
M
src/gb/io.c
→
src/gb/io.c
@@ -341,7 +341,6 @@ case REG_JOYP:
case REG_SB: case REG_TIMA: case REG_TMA: - case REG_LYC: // Handled transparently by the registers break; case REG_TAC:@@ -356,6 +355,9 @@ // TODO: handle GBC differences
GBVideoProcessDots(&gb->video); 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);
M
src/gb/video.c
→
src/gb/video.c
@@ -312,6 +312,16 @@ GBUpdateIRQs(video->p);
} } +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) {
M
src/gb/video.h
→
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);