News: 11 March 2016 - Forum Rules

Author Topic: Selecting which palette a tile uses in a NES title screen?  (Read 2865 times)

RadioTails

  • Sr. Member
  • ****
  • Posts: 391
  • Holding the Mega Drive controller
    • View Profile
Selecting which palette a tile uses in a NES title screen?
« on: February 12, 2013, 03:51:09 pm »
Sorry for the rush topic, but I'm stuck with out internet until the end of the month and using my parents Internet connection.

Basically, I'm editing the Super Mario Bros 2 (US/EU version) title screen for the "Pony Doki Panics" hack.  I know where the data is stored (I'll post offset soon).  The way it lays out the tiles is like so:
X Position, Y Position, Number of Tiles, Tile ID , Tile ID etc

Now I know the data tells the game which palette each tile uses.  But the format is entirely different to the tile position and I can't find much on the subject.

I'll try and upload a screenshot of the problem.
Avatar by LazyNinjartist

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7255
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Selecting which palette a tile uses in a NES title screen?
« Reply #1 on: February 12, 2013, 05:01:52 pm »
Sounds like it's the "attribute table" data your after.
In the NES PPU RAM, the last 64 bytes of each tilemap controls the palettes (23C0-23FF/27C0-27FF/2BC0-2BFF/2FC0-2FFF). Every 2 bits selects the palette (0-3) of a 16x16 pixel (2 tile x 2 tile) region of the screen. So yes, that means every 2 tile x 2 tile square must use the same palette. So 8 bytes will represen a complete 4-tile tall strip of the screen.
Usually the data is uncompressed, so you could try looking at the attribute data in VRAM in the hex editor in FCEUX (for a title screen, it is likely 23C0-23FF) and look for a match in ROM.
"My watch says 30 chickens" Google, 2018

RadioTails

  • Sr. Member
  • ****
  • Posts: 391
  • Holding the Mega Drive controller
    • View Profile
Re: Selecting which palette a tile uses in a NES title screen?
« Reply #2 on: February 14, 2013, 08:12:30 am »
Okay, I found the palette select data, but I can’t get my head around the last bit.

Let’s use this one as an example (makes most of the “2” in the title use an alternative palette).

23 E3 02 88 22

23E2 = PPU Offset to store the values

02 = Number of bytes to copy

8822 = Palette select for the tiles.


From what I understand (I could be wrong), each 2 bits covers a certain area (either 16 x 16 pixels or 32 x 32 pixels, depending on the game).  So converting 8822 into binary gets this:

10 00 10 00 00 10 00 10

From memory, the key would be:
00 = Palette 1
01 = Palette 2
10 = Palette 3
11 = Palette 4

So I can see the game is told to use “Palette 2”, but I don’t get how those bits tell the PPU which tiles to select.

Hopefully someone can explain it. :)
Avatar by LazyNinjartist

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7255
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Selecting which palette a tile uses in a NES title screen?
« Reply #3 on: February 14, 2013, 11:34:22 am »
Okay, I found the palette select data, but I can’t get my head around the last bit.

Let’s use this one as an example (makes most of the “2” in the title use an alternative palette).

23 E3 02 88 22

23E2 = PPU Offset to store the values

02 = Number of bytes to copy

8822 = Palette select for the tiles.


From what I understand (I could be wrong), each 2 bits covers a certain area (either 16 x 16 pixels or 32 x 32 pixels, depending on the game).  So converting 8822 into binary gets this:

10 00 10 00 00 10 00 10

From memory, the key would be:
00 = Palette 1
01 = Palette 2
10 = Palette 3
11 = Palette 4

So I can see the game is told to use “Palette 2”, but I don’t get how those bits tell the PPU which tiles to select.

Hopefully someone can explain it. :)
2 bits always control a 16x16 area (1 BYTE controls a 32x32 area), that's how the PPU works.

PPU $2000-23BF is the tilemap for the upper-left screen in VRAM (which is typically used for single-screen images like title screens). That is the area to change if you want a different tile on the screen. (each of the 4 potential screens are $400 bytes. Note that most games only support 2 screens, using either the top half or the left half, called mirroring. 4 screens requires extra PPU RAM in the cart, and I've heard prohibits the use of on-cart CPU RAM.)

To change which palette is assigned to each 16x16 pixel region, you change the attribute table. That is 23C0-23FF.
Each byte controls 4 of the 16x16 regions (2 16x16 blocks wide by 2 16x16 blocks tall). Bits 0 and 1 (the last 2-bit pair) control the upper left region, bits 2 and 3 control the upper right, bits 4 and 5 control the lower-left region, and bits 6 and 7 (the first 2-bit pair you listed) would control the lower-right.
"My watch says 30 chickens" Google, 2018