Romhacking.net

Romhacking => ROM Hacking Discussion => Topic started by: GlitchyTSP on July 05, 2019, 04:09:48 pm

Title: Super Mario Bros, how to edit Meta-Tile Palette asignment
Post by: GlitchyTSP on July 05, 2019, 04:09:48 pm
Is there a way to edit what Meta-tiles use which palette?

So for as an example (Or rather, what I want to do) I want the cloud Meta-tile to use the ground/brick palette instead of the Cloud palette.
Title: Re: Super Mario Bros, how to edit Meta-Tile Palette asignment
Post by: Cyneprepou4uk on July 05, 2019, 04:35:37 pm
Sure there is a way. Find out why cloud uses cloud palette and change it to brick palette
Title: Re: Super Mario Bros, how to edit Meta-Tile Palette asignment
Post by: GlitchyTSP on July 05, 2019, 04:46:19 pm
Sure there is a way. Find out why cloud uses cloud palette and change it to brick palette

The things is...I don't know how to "Find out why cloud uses cloud palette"
If I did, I probably wouldn't have asked here.
Title: Re: Super Mario Bros, how to edit Meta-Tile Palette asignment
Post by: Cyneprepou4uk on July 05, 2019, 04:49:36 pm
Do you know how palette works for background?
Also do you know how to debug?
Title: Re: Super Mario Bros, how to edit Meta-Tile Palette asignment
Post by: GlitchyTSP on July 05, 2019, 04:59:05 pm
Do you know how palette works for background?
Also do you know how to debug?

Nope, I really don't know how to debug, especially in a NES game.

as for the background, I have a somewhat limited knowledge on how it works.
Title: Re: Super Mario Bros, how to edit Meta-Tile Palette asignment
Post by: Cyneprepou4uk on July 05, 2019, 05:05:20 pm
First you should read this article https://wiki.nesdev.com/w/index.php/PPU_attribute_tables

Then use fceux emulator. Open hex editor, and ppu memory in it. Load a level, make a save, change some bytes to find where cloud palette is. Then add a write breakpoint to it before this byte is loaded here, and look for code in debugger to find out where this byte was read from. That is a basic way to find something you want
Title: Re: Super Mario Bros, how to edit Meta-Tile Palette asignment
Post by: Psyklax on July 07, 2019, 06:20:42 am
I just had a look myself, and it's not as simple as you would hope. Let's reverse engineer and see what I mean.

We start with what we know: the first byte in the PPU RAM that we're interested in is at $23CC. It's A0, which is 1010 0000 in binary. This means the bottom left and right tiles use palette 2 while the top left and right use palette 0. Changing A0 to 50 (0101 0000) would make them use palette 1 instead (the brick palette). The question is, where did the game get this A0, and how do we change it to 50?

I set a write breakpoint for $23CC and see that it comes from $3B5 in RAM, where I can see 23 CC 01 A0. Having worked on early Nintendo games before, I know what this means: start at $23CC, write 1 byte, here it is. Now we need to know how THAT got into RAM. Set a write breakpoint for $3B5 and start again from the lives screen.

This is where it gets tricky. This section of RAM is repeatedly used for doing the PPU writing, so I get numerous breakpoint hits. After clicking through some of the ones I can see that I don't need, I find one where we get 23 CC 01 A0 at that point, and here it's easier to do a trace log file to see everything that led to this point, so I do that and start working backwards.

So the A0 actually comes from $3F9, not far away, so let's see where that came from... well, by going back further, I can see that originally it had 20, not A0, and it became A0 through an OR against the value at $0003 which is 80. I know this all sounds like gibberish at this point, but bear with me. :D My guess is the 20 refers to the palette of one of the four tiles (being palette 2), and the OR is because it must combine with the palette of another tile to produce one byte with both palettes. Hmm...

At this point my brain is melting and I'm having trouble following what's going on. I've exhausted my abilities here, and reading the SMB disassembly isn't helping me much. Maybe someone else wants to pick up where I left off? :(
Title: Re: Super Mario Bros, how to edit Meta-Tile Palette asignment
Post by: GlitchyTSP on July 07, 2019, 07:36:08 am
I just had a look myself, and it's not as simple as you would hope. Let's reverse engineer and see what I mean.

We start with what we know: the first byte in the PPU RAM that we're interested in is at $23CC. It's A0, which is 1010 0000 in binary. This means the bottom left and right tiles use palette 2 while the top left and right use palette 0. Changing A0 to 50 (0101 0000) would make them use palette 1 instead (the brick palette). The question is, where did the game get this A0, and how do we change it to 50?

I set a write breakpoint for $23CC and see that it comes from $3B5 in RAM, where I can see 23 CC 01 A0. Having worked on early Nintendo games before, I know what this means: start at $23CC, write 1 byte, here it is. Now we need to know how THAT got into RAM. Set a write breakpoint for $3B5 and start again from the lives screen.

This is where it gets tricky. This section of RAM is repeatedly used for doing the PPU writing, so I get numerous breakpoint hits. After clicking through some of the ones I can see that I don't need, I find one where we get 23 CC 01 A0 at that point, and here it's easier to do a trace log file to see everything that led to this point, so I do that and start working backwards.

So the A0 actually comes from $3F9, not far away, so let's see where that came from... well, by going back further, I can see that originally it had 20, not A0, and it became A0 through an OR against the value at $0003 which is 80. I know this all sounds like gibberish at this point, but bear with me. :D My guess is the 20 refers to the palette of one of the four tiles (being palette 2), and the OR is because it must combine with the palette of another tile to produce one byte with both palettes. Hmm...

At this point my brain is melting and I'm having trouble following what's going on. I've exhausted my abilities here, and reading the SMB disassembly isn't helping me much. Maybe someone else wants to pick up where I left off? :(

I got help from someone far more skilled them me to help me out, that you for your efforts though.
Title: Re: Super Mario Bros, how to edit Meta-Tile Palette asignment
Post by: 4l3j4ndr0 on August 02, 2019, 09:23:24 pm
@GlitchyTSP Can you please put the answer here to be able to learn about it and help to others.