2

Let's say I want to write K to the top of the status bar in SMB. I can use the following set of statements to write to PPU memory.

    memory.writebyte(0x2001, 0x00) -- Turn off rendering
    memory.readbyte(0x2002) -- PPUSTATUS (reset address latch)
    memory.writebyte(0x2006, 0x20) -- PPUADDR high byte
    memory.writebyte(0x2006, 0x2A) -- PPUADDR low byte
    memory.writebyte(0x2007, 0x14) -- PPUDATA ('K')
    memory.writebyte(0x2001, 0x1e) -- Turn on rendering

enter image description here

I tried changing the color of the text by changing the color palette before writing text as -

memory.writebyte(0x2001, 0x00) -- Turn off rendering
memory.readbyte(0x2002) -- PPUSTATUS (reset address latch)

memory.writebyte(0x2006, 0x3F) -- Selecting high byte color palette
memory.writebyte(0x2006, 0x11) -- Selecting low byte color palette
memory.writebyte(0x2007, 0x16) -- Red color

memory.writebyte(0x2006, 0x20) -- PPUADDR high byte
memory.writebyte(0x2006, 0x2A) -- PPUADDR low byte
memory.writebyte(0x2007, 0x14) -- PPUDATA ('K')
memory.writebyte(0x2001, 0x1e) -- Turn on rendering

However that changes the color of the background objects.

My question is how I can set the color of the displayed text?

  • 2
    I've never tried programming the NES, so maybe I'm completely wrong, but shouldn't you be updating the relevant block in the attribute table (wiki.nesdev.com/w/index.php/PPU_attribute_tables) rather than changing palette entries for this? – occipita Jul 24 at 5:12
  • You're right. My strategy (as in code) may not work. Do I have to reverse calculate the values of attribute table from the desired palette value as in this eq. from the link - value = (bottomright << 6) | (bottomleft << 4) | (topright << 2) | (topleft << 0) – Kulbhushan Chand Jul 24 at 5:50
0

Look at it in the Mesen emulator, under Debugger / PPU Viewer / Palette Viewer (there you can change the palette to see the effect).

For the text color, you want palette address $3F09. This is also the cloud's color. $3F11 is in the sprite palette rather than the background, and it seems to be Mario's outfit color.

Also, note that most games store the palette in RAM, and write to the PPU every vblank. Makes it easier to handle palette cycling, transitions, stuff like that.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.