-
Notifications
You must be signed in to change notification settings - Fork 4
Writing Graphics
This section makes a lot more sense if you understand some basics about the PPU and PPU registers. I HIGHLY recommend digging to the PPU section of the nesdev wiki, and specifically the PPU Registers section, before trying to follow all of this.
Writing background tiles to the screen happens at the beginning of every frame. In order to tell the game to render background tiles, you can use one or more PPU instructions in the the $700-$7FF
RAM space. The instruction format is as follows:
Byte(s) | Description | Notes |
---|---|---|
1 | Sets the value of PPU_CONTROL for the instruction | |
2 | PPU_ADDRESS to which to write bytes (high byte) | Every other address in the game is stored as little endian, meaning the low byte is first. These instructions are big endian, meaning the high byte is first. |
3 | PPU_ADDRESS to which to write bytes (low byte) | |
4 - N | Byte(s) to write to PPU_DATA | "Bytes" here refers to the tile id referred to in the PPU viewer. You can write any number of consecutive bytes to PPU_DATA here, and the PPU_ADDRESS pointer will be incremented by 1 on every write. |
N + 1 | The byte 0xFF is written to indicate the end of a PPU instruction. |
In addition, one final step is necessary to actually execute the instructions. CV2 requires that the length of all PPU instructions you intend to execute is stored at $22
. Without this value set, no instructions will be executed.
As an example, if we wanted to write to the PPU address 0x2030
a holy water icon followed by the string of characters BSAC
, the instruction would look like this:
00 20 30 58 02 13 01 03 FF
| | | | | | | | |
| | | | | | | | +- end of instruction
| | | | | | | +---- tile id for "C" character
| | | | | | +------- tile id for "A" character
| | | | | +---------- tile id for "S" character
| | | | +------------- tile id for "B" character
| | | +---------------- tile id for holy water icon
| | +------------------- low byte of PPU_ADDRESS
| +---------------------- high byte of PPU_ADDRESS
+------------------------- PPU_CONTROL value
And to complete the instruction, the value 9
would be written to $22
, to indicate that there are 9 bytes of PPU instructions to be processed on the next frame.
Join the CV2R crew in the Discord to discuss game play, races, and development of CV2R!