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 > Warning Message I don't get

#42815 - Impatient - Sun May 15, 2005 6:53 am

warning: large integer implicitly truncated to unsigned type
WHY??

in this code:


Code:

#define RGB16(r,g,b) ((r)<<PLTT_RED_SHIFT|((g)<<PLTT_GREEN_SHIFT)|((b)<<PLTT_BLUE_SHIFT))

{
    unsigned char x;
    unsigned char y;
    unsigned short int *ptr_vram = (unsigned short int*)VRAM;

    *(volatile unsigned short int *)REG_DISPCNT = DISP_MODE_3 | DISP_BG2_ON;

    for(x = 0; x < LCD_WIDTH-1; x++)
        for(y = 0; y < LCD_HEIGHT-1; y++)
            ptr_vram [x+ y * LCD_WIDTH] = RGB16(0xff,0xff,0xff);
}

#42816 - sajiimori - Sun May 15, 2005 7:02 am

The value you are creating with the RGB macro is greater than what can fit in a 16 bit value. The color components are 5 bits each, so the blue component (which is in the highest bits) is shifted left 10 bits. If you shift 0xff left 10 bits, then you have an 18 bit value because 0xff is 8 ones. Use 5 ones: 0x1f.

#42820 - Impatient - Sun May 15, 2005 7:14 am

but 0x1f,0x1f,0x1f is not true white color is it??? I thought that was 0xff,0xff,0xff which is the same as 255,255,255 ..

me confused even more :-(

PS but you were right ... replacing 0xff with 0x1f got rid of the warning ...

#42821 - sajiimori - Sun May 15, 2005 7:18 am

GBA uses 15 bit color, not 24 bit. The maximum value for a color channel is 31.

#42827 - Kyoufu Kawa - Sun May 15, 2005 10:17 am

sajiimori wrote:
GBA uses 15 bit color, not 24 bit. The maximum value for a color channel is 31.
...aka 0x1f in case you don't see it.

#42855 - poslundc - Sun May 15, 2005 7:35 pm

Impatient wrote:
but 0x1f,0x1f,0x1f is not true white color is it??? I thought that was 0xff,0xff,0xff which is the same as 255,255,255 ..

me confused even more :-(


You really are impatient.

Work through some of the beginner tutorials already.

Dan.

#42857 - sajiimori - Sun May 15, 2005 7:40 pm

I guess somebody had to say it eventually. :P

#42859 - Impatient - Sun May 15, 2005 7:54 pm

point taken. I will seek advise elsewhere.

#42903 - Lupin - Mon May 16, 2005 3:24 pm

The GBA color components go only from 0-31. So each color can only be in a range from 0-31 (because each color channel has 5 bits, 2^5-1 = 31)

On a PC a 32 bit or 24 bit color each channel would have a range from 0-255

You got your question answered by sajimori already, too bad you don't understand binary :(

Btw, this is the correct macro to define a 16 bit color on the GBA (i dont know if yours is correct):

#define RGB16(r,g,b) (((b)<<10)+((g)<<5)+(r))
_________________
Team Pokeme
My blog and PM ASM tutorials

#42949 - sgeos - Tue May 17, 2005 10:56 am

You should be using int for general purpose variables. Don't bother with unsigned chars, signed longs, etc until you have a real reason to use them. The ram you are saving is not a big deal, and ints will run faster.

-Brendan

#42993 - strager - Tue May 17, 2005 10:01 pm

Try this, to prevent confusion:

Code:

/* If you don't have this already... */
typedef unsigned long int u32;
typedef unsigned short int u16;

/* Define variables */
#define RS 0
#define GS 5
#define BS 10
#define B32TO16S 4

/* Bit maskers */
#define COLV16(c) ( (c) & 31 )
#define COLV32(c) ( (c) & 255 )

/* Color converters */
#define COL32TO16(c) ( COLV16(COLV32(c) >> B32TO16S) )
#define RGB16(r,g,b) ( (u16)( (COLV16(r) << RS) | (COLV16(g) << GS) | (COLV16(b) << BS)) )
#define RGB32(r,g,b) ( RGB16(COL32TO16(r), COL32TO16(g), COL32TO16(b) )


You may need to increase the B32TO16S value 1, or maybe decrease. That number is just off the top of my head.

Greets.

#43116 - Ultima2876 - Thu May 19, 2005 7:15 am

Why do ints run faster?

#43117 - tepples - Thu May 19, 2005 7:26 am

The size of an int is implementation defined. The standard encourages implementations of C (i.e. compilers) to make int the fastest integer data type, meaning it's usually the same size as a machine register. Smaller types stored in registers usually have to be sign-extended or zero-extended every time they're assigned to.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.