SCHG How-to

Edit palettes using hex

From Sonic Retro

(Original guide by Scarred Sun)

For those of you familiar with designing websites, a hex representation of colors is used when picking out colors for your background, text, etc. For instance, since I'm using the Vector skin here, one of the main colors is #136548.

This is a hexadecimal representation of the RGB value 19, 101, 72.

RGB values go from 0 (0% color) to 255 (100% color) for each of the three values. A quick bit of math tells us there's about 16 million different colors that can be represented in RGB format.

How many colors does the Sega Genesis have? 512 colors (1536 when shadowing and highlighting are included). And that's not all--as a general rule, you can only use 61 colors at any one time.

Palettes give us each of these 61 colors. In the main Sonic series, we have 4 palette lines. When in-game, the first palette line is what we use to represent Sonic, and the last three are for each level. The first value in this palette line is always transparent and not used. There's some other lines--such as cycles and shades--but we're going to ignore those for now.

For instance, here's the palette line for Sonic and Tails in Sonic 2:

Sontails palette.png

The color outlined in white is the "transparent" color and the last fifteen are used to color Sonic and Tails.

Now, just like hex values are used to represent colors when writing HTML, hex colors are also used to represent palette colors for the Sega Genesis. Remember, though, that we only have 512 colors. Therefore, when noting RGB values, we use:

0, 2, 4, 6, 8, A, C, E

to represent each value, with 0 being 0% color and E being 100% color. Using math, we can figure out that gives us 512 combinations. Compared to RGB, each value represents

0, 32, 64, 96, 128, 160, 192, 224.

When writing colors for the palette, we actually go BACKWARDS—blank (always represented as 0), B, G, R.

So, if you wanted to write the website color #a0e080 (RGB value 160, 224, 128), we'd call that value 08EA. The zero is a blank formality, and 8=160, E=224, A=128 as seen above.

With that value in mind, let's edit the Sonic and Tails palette line to include it. Using the Palettes Section of the Sonic 2 community hacking guide, we see that the palette line for Sonic and Tails is located at $29E2. Let's open up our hex editor and go to that offset.

Hex palette.png

For our values, we see

00 00 00 00 0A 22 0C 42 0E 44 0E 66 0E EE

Etc. etc.

Let's take these values, then, and group them into sets of two.

00 00 | 00 00 | 0A 22 | 0C 42 | 0E 44 | 0E 66 | 0E EE

If you convert these colors back to RGB, you'll see these are the first seven colors shown above! So, if we change 0C 42 to 08 EA (which we converted earlier), save, and open the ROM, we'll get the following result:

Sonic paletteexample.png

And that's how palettes were edited until palette editors came along (and the world rejoiced, then mourned when it got a bunch of crappy palette hacks). When you use a palette editor, all you are doing is using a graphical frontend to change around these values.

Now, obviously, this would be a rather exhaustive way to edit palettes (it was!), so as far as editors go, I HIGHLY recommend HivePal--it'll list the offsets and hex values for each color in addition to the ability to switch colors more easily.