Page 1 of 1

[solved] 512x512 backgrounds not displaying

Posted: Thu Mar 05, 2009 12:55 pm
by awesomejuice
Hi there, I'm working with a team trying to make an NDS game, and we're stumped trying to get 512x512 backgrounds displaying. Our code is below; we have no idea what we're doing wrong or simply not doing what we should be because the documentation we've found is sparse and tutorials covering this all seem to stop immediately before making this work. Any help is appreciated.

Code: Select all

#include <nds.h>
#include <stdio.h>
#include "rah.h" // our grit-generated graphics header

int main(void)
{
   // Turn on 2d graphics core
   powerOn ( POWER_ALL_2D );
   
   // Video mode
   videoSetMode ( MODE_5_2D | DISPLAY_BG3_ACTIVE );

   // Tried these three as well as vramSetMainBanks, equally unsuccessful:
   //
   //vramSetBankA ( VRAM_A_MAIN_BG_0x06000000 );
   //vramSetBankA(VRAM_A_MAIN_BG);
   //vramSetBankB(VRAM_B_MAIN_BG);

   vramSetMainBanks(
            VRAM_A_MAIN_BG_0x06000000,
            VRAM_B_MAIN_BG_0x06020000,
            VRAM_C_MAIN_BG_0x06040000,
            VRAM_D_MAIN_BG_0x06060000);

   consoleDemoInit();

   // Taken from one of the examples
   iprintf("\n\n\tHello DS devers\n");
   iprintf("\twww.drunkencoders.com\n");
   iprintf("\t256 color bitmap demo");

   // Initialize our background and place it in memory
   int bg1 = bgInit( 3, BgType_Bmp8, BgSize_B8_512x512, 0, 0 );
   dmaCopy( rahBitmap, bgGetGfxPtr(bg1), rahBitmapLen );
   dmaCopy( rahPal, BG_PALETTE, rahPalLen );

   while(1)
   {
      swiWaitForVBlank();
   }

   return 0;
}

Re: 512x512 backgrounds not displaying

Posted: Fri Mar 06, 2009 5:32 pm
by Sylus101
If you've updated to the latest libnds...

You don't need powerOn ( POWER_ALL_2D );

videoSetMode ( MODE_5_2D ); is fine, the bg will be made active inside the bgInit function.

Instead of using bgGetGfxPtr(bg1) when coping the bitmap data, try just BG_GFX. I think bgGetGfxPtr(bg1) should work, but just for sake of argument...

Everything else looked fine as far as I can tell.

Re: 512x512 backgrounds not displaying

Posted: Sun Mar 08, 2009 3:36 am
by awesomejuice
Nevermind. Using memcopy instead of dmacopy seems to have worked for us.

Re: 512x512 backgrounds not displaying

Posted: Sun Mar 08, 2009 11:03 am
by mido
awesomejuice wrote:Nevermind. Using memcopy instead of dmacopy seems to have worked for us.
I believe that you can't DMA Copy onto the stack (which your bg1 variable is).
I could be wrong but that's my understanding. I've had issues with DMA Copy before and it had to do with moving memory to/from the stack. Has to be global I think.

Re: 512x512 backgrounds not displaying

Posted: Sun Mar 08, 2009 11:22 am
by Sylus101
mido wrote:
awesomejuice wrote:Nevermind. Using memcopy instead of dmacopy seems to have worked for us.
I believe that you can't DMA Copy onto the stack (which your bg1 variable is).
I could be wrong but that's my understanding. I've had issues with DMA Copy before and it had to do with moving memory to/from the stack. Has to be global I think.
The dmaCopy wouldn't have been writing to bg1, it would have been writing to the location that bgGetGfxPtr(bg1) returns which is a pointer to a VRAM memory address. I should have worked...