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);
}
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));
}
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));
}