IRQ and APU

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
IRQ and APU
by on (#147730)
Im counting cpu cycles and in $4017 mode 0 when i reach 14914 * 2 or 14914.5 * 2 or 14915 * 2 CPU cc i set an IrqCollector = 0 flag if irq_inhibit is clear (as the wiki says) signaling that the next time my RunCpu() function find irqCollector == 0 IRQ needs to be served.
The thing that when RunCpu() fires the IRQ Double Dragon, 3D Battles of World Runner, Mario Is Missing, and Mario time machine behaves bad. They don't load propertly. 3D Battles is executing a CLI and thus allowing IRQs. But when it allows them stays in an infinite loop with a JMP Absolute to that same address as if it will be waiting for an interrupt, but never set $2001 to allow an NMI.
When i don't set the IrqCollector = 0 when i reach the cc mentioned above the games runs fine.

Any idea what could be happenning?
Re: IRQ and APU
by on (#147794)
1. In my emulator, the PPU frame starts at VBlank. Try "Time Lord" by playing the first level - if the scorebar is perfect, your APU IRQ is fine too.

2. A taste... check if it helps you.
Code:
      case 29828: //step 4, frameIRQ 1
        if(~reg4017 & 0x80) {
           APU_QUARTER_FRAME();
           APU_HALF_FRAME();
        }
      case 29829: //frameIRQ 2
        if(0 == (reg4017 & 0xC0)) {
           cpu_irqtrigger(TIRQ_FRA);
        } break;

      case 29830: //frameIRQ 3 + reset for mode #0
        if(0 == (reg4017 & 0xC0)) {
           cpu_irqtrigger(TIRQ_FRA);
        }
        if(~reg4017 & 0x80) {
           apuCYC = 0; /* goes 0->1 next */
        } break;
Re: IRQ and APU
by on (#147855)
Thanks Zepper i checked your code against mine and i was manipulating bad the irq flag. Now the games RUN :D