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 > Sprite not showing up

#117826 - pmcc - Wed Feb 07, 2007 10:31 pm

Hey,
I started homebrew development a few days ago and I'm stuck on sprites. Like the title of this thread says, my sprite is not showing up on my DS / Dualis / no$gba but IT DOES in desmume...I'm trying to figure out what's wrong with my code and it's driving me crazy for 2 days now :).
I'm using devkitPro and libnds.
Here's some portions of my code :

Code:

  powerON(POWER_ALL_2D);
  // Map vram, one bg and sprite banks for each core
  vramSetMainBanks(VRAM_A_MAIN_BG,
         VRAM_B_MAIN_SPRITE,
               VRAM_C_SUB_BG,
         VRAM_D_SUB_SPRITE);
  // Set video mode to mode 0 (0,1,2,3 -> text) with sprites support
  eng.SetVideoMode(MODE_0_2D | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_LAYOUT);
  eng.SetSubVideoMode(MODE_0_2D | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_LAYOUT);
  // Enable main and sub background 1
  eng.EnableBackground(1);
  eng.EnableSubBackground(1);
  // Load palette into memory
  eng.LoadPalette(tilesetPal);
  eng.LoadSubPalette(tilesetPal);
  // Set main background 1
  eng.SetBackgroundTileBase(1, 0);
  eng.SetBackgroundMapBase(1, 30);
  eng.SetBackgroundColors(1, BG_COLOR_256);
  // Set sub background 1
  eng.SetSubBackgroundTileBase(1, 1);
  eng.SetSubBackgroundMapBase(1, 31);
  eng.SetSubBackgroundColors(1, BG_COLOR_256);
  // Copy our tiles data into memory where the hardware is expecting them
  dmaCopy(tilesetTiles, (void*)CHAR_BASE_BLOCK(0), sizeof (tilesetTiles));
  dmaCopy(tilesetTiles, (void*)CHAR_BASE_BLOCK_SUB(1), sizeof (tilesetTiles));
  // Copy one half of the map in each screen memory
  for (int i = 0; i < 768; ++i)
    {
      ((u16*)SCREEN_BASE_BLOCK(30))[i] = test_map[i];
      ((u16*)SCREEN_BASE_BLOCK_SUB(31))[i] = test_map[i + 768];
    }
  eng.InitOAM();
  // temp code...
  SpriteEntry* sprites = eng.GetSprites();
  sprites[0].attribute[0] = ATTR0_COLOR_16 | ATTR0_SQUARE | OBJ_Y(50);
  sprites[0].attribute[1] = ATTR1_SIZE_8 | OBJ_X(50);
  // temp code...
  for (int i = 0; i < sizeof (ballPal); ++i)
    {
      SPRITE_PALETTE[i] = ballPal[i];
    }
  for (int i = 0; i < sizeof (ballTiles); ++i)
    {
      SPRITE_GFX[i] = ballTiles[i];
    }
  while(1)
    {
      swiWaitForVBlank();
      dmaCopy(eng.GetSprites(), OAM, 1024);
      dmaCopy(eng.GetSubSprites(), OAM_SUB, 1024);
    }

void CEngine::InitOAM()
{
  m_sprites = new SpriteEntry[128];
  m_spritesRotation = reinterpret_cast<SpriteRotation*>(m_sprites);
  m_spritesSub = new SpriteEntry[128];
  m_spritesRotationSub = reinterpret_cast<SpriteRotation*>(m_spritesSub);
  for (int i = 0; i < 128; ++i)
    {
      m_sprites[i].attribute[0] = ATTR0_DISABLED;
      m_sprites[i].attribute[1] = 0;
      m_sprites[i].attribute[2] = 0;
      m_spritesSub[i].attribute[0] = ATTR0_DISABLED;
      m_spritesSub[i].attribute[1] = 0;
      m_spritesSub[i].attribute[2] = 0;
    }
  for (int i = 0; i < 32; ++i)
    {
      m_spritesRotation[i].hdx = 256;
      m_spritesRotation[i].hdy = 0;
      m_spritesRotation[i].vdx = 0;
      m_spritesRotation[i].vdy = 256;
      m_spritesRotationSub[i].hdx = 256;
      m_spritesRotationSub[i].hdy = 0;
      m_spritesRotationSub[i].vdx = 0;
      m_spritesRotationSub[i].vdy = 256;
    }
}


Well...like I said it shows up perfectly on desmume. I've checked first sprite entry in dualis and everything is ok (size, colors, etc) but it doesn't display the sprite preview...
Kudos to anyone that can help me on this one !
Thanks.
_________________
www.gotrooted.net

#117830 - pmcc - Wed Feb 07, 2007 11:22 pm

Ok so, I found out what was wrong *points to libnds VRAM defines*.
SPRITE_GFX is memory address 0x6400000, VRAM_B_MAIN_SPRITE is in fact 0x6420000 so memory address 0x6400000 was not mapped...swapped VRAM_B_MAIN_SPRITE with VRAM_B_MAIN_SPRITE_0x6400000 and now my sprite is showing up.
_________________
www.gotrooted.net

#117899 - Mr Snowflake - Thu Feb 08, 2007 3:00 pm

The VRAM_*_MAIN_ are always follow ups. If you plan on using VRAM_B_MAIN_SPRITE you should also use VRAM_A_MAIN_SPRITE As the VRAM_A_MAIN_SPRITE is mapped to the first Sprite block. That's why lot of programs always use the VRAM_B_MAIN_SPRITE_0x?????00 form
_________________
http://www.mrsnowflake.be

#117965 - Lick - Thu Feb 08, 2007 10:57 pm

Also, don't use dmaCopy but use memcpy.
_________________
http://licklick.wordpress.com

#117992 - pmcc - Fri Feb 09, 2007 12:33 am

Why should I use memcpy over dmaCopy / dmaCopyWords?
_________________
www.gotrooted.net