From 6e3567ad162552bb311949a83f2c4392035c8bd7 Mon Sep 17 00:00:00 2001 From: zeromus Date: Thu, 24 Jul 2014 06:25:53 +0000 Subject: [PATCH] apply r7371 from bizhawk to mmc5 IRQ handling to fix metal slader glory credits. this may have impact in other MMC5 programs; not tested --- trunk/src/boards/mmc5.cpp | 33 ++++++++++++++++++++++++++------- trunk/src/ppu.cpp | 8 ++++---- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/trunk/src/boards/mmc5.cpp b/trunk/src/boards/mmc5.cpp index 1a4e870c..a9789c45 100644 --- a/trunk/src/boards/mmc5.cpp +++ b/trunk/src/boards/mmc5.cpp @@ -512,21 +512,40 @@ void MMC5Synco(void) { } void MMC5_hb(int scanline) { - if (scanline == 240) { + //zero 24-jul-2014 - revised for newer understanding, to fix metal slader glory credits. see r7371 in bizhawk + + int sl = scanline + 1; + int ppuon = (PPU[1] & 0x18); + + if (!ppuon || sl >= 241) + { + // whenever rendering is off for any reason (vblank or forced disable + // the irq counter resets, as well as the inframe flag (easily verifiable from software) + MMC5IRQR &= ~0x40; + MMC5IRQR &= ~0x80; MMC5LineCounter = 0; - MMC5IRQR = 0x40; + X6502_IRQEnd(FCEU_IQEXT); return; } - if (MMC5LineCounter < 240) { - if (MMC5LineCounter == IRQScanline) { + + if (!(MMC5IRQR&0x40)) + { + MMC5IRQR |= 0x40; + MMC5IRQR &= ~0x80; + MMC5LineCounter = 0; + X6502_IRQEnd(FCEU_IQEXT); + } + else + { + MMC5LineCounter++; + if (MMC5LineCounter == IRQScanline) + { MMC5IRQR |= 0x80; if (IRQEnable & 0x80) X6502_IRQBegin(FCEU_IQEXT); } - MMC5LineCounter++; } - if (MMC5LineCounter == 240) - MMC5IRQR = 0; + } void MMC5_StateRestore(int version) { diff --git a/trunk/src/ppu.cpp b/trunk/src/ppu.cpp index 168e26fd..13414730 100644 --- a/trunk/src/ppu.cpp +++ b/trunk/src/ppu.cpp @@ -1221,7 +1221,7 @@ static void DoLine(void) { int x; uint8 *target = XBuf + (scanline << 8); - if (MMC5Hack && (ScreenON || SpriteON)) MMC5_hb(scanline); + if (MMC5Hack) MMC5_hb(scanline); X6502_Run(256); EndRL(); @@ -1790,7 +1790,7 @@ int FCEUPPU_Loop(int skip) { DEBUG(FCEUD_UpdatePPUView(scanline, 1)); DoLine(); } - if (MMC5Hack && (ScreenON || SpriteON)) MMC5_hb(scanline); + if (MMC5Hack) MMC5_hb(scanline); for (x = 1, max = 0, maxref = 0; x < 7; x++) { if (deempcnt[x] > max) { max = deempcnt[x]; @@ -2033,7 +2033,7 @@ int FCEUX_PPU_Loop(int skip) { DEBUG(FCEUD_UpdateNTView(scanline = yp, 1)); } - if (sl != 0) if (MMC5Hack && PPUON) MMC5_hb(yp); + if (MMC5Hack) MMC5_hb(yp); //twiddle the oam buffers @@ -2303,7 +2303,7 @@ int FCEUX_PPU_Loop(int skip) { runppu(1); } //scanline loop - if (MMC5Hack && PPUON) MMC5_hb(240); + if (MMC5Hack) MMC5_hb(240); //idle for one line runppu(kLineTime);