Shortening my background loading functions? [PART. SOLVED]

Post Reply
Quipeace
Posts: 6
Joined: Sun Dec 27, 2009 9:31 pm

Shortening my background loading functions? [PART. SOLVED]

Post by Quipeace » Thu Jan 07, 2010 8:50 pm

Hey all,

I've finally managed to load some simple backgrounds,and thought it be useful to create a simple function so I don't have to go trough the same stuff every time.

This is what i've got now:

Code: Select all

void Load8bitBg(bool screen, int Bg, const u8 img[], const u8 pal[], u32 img_s, u32 pal_s)
{
	dmaCopy(img, bgGetGfxPtr(Bg), img_s);
	if(screen)	dmaCopy(pal, BG_PALETTE, pal_s);
	else		dmaCopy(pal, BG_PALETTE_SUB, pal_s);

}
void LoadTileBg(bool screen, int Bg, const u8 img[], const u8 map[], const u8 pal[], u32 img_s, u32 map_s, u32 pal_s)
{
	int Base = bgGetTileBase(Bg);

	dmaCopy(img, BG_TILE_RAM(Base), img_s);
	dmaCopy(map, bgGetMapPtr(Bg)  , map_s);
		
	if(screen)	dmaCopy(pal, BG_PALETTE, pal_s);
	else		dmaCopy(pal, BG_PALETTE_SUB, pal_s);

}
As you can see, LoadTileBg expects 8 arguments the way i've got it now, and Load8bitBg wants 5...
How would I decrease the number of arguments required? so that the whole function would at least fit on my screen? If it can't be done I'll just put them all in a struct I suppose...


EDIT: SOLVED MY OWN PROBLEM (partially)

I found out that I could use sizeof() instead of the lengthy bg_img_bin_size, so the resulting code would be this:

Code: Select all

void Load8bitBg(bool screen, int Bg, const u8 img[], const u8 pal[])
{
	dmaCopy(img, bgGetGfxPtr(Bg), sizeof(img));
	if(screen)	dmaCopy(pal, BG_PALETTE, sizeof(pal));
	else		dmaCopy(pal, BG_PALETTE_SUB, sizeof(pal));
}

void LoadTileBg(bool screen, int Bg, const u8 img[], const u8 map[], const u8 pal[])
{
	int Base = bgGetTileBase(Bg);

	dmaCopy(img, BG_TILE_RAM(Base), sizeof(img));
	dmaCopy(map, bgGetMapPtr(Bg)  , sizeof(map));
		
	if(screen)	dmaCopy(pal, BG_PALETTE, sizeof(pal));
	else		dmaCopy(pal, BG_PALETTE_SUB, sizeof(pal));
}
However, I tried using the same method with sprites, but found out that it wouldn't work!

Code: Select all

void LoadSprite(bool screen, u16* gfx, const u8 img[], const u8 pal[], u32 img_s)
{
	dmaCopy(img, gfx, img_s);                       // this works
        //dmacopy(img, gfx, sizeof(img));              // this does not
	if(screen)	dmaCopy(pal, SPRITE_PALETTE, sizeof(pal));
	else		dmaCopy(pal, SPRITE_PALETTE_SUB, sizeof(pal));
}
Could anyone explain exactly why that wont work?

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests