MMC3 IRQs and SEI and CLI instructions

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

MMC3 IRQs and SEI and CLI instructions

Post by tokumaru »

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?
User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

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.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

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...
Post Reply