How to change an assigned palette for another one?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
andypalido
Posts: 2
Joined: Fri Apr 16, 2021 12:16 pm

How to change an assigned palette for another one?

Post by andypalido »

Hello, my name is andy, im new in this foro.

I've been working in a hack rom and I'm having trouble with the color palettes

I have read that sprites have a structure that can be seen using the OAM Viewer of the FCEUX or Mesen emulators. I read that this structure consists of y pos, tile index, attributes and x pos.

I understand that the assigned palette is found in these attributes but I'm not sure how to change it. In the OAM viewer I found the values but i cannot modify it to test because it is constantly refreshed. I want to find it in the rom file using hex editor but i don’t know how to find it there. I try putting “?” Replacing X pos and Y pos values who are variables.

Specifically, the problem I am having is trying to hack the Kunio kun no nekketsu soccer league game, in which I want to make the white of the eyes not be the same as the white of the uniform.

Thank you very much for the help and sorry for my bad English (my native language is Spanish)
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How to change an assigned palette for another one?

Post by tokumaru »

andypalido wrote: Fri Apr 16, 2021 7:16 pmIn the OAM viewer I found the values but i cannot modify it to test because it is constantly refreshed.
The OAM is the final destination for those values, so if you change it there (using debugging tools) the game code will immediately overwrite your changes. You need to find the source for these values, and change it there. How this information is organized in the ROM varies from grame to game, and you'll have to use the emulator's breakpoint feature to find out where the sprite attributes are coming from. A breakpoint is a condition that causes the emulator to stop, so you can look at what the program is doing step by step. Search online to see how to use breakpoints in the emulator you're using.

NES games don't write to the OAM directly, they first write all the OAM data to a page (256-byte block) in RAM, and then tell the system to copy those 256 bytes to the OAM. This is done by writing the page number to register $4014. The first thing you have to do is set up a breakpoint for writes to address $4014. Once the emulator pauses, look at the value that's being written and that will tell you the RAM page where the game prepares the OAM data (i.e. if the game is writing $02 to $4014, then the OAM buffer is at memory addresses $0200-$02ff). Nearly all NES games use page 2 ($0200-$02ff) for this.

Next you have to set up a breakpoint for writes to the address of one of the attribute bytes in that memory page. For example, if the OAM buffer is in page 2, then addresses $0202, $0206, $020a, $020e, $0212, (...), $02fe will all contain attribute bytes. Set a breakpoint for writes to one of these addresses and wait for the emulator to pause. Then you're gonna have to look at the disassembly and try to figure out what the program is doing. Look at the instructions that were executed before the one that triggered the breakpoint, and see if the source of the attribute value is obvious. If not, step through the program from that point on and see if you can find out where the next attribute byte (for the next sprite) is coming from.

If the attribute bytes are coming from RAM, then you're gonna have to set a breakpoint for THAT address, and you're gonna have to keep tracing the origins of the palette bits until you find the original ROM location where they come from, and that's what you'll have to modify in order to make the change permanent.
I want to make the white of the eyes not be the same as the white of the uniform.
Keep in mind that the palette bits in the sprite attributes merely select which of the 4 sprite palettes each sprite uses, you can't select or modify individual colors that way.

EDIT: Looking at screens from the game, I can't tell how the palettes are set up, but since different teams have uniforms of different colors, it is possible that each player's body uses a different palette from their head, so you may be able to assign a different palette for the body of players in white uniform.
andypalido
Posts: 2
Joined: Fri Apr 16, 2021 12:16 pm

Re: How to change an assigned palette for another one?

Post by andypalido »

tokumaru wrote: Fri Apr 16, 2021 8:28 pm You need to find the source for these values, and change it there. How this information is organized in the ROM varies from grame to game, and you'll have to use the emulator's breakpoint feature to find out where the sprite attributes are coming from. A breakpoint is a condition that causes the emulator to stop, so you can look at what the program is doing step by step. Search online to see how to use breakpoints in the emulator you're using.
Thank you very much Tokumaru for your answer. This is very helpful to me.
I will read about the breakpoints and the debugging tool to be able to do what you suggest.
tokumaru wrote: Fri Apr 16, 2021 8:28 pm EDIT: Looking at screens from the game, I can't tell how the palettes are set up, but since different teams have uniforms of different colors, it is possible that each player's body uses a different palette from their head, so you may be able to assign a different palette for the body of players in white uniform.
That's right, in this game there are other teams that use a different color palette for the eyes than for the uniform. In vs mode of 2 players, for example you can see how the teams of player 1 have a white uniform, however the teams of player 2 use uniforms of a color other than the color of the eyes. I attach a screenshot:

Image

I made a note of the YYTTAAXX values and found them in the debug tool so I think I'm close to solving it thanks to your help. I just need to read a bit of the breakpoints and see how to edit this in the rom file:

Image

Thank you tokumaru :D
Post Reply