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.

DS development > Question concerning sprites.

#79262 - Dark Knight ez - Wed Apr 12, 2006 3:31 pm

Hey everybody. Yet another question. This time concerning sprites.

I've been checking out several tutorials/examples which use sprites, but they do not give enough information for me to fully comprehend it all. Why some specific values are used, amongst other things.

Using Patater's guide, the sprite initializing (palette and graphics) seems to crash (or at least stay stuck therein for a VERY long time - didn't have the patience to check).
To be more precise, this seems to happen in the for-loop which addresses SPRITE_GFX_SUB. (Note that I used '0' as gfxID in the code by commenting that piece out.)
Code:
    //copy in the sprite palettes
    dmaCopy(sprite_pal_bin, (uint16 *)SPRITE_PALETTE_SUB, sprite_pal_bin_size); //size of data to copy
    //copy the sprite grahics in obj graphics mem
    for(unsigned int i=0; i<font_8x8_digits_bin_size << 16; i++)
        SPRITE_GFX_SUB[/*font_8x8_gfxID * 16 +*/ i] = ((uint16*)font_8x8_digits_bin)[i];

Now, my question is, why is there in the for-loop a 16(!) bit-shift to the left and if that's not the fault here, what else could it be?

Oh, one remark which might affect things:
The graphics I'm using (font_8x8_digits_bin) was actually a 88*8 picture. Would I be right in assuming that once that's loaded in properly, I could just pick out the x-th tile by using x as gfxID? (The picture contains all the digits and a ':' symbol in a row.)

Thanks in advance for any help.

#79418 - Dark Knight ez - Thu Apr 13, 2006 4:16 pm

Adjusted the for-loop to be this:

Code:
for(unsigned int i=0; i<font_8x8_digits_bin_size << 2; i++)
        SPRITE_GFX_SUB[i] = ((uint16*)font_8x8_digits_bin)[i];


Having replaced << 16 with << 2, since that would make more sense to me. (Effectively cutting the for-loop in half, since two bytes are written each time instead of one.) It seems to me the tutorial is just wrong on that one, but I can see why the wrong value was used (16 bits = 2 bytes).

Now at least the first tile is displayed properly. The other tiles seem almost random (using attribute 2 to choose the xth tile). It might be a problem with converting the picture, I don't know.
Using gfx2gba, would this be the correct way to convert the 88x8 pcx file?
gfx2gba.exe in.pcx out.bin -8 -z 256 -b -p out_pal.bin
(At least the palette seems to be okay this way)

#79558 - Dark Knight ez - Fri Apr 14, 2006 9:37 am

It seems I needed to use 2x as gfxID for the xth tile. It's fixed now.
This because I'm using 256 colours, which takes up twice as much space for one tile as in the other case.
Really wished tutorials would be more in depth on this aspect.


Last edited by Dark Knight ez on Fri Apr 14, 2006 7:49 pm; edited 1 time in total

#79636 - Dark Knight ez - Fri Apr 14, 2006 7:48 pm

For future reference, I made a mistake with this as well (although the bugs were not obvious at first). Not only was the bit-shift value wrong -- it should be shifted by 1 bit which means the size is altered by a factor of two -- also the direction was completely wrong. It should be dimished by a factor of two, not enlarged.

So this old code:
Code:
for(unsigned int i=0; i<font_bin_size << 16; i++)
        SPRITE_GFX_SUB[i] = ((uint16*)font_bin)[i];

Becomes this:
Code:
for(unsigned int i=0; i<font_bin_size >> 1; i++)
        SPRITE_GFX_SUB[i] = ((uint16*)font_bin)[i];


Meaning Patater's tutorial was also double wrong on this aspect.
Hope this helps out others who experience problems using sprites.

#92639 - mhackman - Fri Jul 14, 2006 8:22 am

For a custom font I have a 32x32 sprite table with 96 items. The picture size is 32x3072. The picture shows: ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E.......etc....well you get the picture ;)
I am using this code:

Code:

dmaCopy(palette_bin, SPRITE_PALETTE_SUB, 256*2);
dmaCopy(font_bin, SPRITE_GFX_SUB, 32*3072);


I know that there are a lot of other code possibilities like :
Code:

   for(i = 0; i < font_bin_size; i++) {
      SPRITE_GFX_SUB[i] = (font_bin[i*2]) | ((font_bin[i*2+1])<<8);
   }


or

Code:

   for(i = 0; i < font_bin_size << 1; i++) {
      SPRITE_GFX_SUB[i] = ((uint16*)font_bin)[i];
   }


etc....it's all works. The problem is that in Dualis OAM view I only get to see these characters: ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ?. After that the tiles will repeat.

I am using gfxID 0, 32, 64, 98, etc... ( += 32 )

The bins are created with: gfx2gba myfont.bmp font.bin -8 -z 256 -b -p palette.bin

Is there a limit of 32 tiles for 32x32 that I can load??

#93289 - Dark Knight ez - Tue Jul 18, 2006 10:58 am

First of all, dmaCopy might be fast, but it tends to make things crash.
Even when it works on your own set-up, on others it could create a crash or other unwanted behaviour.

Having said that, in what VRAM bank are you trying to put your sprites? Is it big enough to hold it all? You will want to use a VRAM bank which is equal or larger than 96 kb in size. (see http://www.bottledlight.com/ds/index.php/Video/Modes)
Hope that helps.