Friday, February 28, 2014

NES Character Sets

A character set, also known as a tile set or pattern table, is simply a collection of 256 8x8 tiles which are used to build the display. There is no built-in character set for the NES so at least one needs to be provided. Without using any memory managers (a complex subject that will be covered when developing the map games) the NES supports 2 character sets. One for building the game screen with and optionally a second set for sprites.

There are a number of tools available for the creation of NES character sets, with YY-Chr being the tool that I currently am using. There are others available and the format for character sets is simple enough that it would be fairly easy to create your own tool for editing or converting images into character sets. As some of the tools I am creating for editing map data is similar to what would be needed, I may develop a very simple character set editor myself. It is also possible that the cartridge contains RAM for the character set in which case you can manipulate the character set in code.

Each character is 16 bytes with with the 256 characters in consecutive order. In other words, the first 16 bytes are for the first character (index 0), the next 16 bytes are for the second character (index 1), and so on. As characters make use of a 4-color palette, two bits are needed for each pixel. This is where things can be confusing as instead of putting the bits together, they are stored as separate bit-planes. Bit-planes store color information by combining separate proper bitmaps to form the color as shown in the following image.



The image shows the high bit first followed by the low bit, which is the opposite order that the NES expects the planes to be stored. The first 8 bytes represent the low-order bits with the next 8 bytes being the high-order bits.

Now that we know how graphics are stored, we need to create a character set for use in the trivia game that we are ultimately going to make. That will be covered next.

No comments: