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 > n00b topic - how to display a sprite on the sub screen

#108006 - djmcbell - Sat Nov 04, 2006 12:46 am

Yep, I'm willing to bet you've had absolutely *LOADS* of these, but here we are again. I've been using the Patatersoft tutorial, which assures me I should have a sprite up and going on the bottom screen. Which would be nice and dandy, except there isn't. It displays on the top (and my modified version below displays nothing on top, as expected, but nothing on bottom), but how do I display it on the bottom instead?

I'm just using a ball sprite (I'm trying to get up and running by creating my own little vertical Pong demo, but that's by the by) so here's the important code -

updateOAM - I know I should be writing to OAM_SUB, but I don't know the settings
Code:
//Update the OAM - OAM_SUB
void updateOAM(SpriteEntry * spriteEntry)
{
   DC_FlushAll();
   dmaCopy(spriteEntry, OAM, 128 * sizeof(SpriteEntry));
}


InitVideo - I've changed a few things on the subscreen, I don't think it should make a different here
Code:
void initVideo()
{
   /*map vram to display a bg on the main and sub screen and give us lots
   of sprites*/
   vramSetMainBanks( //map A and B to main background memory
               //this gives us 256KB which is a healthy amount for
               // 16-bit gfx
               VRAM_A_MAIN_BG_0x6000000,
               VRAM_B_MAIN_BG_0x6020000,
               //map C to sub background memory
               VRAM_C_SUB_BG_0x6200000,
               //map D to LCD free space
               VRAM_D_LCD);
   //map a bank for use with sprites
   vramSetBankE(VRAM_E_MAIN_SPRITE);
   //mapping E to main sprites gives us 64k for sprites
   //(64k is the max space that 1024 tiles take up in 256 color mode)
   //set the video mode on the main screen
   videoSetMode( MODE_5_2D | //set the graphics mode to Mode 5
            DISPLAY_SPR_ACTIVE | //turn on sprites
            DISPLAY_BG3_ACTIVE | //turn on background 3
            DISPLAY_SPR_1D); //this is used when in tile mode
   //set the video mode on the sub screen
   videoSetModeSub(MODE_5_2D |
            DISPLAY_SPR_ACTIVE |
            DISPLAY_BG3_ACTIVE |
            DISPLAY_SPR_1D);
}


And our initSprites itself - again, changed the sprite so that it *should* go into the submemory
Code:
void initSprites(SpriteEntry * spriteEntry, SpriteRotation * spriteRotation)
{
   //init OAM
   initOAM(spriteEntry, spriteRotation);
   ballx = SCREEN_WIDTH/2 - 64;
   bally = SCREEN_HEIGHT/2 - 64;
   //create the ball sprite
   int ballGfxID = 64;
   spriteEntry[0].attribute[0] = ATTR0_COLOR_256 |
                     ATTR0_ROTSCALE_DOUBLE | //able to rotscale
                     bally;
   spriteEntry[0].attribute[1] = ATTR1_ROTDATA(0) |
                     ATTR1_SIZE_64 | //size 64x64
                     ballx;
   spriteEntry[0].attribute[2] = ballGfxID;
   //set initial rotation attributes
   rotateSprite(&spriteRotation[0], 0);
   //copy in the sprite palettes
   dmaCopy(ballpalette_bin, //from address
      (uint16 *)SPRITE_PALETTE_SUB, //to address
      ballpalette_bin_size); //size of data to copy
   //copy the sprite graphics in obj graphics mem
   dmaCopy(balldata_bin, //from address
      &SPRITE_GFX_SUB[ballGfxID * 16], //to address
      balldata_bin_size); //size of data to copy
   //update the OAM
   updateOAM(spriteEntry);
}


I've been doing some GBA coding (quite enjoying that) but really want to get into DS coding, so any quick help here would be appreciated.[/code]

#108009 - Lick - Sat Nov 04, 2006 12:57 am

You need to reserve some VRAM for the VRAM_x_SUB_SPRITE.

Code:
void updateOAM_SUB(SpriteEntry * spriteEntry)
{
   DC_FlushAll();
   dmaCopy(spriteEntry, OAM_SUB, 128 * sizeof(SpriteEntry));
}

_________________
http://licklick.wordpress.com

#108035 - djmcbell - Sat Nov 04, 2006 5:59 pm

Thanks Lick, but unfortunately this is a case of "been there, done that".

I have tried what you said, and that's not working. I have no doubt that it's reserving the memory as it's supposed to, but it doesn't appear to show up.

If it helps, I'm using dualis as my emulator to try it with.

#108046 - thegamefreak0134 - Sat Nov 04, 2006 7:47 pm

Have you tried testing on real hardware? I've heard lots of issues with the emulators not liking the whole screen swap thing at all.
_________________
What if the hokey-pokey really is what it's all about?

[url=http:/www.darknovagames.com/index.php?action=recruit&clanid=1]Support Zeta on DarkNova![/url]

#108144 - djmcbell - Sun Nov 05, 2006 10:33 pm

Well, that was annoying but I got it. Mapped sub-sprites to bank D (did a Google search on sprite banks) and it worked. So my sprite was correct, I just didn't have them going anywhere.

Thanks for all the help anyhow guys. No, I don't have anything to test it on (I do have a DS with a 256mb EFA linker, but no PassMe1 device yet - I've checked and that's the one I'd need). Only just getting started though at the minute.

#108146 - Lick - Sun Nov 05, 2006 10:41 pm

Lick wrote:
You need to reserve some VRAM for the VRAM_x_SUB_SPRITE.

djmcbell wrote:
Well, that was annoying but I got it. Mapped sub-sprites to bank D (did a Google search on sprite banks) and it worked. So my sprite was correct, I just didn't have them going anywhere.

So I was right. =/
_________________
http://licklick.wordpress.com

#108340 - djmcbell - Tue Nov 07, 2006 9:53 pm

*apologies for necro-post*

Yep, I just mis-understood your reply. I had tried the OAM_SUB but hadn't reserved anything for sub sprites. Thanks!