This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

MMC3 IRQs and SEI and CLI instructions

MMC3 IRQs and SEI and CLI instructions
by on (#31095)
I was just now having my ass kicked by the MMC3, I couldn't get it to fire a single IRQ, no matter what I tried.

Out of desperation, I tried something that fixed the thing: I enabled interrupts (with the CLI instruction) before entering the main loop that is interrupted by the NMI that sets the IRQ.

I was now hoping that someone could explain to me what just happened here... Every single game I looked at had a CLI instruction after the setting up of the IRQ (the writes to $C000, $C001 and $E001). In my startup routine, I have a SEI instruction, and I wasn't messing with the I flag anymore until the CLI that comes after setting up the IRQ. That wasn't working.

It only worked when I removed that CLI and placed it outside of the NMI routine, before the NMI routine runs for the first time.

Now, I really can't imagine why this is happening, can anyone help me out please?

by on (#31096)
Quote:
It only worked when I removed that CLI and placed it outside of the NMI routine, before the NMI routine runs for the first time.

You are aware that RTI restores the status flags (including I) to what it was before NMI was entered, right? I'm guessing that's your problem.

by on (#31100)
Duh! Yeah, you are probably right!

Well, CLI is completely useless inside the NMI then. I'd be better off manipulating the value in the stack then...