gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Background Fading

#2522 - np_soft - Wed Feb 05, 2003 5:37 pm

Does anyone know where I can find sample source code in C or C++ that does background fade in/out using GBA's hardware?

Or if it's really easy, just post me some code?
Thanks

Edmund

#2523 - tepples - Wed Feb 05, 2003 6:27 pm

np_soft wrote:
Does anyone know where I can find sample source code in C or C++ that does background fade in/out using GBA's hardware?

There are two ways to do it: either change the palette registers in a loop, or use the hardware fader. The hardware fader is easier, but you can't use it if you're using alpha blending or if you're trying to fade out only one object.

To learn how to use the hardware fader, see Cowbite Spec: Effects Registers
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#2530 - darkcloud - Wed Feb 05, 2003 10:30 pm

You might need to edit these to fit your needs, but they work pretty well:
Code:

void SleepQ(int i)
{
   int x, y;
   int c;
   for (y = 0; y < i; y++)
   {
      for (x = 0; x < 4000; x++)
         c = c + 2; // do something to slow things down
   }
}


//******************************************************************************
void fadeout( u32 aWait )
{
   s8 Phase;
   REG_BLDMOD = 0 | 1 | 2 | 4 | 8 | 128 | 64 | 32;
   for( Phase = 0; Phase < 17; Phase++ )
   {
      REG_COLEY = Phase;
      SleepQ( aWait );
   }
}

//******************************************************************************
void fadein( u32 aWait )
{
   s8 Phase;
   REG_BLDMOD = 0 | 1 | 2 | 4 | 8 | 128 | 64 | 32;
   for( Phase = 0; Phase < 16; Phase++ )
   {
      REG_COLEY = 16-Phase;
      SleepQ ( aWait );
   }
}


I found these in some example I was looking at and don't remember where.
_________________
Maybe in order to understand mankind, we have to look at the word itself: "Mankind". Basically, it's made up of two separate words - "mank" and "ind". What do these words mean ? It's a mystery, and that's why so is mankind.

#2531 - arog - Wed Feb 05, 2003 10:46 pm

I borrowed some code to fade in to and out from black.
It was written for HAM, but I am sure you can figure out
the relevant parts.

http://www.aaronrogers.com/ham/Games/HAM_Hearts/html/splash_h.htm
http://www.aaronrogers.com/ham/Games/HAM_Hearts/html/splash_cpp.htm

- Aaron Rogers
HAM Tutorial