nesdev.com
http://forums.nesdev.com/

Does reading 2002 one tick after VBL really suppress NMI?
http://forums.nesdev.com/viewtopic.php?f=3&t=16809
Page 1 of 1

Author:  fred [ Sun Dec 10, 2017 7:49 am ]
Post subject:  Does reading 2002 one tick after VBL really suppress NMI?

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:
Quote:
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:
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:
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 7 times

Author:  Dwedit [ Sun Dec 10, 2017 10:52 am ]
Post subject:  Re: Does reading 2002 one tick after VBL really suppress NMI

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.

Author:  fred [ Sun Dec 10, 2017 11:49 am ]
Post subject:  Re: Does reading 2002 one tick after VBL really suppress NMI

Quote:
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?

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/