back

Lecture 3 (01.30.21) - Palettes and Pixel Data

Recorded Lecture

Finish These Before You Leave

  • Edit a palette somewhere in the game.
  • Change a sprite somewhere in the game.
  • Create a IPS Patch with LIPS.
  • Send your patch in the Discord with a short description of what you changed.

Palettes

The Problem

In computers, colors are stored as 3 byte RGB values. However, the NES cannot not store each pixel as its full 3 byte color value. The pictures would take up WAY too much data.

For context, all of SMB1 takes up 40,976 bytes. In the entire game, 31,488 sprite pixels are stored, which would take up 231% of the game's entire data... We need a form of compression.

Solution 1

One method is just to limit the amount of colors. The NES actually limits itself to just 60 colors, instead of the 16,777,216 that computers today use.

NES Colors

This brings down the number of bytes used to 31,488. But this is still 77% of the game’s capacity used.

Solution 2

Another way to limit each picture to only 3 colors, and then store which colors are used as a palette. This is a technique called paletting And this is the strategy NES game developers used.

Toad Palette

This brings down our number of bytes used to 7,872, or just 19% of the game’s capacity used. Much better!

Sprites

We break down these 3-color images into chunks of 8 × 8 pixels called sprites. Sprites can be combined to create meta sprites.

Mario Sprite

A sprite stores each pixel with 2 bits, and a row of pixels with 2 bytes. Since there are 8 rows, each sprite takes up 16 bytes.

Sprite Pixels

Example of How NES Game Developers Use Sprites

FCEUX PPU Viewer

The FCEUX PPU viewer lists each of the palettes and sprites that are currently loaded. Use this to find the value of a palette.

FCEUX PPU Viewer

Search for this palette value in Gold Finger and edit it to your new desired palette.

GF Palette

Using Tile Layer Pro

Tile Layer Pro is a hex editor, similar to Gold Finger, except it displays colors instead of hex values.

TLP Sprites

TLP is very nice because it lets you open multiple NES ROM files and you can click and drag a sprite from one file into another file. You can use this to edit a sprite in the game.