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 > Sprite Data

#170144 - Azenris - Thu Sep 03, 2009 5:11 pm

Hi I was hoping you could help me with something

how exactly is the sprite data sorted, stored before being used in the memory.
basically this is what I have

Code:

dmaCopy(g_StandardGamePalette, SPRITE_PALETTE, g_StandardGamePalette_size);
dmaCopy(tile_graphic_272_, &SPRITE_GFX[0], 256);


I have tested it with an old bin file of a sprite i used to have
and got it to work so im assuming the problem is with how ive stored the
data.

the tile stored as

Code:

const u8 tile_graphic_272_[] = {
   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
   0,  0,  0,  0,  0,  0,134,134,134,134,  0,  0,  0,  0,  0,  0, 
   0,  0,  0,  0,  0,134, 81, 81, 81, 81,134,  0,  0,  0,  0,  0,
   0,  0,  0,134, 81, 81, 81, 81, 81, 81,134,  0,  0,  0,  0,  0,
   0,  0,  0,134, 81, 81, 81, 81,  9, 81,134,  0,  0,  0,  0,  0, 
   0,  0,  0,134, 81, 81, 81, 81,  9, 81,134,  0,  0,  0,  0,  0,
   0,  0,  0,134, 81, 81, 81,  9, 81, 81,134,  0,  0,  0,  0,  0,
   0,  0,  0,  0,134, 81, 81, 81, 81,134,  0,  0,  0,  0,  0,  0,
   0,  0,  0,  0,  0,134,134,134,134,  0,  0,  0,  0,  0,  0,  0,
   0,  0,  0,  0,  0,  0,  0,  0,134,  0,  0,  0,134,  0,  0,  0,
   0,  0,  0,  0,  0,  0,  0,  0,  0,134,134,134,  0,  0,  0,  0,
   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
}; // end of tile_graphic_272_


the palette is stored as

Code:

const u16 g_StandardGamePalette[] = {
0x7C7F,0x1B20,0x3260,0x180,0x26C,0x1A73,0x18D3,0x318C,0x18C6,0x7FFF,0x1B,0x27FD,0x1B60,0x0,0x7FFF,
0x4E73,0x3FF,0x5EF7,0x1F,0x3180,0x6666,0x33E6,0x4F26,0x6660,0x7D86,0xDF,0x27F,0x19F,0x193,0x1993,
0x279,0x273,0x1B33,0x3F9,0x33E0,0x3F3,0x33F,0x1B26,0x3E6,0xD3,0x339,0x1A7F,0x1BFF,0x1A60,0x332C,0x1BF9,
0x67E6,0x658C,0x333,0x30DF,0x1B3F,0x6413,0x4E6C,0x7FE0,0xCC,0x1999,0x18C,0x32C,0xD9,0x13,0x1B39,0x199,
0x6,0x30D3,0x199F,0x33F3,0x7F26,0x64D3,0x19,0x3266,0x4D80,0x4CC0,0x327F,0x7CD9,0x7FF9,0x6673,0x13,
0x33F,0x1B2E,0x64C0,0x7D93,0x1F,0x3FF,0x2BF3,0x7F26,0x7CCC,0x3193,0x333F,0x7FF3,0x7E60,0x672C,0x67F3,
0x4F2C,0x7FE6,0x7E6C,0x4F39,0x67E0,0x666C,0x7FEC,0x7F2C,0x3E0,0x260,0x320,0x4E79,0x4E66,0x4FFF,0x4FEC,
0x7F39,0x6720,0x67EC,0x180,0x1A60,0x3000,0x7C00,0x4E73,0x26C,0x7F20,0x19,0x4C19,0x3320,0x3260,0x1A6C,
0x672C,0x4FFF,0x18C6,0x4F26,0x7F2C,0x30DF,0x199F,0x6726,0x4FE6,0x7E66,0x6739,0x4FF9,0x14,0x3EC,0x1BF3,
0x33E6,0x7FE0,0x333F,0x1A7F,0x7F33,0x4FE0,0x318C,0x67E6,0x4E7F,0x181F,0x327F,0x658C,0x1B20,0x4E6C,0x332C,
0x1BEC,0x4F20,0x67F9,0x4FF3,0x6580,0x7FEC,0x7E73,0x33F9,0x6673,0x6733,0x67FF,0x18C0,0x3279,0x180C,0x1B2C,
0x1BEC,0x7D80,0x3326,0x326C,0x3273,0x18C,0x3181,0x5EE2,0x6650,0x4260,0x11A0,0x2A62,0x2B40,0x1260,0x7CDF,
0x7C1F,0x77AB,0x326C,0x1B2C,0x1819,0x1B26,0x18C0,0x7FF9,0x33FF,0x7FF,0x4E60,0x199,0x32C,0xC,0x7D80,0x673F,
0x4D9F,0x6580,0x339,0x667F,0x7D9F,0x19F,0x4F20,0x7F20,0x1B3F,0x3279,0x4CC0,0x27F,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
}; // end of g_StandardGamePalette[]


When i run the code I end up with a weird looking scrible. from the colours I can see it
is showing correctly, so I think the palette is ok.

