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 > Sprites show in Dualis, but not Hardware [SOLVED]

#114873 - JessTicular - Thu Jan 11, 2007 6:01 am

Howdy :)

I'm not exactly new to DS development, but this one has me stumped!

I've set up and am using sprites (tall rotated, square rotated and just square), all of which display perfectly in Dualis, and function without any worries.

However, when I upload it to my DS (WiFiMe), the sprites simply wont show. All the game logic works, I can still press the buttons, and the touch-screen interface works fine, yet no Sprites...

some code:
main_arm9.cpp (main code)
sprites.cpp (sprite handling)

and a binary so you can check for yourself (to make sure it's not my DS :P)
xmas.nds (~723KB)
( The game-logic for the code and binary supplied have been removed to make sure none of that was interfering )


Thanks for any and all help that you can provide!

Jess.

[SOLUTION]

The problem was with the Alpha.
I had: sprites[0].attribute[2] = ATTR2_ALPHA(0)
When I should have had: sprites[0].attribute[2] = ATTR2_ALPHA(1)

I don't know why its different between hardware and emulator, but it is, and lesson learnt!

[/SOLUTION]
_________________
Nintendo DS & Dominos :: DS Dominos
http://jt0.org


Last edited by JessTicular on Sat Jan 13, 2007 8:35 am; edited 1 time in total

#114890 - JessTicular - Thu Jan 11, 2007 9:32 am

Ok, I extended my searching outside of just the NDS boards and found this thread that has a similar problem.

I'm pretty sure that that is the problem, as I have read (quite a few times actually) about it. I'll go and try it now :)

[EDIT]
Nope, no-go... I'm writting u16's which should be perfectly safe.
[/EDIT]

[EDIT2]
I'm not even doing that, I'm copying entire blocks (admittedly, non-aligned blocks) of the entire image across at a time!
[/EDIT2]
_________________
Nintendo DS & Dominos :: DS Dominos
http://jt0.org


Last edited by JessTicular on Thu Jan 11, 2007 4:04 pm; edited 1 time in total

#114910 - Lick - Thu Jan 11, 2007 3:15 pm

Don't use DMACopy. Use memcpy (string.h) instead.

Also, try adding DISPLAY_SPR_1D_LAYOUT.
_________________
http://licklick.wordpress.com

#114915 - JessTicular - Thu Jan 11, 2007 4:03 pm

I never thought of trying memcpy instead of dmaCopy, but unfortunately it didn't work, and neither did the DISPLAY_SPR_1D_LAYOUT flag.

Thanks all the same, though.
_________________
Nintendo DS & Dominos :: DS Dominos
http://jt0.org

#115002 - koryspansel - Fri Jan 12, 2007 3:26 am

This is just a (long) shot in the dark...but, maybe, you need to update the OAM in your main loop? It would seem pretty ridiculous for the DS to clear the OAM each frame, but that could explain why it works on the emulator.

--
Kory

#115134 - JessTicular - Sat Jan 13, 2007 4:50 am

koryspansel,

Unforunatly that doesn't work either :( Good idea, though.
_________________
Nintendo DS & Dominos :: DS Dominos
http://jt0.org

#115141 - JessTicular - Sat Jan 13, 2007 5:54 am

Alright, this is getting to be rediculous...

I've pretty much mutilated my code to bring it to down to the very, very basics of what should be done to get a sprite to work.
And yet, it still doesn't work :(

Looky;

Code:

#include <nds.h>
#include <stdio.h>
#include <cstdlib>
#include <string.h>


// Sprites
SpriteEntry sprites[128];

//turn off all the sprites
void initSprites(SpriteEntry* sprites)
{
   for(int i = 0; i < 128; i++){
      sprites[i].attribute[0] = ATTR0_DISABLED; // 'Hidden' Bit Setter
      sprites[i].attribute[1] = 0;
      sprites[i].attribute[2] = 0;
      sprites[i].attribute[3] = 0;
   }
}

//copy our sprite to object attribute memory
void updateOAM(SpriteEntry* sprPtr, int size)
{
   DC_FlushAll();
   dmaCopy(sprPtr, OAM, size * sizeof(SpriteEntry));
}


//---------------------------------------------------------------------------------
void VblankHandler(void) {
//---------------------------------------------------------------------------------
   if(REG_IF & IRQ_VBLANK) {
      // Handle vertical blank interrupt
      VBLANK_INTR_WAIT_FLAGS |= IRQ_VBLANK;
      REG_IF |= IRQ_VBLANK;
   }else{
      // Ignore all other interrupts
      REG_IF = REG_IF;
   }

}

//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------

   powerON(POWER_ALL_2D);
   irqInit();
   irqSet(IRQ_VBLANK, VblankHandler);
   irqEnable(IRQ_VBLANK);
   lcdSwap();

   // Set the mode to 0 and activate 1D Sprites
   videoSetMode(MODE_0_2D | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_BMP);

   // Map VRAM A to sprite memory
   vramSetBankA(VRAM_A_MAIN_SPRITE);

   // hide all sprites
   initSprites(sprites);

   // copy sprite data to hardware
   updateOAM(sprites, 128);

   // fill in a red blob
   for(uint16 i = 0; i < 1024; i++){
      SPRITE_GFX[i] = RGB15(31,0,0) | (1 << 15);
   }


   // Sprite
   // Set the attributes
   sprites[0].attribute[0] = ATTR0_BMP | ATTR0_TALL;
   sprites[0].attribute[1] = ATTR1_SIZE_64 | 0;

   // set the positions and what-not now
   sprites[0].attribute[2] = ATTR2_ALPHA(0) | ATTR2_PRIORITY(1) | 0;   // Tile-number (tiles are 8x8)
   

   sprites[0].attribute[0] &= 0xFF00;      // Remove the position data
   sprites[0].attribute[0] |= (97 & 0x00FF);   // put in the Y position data

   sprites[0].attribute[1] &= 0xFE00;      // Remove the position data
   sprites[0].attribute[1] |= (24 & 0x01FF);   // put in the X position data


   // reflect the changes in hardware
   updateOAM(sprites, 128);


   while(1) {

      swiWaitForVBlank();

   }   // END While

   return 0;
}

_________________
Nintendo DS & Dominos :: DS Dominos
http://jt0.org

#115151 - JessTicular - Sat Jan 13, 2007 8:35 am

The problem was with the Alpha.
I had: sprites[0].attribute[2] = ATTR2_ALPHA(0)
When I should have had: sprites[0].attribute[2] = ATTR2_ALPHA(1)

I don't know why its different between hardware and emulator, but it is, and lesson learnt!
_________________
Nintendo DS & Dominos :: DS Dominos
http://jt0.org