This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Palette vs. normal VRAM reads

Palette vs. normal VRAM reads
by on (#14879)
Someone sent me a message about getting an error #6 with my blargg_ppu_tests_2005.09.15b VRAM access tests, "Palette read should also read VRAM into read buffer". I'm posting my answer here since it might benefit others. The problem is likely that the emulator isn't treating a palette read as a normal read regarding the internal read buffer (I don't have my notes right now so this is all from memory):
Code:
Normal  VRAM read:  VRAM    ---> buffer -> CPU

Palette VRAM read:  VRAM    ---> buffer
                    Palette ---> CPU

Shown in code:
Code:
; Normal VRAM access
lda #$10   ; VADDR = $1000
sta $2006
lda #$00
sta $2006
lda $2007  ; A = ?? (previous contents of internal buffer)
lda $2007  ; A = VRAM at $1000

; Palette VRAM access
lda #$3F   ; VADDR = $3F12 (palette area)
sta $2006
lda #$12
sta $2006
lda $2007  ; A = Palette RAM at $12
lda $2007  ; A = Palette RAM at $13
lda #$10   ; VADDR = $1000
sta $2006
lda #$00
sta $2006
lda $2007  ; A = VRAM at $2F13 (filled earlier)
lda $2007  ; A = VRAM at $1000

by on (#14881)
I was under the impression that palette reads will return the palette without buffering, but will put the mirrored NT byte in the read buffer.

IE: reading $3F00 will give you the palette entry at $3F00 and will put the byte in VRAM[$2F00] in the read buffer.

That's what I have my emu doing and it passes.

by on (#14882)
Yeah sorry, I just corrected the code example. My memory buffer wasn't working right.

by on (#14883)
blargg wrote:
My memory buffer wasn't working right.



hahahahaha

oh man, we're such nerds, I swear.


EDIT -- Also, I just recalled one other weird thing that your test ROMs don't test. Reading a palette entry from $2007 when in monochrome mode will return the desired color AND $30.