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 > [SOLVED] Background Woes - Main BG going black

#160707 - thesean - Sun Jul 20, 2008 9:04 pm

Hi all, I'm having what I'm guessing is a simple problem, but I can't figure it out =/

I'm displaying 2 backgrounds, one on main, one on sub, and printing console text to the sub screen. All of this works fine. I was using a third background on the main screen, a 128x128 one, but I don't want to use it at this point and have commented it out.

When I comment out the third background, my main screen background goes black, but only if it's horizontal scroll register is set to 0. If I set the scroll register to anything greater than 0, it shows up fine, otherwise, the whole main screen goes black (and covers up 1 of my 2 sprites).

If anyone has any hints toward what to check for, I'd be very grateful. Here's the code in question:

Code:

BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_PRIORITY(3) | BG_WRAP_ON;

    BG3_XDX = 1 << 8;
    BG3_XDY = 0;
    BG3_YDX = 0;
    BG3_YDY = 1 << 8;
   //background at origin
    BG3_CX = 0;
    BG3_CY = 0;

    /*  Don't want to use this BG at the moment (causes main bg to go black when h_scroll <= 0)
    //BG2_CR = BG_BMP16_128x128 | BG_BMP_BASE(6) | BG_PRIORITY(2);

    //BG2_XDX = 1 << 8;
    //BG2_XDY = 0;
    //BG2_YDX = 0;
    //BG2_YDY = 1 << 8;

    //place at correct spot...
    //BG2_CX = -(SCREEN_WIDTH / 2 - 32) << 8;
    //BG2_CY = -32 << 8;   */

   // setup bg3 control
   // SUB_BG3_CR is the register that controls BG3's behavior on the sub-display
   // this is the top screen background (works fine)
   SUB_BG3_CR = BG_BMP16_256x256 |  BG_BMP_BASE(0) | BG_PRIORITY(2) | BG_WRAP_ON;
   
   SUB_BG3_XDX=1<<8;
   SUB_BG3_XDY=0;
   SUB_BG3_YDX=0;
   SUB_BG3_YDY=1<<8;  //1<<8 =  256
   
   // scroll the bg past the section used by the console
   SUB_BG3_CY = 16<<8; // CY is a fixed point number, 16*256 = 16.0 pixels

   //character tiles occupy map bases 0 and 1
   //setup the console bg to map base 2
   SUB_BG0_CR = BG_MAP_BASE( 2 );

   //copy the backgrounds in to MM
   dmaCopyHalfWords(DMA_CHANNEL, botbgBitmap, (uint16 *) BG_BMP_RAM(0), botbgBitmapLen); //main
   //dmaCopyHalfWords(DMA_CHANNEL, planetBitmap, (uint16 *)BG_BMP_RAM(8), planetBitmapLen);//main - not used for now
   dmaCopyHalfWords(DMA_CHANNEL, topbgBitmap, (uint16 *)BG_BMP_RAM_SUB(0)+(8*1024)/2, topbgBitmapLen); //sub + 8 KB from console

The perplexing part (and probably for a simple reason) is that if I don't comment out this line:
Code:
//BG2_CR = BG_BMP16_128x128 | BG_BMP_BASE(6) | BG_PRIORITY(2);
the whole thing works fine...

Last edited by thesean on Sun Jul 20, 2008 10:09 pm; edited 1 time in total

#160708 - Maxxie - Sun Jul 20, 2008 9:19 pm

Unset the enable bit for bg2 in the (sub)screen mode.

Leaving (sub_)BG2_CR in undefined state (whatever it was set before) doesn't disable it.
_________________
Trying to bring more detail into understanding the wireless hardware

#160711 - thesean - Sun Jul 20, 2008 10:08 pm

Aha, that did the trick, thanks so much!

For documentation purposes, I changed:
Code:

videoSetMode(MODE_5_2D | // Set the graphics mode to Mode 5
                 DISPLAY_BG2_ACTIVE | // Enable BG2 for display
                 DISPLAY_BG3_ACTIVE | // Enable BG3 for display
                 DISPLAY_SPR_ACTIVE | // Enable sprites for display
                 DISPLAY_SPR_1D       // Enable 1D tiled sprites
   );


to

Code:

videoSetMode(MODE_5_2D | // Set the graphics mode to Mode 5
                 //DISPLAY_BG2_ACTIVE | // Enable BG2 for display
                 DISPLAY_BG3_ACTIVE | // Enable BG3 for display
                 DISPLAY_SPR_ACTIVE | // Enable sprites for display
                 DISPLAY_SPR_1D       // Enable 1D tiled sprites
   );


Can't believe I didn't see that myself. Thanks, Maxxie!