- Drawing background tiles
- Drawing sprites
- Scrolling the screen up/down, left/right and moving those sprites around.
- It also does some audio stuff that frankly baffles me and I refuse to talk about...
So how does this all work on a big picture level?
- The CPU works out what sprites it wants to draw and what properties those sprites have (X/Y coordinates etc).
- The CPU works out what tiles it wants to draw and what properties those tiles have (X/Y coordinates etc).
- The CPU works out various miscellanous stuff (like where it wants to scroll the screen to).
- All this information is written to the Picture Processing Unit (PPU).
- The PPU uses this to draw a single frame. While it is drawing, the CPU starts to work out everything it wants for the next frame.
- Once the PPU is done drawing, it sends a flag to the CPU that it is ready to recieve the next frame.
- Once the CPU is done, it sends the next frame of data to the PPU.
- Repeat for every frame.
- The one wrinkle in all this is that the CPU starts working things out WHILE the PPU is drawing a frame and MUST send all its data over before the next frame starts drawing, or terrible things happen.
To zoom in slightly on a couple of things (though this isn't actually needed at this point):
- Sprite data is written into the PPU's OAM (Object Attribute Memory). There is a hard limit of 64 8x8 pixel sprites here that cannot be extended. The data sent over includes their X/Y coordinates, whether you want to flip them horizontally or vertically, and what colour palette you want to use
This is a representation of the OAM in the Legend of Zelda. Zelda actually uses 8x16 sprites, which lets it get a little more out of that 64 sprite limit, but the principle is the same.
- Tiles are written to a nametable. Nametables are complicated...
- The NES has enough VRAM to store two screens of level at any given time, each screen taking up one nametable. Buuuuut, it actually has 4 nametables. The end result of this is that it lets the NES scroll its levels. Imagine that two screen's worth of your level are plonked adjacent to each other in two nametables. The camera is like a window into this that you can move around those two screens. So if you're really clever, you can replace bits of level ahead and behind you as you go, giving the impression of a scrolling level. The same thing can be done if you stack your level vertically to scroll up and down.
This is all 4 nametables. Note there are only 2 unique screens and the other 2 are mirrors.
Next time: hopefully a basic loop!