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.

C/C++ > 256 colors to 16 colors

#26412 - Mephisto - Wed Sep 15, 2004 12:36 am

To display a sprite, i use dma, to put sprite info into vram
In 256 colors mode, i use this code and it works fine.
Code:
unsigned char* SpriteData;

REG_DM3SAD = (u32)&SpriteData[***];
REG_DM3DAD = (u32)&VRAM[***];
REG_DM3CNT = TileWidth * TileHeight / 2 | DMA_16NOW;



but recently i needed to switch to 16 colors mode, but with the following code, VRAM is filled only 1 colomn / 2 ...
Code:
unsigned char* SpriteData;

REG_DM3SAD = (u32)&SpriteData[***];
REG_DM3DAD = (u32)&VRAM[***];
REG_DM3CNT = TileWidth * TileHeight / 4 | DMA_16NOW;


what do i need to change ? plz
(to avoid any array fusion)

#26414 - sajiimori - Wed Sep 15, 2004 1:41 am

Nothing -- just make sure you're reading from a halfword-aligned address.

#26418 - Mephisto - Wed Sep 15, 2004 2:00 am

how do you "shift" an adress, incrementing it ?
so it would be
Quote:
(u32)&SpriteData[***] + 4;

but it doesnt work, always fill 1 colomn on 2

#26420 - sajiimori - Wed Sep 15, 2004 2:48 am

I don't know why you're adding anything to the address, but adding 4 to the address is the same as adding 4 to the value inside the brackets (since SpriteData is u8*).

#26430 - Mephisto - Wed Sep 15, 2004 3:11 pm

My Spritedata in 256 color was like :
{ 0xFF, 0xFF, 0xFF, ... }

But in 16 color with the same bmp2gba converting tool its like :
{ 0x0F, 0x0F, 0x0F, ... }

that why VRAM is filled 1 colomn on 2, so there is no way to display well without fusing ...
So if anyone use well Tilestudio and the GBA_C_SPRITE.tsd of Edorul, could tell me how to fuse 2 pixels ( ( (pixel + 1) << 4) + pixel ), i didnt do it succefully ...
i dont really understand this language ^^

Code:
#tinytiles 8 8
const unsigned short <ProjectName>_<TileSetIdentifier>_Tiles[] = {
#tstile
   // Tile <TileNumber>
#tiledata "\n   "  ","  ",\n   "  ",\n   "  ",\n"
<(Pixel+1):"%3d">
#end tiledata
#end tstile
   0 };
#end tinytiles
#end tileset

#26440 - sajiimori - Wed Sep 15, 2004 6:05 pm

Maybe you're giving the wrong arguments to bmp2gba, or maybe you should switch to gfx2gba since people seem to like it.

#26441 - Mephisto - Wed Sep 15, 2004 7:18 pm

the bmp2gba tool is TileStudio ^^

#26479 - Quirky - Thu Sep 16, 2004 8:15 pm

The sprite data should be 4 bits per pixel for 16 colour sprites.

16 colour pixels using colour 15: 0F 0F 0F 0F
as 16 colour data they are 2 bytes> FF, FF
as 256 colour data they are 4 bytes> 0f, 0f, 0f, 0f

Do you see what I mean? You have to "pack" your 4 bits together. Now gfx2gba does this, it looks like what you use doesn't (or not with the options you give it at least) - it treats your 16 colour image as though it has 256 colours, possibly because you need to tell it otherwise.