Why can't I see the palette in the memory debug?

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
ludoVIC
Posts: 31
Joined: Fri Jan 08, 2021 8:36 am

Why can't I see the palette in the memory debug?

Post by ludoVIC » Thu Jan 21, 2021 4:41 am

According to the Nerdy Nights basic guide, an introductory way for loading the Palettes is with a simple loop:

Code: Select all

  ;; Tell the PPU to write from $3F00 on
  lda #$3F
  sta $2006
  lda #$00
  sta $2006

  ;; Palette loading
  ldx #$00
LoadPalette:
  lda PaletteData, x
  sta $2007
  inx
  cpx #$20
  bne LoadPalette
Where "PaletteData" is stored somewhere (preferably in the ROM memory from $8000 on, right?).
If I understand correctly, we are telling the PPU to store our Palettes from the memory addresses $3F00 on.
Now, if I open the .nes file with FCEUX, I see that the Palettes are loaded correctly (PPU viewer).
Despite this fact, the addresses $3F00 do not seem to contain my palette Bytes, rather they are like:

Code: Select all

   :3F00: 00        BRK
   :3F01: 80        UNDEFINED
   :3F02: 9A        TXS
While my Palette data is:
.dw $0F,$31,$32, ...

In other words, why don't I see in my memory a structure like the following?

Code: Select all

  :3F00: 0F
  :3F01: 31
  :3F02: 32, ....

EDIT: I modified the post title in order to facilitate possible future readers.
Last edited by ludoVIC on Thu Jan 21, 2021 5:04 am, edited 2 times in total.

User avatar
tokumaru
Posts: 12000
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Where are the Palette actually stored?

Post by tokumaru » Thu Jan 21, 2021 4:56 am

The NES has 2 separate memory spaces, one for the CPU and one for the PPU. $3F00 on the CPU memory is just a mirror of PPU registers $2000-$2007, which repeat over and over until $3FFF, so you don't want to mess with that.

When you write data via PPU registers $2006 and $2007 you're actually sending data to PPU memory, the space where pattern tables, name tables, etc. live. But even then, the palette is kind of a special case, because the memory range $3F00-$3FFF overlaps with a mirror of the name tables, so the PPU deliberately interferes with accesses to this range and redirects the palette data to a small chunk of memory inside the PPU itself. This is why you won't find the palette in a memory viewer, unless it has an option to display the palette RAM. Mesen has an option for this (Debug -> Memory Tools -> View: Palette RAM), but FCEUX doesn't appear to.

EDIT: Even though FCEUX doesn't have an option to display the palette RAM specifically, it will show the palette overlaid on top of the NT mirror (from $3F00 to $3FFF) if you select View -> PPU Memory in its hex editor.

ludoVIC
Posts: 31
Joined: Fri Jan 08, 2021 8:36 am

Re: Where are the Palette actually stored?

Post by ludoVIC » Thu Jan 21, 2021 5:03 am

Ohhh, great! Crystal clear and complete explanation: thank a lot! :beer: :D

Post Reply