NMI/Vblank timings etc.

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
NMI/Vblank timings etc.
by on (#58532)
This evening I've been looking over my old emulator timings a bit. I've tried a few CPU-test ROMs floating around and I get a few errors.
But the problem is, I don't really know where to start looking for fixing the errors.
I've studied the sourcecode provided with the test-roms but they really don't give much clue on how to fix the error, since the errors aren't really explained in detail.
The information concerning this subject in the wiki is kind of scattered I think and is hard to get a grip on.
I've checked out a few documents but the information sometimes differ from the information in the wiki.
Is there a really good document (=readable by mortals like myself) concerning this subject that I've missed?

I'd love to have some sort of graphical diagram on what happens during a frame on the NES. What flags gets/set cleared etc and on which scanline. All of this represented in one image.
Re: NMI/Vblank timings etc.
by on (#58533)
oRBIT2002 wrote:
I'd love to have some sort of graphical diagram on what happens during a frame on the NES. What flags gets/set cleared etc and on which scanline. All of this represented in one image.


Here's a ghetto ascii diagram which is the best I can come up with by memory in a forum post during my lunch break at work:

Code:
NTSC = 1 "idle" scanline
     + 20 scanlines of VBlank
     + 1 "pre render" scanline
     + 240 rendered scanlines

+---------------------------+
|      1 idle scanline      |
+---------------------------+  <--  $2002.7 goes high here
|                           |
|    20 VBlank scanlines    |
|                           |
+---------------------------+  <--  all $2002 bits are cleared here
|   1 prerender scanline    |        and vblank is officially "over"
+---------------------------+
|                           |
|                           |
|   240 rendered scanlines  |
|                           |
|                           |
+---------------------------+


* Each scanline is 341 "dots" (aka PPU cycles)
    with the exception of the pre-render scanline which is 340 dots
    on odd frames, and only if PPU is enabled.

* dots 0-255 render actual pixels

* sprite 0 hit happens on whatever dot the hit occurs.  So if the hit happens
    on scanline 3 on the 8th pixel (dot 7), the $2002.6 goes high on dot 7 of that
    scanline

* The prerender scanline behaves exactly like the 240 rendered scanlines
   (so it should be considered part of "rendering") except for 3 things:
   1)  no pixels are rendered
   2)  scroll is reset near the end of it
   3)  it is sometimes 340 dots instead of 341 as previously mentioned

* The PPU is inactive during the idle scanline and vblank scanlines.


I left out scrolling stuff because I don't have that quite memorized and can't dig up a reference at work.

Dunno if that's the kind of thing you're looking for either.

by on (#58535)
Thanks! This is excellent work, this is stuff like this I really miss.
Nice, thanks again! :)