any ideas what im misunderstanding or doing wrong :( TY in advance
_________________
My Homebrew Games

#170145 - Kyoufu Kawa - Thu Sep 03, 2009 5:43 pm

Azenris wrote:
how exactly is the sprite data sorted, stored before being used in the memory.
Same way in both. Depending on the graphics mode, it's either four bits per pixel reversed (like on the MD/Genesis but in another order) or eight bits per pixel.

Imagine you have a palette that goes black, red, white in that order. Each byte of tile data is worth two pixels:
Code:

{
  0x01, 0x20, 0x02, 0x10,
  0x10, 0x20, 0x02, 0x01,
  0x00, 0x01, 0x10, 0x00,
  0x22, 0x10, 0x01, 0x22,
  0x22, 0x10, 0x01, 0x22,
  0x00, 0x01, 0x10, 0x00,
  0x10, 0x20, 0x02, 0x01,
  0x01, 0x20, 0x02, 0x10
};


That would be a red X mark with white blobs on each side. Replacing each nibble (half of a byte) with characters, you'd get this:
Code:

.#$..$#.
#.$..$.#
...##...
$$#..#$$
$$#..#$$
...##...
#.$..$.#
.#$..$#.


Reversing the order of each pair of nibbles, you get this recognizable shape, as described:
Code:

#..$$..#
.#.$$.#.
..#..#..
$$.##.$$
$$.##.$$
..#..#..
.#.$$.#.
#..$$..#


Eight bits per pixel has each byte be a color index.

#170146 - Cearn - Thu Sep 03, 2009 5:50 pm

The problem is that tile_graphic_272_ isn't tiled. A GBA/NDS tile always means a 8x8 tile. In tiled format, memory is laid out tile-for-tile, not scanline-for-scanline like regular bitmaps. tile_graphic_272_ is stored as a 16x16 bitmap, which comes out wrong because the hardware will use the data as 8x8 tiles. This mismatch of formats tends to end up messy.

Most graphics converters can translate from bitmapped to tiled data for you. If you want to translate in-game, you'd have to write your own function for that.

#170147 - Azenris - Thu Sep 03, 2009 6:26 pm

Im not actually trying to do tiles, its a sprite. I know its a weird name.

yea not using a standard graphics converter, my sprites where being made by my map editor. tile_graphic_272_ is actually a cherry sprite. It starts as a bitmap and I wanted to make it a sprite which could then by written to the sprite graphics memory and pointed to by the sprites.

the reason it was called tile was actually I was hoping I could store an image once in a const array and use it for both tiles and spites. I thik I understand the tiling problem and how I will have to create the tileset ingame. But i dont understand the sprite problem.

I thought it would be a byte per pixel (as the palette is 256 in size). My video setup is

Code:

void InitVideo(u8 screen)
{
   if (screen == GAME_SCREEN)
   {
      // init the main screen
      vramSetBankA(VRAM_A_MAIN_BG_0x06000000);   // bank a: (main)   bg memory
      vramSetBankB(VRAM_B_MAIN_BG_0x06020000);   // bank b: (main)   bg memory
      vramSetBankE(VRAM_E_MAIN_SPRITE);         // bank e: (main)   sprites

      videoSetMode(MODE_0_2D |         // use mode 0
                DISPLAY_SPR_ACTIVE |   // enable sprites
                DISPLAY_BG0_ACTIVE |   // enable BG0 layer 0
                DISPLAY_BG1_ACTIVE |   // enable BG1 later 1
                DISPLAY_BG2_ACTIVE |   // enable BG2 undefined
                DISPLAY_SPR_1D);      // map sprites as 1D

      REG_BG0CNT = BG_32x32 | BG_COLOR_256 | BG_MAP_BASE(0) | BG_TILE_BASE(1) | BG_PRIORITY(2);   // setup the background 0
      REG_BG1CNT = BG_32x32 | BG_COLOR_256 | BG_MAP_BASE(1) | BG_TILE_BASE(2) | BG_PRIORITY(2);   // setup the background 1
      REG_BG2CNT = BG_32x32 | BG_COLOR_256 | BG_MAP_BASE(2) | BG_TILE_BASE(3) | BG_PRIORITY(2);   // setup the background 2

      // init the sub screen
      vramSetBankC(VRAM_C_SUB_BG_0x06200000);      // bank c: (sub)   bg memory

      videoSetModeSub(MODE_0_2D |               // use mode 0
                  DISPLAY_BG0_ACTIVE |      // enable BG0
                  DISPLAY_BG1_ACTIVE);      // enable BG1


   }
}


EDIT:

[Images not permitted - Click here to view it]
_________________
My Homebrew Games

#170149 - Cearn - Thu Sep 03, 2009 8:06 pm

Azenris wrote:
Im not actually trying to do tiles, its a sprite. I know its a weird name.

Both backgrounds and objects use tiled graphics (well mostly), so you still need the conversion.

#170152 - Azenris - Thu Sep 03, 2009 9:13 pm

ok i understand, gonna try it out, thanks.

EDIT:

just came back to say I got it working, i mean all except my image is upside down, but thats how the bitmap is stored, will just have to flip it before writing it to the array. But anyway got it working thanks.
_________________
My Homebrew Games