Is there a location we can insert code into the wait vblank area?

drexegar

Member
I learn how to change color which forces me to write to the PPU

of course doing this during drawing will ruin make the HUD jump and ruin backgrounds graphics,

Ive been looking everywhere for a piece of code, wether HUD update or scrolling or anything that can update before the next vblank.

Does anybody know where I can find it?
 

MistSonata

Moderator
You'll be happy to know that Joe has you covered there. If you want to trigger a palette change, you can do something like this:

Code:
;; suppose you wanted to change the 3rd sprite palette, and the 2nd background palette

;; You load up the color you want into the accumulator, then store it into spritePalFade/bckPal PLUS the index of the palette color you want to change (0-15)
;; +0-3 = 1st palette
;; +4-7 = 2nd palette
;; +8-11 = 3rd palette
;; +12-15 = 4th palette

LDA #$0F ; black
STA spritePalFade+8 ; 3rd sprite palette, 1st color
LDA #$00 ; dark grey
STA spritePalFade+9 ; 3rd sprite palette, 2nd color
LDA #$10 ; light grey
STA spritePalFade+10 ; 3rd sprite palette, 3rd color
LDA #$20 ; white
STA spritePalFade+11 ; 3rd sprite palette, 4th color

;; Now we do the same for the background palette

LDA #$0F ; black
STA bckPal+4 ; 2nd background palette, 1st color
LDA #$00 ; dark grey
STA bckPal+5 ; 2nd background palette, 2nd color
LDA #$10 ; light grey
STA bckPal+6 ; 2nd background palette, 3rd color
LDA #$20 ; white
STA bckPal+7 ; 2nd background palette, 4th color

;; IMPORTANT!!!
;; Once you've done all the palette changes you want, you're going to load a non-zero number into the variable updatePalettes
;; This will tell the palette update script that runs during vblank to make the appropriate PPU writes
;; If you forget to load a non-zero number into updatePalettes, your palette changes will fail to update, and you will be sad :(

LDA #$01
STA updatePalettes
RTS
 

drexegar

Member
MistSonata said:
You'll be happy to know that Joe has you covered there. If you want to trigger a palette change, you can do something like this:

Thank you so much! now I can put this to good use!
 
Top Bottom