It is currently Sun Oct 22, 2017 6:02 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Fading background
PostPosted: Sat Jan 31, 2015 8:09 am 
Offline

Joined: Thu Jan 29, 2015 10:28 am
Posts: 7
Location: Moscow, Russian Federation
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!


Attachments:
ready.gif
ready.gif [ 8.99 KiB | Viewed 1365 times ]
Top
 Profile  
 
 Post subject: Re: Fading background
PostPosted: Sat Jan 31, 2015 9:22 am 
Offline
User avatar

Joined: Mon Sep 15, 2014 4:35 pm
Posts: 3074
Location: Nacogdoches, Texas
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:
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.


Top
 Profile  
 
 Post subject: Re: Fading background
PostPosted: Sun Feb 01, 2015 2:37 am 
Offline

Joined: Thu Jan 29, 2015 10:28 am
Posts: 7
Location: Moscow, Russian Federation
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:
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.


Top
 Profile  
 
 Post subject: Re: Fading background
PostPosted: Sun Feb 01, 2015 3:04 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7234
Location: Chexbres, VD, Switzerland
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:
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.


Top
 Profile  
 
 Post subject: Re: Fading background
PostPosted: Sun Feb 01, 2015 7:39 am 
Offline
User avatar

Joined: Mon Sep 15, 2014 4:35 pm
Posts: 3074
Location: Nacogdoches, Texas
Code:
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. :?


Top
 Profile  
 
 Post subject: Re: Fading background
PostPosted: Sun Feb 01, 2015 9:38 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19115
Location: NE Indiana, USA (NTSC)
It appears to be pseudocode, not a real language that can be compiled for 6502.


Top
 Profile  
 
 Post subject: Re: Fading background
PostPosted: Sun Feb 01, 2015 1:16 pm 
Offline
User avatar

Joined: Sat Jul 12, 2014 3:04 pm
Posts: 936
Slightly buggy pseudocode, at that. 0-32 is a 33-value range.

Code:
;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?


Top
 Profile  
 
 Post subject: Re: Fading background
PostPosted: Sun Feb 01, 2015 3:10 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10066
Location: Rio de Janeiro - Brazil
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group