Menu

#6 Higher level helper functions in libgba

open
nobody
libgba (1)
3
2012-10-09
2006-01-19
No

Some functions in libgba for handling, e.g., basic
video stuff would be cool. For example: initialising
backgrounds, fading/alpha blending, initialising
sprites, etc. I don't mean as high level as, say,
HAMlib, but something a bit higher than writing direct
to registers. If only to make code less wordy. For
example, to initialise a background I have this kind of
thing (untested, hacked out of c++ code):

define BG_ON(n) (1 << (8+n))

void gba_set_background(
int number,
int charbase,
int screenbase,
int flags )
{
REG_DISPCNT |= BG_ON(number);
BGCTRL[number] = SCREEN_BASE(screenbase) |
CHAR_BASE(charbase) | flags;
}

Also, for hardware "fading":

define BLDMOD_BG0 BIT(0)

define BLDMOD_BG1 BIT(1)

define BLDMOD_BG2 BIT(2)

define BLDMOD_BG3 BIT(3)

define BLDMOD_OBJ BIT(4)

define BLDMOD_BD BIT(5)

define BLDMOD_MODE(n) (n<<6)

typedef enum {
BLDMOD_OBJECT=0,
BLDMOD_ALPHA=1,
BLDMOD_WHITE=2,
BLDMOD_FADE=3,
} BLDMOD_MODE_t;

void gba_set_blend(int first, int second, BLDMOD_MODE_t
mode) {
REG_BLDCNT = ((first)|((second)<<8)|(BLDMOD_MODE(mode)));
}

void gba_screen_fade(int level)
{
if (level > 16)
level = 16;
if (level < 0)
level = 0;
gba_set_blend( BLDMOD_BG1 | BLDMOD_BG0 | BLDMOD_BG2|
BLDMOD_OBJ ,
BLDMOD_BD , BLDMOD_FADE);
REG_BLDY = level;
}

Naming conventions are probably wrong there, but that's
the idea. Nothing really clever, just funcitons to save
typing LOTS_OF_THINGS = IN_CAPS. Or is this not the
direction libgba should take?

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.