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 > background bug(?)

#4122 - Ninj4D4n - Wed Mar 19, 2003 8:41 pm

Hey all, i've been playing with backgrounds for a few days and keep finding this wierd occurance that seems to be giving me most of the trouble.

Here's my function
[code]
void Intro(void)
{
SetMode(MODE_1 | OBJ_ENABLE | OBJ_MAP_1D);
Bg FlashBG, AtariBG;

//////////////////////////////////
//setup data
u16 loop;
//load palette
for(loop = 0; loop < 256; loop++)
BGPalette[loop] = tilesPalette[loop];

u16* tempData = (u16*)CharBaseBlock(0);
//load tile set; charbase block 0
for(loop = 0; loop < tiles_WIDTH * tiles_HEIGHT /2; loop++)
tempData[loop] = tilesData[loop];

//load maps
u16* tempLoad;
u16* tempMap;

//rot bg
tempMap = (u16*)ScreenBaseBlock(28);
tempLoad = (u16*)clouds;
for(loop = 0; loop < 32*32/2; loop++)
tempMap[loop] = tempLoad[loop];

AtariBG.number = 2;
AtariBG.charBaseBlock = 0; //tiles in 0
AtariBG.screenBaseBlock = 28; //AtariBG in 28 (above)
AtariBG.colorMode = BG_COLOR_256;
AtariBG.size = ROTBG_SIZE_256x256;
AtariBG.mosaic = 0;
AtariBG.x_scroll = 0;
AtariBG.y_scroll = 0;

EnableBackground(&AtariBG);
}
[/code]

as you can see, it just loads all the data necessary to setup background 2. This works fine. The bug is if i switch the decleration:
Bg FlashBG, AtariBG;

to

Bg AtariBG, FlashBG;

Nothing is displayed. Total black screen.

I'm currently using the files i found at the pern project so my struct Bg is:
[code]
//structure for a background
typedef struct Bg
{
u16* tileData;
u16* mapData;
u8 mosaic;
u8 colorMode;
u8 number;
u16 size;
u8 charBaseBlock;
u8 screenBaseBlock;
u8 wraparound;
s16 x_scroll,y_scroll;
s32 DX,DY;
s16 PA,PB,PC,PD;
}Bg;
[/code]

So.... any ideas? Also, if i don't declare FlashBG before AtariBG i also get black.

--Ninj4D4n

#4151 - pollier - Fri Mar 21, 2003 1:59 am

Either some other process like a music player is corrupting it, or you're relying on these values to be pre-initialised. It might be a good idea to do a memset(AtariBG, 0, sizeof(Bg)) or something...or does that apply for local declarations like this? Alternatively, you might want to check your linkscript for your IWram/EWram settings, or setup a data breakpoint in an emulator to find the source of the error.
_________________
(Works for me!)

#4432 - Ninj4D4n - Mon Mar 31, 2003 3:14 am

Ok, so i played around a little more. If i make AtariBG a global variable.. everything works fine. haha... so now i'm really confused.

--Ninj4D4n