HackMew
December 1st, 2007, 10:21 AM
HackMew's Knowledge
A comprehensive guide to everything I know regarding Advance hacking
All right, this is the place I'm going to post all my documents and tutorials. Before saying anything else, I'd like to tell you this thread shouldn't be used for nothing but readers' feedback, criticisms or suggestions. Therefore, for any questions, feel free to ask in the Simple Questions (http://pkmncommunity.com/showthread.php?t=79614) thread instead. If it wasn't answered yet, of course.
Anyway, this thread is still a work in progress so remembercheck often for updates ;)
Documents - Table of Contents
[alink id="palette"]GBA Palette Format: What is and how is stored a color palette?[/alink id]
Tutorials - Table of Contents
[alink id="APE1"]Palette Editing with APE: Part 1 - Searching and Replacing an uncompressed palette[/alink id]
[A ID]palette[/A ID][DOC] GBA Palette Format
What is and how is stored a color palette? v1.0
From Wikipedia (http://en.wikipedia.org/wiki/Palette_%28computing%29)
A palette, in computer graphics, is a designated subset of the total range of colors supported by a particular image. Each color in the palette is assigned an index, and for each pixel one of these indices is stored to determine the color of the pixel.
Palettes into RAM
Palettes are divided into two types: background and object ones. Background palettes are stored in the range of addresses 05000000-050001FF. As you can see they use a total of 0x200 bytes which is in decimal 512. Therefore this range of memory can have up to 256 colors.
Object palettes are really close to the background ones except their address which is 05000200-050003FF.
Each background and object palette into RAM may be either split into 16 palettes with 16 colors each, or may be used as a single palette with 256 colors.
Color Definitions
GBA supports up to 32768 colors (0x8000). Each color occupies two bytes. Since the the cubic root of 32768 is 32, each color level (Red, Green and Blue) has 32 possible variations, from 0 to 31. Colors go from 0x0000 to 0x7FFF, where the first represent the black color and the latter the white one.
Transparent Colors
Color 0 of all background and object palettes is treated as transparent. Since palettes can have either 16 or 256 colors, only 15 and 255 colors respectively are actually visible.
Backdrop Color
Color 0 of the background palette 0 is used as backdrop color. That means this color is displayed if an area of the screen is not covered by any non-transparent background or object dots.
Palette into ROM
Palette are stored into the ROM following the Little Endian ordering. This means the first and the second byte of each colors are swapped. For example, the white color (0x7FFF) would be found as FF7F.
Palettes are usually stored uncompressed but you could find them compressed as well.
Here's the structure of a 16 color palette, uncompressed:
[Color1 Byte2 Color1 Byte1] [Color2 Byte2 Color2 Byte1] [Color3 Byte2 Color3 Byte1] [Color4 Byte2 Color4 Byte1] [Color5 Byte2 Color5 Byte1] [Color6 Byte2 Color6 Byte1] [Color7 Byte2 Color7 Byte1] [Color8 Byte2 Color8 Byte1] [Color9 Byte2 Color9 Byte1] [Color10 Byte2 Color10 Byte1] [Color11 Byte2 Color11 Byte1] [Color12 Byte2 Color12 Byte1] [Color13 Byte2 Color13 Byte1] [Color14 Byte2 Color14 Byte1] [Color15 Byte2 Color15 Byte1]
Example:
[00 00] [F7 47] [50 33] [47 1A] [67 09] [8E 31] [E8 18] [1F 7C] [71 5F] [1F 3B] [1D 36] [D8 20] [94 63] [2E 53] [C8 46] [83 36]
As I said palette can also be compressed, LZ77 compressed in particular. The main difference is that LZ77 compressed palette have an appropriate header before the actual "color part". This "color part" doesn't follow a strict structure since it depends on the number of colors and on the LZ77 compression too. I will provide a common LZ77 compressed 16 color palette:
[LZ77 Header - 5 bytes] [Color0 Byte2 Color0 Byte1] [Color1 Byte2 Color1 Byte1] [Color2 Byte2 Color2 Byte1] [Color3 Byte2 Color3 Byte1] [00] [Color4 Byte2 Color4 Byte1] [Color5 Byte2 Color5 Byte1] [Color6 Byte2 Color6 Byte1] [Color7 Byte2 Color7 Byte1] [00] [Color8 Byte2 Color8 Byte1] [Color9 Byte2 Color9 Byte1] [Color10 Byte2 Color10 Byte1] [Color11 Byte2 Color11 Byte1] [00] [Color12 Byte2 Color12 Byte1] [Color13 Byte2 Color13 Byte1] [Color14 Byte2 Color14 Byte1] [Color15 Byte2 Color15 Byte1]
Example:
[10 20 00 00 00] [39 57] [FF 7F] [0C 5E] [48 45] [00] [05 31] [A3 28] [3C 37] [00] [76 2A] [91 11] [7F 03] [7F 02] [00] [9F 01] [1D 00] [31 46] [42 08]
[COLOR="gray"]Parts of this document were freely inspired by the GBATEK specifications (http://www.work.de/nocash/gbatek.htm).
This tutorial is Copyright © 2007 by HackMew.
You are [B]not allowed to copy, modify or distribute it without permission.
[A ID]APE1[/A ID][TUT] Palette Editing with APE
Part 1 - Searching and Replacing an uncompressed palette v1.0
Requirements: VisualBoyAdvance v1.7.2 or later, latest APE, some ROMs to edit.
For this tutorial we're going to use a FireRed US v1.0 ROM. Anyway, keep in mind the tutorial is fully compatible with any other Advance ROMs.
Let's say we want to replace the color of the trees in order to make them snowy.
First of all, open APE and load your favourite ROM. Run VBA and load the same ROM. Load a savegame or start a new game, as you like. Once you're in some areas outside the first city (or hany other city/route which has some trees), open the Palette Viewer (Tools -> Palette viewer).
[css-div="width: 818px; padding: 5px 5px 5px 5px; border: solid 1px dimgray; background-color: #FFFFFF;"]http://www.geekimages.com/pics/20070814/APE1_1.png
Figure 1. Opening the Palette Viewer.[/css-div]
Once there, save the background palette by pressing the Save BG button. You can save the palette either using the Paintshop format or the Adobe Color Table one. Avoid using the Microsoft Palette format (selected by default) since it wouldn't be loaded by APE.
[css-div="width:569px; padding: 5px 5px 5px 5px; border: solid 1px dimgray; background-color: #FFFFFF;"]http://www.geekimages.com/pics/20070814/APE1_2.png
Figure 2. Saving the background palette.[/css-div]
Close VBA and return to APE, choose the Search Palette option and import the palette you've just saved into the Actual Palette. (Edit -> Actual Palette -> Import - or just click the image button on the right side)
[css-div="width:540px; padding: 5px 5px 5px 5px; border: solid 1px dimgray; background-color: #FFFFFF;"]http://www.geekimages.com/pics/20070814/APE1_3.png
Figure 3. Importing the palette into APE.[/css-div]
Now click the Search button. If everything went fine, APE will find the palette and it will display its offset and the colors as well.
[css-div="width:540px; padding: 5px 5px 5px 5px; border: solid 1px dimgray; background-color: #FFFFFF;"]http://www.geekimages.com/pics/20070814/APE1_4.png
Figure 4. Searching the palette with APE.[/css-div]
Copy the Actual Palette to the Changed one (Edit -> Actual Palette -> Copy- or simply using the image buttons). As you can notice the Replace button has just been enabled.
[css-div="width:540px; padding: 5px 5px 5px 5px; border: solid 1px dimgray; background-color: #FFFFFF;"]http://www.geekimages.com/pics/20070814/APE1_5.png
Figure 5. Copying the Actual Palette to the Changed one.[/css-div]
Well, let's edit the palette now! The color we will use are the following:
[css-div="width:540px; padding: 5px 5px 5px 5px; border: solid 1px dimgray; background-color: #FFFFFF;"]http://www.geekimages.com/pics/20070814/APE1_6.png
Figure 6. Replacing the old colors.[/css-div]
Edit the palette showed in the the Changed Palette in order to get the appropriate colors. When you're done, just press the Replace button. Open VBA again and try the ROM you've just edited to see the changes.
But...
[css-div="width:240px; padding: 5px 5px 5px 5px; border: solid 1px dimgray; background-color: #FFFFFF;"]http://www.geekimages.com/pics/20070814/APE1_7.png
Figure 7. What the heck?[/css-div]
the colors are still the same! What the heck happened? There are, in fact, multiple outdoor palettes inside the ROM. Until now we've just edited one of them. All you have to do is to replace the rest of them.
How? Simply search the old palette and while keeping the same Changed Palette hit the Replace button, until you can't find the old palette any more. Close the ROM from VBA and open it again to see the changes.
[css-div="width:240px; padding: 5px 5px 5px 5px; border: solid 1px dimgray; background-color: #FFFFFF;"]http://www.geekimages.com/pics/20070814/APE1_8.png
Figure 8. The final result.[/css-div]
Have fun replacing palettes!
This tutorial is Copyright © 2007 by HackMew.
You are not allowed to copy, modify or distribute it without permission.
A comprehensive guide to everything I know regarding Advance hacking
All right, this is the place I'm going to post all my documents and tutorials. Before saying anything else, I'd like to tell you this thread shouldn't be used for nothing but readers' feedback, criticisms or suggestions. Therefore, for any questions, feel free to ask in the Simple Questions (http://pkmncommunity.com/showthread.php?t=79614) thread instead. If it wasn't answered yet, of course.
Anyway, this thread is still a work in progress so remembercheck often for updates ;)
Documents - Table of Contents
[alink id="palette"]GBA Palette Format: What is and how is stored a color palette?[/alink id]
Tutorials - Table of Contents
[alink id="APE1"]Palette Editing with APE: Part 1 - Searching and Replacing an uncompressed palette[/alink id]
[A ID]palette[/A ID][DOC] GBA Palette Format
What is and how is stored a color palette? v1.0
From Wikipedia (http://en.wikipedia.org/wiki/Palette_%28computing%29)
A palette, in computer graphics, is a designated subset of the total range of colors supported by a particular image. Each color in the palette is assigned an index, and for each pixel one of these indices is stored to determine the color of the pixel.
Palettes into RAM
Palettes are divided into two types: background and object ones. Background palettes are stored in the range of addresses 05000000-050001FF. As you can see they use a total of 0x200 bytes which is in decimal 512. Therefore this range of memory can have up to 256 colors.
Object palettes are really close to the background ones except their address which is 05000200-050003FF.
Each background and object palette into RAM may be either split into 16 palettes with 16 colors each, or may be used as a single palette with 256 colors.
Color Definitions
GBA supports up to 32768 colors (0x8000). Each color occupies two bytes. Since the the cubic root of 32768 is 32, each color level (Red, Green and Blue) has 32 possible variations, from 0 to 31. Colors go from 0x0000 to 0x7FFF, where the first represent the black color and the latter the white one.
Transparent Colors
Color 0 of all background and object palettes is treated as transparent. Since palettes can have either 16 or 256 colors, only 15 and 255 colors respectively are actually visible.
Backdrop Color
Color 0 of the background palette 0 is used as backdrop color. That means this color is displayed if an area of the screen is not covered by any non-transparent background or object dots.
Palette into ROM
Palette are stored into the ROM following the Little Endian ordering. This means the first and the second byte of each colors are swapped. For example, the white color (0x7FFF) would be found as FF7F.
Palettes are usually stored uncompressed but you could find them compressed as well.
Here's the structure of a 16 color palette, uncompressed:
[Color1 Byte2 Color1 Byte1] [Color2 Byte2 Color2 Byte1] [Color3 Byte2 Color3 Byte1] [Color4 Byte2 Color4 Byte1] [Color5 Byte2 Color5 Byte1] [Color6 Byte2 Color6 Byte1] [Color7 Byte2 Color7 Byte1] [Color8 Byte2 Color8 Byte1] [Color9 Byte2 Color9 Byte1] [Color10 Byte2 Color10 Byte1] [Color11 Byte2 Color11 Byte1] [Color12 Byte2 Color12 Byte1] [Color13 Byte2 Color13 Byte1] [Color14 Byte2 Color14 Byte1] [Color15 Byte2 Color15 Byte1]
Example:
[00 00] [F7 47] [50 33] [47 1A] [67 09] [8E 31] [E8 18] [1F 7C] [71 5F] [1F 3B] [1D 36] [D8 20] [94 63] [2E 53] [C8 46] [83 36]
As I said palette can also be compressed, LZ77 compressed in particular. The main difference is that LZ77 compressed palette have an appropriate header before the actual "color part". This "color part" doesn't follow a strict structure since it depends on the number of colors and on the LZ77 compression too. I will provide a common LZ77 compressed 16 color palette:
[LZ77 Header - 5 bytes] [Color0 Byte2 Color0 Byte1] [Color1 Byte2 Color1 Byte1] [Color2 Byte2 Color2 Byte1] [Color3 Byte2 Color3 Byte1] [00] [Color4 Byte2 Color4 Byte1] [Color5 Byte2 Color5 Byte1] [Color6 Byte2 Color6 Byte1] [Color7 Byte2 Color7 Byte1] [00] [Color8 Byte2 Color8 Byte1] [Color9 Byte2 Color9 Byte1] [Color10 Byte2 Color10 Byte1] [Color11 Byte2 Color11 Byte1] [00] [Color12 Byte2 Color12 Byte1] [Color13 Byte2 Color13 Byte1] [Color14 Byte2 Color14 Byte1] [Color15 Byte2 Color15 Byte1]
Example:
[10 20 00 00 00] [39 57] [FF 7F] [0C 5E] [48 45] [00] [05 31] [A3 28] [3C 37] [00] [76 2A] [91 11] [7F 03] [7F 02] [00] [9F 01] [1D 00] [31 46] [42 08]
[COLOR="gray"]Parts of this document were freely inspired by the GBATEK specifications (http://www.work.de/nocash/gbatek.htm).
This tutorial is Copyright © 2007 by HackMew.
You are [B]not allowed to copy, modify or distribute it without permission.
[A ID]APE1[/A ID][TUT] Palette Editing with APE
Part 1 - Searching and Replacing an uncompressed palette v1.0
Requirements: VisualBoyAdvance v1.7.2 or later, latest APE, some ROMs to edit.
For this tutorial we're going to use a FireRed US v1.0 ROM. Anyway, keep in mind the tutorial is fully compatible with any other Advance ROMs.
Let's say we want to replace the color of the trees in order to make them snowy.
First of all, open APE and load your favourite ROM. Run VBA and load the same ROM. Load a savegame or start a new game, as you like. Once you're in some areas outside the first city (or hany other city/route which has some trees), open the Palette Viewer (Tools -> Palette viewer).
[css-div="width: 818px; padding: 5px 5px 5px 5px; border: solid 1px dimgray; background-color: #FFFFFF;"]http://www.geekimages.com/pics/20070814/APE1_1.png
Figure 1. Opening the Palette Viewer.[/css-div]
Once there, save the background palette by pressing the Save BG button. You can save the palette either using the Paintshop format or the Adobe Color Table one. Avoid using the Microsoft Palette format (selected by default) since it wouldn't be loaded by APE.
[css-div="width:569px; padding: 5px 5px 5px 5px; border: solid 1px dimgray; background-color: #FFFFFF;"]http://www.geekimages.com/pics/20070814/APE1_2.png
Figure 2. Saving the background palette.[/css-div]
Close VBA and return to APE, choose the Search Palette option and import the palette you've just saved into the Actual Palette. (Edit -> Actual Palette -> Import - or just click the image button on the right side)
[css-div="width:540px; padding: 5px 5px 5px 5px; border: solid 1px dimgray; background-color: #FFFFFF;"]http://www.geekimages.com/pics/20070814/APE1_3.png
Figure 3. Importing the palette into APE.[/css-div]
Now click the Search button. If everything went fine, APE will find the palette and it will display its offset and the colors as well.
[css-div="width:540px; padding: 5px 5px 5px 5px; border: solid 1px dimgray; background-color: #FFFFFF;"]http://www.geekimages.com/pics/20070814/APE1_4.png
Figure 4. Searching the palette with APE.[/css-div]
Copy the Actual Palette to the Changed one (Edit -> Actual Palette -> Copy- or simply using the image buttons). As you can notice the Replace button has just been enabled.
[css-div="width:540px; padding: 5px 5px 5px 5px; border: solid 1px dimgray; background-color: #FFFFFF;"]http://www.geekimages.com/pics/20070814/APE1_5.png
Figure 5. Copying the Actual Palette to the Changed one.[/css-div]
Well, let's edit the palette now! The color we will use are the following:
[css-div="width:540px; padding: 5px 5px 5px 5px; border: solid 1px dimgray; background-color: #FFFFFF;"]http://www.geekimages.com/pics/20070814/APE1_6.png
Figure 6. Replacing the old colors.[/css-div]
Edit the palette showed in the the Changed Palette in order to get the appropriate colors. When you're done, just press the Replace button. Open VBA again and try the ROM you've just edited to see the changes.
But...
[css-div="width:240px; padding: 5px 5px 5px 5px; border: solid 1px dimgray; background-color: #FFFFFF;"]http://www.geekimages.com/pics/20070814/APE1_7.png
Figure 7. What the heck?[/css-div]
the colors are still the same! What the heck happened? There are, in fact, multiple outdoor palettes inside the ROM. Until now we've just edited one of them. All you have to do is to replace the rest of them.
How? Simply search the old palette and while keeping the same Changed Palette hit the Replace button, until you can't find the old palette any more. Close the ROM from VBA and open it again to see the changes.
[css-div="width:240px; padding: 5px 5px 5px 5px; border: solid 1px dimgray; background-color: #FFFFFF;"]http://www.geekimages.com/pics/20070814/APE1_8.png
Figure 8. The final result.[/css-div]
Have fun replacing palettes!
This tutorial is Copyright © 2007 by HackMew.
You are not allowed to copy, modify or distribute it without permission.