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.

Beginners > Centering a Mode 5 picture

#43391 - Impatient - Mon May 23, 2005 12:50 am

I have a mode 5 image that I need to center on the GBA display. I seem to recall there is a bit somewhere you just flick, and that centers the Mode5, am I correct?

#43395 - strager - Mon May 23, 2005 1:34 am

To center a box:

Code:

/* n - new */
/* s - screen */
/* b - box */

nx = (sw/2) - (bw/2);
ny = (sh/2) - (bh/2);

BG2X = nx << 8;
BG2Y = ny << 8;


Plug in some numbers:
Code:

nx = (240/2) - (160/2);
ny = (160/2) - (128/2);

BG2X = nx << 8;
BG2Y = ny << 8;


Do the math:
Code:

nx = 160 - 80 = 80;
ny = 80 - 64 = 16;

BG2X = nx << 8;
BG2Y = ny << 8;


And shift:
Code:

nx = 80;
ny = 16;

BG2X = 80 << 8 = 0x5000;
BG2Y = 16 << 8 = 0x1000;


So all you have to do is this:
Code:

BG2X = 0x00005000;
BG2Y = 0x00001000;


Do you understand my weird method of teaching?

#43403 - Impatient - Mon May 23, 2005 2:17 am

oh, indeed I understand your math. But I am displaying a Mode5 picture and I want the entire "Mode5" which is smaller than the normal fullscreen Mode3 centered. I was sure there was a bit in some register you just pulled to achieve this.

#43599 - Impatient - Wed May 25, 2005 1:44 am

works now like a dream!

#43600 - Impatient - Wed May 25, 2005 1:55 am

by the way, your values are wrong! they should be:

0xFFFFD7FF
0xFFFFEFFF