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 > Fixed point format for registers

#45270 - jormundgard - Thu Jun 09, 2005 3:34 am

Hi, this is probably a simple question, but I haven't been able to confirm it.

I know that the rotation/scaling registers (BGxPA, etc.) are in a fixed point format (1 sign, 7 integer, 8 fractional), but I wasn't sure exactly what format it was. Playing around, it looks like it might be a 2s complement, but I wasn't sure and wanted to ask about it. Is it 2s complement, 1s complement, or just a sign bit?

#45289 - poslundc - Thu Jun 09, 2005 6:38 am

The IO registers all use two's-complement, the same internal representation used by the C compiler and the ARM7. This means you can safely assign a negative number or signed variable directly to the register from within C.

Dan.

#45442 - jormundgard - Fri Jun 10, 2005 6:35 pm

Thanks, reading my docs made it seem like there was a just a sign bit, and I was told that ARM uses 1s comp (which I'm not so sure about anymore), yet the little output I could check was 2s comp.

As for the BGxX_L, BGxX_H registers, is there any advice on managing these? I've just been doing arithmetic on 32bit signed data, then doing something like
Code:

BG2X_L = x0;
BG2X_H = x0 >> 16;

which seems like it should be sensible, since 2s comp just repeats the leading bits when youre within some +/- range of zero.

#45446 - poslundc - Fri Jun 10, 2005 6:55 pm

Just use the entire 32-bit register, BG2X. Don't treat the low and high half-words separately.

Code:
int     x = 134 << 8;     // Fixed point 24.8 format
int     y = -47 << 8;

BG2X = x;
BG2Y = y;


Dan.

#45447 - jormundgard - Fri Jun 10, 2005 6:57 pm

Even better! Thanks