Page 1 of 1
Fading background
Posted: Sat Jan 31, 2015 8:09 am
by Bionja
Hello everyone! I wanna make some effects for own game, but I don't get how to make fading/disappearing background. By the way, I can't write a code to do this stuff. In theory, background (or some words in my case, whatever) appears from 0 to 255 and fades from 255 to 0 respectively. So, I need to replace all frames in sequence, but how it goes in code? Your advices would help me!
Re: Fading background
Posted: Sat Jan 31, 2015 9:22 am
by Drew Sebastino
Bionja wrote:appears from 0 to 255 and fades from 255 to 0 respectively
What the... Do you think the NES uses 24bit RGB? I know the NES has:
a shade of black,
a shade of dark grey,
a shade of light grey,
and a shade of white, that's literally it.
(That's why the fading looks kind of choppy in the picture)
and about fading the background, I heard the NES doesn't have a universal brightness register, so you'd have to fade the background by having multiple palettes that you switch through every couple of frames or so.
I've never coded for the NES, but I know you would probably use a table that would hold the different color values, then you would upload the color to CGRAM. (Somehow. Like I said, I've never done anything on the NES.)
here's a little code:
Code: Select all
infinite_loop:
wai ;make it so the NES doesn't go at 3000 miles per hour
ldx FrameNumber ;this is a register
cpx #$?? ;this number can be anything, just don't make it longer than the table! (The table is four) this sees if you are done fading
beq infinite_loop ;jump back to infinite_loop because the fading is done
lda #Pallete,x ;this is the address of a table that holds the different palette numbers
sta Somewhere ;don't know, I've never coded for the NES
inx ;increase x ;x says how many frames you have gone through
stx FrameNumber ;this is a register
bra infinite_loop
Pallete:
.DB $??,$??,$??,$??
The code above only changes one palette though, and don't expect it to work how it is now, because you still need an init code to clear registers and you need to create a code to say what happens during v blank.
Just thinking, could you actually have a table that points to another table? that would be a way to change multiple colors per frame.
Re: Fading background
Posted: Sun Feb 01, 2015 2:37 am
by Bionja
Espozo wrote:Bionja wrote:appears from 0 to 255 and fades from 255 to 0 respectively
What the... Do you think the NES uses 24bit RGB? I know the NES has:
a shade of black,
a shade of dark grey,
a shade of light grey,
and a shade of white, that's literally it.
(That's why the fading looks kind of choppy in the picture)
and about fading the background, I heard the NES doesn't have a universal brightness register, so you'd have to fade the background by having multiple palettes that you switch through every couple of frames or so.
I've never coded for the NES, but I know you would probably use a table that would hold the different color values, then you would upload the color to CGRAM. (Somehow. Like I said, I've never done anything on the NES.)
here's a little code:
Code: Select all
infinite_loop:
wai ;make it so the NES doesn't go at 3000 miles per hour
ldx FrameNumber ;this is a register
cpx #$?? ;this number can be anything, just don't make it longer than the table! (The table is four) this sees if you are done fading
beq infinite_loop ;jump back to infinite_loop because the fading is done
lda #Pallete,x ;this is the address of a table that holds the different palette numbers
sta Somewhere ;don't know, I've never coded for the NES
inx ;increase x ;x says how many frames you have gone through
stx FrameNumber ;this is a register
bra infinite_loop
Pallete:
.DB $??,$??,$??,$??
The code above only changes one palette though, and don't expect it to work how it is now, because you still need an init code to clear registers and you need to create a code to say what happens during v blank.
Just thinking, could you actually have a table that points to another table? that would be a way to change multiple colors per frame.
Of course not, it does not use 24bit, that was a simple example of what I'm thinkin' about and probably goin' to make. I cut this little scene from Mitsume ga Tooru and tried to interpret it in GIF format. Thanks for help , I'll try to do something.
Re: Fading background
Posted: Sun Feb 01, 2015 3:04 am
by Bregalad
You should really look at how the NES palette works. Despite having only 52 colours, they are arranged in a way that makes them very easy to fade :
- The low 4 bits select the colour itself (i.e. "hue"), there is some exeptions such as the columns $0, $c, $d, $e and $f
- The high 2 bits select the luminosity
Thus fading to black is equivalent to subtracting $10 from all the colours, but when you reach a negative number you should manually replace them with $0f.
In pseudo code it'd look like the collowing
Code: Select all
for x=0:32
temp = palette[x] - $10
if(temp < 0)
temp = $0f
palette[x] = temp
I hope this helps. There is probably other approaches, but that's the one I use.
Re: Fading background
Posted: Sun Feb 01, 2015 7:39 am
by Drew Sebastino
Code: Select all
for x=0:32
temp = palette[x] - $10
if(temp < 0)
temp = $0f
palette[x] = temp
Wait, what? I know your post was directed toward Bionja, but what does if, temp, or palette mean? I would say that palette is a register, but you have it in the opcode spot. Are they supposed to be opcodes, because if so, programming for the NES is a lot different than I thought.

Re: Fading background
Posted: Sun Feb 01, 2015 9:38 am
by tepples
It appears to be
pseudocode, not a real language that can be compiled for 6502.
Re: Fading background
Posted: Sun Feb 01, 2015 1:16 pm
by Myask
Slightly buggy pseudocode, at that. 0-32 is a 33-value range.
Code: Select all
;first, have copied palette into CPU's RAM [not shown]
;then, on each frame you change the palette, do this function and copy it back
palette-drain:
;insert desired pushes here
LDX #$1F
go2:
LDA palettes,X
SEC
SBC #$10
BNE black
CMP #$0D ;avoid bad color
BNE next
black:
LDA #$0F
next:
STA palettes,X
DEX
BPL go2;for pun
;insert desired pulls here
RTS
Do the color emphasis bits fit at all neatly between steps of such a fading scheme?
Re: Fading background
Posted: Sun Feb 01, 2015 3:10 pm
by tokumaru
Myask wrote:Do the color emphasis bits fit at all neatly between steps of such a fading scheme?
thefox coded an
interesting demo you might want to check out.
I must say I absolutely despise the 4-step fade found in the typical NES game. It only looks good if animated really fast, to the point where you barely notice there's any fading going on, so I almost prefer no fading at all than that same old choppy animation.