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.

DS development > Filling the screen with one colour?

#118445 - Kheldar - Tue Feb 13, 2007 3:10 pm

I've just started writing code for the DS and am trying to make a rain effect for the hell of it. I've got rain working fine and now I want to add lightning as well.

I want to randomly decide if lightning should start, then quickly change the background colour from black through grey to white then back again. I've got the random chance done but my fillScreen() function it seems way to slow. It causes rain not to be drawn to random parts of the screen (I assume I'm talking too long in the Vblank to finish drawing?)

This is how I'm filling the screen with a colour:
Code:
void fillScreen()
{
   int i;

   for(i = 0; i < 256 * 192; i++)
   {
      VRAM_A[i] = RGB15(0,0,0);
   }
}


Is there a way I could just fill the whole of VRAM with one colour (like memset?) instead of doing it per pixel? Do I need double buffering?

Thankyou!

#118449 - Lick - Tue Feb 13, 2007 3:55 pm

I think you can use the Master Brightness for this matter. BRIGHTNESS and SUB_BRIGHTNESS.

You can check out this demo I wrote recently.
_________________
http://licklick.wordpress.com

#118451 - Sausage Boy - Tue Feb 13, 2007 4:01 pm

If you have a background and vram to spare, you can just fill it once, hide it, and show it when you need to. A tiled background would be very suitable for this purpose.

I must admit that using the brightness stuff for this is much cooler, if it's an effect like that you want. But, I think It could get annoying if it happens all the time.
_________________
"no offense, but this is the gayest game ever"

#118469 - Mighty Max - Tue Feb 13, 2007 7:40 pm

There is also a brightness in/decrease in the special color effect control.

This allows you to create black or white filled rectangles of any size in 4 register writes.
_________________
GBAMP Multiboot

#118473 - tepples - Tue Feb 13, 2007 7:44 pm

What kind of background are you using? You may be able to draw the sky by changing BG_PALETTE[0].
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#118555 - GrizzlyAdams - Wed Feb 14, 2007 6:05 am

theres a function that should probably be in libnds:

Code:
#ifdef ARM9
#define DMA_FILL(n) (*(vuint32*)(0x040000E0+(4*n)))
 
void dmaFill(uint8 channel, const void *Dest, u16 Value, uint32 Size) {
   DMA_FILL(channel) = Value;
   DMA_SRC(channel) = (uint32)&DMA_FILL(channel);
   DMA_DEST(channel) = (uint32)Dest;
   DMA_CR(channel) = DMA_COPY_HALFWORDS | DMA_SRC_FIX | (Size>>1);
   while(DMA_CR(channel) & DMA_BUSY);
}
#else
void dmaFill(uint8 channel, const void *Dest, u16 Value, uint32 Size) {
   u16 Source = Value;
   DMA_SRC(channel) = (uint32)&Source;
   DMA_DEST(channel) = (uint32)Dest;
   DMA_CR(channel) = DMA_COPY_HALFWORDS | DMA_SRC_FIX | (Size>>1);
   while(DMA_CR(channel) & DMA_BUSY);
}
#endif


I'm not 100% sure if this is correct or not. I've used the ARM7 version a few times and it seemed to work ok, but it turns out the cache will be involved if you use main ram for the fixed source. The DMA_FILL(n) is supposed to be used specifically for dma fills from the arm9 according to GBATEK.

#118562 - Mighty Max - Wed Feb 14, 2007 8:23 am

It's just my humble opinion, but setting up DMA transfers and then just going into busy waiting on the CPU is a bit ... wasting.

A stm-loop should fill faster anyways.
_________________
GBAMP Multiboot

#118622 - GrizzlyAdams - Wed Feb 14, 2007 9:10 pm

Mighty Max wrote:
It's just my humble opinion, but setting up DMA transfers and then just going into busy waiting on the CPU is a bit ... wasting.

A stm-loop should fill faster anyways.


Seeing as I've based this function on the DMA functions already in libnds, I'm the wrong person to tell. I just added the fixed source address version.