Backgrounds - Falmouth-Games-Academy/comp310-wiki GitHub Wiki

The Picture Processing Unit (PPU) was capable of rendering a background that could be scrolled in both the X and Y direction, one pixel at a time. The backgrounds which were used for an NES emulator1(https://medium.com/@fogleman/i-made-an-nes-emulator-here-s-what-i-learned-about-the-original-nintendo-2e078c9b28fe) were made up of 8x8 tiles (256x240 pixels) spread over a 32x30 tile screen (totalling 61,440 pixels).

The backgrounds of a NES game are made up of 4 different components that are all combined to see the image on the background. Since it is split up into 4 separate parts it is more memory efficient and allows it to be easily changed when needed 2(http://www.dustmop.io/blog/2015/04/28/nes-graphics-part-1/).

CHR

The CHR is an area of read-only memory which stores the pixel art itself. The pixel art is usually 8x8 tiles and is a maximum of 16 bytes per square. The pixels can all be individually coloured but only transparent, or 1 of 3 colours 3(https://n3s.io/index.php?title=How_It_Works). characters can be made up of multiple 8x8 tiles 3(https://n3s.io/index.php?title=How_It_Works). The CHR can store 256 background tiles which consist of 8x8 pixel tiles 4(http://nesdev.com/NESTechFAQ.htm).

On a NES background at any one time you can have a maximum of 13 different colours with a further 12 for sprites 4(http://nesdev.com/NESTechFAQ.htm), this makes it harder as you are very limited with what you can do for colours.

CHR Representation[2]

Above is how the CHR is represented, each square is usually replicated due to memory constraints. Since each pixel takes 2 bits per pixel to store, this means that due to there being 960 tiles on screen you can only have up to 256 different pixels which cause tiles to be repeated 3.75 times 2(http://www.dustmop.io/blog/2015/04/28/nes-graphics-part-1/).

Nametable

The nametable is what assigns a CHR tile in a 2x2 square on the screen 4(http://nesdev.com/NESTechFAQ.htm)[5](/Falmouth-Games-Academy/comp310-wiki/wiki/5)(https://wiki.nesdev.com/w/index.php/PPU_nametables). One screen full of background tiles is called a nametable 11(https://taywee.github.io/NerdyNights/nerdynights/backgrounds.html). The 8x8 tiles have 4 addresses, the first one is at $2000 and occupies the top left of the screen, the next is $2400 which is the top right, $2800 is bottom left and $2C00 is the bottom right 5(https://wiki.nesdev.com/w/index.php/PPU_nametables).

Horizontal Mirroring Example[6]

Mirroring is how the 8x8 tiles are laid out on the screen 3(https://n3s.io/index.php?title=How_It_Works). There are 4 examples of mirroring, vertical, horizontal, 4-screen and single screen. However 4-way and single screen mirroring need additional V-Ram 3(https://n3s.io/index.php?title=How_It_Works). Vertical mirroring is when the 2 nametables on either the left or right side are the same (AB & AB), horizontal is the same but instead either the top or bottom (AA & BB). Single screen is where they are all the same and 4-screen is where they are all different 6(https://wiki.nesdev.com/w/index.php/Mirroring).

Attribute Table

Using the tiles which have been referenced using the nametable; the attribute table is used to select which colour is applied to the tiles NES Attribute Table [8]

This image displays how a sprite's colours can be changed using an attribute table. For example, in this image, if the value in memory is written as '11100110' then third colour palette of the list would be selected and the sprite would use a mix of blue, grey and turqoise. It is important to note that each tile can only support up to 4 colours 11(https://taywee.github.io/NerdyNights/nerdynights/backgrounds.html).

Due to the nametable working in 8x8 squares of pixel tiles and the attribute table working in 16x16 squares of pixel tiles there can sometimes be palette glitching when moving diagonally. This effect can be seen in Super Marios 3 and Kirby's adventure [9]. The result of this palette gitching is sprites and certain parts of the background being incorrectly coloured using different colours from the palette.

Palette

The NES allows you to use a total of 64 colours overall, at one time however you are limited (see above). The colours can be listed out in decimal form, hexadecimal form or hexadecimal comma separated 7(http://www.thealmightyguru.com/Games/Hacking/Wiki/index.php/NES_Palette). An example of decimal colour would be 124,124,124 each number represents the RGB value, hexadecimal is #7C7C7C and hexadecimal comma separated is the same as hexadecimal but separated with commas (in the name) 7C, 7C, 7C.

Full NES Colour Palette[7]

As you can see the colour palette is very limited, there are lots of blues, greens and far too many blacks. There doesn't seem to be a yellow at all more of a greeny yellow.

There are always eight palettes loaded at all times. These are split into four palettes for backgrounds and four palettes for sprites. Each of the palettes is made up of four colors and the first color of each palette will be a typical transparent or background color. In the case of background palettes, the first color will be a color that all the background palettes have in common. This is usually black or a dominant color in your background image. In the case of sprites the first color will will act as a transparent color as it is not rendered in the game [10].

Colour palettes <- More in depth of colour palettes

References


Discussion

Article about creating NES backgrounds
NES Batman Parallax scrolling example