So just futzing around with a simple fade screen transition. I have the palette in RAM and have a routine that updates that ram. The palette is updated in the NMI. I have a routine (LoadPaletteRam) that I can call which changes a palette (uses variable backgroundPaletteOffset to pull values from the correct place in a table). That's all working. But I can't get any sort of gradual fade.
I figured something like the following would work - the X register SHOULD work as a timer. However the result still appears as instantaneous...from first palette to last palette rather than showing one at a time. I generally understand why - I'd venture that all the math is happening before the NMI displays the result, giving the impression it was just a single "change" rather than four "changes", but I thought I'd at least share this as my first idea for it.
There's nothing *wrong* with this code - it does exactly what I'm telling it to do, but it's happening all before the screen is updated (my conjecture), so the effect is never seen. How do people generally handle simple fades like this? Anyone have any suggestions?
Thanks!
I figured something like the following would work - the X register SHOULD work as a timer. However the result still appears as instantaneous...from first palette to last palette rather than showing one at a time. I generally understand why - I'd venture that all the math is happening before the NMI displays the result, giving the impression it was just a single "change" rather than four "changes", but I thought I'd at least share this as my first idea for it.
Code:
ScreenTransition:
LDX #$20 ; load 20 into x to act as a countdown
FadeOut:
DEX ; after counts down from 20 to 0
BNE FadeOut
LDA backgroundPaletteOffset
CLC
ADC #$10 ; increase the table offset by a 'row'
CMP #$40 ; the highest 'row' is 40
BPL doneFadingOut ; if it has reached 40, get out of the routine
STA backgroundPaletteOffset ; if not, keep the new value
TAY
JSR LoadPaletteRam ;; in this routine, what is in y determines where in the table to grab values from
JMP ScreenTransition ; start it over again with the countdown
doneFadingOut:
LDX #$20 ; load 20 into x to act as a countdown
FadeOut:
DEX ; after counts down from 20 to 0
BNE FadeOut
LDA backgroundPaletteOffset
CLC
ADC #$10 ; increase the table offset by a 'row'
CMP #$40 ; the highest 'row' is 40
BPL doneFadingOut ; if it has reached 40, get out of the routine
STA backgroundPaletteOffset ; if not, keep the new value
TAY
JSR LoadPaletteRam ;; in this routine, what is in y determines where in the table to grab values from
JMP ScreenTransition ; start it over again with the countdown
doneFadingOut:
There's nothing *wrong* with this code - it does exactly what I'm telling it to do, but it's happening all before the screen is updated (my conjecture), so the effect is never seen. How do people generally handle simple fades like this? Anyone have any suggestions?
Thanks!