News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: NES: Palette Swap  (Read 4803 times)

f0

  • Jr. Member
  • **
  • Posts: 7
    • View Profile
NES: Palette Swap
« on: January 11, 2012, 11:43:15 pm »
Hi everyone.

I'm working on my second hack, which is a complete graphical overhauling of NES game Chaos World.

I got covered a good part of the bitmaps hacking already but I'm starting to think that this time I won't be able to get around the original 4 colors set palette assignation, which is gonna lead to Chaos (no pun intended).

In more detail, I need some of the new tiles to use a different 4 colors set instead of editing the currently assigned ones. I'm not thinking about creating a new 4 colors set, but swapping it with an existing one.

Could someone please, point me in the right direction?
« Last Edit: January 12, 2012, 12:07:33 am by f0 »

snarfblam

  • Submission Reviewer
  • Hero Member
  • *****
  • Posts: 589
  • CANT HACK METROID
    • View Profile
    • snarfblam
Re: NES: Palette Swap
« Reply #1 on: January 12, 2012, 08:41:07 am »
So... you are trying to make some graphics in the game use a different palette that is already defined in the game? How this is done varies from game to game since they are all programmed differently and store data differently. Definitely hard to say without more info. Do you want to load a different palette into the PPU, or do you want the graphics to use a different palette that is already loaded? What are the tiles used for? Background graphics?

f0

  • Jr. Member
  • **
  • Posts: 7
    • View Profile
Re: NES: Palette Swap
« Reply #2 on: January 12, 2012, 03:51:39 pm »
So... you are trying to make some graphics in the game use a different palette that is already defined in the game? How this is done varies from game to game since they are all programmed differently and store data differently. Definitely hard to say without more info. Do you want to load a different palette into the PPU, or do you want the graphics to use a different palette that is already loaded? What are the tiles used for? Background graphics?

Your answer makes me think this is not gonna be a single case nor its gonna be straight forward. Since I'm not entirely sure about what you mean, I'll try to answer by explaining myself better:

The in-game Menu Screen where you see your party avatars and their stats

As you can see in the image above the new tiles (right) still use the same palettes as the old ones (left), If I just change the colors in the palettes that look bad, I'm gonna mess with everything else that uses those palettes and look good. That's why I need to swap some palettes. The flesh in some of the new tiles is now white, I'd like to reuse the palette where a bright orange is in its place; the hair in Enak's avatar is blue in the lower left tile, I'd like to re-use the palette where it's green, and so on.
« Last Edit: January 12, 2012, 08:50:06 pm by f0 »

snarfblam

  • Submission Reviewer
  • Hero Member
  • *****
  • Posts: 589
  • CANT HACK METROID
    • View Profile
    • snarfblam
Re: NES: Palette Swap
« Reply #3 on: January 12, 2012, 06:18:44 pm »
That definitely helps. It looks like you want to change it so that, for example, the graphics are shown with palette #1 instead of palette #3. I looked into the game and those graphics are drawn as sprites. In order to change which palette they use, you'll want to modify OAM (object attribute memory) data. If you're unfamiliar with OAM, you should probably read up on it. The NESDev OAM article looks pretty decent. It's the data that defines the tiles and locations of each sprite.

The OAM format is four bytes per sprite: YY TT AA XX, where YY = sprite y position, XX = sprite X position, TT = tile number, and AA = attribute data. It's AA that you're concerned about because this byte specifies which palette the sprite uses.

If you pause and use a memory viewer, you'll see that OAM is written in RAM at $200. The nice thing about this situation is that the sprites stay in one place (in most games, each sprite moves to a different memory location each frame). If you go ahead and start changing sprite memory, you'll notice that every time you change a byte, one 8x16 tile on the screen flickers for a single frame. (On the next frame, the game re-writes the sprite data and fixes what you've changed.) This lets you easily figure out which memory is for which sprites. I kept messing with them until I found the sprites for the characters on the screen.

Once you've found the memory for the sprite you want to modify, you can search the ROM for that data, and then change it. For example, the sprite I wanted to change had the data: 28 20 03 28   28 22 03 30   28 24 03 38   28 26 03 40   38 28 01 28   38 2A 01 30   38 2C 01 38   38 2E 01 40 (eight 8x16 sprites gives you your 32x32 graphic).

When the data is stored in the ROM, the x and y values are usually stored as relative values, which means it will be different in the ROM than it is in RAM. If you search the ROM for "28 20 03 28 28 22 03 30" you wont find anything. You can do a wildcard search and omit the x and y values: "28 20 03 28 28 22 03 30" becomes "? 20 03 ? ? 22 03 ?". That search lead me straight to the sprite data I was searching for. Once you find it, you can change the attribute byte of each four-byte entry to use a different palette.

« Last Edit: January 13, 2012, 07:53:36 pm by snarfblam »

f0

  • Jr. Member
  • **
  • Posts: 7
    • View Profile
NES OAM
« Reply #4 on: January 12, 2012, 08:54:49 pm »
Thank you so much @snarfblam. You have opened a whole new set of possibilities, I really appreciate this.

Edit: These avatars were discarded currently
« Last Edit: January 19, 2012, 02:40:42 am by f0 »

Sephirous

  • Sr. Member
  • ****
  • Posts: 414
    • View Profile
Re: NES: Palette Swap
« Reply #5 on: November 25, 2016, 10:26:58 pm »
Hey,

I am currently dealing with the same situation.

Castlevania III, I want to separate Dracula's Second Form from the Candles Palette and use a different set.
So when you change Dracula's Sprite Colors you don't end up with crazy colored Candles.

I am going to read that article posted above but for the moment this is not clicking in my brain just yet. :thumbsup: