7

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?

kbc
  • 71
  • 6

2 Answers2

2

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.

Memblers
  • 186
  • 2
  • 5
0

Instead of changing the palette itself you might find it easier to change the attributes instead.

Try this:

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

memory.writebyte(0x2006, 0x23) -- Selecting high byte attribute table memory.writebyte(0x2006, 0xC1) -- Selecting low byte attribute table ; you might need to fiddle with this number, should be somewhere between 0xC0 and 0xC8 memory.writebyte(0x2007, 0x00) -- Use Palette 0

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

Equivalent assembly code if you prefer:

LDA #$00
STA $2001
LDA $2002

LDA #$23 STA $2006 LDA #$C1 STA $2006

LDA #$00 STA $2007

LDA #$20 STA $2006 LDA #$2A STA $2006

LDA #$14 STA $2007

LDA #$1E STA $2001

puppydrum64
  • 1,638
  • 5
  • 18