Does reading 2002 one tick after VBL really suppress NMI?

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
fred
Posts: 67
Joined: Fri Dec 30, 2011 7:15 am
Location: Sweden

Does reading 2002 one tick after VBL really suppress NMI?

Post by fred »

I haven't been working on nes stuff for quite a while so my knowledge is super rusty... but here goes anyway.

The wiki says this about VBL / NMI:
Reading one PPU clock before reads it as clear and never sets the flag or generates NMI for that frame. Reading on the same PPU clock or one later reads it as set, clears it, and suppresses the NMI for that frame.
I recently checked through my nes code and remembered that one of my last changes was related to this:

Code: Select all

Before:
uint8_t Ppu::StatusRead() //2002
{
	if(scanlineV == 241 && scanlineH < 3)
	{ //suppress NMI }
	[...]
}

After:
uint8_t Ppu::StatusRead() //2002
{
	if(scanlineV == 241 && scanlineH < 2) //does dot 2 really suppress?
	{ //suppress NMI }
	[...]
}
I was still passing blargg's nmi suppresion test with this. This was based on testing done in visualNES. I'll attach the 4 states i saved, which reads 0x2002 at 4 different ticks near the VBL flag getting set.

Code: Select all

nmiEnabled339 = 339,340,000 nmi happens
nmiEnabled340 = 340,000,001 nmi doesn't happen, flag not set (A=0x20)
nmiEnabled0   = 000,001,002 nmi doesn't happen, flag set     (A=0xA0)
nmiEnabled1   = 001,002,003 nmi happens
Like I said, I haven't been working on nes stuff for a while so I'd rather have someone else tell me if this stuff is faulty, the usual alignment shenanigans, wrong or right or whatever. Haha.
Attachments
nmiSuppress.7z
(4.05 KiB) Downloaded 189 times
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Does reading 2002 one tick after VBL really suppress NMI

Post by Dwedit »

Note that instructions take multiple cycles to complete. Instructions like LDA abs or STA abs are 4 cycles long.
The actual read/write happens as the last cycle ends.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
fred
Posts: 67
Joined: Fri Dec 30, 2011 7:15 am
Location: Sweden

Re: Does reading 2002 one tick after VBL really suppress NMI

Post by fred »

The actual read/write happens as the last cycle ends.
That's one detail I had forgotten. (one of many...)

The numbers in these lines: "339,340,000 nmi happens" are simply the dots when 2002 is on the cpu address bus... I don't actually know the exact boundaries of when a cpu cycle starts and ends, hah.
Still, I can only get visualNES to block NMIs at two dots, not three like the wiki suggests. Or am I reading it wrong?
Post Reply