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.

Coding > Clearing memory/BG layers

#7060 - Lupin - Sat Jun 07, 2003 2:47 pm

How could I clear an whole text bg layer? I want to do text output, so I need to clear the bg layers when the text changes

#7061 - tepples - Sat Jun 07, 2003 5:12 pm

Clearing a map is easy: Just write spaces to the entire map. If your pattern table follows the ascii format (0x0020 is a space), write 0x0020 to every tile in the map.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#7077 - Lupin - Sun Jun 08, 2003 5:54 pm

looping through an 256x256 background would be kinda slow, I need to set the whole background to 0, because my ascii table starts at the 32th character

#7079 - tepples - Sun Jun 08, 2003 6:01 pm

Lupin wrote:
looping through an 256x256 background would be kinda slow

Actually, it's a 32x32 tile background, and no, I wouldn't find 1024 tiles "slow" to loop through.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#7080 - niltsair - Sun Jun 08, 2003 6:04 pm

Use DMA.

Create a variable that contains the Tile number of space or of a blank tiles.

Initiate a DMA transfer of the number of tiles your map contains in DMA_16, and select fixed address for the source with your variable address, and the destination would be the memory location of your map.

#7082 - Lupin - Sun Jun 08, 2003 8:30 pm

thx niltstair

tepples, I think DMA would be faster, I know that it wouldn't drop the FPS down to 1 or sth like this, but I take every speed improve I could get ;)

#7087 - Lupin - Mon Jun 09, 2003 8:33 am

I tried to write an 16 bit clearing function wich should set the whole memory to 2, but the compiler doesn't like my code and it sets everything to 0 though :(

u16 clear = 2;
REG_DMA0SAD = (u32)(void*)clear; //C doesn't like casting u16 to void* :(
REG_DMA0DAD = (u32)dest;
REG_DMA0CNT = WordCount | DMA_ENABLE | DMA_TIMEING_IMMEDIATE | DMA_16 | DMA_SOURCE_FIXED;


I'm not that good in C, I think I did an newbie mistake :(

#7089 - Touchstone - Mon Jun 09, 2003 10:30 am

Lupin wrote:
REG_DMA0SAD = (u32)(void*)clear; //C doesn't like casting u16 to void* :(


shouldnt you take the address to 'clear'? like so:
REG_DMA0SAD = (u32)(void*)&
_________________
You can't beat our meat

#7097 - Lupin - Mon Jun 09, 2003 3:09 pm

I thought (void*) would get the adress in memory :)