The PPU draws 262 lines of 341 dots on an NTSC console, one pixel per dot. It does not read a finished picture from memory. On every dot it either fetches a byte or shifts bits out of registers that earlier fetches filled. This page lists what happens on which dot. The scroll registers it uses are on scrolling internals, the sprite side is on sprite evaluation, and the register bits are on PPU registers.
The picture and the border
- The picture region is 256 × 240 pixels. Around it is a border of 16 pixels on the left, 11 on the right and 2 below (283 × 242 in all).
- The background fills the whole picture. Sprites are small and can sit nearly anywhere on it.
- The border, and every transparent pixel, shows the palette entry chosen by the PPU’s EXT input. On a stock console the EXT pins are grounded, so that is entry 0: the colour at
$3F00, the “backdrop”. - The border is affected by the emphasis and greyscale bits of PPUMASK. The first border pixel on the left is drawn with greyscale on.
- PAL PPUs render like NTSC ones except for the border: it is always black, 1 pixel into the top and 2 pixels into the left and right edges, and emphasis and greyscale do not touch it. The sprite 0 hit is not changed by it.
How a fetch works
The PPU shares its low eight address pins with the data bus. Each memory fetch therefore takes two dots. On the first, the whole 14-bit address goes out and the low 8 bits are stored in an external latch (the ALE signal). On the second, the PPU outputs only the upper 6 bits, the latch supplies the low 8, and the byte is read on the low pins. For a read of $2001 that returns $AB the pins show $2001 and then $20AB.
With rendering on, the address bus carries what the sections below describe. With rendering off, or in vblank, it carries the current value of v.
Background pixels
On dots 321 to 336 and 1 to 256 of lines 0 to 239 and 261 the PPU fetches background data. Every 8 dots it makes four fetches, using v to form the addresses:
- the tile number from the nametable;
- the attribute byte from the attribute table;
- the low bit plane of the tile’s pattern;
- the high bit plane, 8 bytes above the low one.
The fetched bytes wait in internal latches. On the 8th dot, the same dot on which coarse X of v is incremented, they are moved into the registers that make pixels:
- The pattern bytes go into the high 8 bits of two 16-bit shift registers.
- Only 2 bits of the attribute byte are moved. Coarse X bit 1 and coarse Y bit 1 select them. They go into two 1-bit latches that feed two 8-bit shift registers. One attribute is enough for all 8 pixels of a tile, so each tile is forced to a single palette.
- On every dot the fine X register picks one bit from each of the four registers, giving a 4-bit background pixel (2 bits of pattern, 2 bits of palette), and the registers shift.
Because the first two tiles of each line are loaded on the previous line, the first tile fetched on a visible line is tile 3. The shifters reload on dots 9, 17, 25 and so on up to 257.
Choosing between background and sprite
The background pixel and the 4-bit pixel from the sprite units meet at a priority multiplexer. A pixel is transparent when its low two bits are 0.
| Background pixel | Sprite pixel | Sprite priority bit | Output |
|---|---|---|---|
| 0 | 0 | any | EXT input (the backdrop, $3F00) |
| 0 | 1 to 3 | any | sprite |
| 1 to 3 | 0 | any | background |
| 1 to 3 | 1 to 3 | 0 (in front) | sprite |
| 1 to 3 | 1 to 3 | 1 (behind) | background |
- The result is a 5-bit value: the top bit says whether the background (0) or a sprite (1) won. It indexes palette RAM, and the colour read can then be changed by emphasis and greyscale.
- Among sprites, the lower OAM index wins, and that choice is made before background priority is looked at. So a sprite behind the background can hide a lower-priority sprite that is in front, and the background then seems to be in front of that sprite (the “sprite priority quirk”).
- If EXT output is enabled, the PPU puts the low 4 bits of the selected pixel on the EXT pins, and the EXT input then always reads 0. The pins are grounded on every known console, so output mode risks damage and is never used.
Odd details of the pipeline
- A read uses the latched low 8 bits and the current high 6 bits. If rendering is switched on or off mid-fetch, the two halves can come from different addresses, giving an address the PPU never put out.
- The two 16-bit pattern shift registers shift in a constant (1 for the high plane, 0 for the low plane). It is normally overwritten every 8 dots. Switching rendering on mid-frame can allow more than 8 shifts and so show the constants.
- The storage and shift registers decay to 0 over about two frames, which can be seen when rendering is turned on mid-frame. Registers that hold inverted data give a 1 when they decay.
With rendering off
- Both the picture and the border show only the EXT input (the backdrop).
- When the low 14 bits of
vpoint into palette RAM ($3F00to$3FFF) the PPU draws the colour at that address instead of the backdrop. This is the “backdrop override”. Some programs use it on purpose. - Emphasis and greyscale still apply.
- On the RP2C02G and RP2C02H, which allow CPU reads of palette RAM, the automatic greyscale on the first border pixel is cancelled if a CPU palette read happens at exactly the same time.
Line by line (NTSC)
Line numbers are those of the PPU’s internal counter. Dendy PPUs have 51 post-render lines instead of 1. PAL PPUs have 70 vblank lines instead of 20 and run 3.2 PPU dots per CPU cycle (106.5625 CPU cycles a line).
| Line | What happens |
|---|---|
| 261 (also called -1): pre-render | No pixels are drawn, but all the fetches of a normal line are made, using the current v and whatever is in secondary OAM. Vertical bits are copied from t to v on dots 280 to 304 when rendering is on. On odd frames, with rendering on, the last dot is skipped: the PPU jumps from (339, 261) to (0, 0). |
| 0 to 239: visible | The picture is drawn. See the dot table below. |
| 240: post-render | Idle. The PPU memory could be used safely here, but the vblank flag is not set yet. |
| 241 to 260: vblank | The vblank flag is set on dot 1 of line 241, and the NMI is raised then if enabled. The PPU makes no memory accesses, so the program may use PPU memory freely. |
The odd-frame skip compensates for the way the PPU makes its video signal and gives a sharper still picture. Keeping rendering off until after the pre-render line gives a dot-crawl pattern like that of interlaced video.
Dot by dot on a visible line
| Dots | What happens |
|---|---|
| 0 | Idle. The address bus seems to hold the CHR address used for the low background tile byte that is fetched from dot 5. |
| 1 to 256 | Background fetches (four per tile, two dots each), the shifters reload on dots 9, 17, …, 257. Sprite evaluation for the next line runs alongside (see sprite evaluation). The sprite 0 hit acts as if the image starts at dot 2, the first shift, so that is the earliest the flag can be raised. The first pixel actually leaves on dot 4 because of pipelining. Coarse X is incremented every 8 dots; Y is incremented on dot 256. |
| 257 to 320 | Sprite fetches for the next line: 8 sprites of 8 dots each, four fetches per sprite (garbage nametable, garbage nametable, pattern low, pattern high). Empty slots fetch tile $FF and are then made transparent. The sprite attribute byte is loaded on the first tick of the second garbage fetch and the X position on the second tick. Horizontal bits are copied from t to v on dot 257. |
| 321 to 336 | The first two background tiles of the next line are fetched (four fetches each) and loaded. |
| 337 to 340 | Two nametable fetches, both of the byte that will be fetched first on the next line (tile 3). Their purpose is unknown. The MMC5 mapper uses this run of three equal nametable fetches to count scanlines. |
The first garbage nametable fetch of the sprite phase has a mixed address: its low 8 bits show both increments of v made on dot 256, and its upper 6 bits are already the reloaded ones. The other garbage fetches use the same address as the first nametable fetch of the next line. The wiki gives a full frame diagram; it is a picture and is not copied here.
Sources
The NESdev Wiki text is available under CC BY-SA 3.0. This page is written in our own words from the raw wikitext kept in samples/nes/sources/hardware.