NOP interrupt polling

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

User avatar
koitsu
Posts: 4217
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: NOP interrupt polling

Post by koitsu » Fri Sep 07, 2018 11:30 pm

rainwarrior wrote:If you read status from $2002 on the same cycle that the NMI hits, the NMI flag is cleared before the interrupt happens and it's "cancelled", and the read also returns a 0 for vblank status.

It's the reason why you can't really use a bit $2002 polling loop to time a frame, it will only reliably wait "at least" one frame, but if you're unlucky it'll be more.
Oh, that. Yes, the age-old thing that I used to do in my own (old) code because I assumed the NES did it like the SNES. :/ Anyway, I didn't know that's what "the NMI cancelling reading" referred to. Makes sense now. Thank you! :-)

JonteP
Posts: 10
Joined: Tue Aug 14, 2018 5:32 am

Re: NOP interrupt polling

Post by JonteP » Sat Sep 08, 2018 1:57 am

Code: Select all

; A taken non-page-crossing branch ignores IRQ during
; its last clock, so that next instruction executes
; before the IRQ. Other instructions would execute the
; NMI before the next instruction.
koitsu wrote:Wow, this is the first I've heard of IRQ and NMI differing in behaviour, particularly tied to specific opcodes (re: how the underlying opcodes are implemented in silicon). Yikes.
I just assumed that mixing of IRQ and NMI in Blargg's source comment was a typo. I treat them the same in the branch opcodes anyway.

User avatar
Zepper
Formerly Fx3
Posts: 3192
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: NOP interrupt polling

Post by Zepper » Sun Sep 09, 2018 7:07 am

JonteP wrote:I just assumed that mixing of IRQ and NMI in Blargg's source comment was a typo. I treat them the same in the branch opcodes anyway.
No, it wasn't. Did you read the entire test source code? Here's the FULL description...

Code: Select all

; A taken non-page-crossing branch ignores IRQ during
; its last clock, so that next instruction executes
; before the IRQ. Other instructions would execute the
; NMI before the next instruction.
;
; The same occurs for NMI, though that's not tested here.
I suggest you to read the full source of 3-nmi_and_irq - "NMI behavior when it interrupts IRQ vectoring".

Post Reply