Palette Modifications of an NES file using a Hex Editor
Palette Modifications of an NES file using a Hex Editor
Version 1.8
by aStROcReEp 2000
NOTICE: all thanks go out to Zelan at the ROM Hack page for his original documentation on this process...this text file here was written merely to help him better explain things to his page's visitors, but I have decided to release it here also, since his page is no more (thanks to all the whining cry babies who couldn't keep their mouths shut about how he should run HIS OWN DAMN PAGE...)
Welcome all! Yes, the same person who brought you the "Dummy guide to NES emulation and using the NESticle emulator", as well as "Hacking Your Way to Super Stardom with NESticle", is now bringing you a text file on how to modify a specific game's palette! Why do you want to do this, you say? Because every game has a pre-set amount of colors it uses, and often times once you've hacked a game, some of these colors don't match what the effect you want for what you're trying to do! Color conflicts in hacking happens often, more so than you might think if your graphic editing is heavy and frequent. Also, graphics that have been cut and pasted from different games use totally different palettes and cause the new game to look odd (as in Metroid Mario). So it always helps to be able to change colors.
First of all, you need a Hex Editor program. I suggest Hexposure, which can be found at my Hacker's Guide page at the following URL :
http://www.dragonfire.net/~ac2k/nes/hackguid.htm
Go to the utilities section and download and extract the program to a directory somewhere on your hard drive or create a new one. The reason for using Hexposure is that you can create a table file and assign certain ASCII characters to hex values.
Now that you're ready with your hex editor, here is where things get rough. Open up your NESticle emulator and load the ROM into play. Get to a point where you can see the sprite you want to modify. You may want to pause the game (either the Start Button or Alt+P). Make sure you know exactly which color of the sprite it is you wish to change as well. Click on Settings from the menu bar, then click on Palette. Or, just press F4, either way. NESticle should bring up a rectangular window, 2 rows by 16 columns. Each box in this window represents a color the game uses for certain sprites, etc. Yes, there will be multiples of many different colors. Some sprites even share colors. Don't worry about that. Just look at your window and try to imagine it as being 8 sets of 2x2 rectangles. In example, this is what the palette looks like and what each box means :
_______________________________________________
0|1 |2 |3 |4 |5 |6 |7 |8 |9 |A |B |C |D |E |F |
_|__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|
0|1 |2 |3 |4 |5 |6 |7 |8 |9 |A |B |C |D |E |F |
_|__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|
The top row is *USUALLY* background colors, the bottom row - usually sprite colors.
Now you need to prepare your table file. Get out pen & paper, and for each square in the palette table you should click on the color with the mouse button and write down the number that appears on the new window that will open. The window will be titled "Sprite Color X" or "BG Color X" according to it's place in the above table. But where you need to be looking at is the number located on the colored square itself, NOT the number in the window's title. As you are writing your numbers you should do it in a fashion so as to make yourself a chart similar to the one above, only using 2-digit hex values instead of "0 1 2 3 4 5 6 7 8 9 A B C D E F".
As an example, let's look at how SMB1's pattern table looks after jotting it down in the manner above. If you are doing things correctly it would like like so :
_______________________________________________
22|29|0A|0F|22|36|17|0F|22|30|21|0F|22|27|17|0F|
_ |__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|
22|16|27|18|22|1A|30|27|22|16|30|27|22|0F|36|17|
_ |__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|
Now that you have all this written down, you are almost ready to go and create your table file for Hexposure. One thing remains - you must create your own scheme by which to recognize colors. With your pen/paper, write down an equivalent description of each of the colors that go with the 2 digit hex value. For example, 22 would be Sky Blue, 0F is Black, etc. Now the hard part : devise a scheme for abbreviating each color. Why is this hard? It needs to be a one-character abbreviation. One letter or number or character ONLY. Black could be B, for example, and Blue - U...Grey as G, or something to that effect. This is important as you will see in the future.
Now to actually CREATE your table file. You probably should download my default table file at http://www.dragonfire.net/~ac2k/nes/default.zip Extract it to the same directory as Hexposure and make a copy of it, renaming it as palette.tbl. Editing this specific file will make it easiest to single out hex that is ONLY related to color. To edit the file, open it up in Notepad (or DOS Edit command in DOS) or Wordpad. Scroll through the file, and for each 2 digit hex number you see - check to see if it matches with one of the ones you wrote down. If so, make a blank space underneath that particular line and make documentation of the color name that goes with that value. To do this, just use the new line underneath and type ; followed by the color name. This is important because Hexposure can not recognize strings of text for replacing ONE thing. It's like putting a 2 dimensional variable in a 1 dimension array.
What you should now is write down the one letter abbreviation for the color in place of the period that goes with the same line as the hex value. In case you're lost at this point, I'll give an example (using SMB1). Let's say you opened up your palette.tbl file in Notepad and found the 0F fairly quick. As you should recognize from what you wrote down, 0F is Black and B is a good abbreviation for it. So make a line under 0F and write ;Black on this new line. This will help you remember what colors go with what abbreviations when you look at the ROM in Hexposure. On the same line as the 0F, however, replace the . by B, the ACTUAL abbreviation.
Repeat this process for each color/value/abbreviation you wrote down earlier. Save the table file but DO NOT quit your program unless you're in DOS and have no choice. Now get Hexposure open and highlight the name of the ROM you want to edit. When it loads, press F6 and give it the name of the table file you created. In our example it was palette.tbl. You should see the hex data reload for the far right colum and find nothing but .'s and letters
and numbers correspond to the abbreviations you made earlier. Scroll down through the ROM until you come to a block of these letters/numbers that seems to replicate what you wrote down earlier. This means a whole line of the same letter probably has nothing to do with the palette but a line of continuous alternating letters (NO SPACES or .'s) probably DOES represent the palette. For example, BWGRBROY would most likely be palette data (Black White Green Red Black Red Orange Yellow) but GGGGGGGGGG probably isn't palette data but just spaces in the ROM that happen to have the same hex values as one of your colors.
Now test yourself. Say you wanted to replace the Black from our SMB example with a red color. Press TAB to move the cursor to the far right column, highlight the letter B, and write and R overtop of it (assuming R is the abbreviation for Red). Use F5 to save your progress and quit the program to test the ROM in NESticle to see if you made the right changes. If so, you've successfully found the palette in the ROM and can go back to Hexposure, making other changes to it as necessary.
Now, you should be done !!! If you ever have any questions or problems concerning the procedure explained in this document, ALWAYS feel free to e-mail me at jason1@ipa.net WITH A COMPLETE, DETAILED, ELABORATE description of the problem. I'll do whatever I can to help :) It's especially good to let me know what game you're modifying and what you're trying to modify, I may be able to do it in my own time and get back to you. Also, feel free to distribute this document fully and freely to any and all persons who might need it, just make sure you do not change it in any manner unless credit is thrown in both mine AND Zelan's direction (for his original document). Last, but not least, if you think you can do a better job of explaining it - GO FOR IT. AND LET ME KNOW. Thank you for reading this document and don't let those demon voices in your head take control.