Problem Setting Up Backgrounds and VRAM

Post Reply
TiagoGomes
Posts: 5
Joined: Wed Feb 20, 2013 4:03 pm
Location: Brazil

Problem Setting Up Backgrounds and VRAM

Post by TiagoGomes » Wed Feb 20, 2013 5:01 pm

I've been working on a project for nds lately and got stuck on a problem while trying to setup backgrounds.

As a starting point I tried the following setup:
> Mainscreen: Text and BMP Framebuffer
> Subscreen: BMP Framebuffer

Here is the code:

Code: Select all

  System::System( void )
  {
    videoSetMode     ( MODE_5_2D );
    videoSetModeSub( MODE_5_2D );

    vramSetBankA( VRAM_A_MAIN_BG );
    vramSetBankB( VRAM_B_MAIN_BG );
    vramSetBankC( VRAM_C_SUB_BG  );

    consoleInit( NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 4, 0, true, true );
    
    bgIndex = bgInit( 2, BgType_Bmp16, BgSize_B16_256x256, 5, 0 );
    this->mainScreen.setFrameBuffer( ( u16 * ) bgGetGfxPtr( bgIndex ) );
    
    bgIndex = bgInitSub( 3, BgType_Bmp16, BgSize_B16_256x256, 0, 0 );
    this->subScreen.setFrameBuffer( ( u16 * ) bgGetGfxPtr( bgIndex ) );
  }
The problem is whenever I try to draw on the buffers and print text I get graphic artifacts, which from what I read is probably being caused by backgrounds sharing the same piece of VRAM memory, but I can't figure out how to properly setup my backgrounds.

I'd really appreciate if anyone could help me with this problem and maybe give some insight on how to setup Backgrounds and VRAM Banks.

Thanks in advance.

mtheall
Posts: 211
Joined: Thu Feb 03, 2011 10:47 pm

Re: Problem Setting Up Backgrounds and VRAM

Post by mtheall » Mon Feb 25, 2013 4:23 pm

This is sort of a duplicate of this post, but with these settings, but in this example VRAM_B is correctly mapped to account for going over the 128KB boundary. This setup should not be experiencing artifacts, so we may need more info about what you're doing (maybe paste the code where you're drawing).

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: Problem Setting Up Backgrounds and VRAM

Post by elhobbs » Mon Feb 25, 2013 10:50 pm

you may want to take a look at this in an emulator like desmume. It may be something as simple as layer 1 being active/visible and showing garbage. with an emulator you can look at each layer individually.

TiagoGomes
Posts: 5
Joined: Wed Feb 20, 2013 4:03 pm
Location: Brazil

Re: Problem Setting Up Backgrounds and VRAM

Post by TiagoGomes » Tue Feb 26, 2013 9:26 pm

Yes mtheall, this was a duplication of this post and that's my bad. As a first time poster I didn't notice posts had to be accepted by administrator and I thought it was some sort of error my post the fact that my post did not appear, so I posted again.
Regarding the problem, here is a screenshot of my result with the following code.

Image

Code used for initialization:

Code: Select all

  System::System( void )
  {
    videoSetMode   ( MODE_5_2D );
    videoSetModeSub( MODE_5_2D );

    vramSetBankA( VRAM_A_MAIN_BG );
    vramSetBankB( VRAM_B_MAIN_BG );
    vramSetBankC( VRAM_C_SUB_BG  );

    consoleInit( NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 4, 0, true, true );
    
    bgIndex = bgInit( 2, BgType_Bmp16, BgSize_B16_256x256,5, 0 );
    this->mainScreen.setFrameBuffer( ( u16 * ) bgGetGfxPtr( bgIndex ) );
    
    bgIndex = bgInitSub( 3, BgType_Bmp16, BgSize_B16_256x256, 0, 0 );
    this->subScreen.setFrameBuffer( ( u16 * ) bgGetGfxPtr( bgIndex ) );
  }
Redraw function:

Code: Select all

static Framework::Geometry::Rectangle area( 0, 0, 100, 100 );

void drawScreens( void )
{  
  if ( !contains )
  {
    systemHandler->subScreen.drawRectangle ( area, Framework::Util::Color::CYAN );
    systemHandler->mainScreen.drawRectangle( area, Framework::Util::Color::CYAN );
  } else
  {
    systemHandler->subScreen.drawRectangle ( area, Framework::Util::Color::BLACK );
    systemHandler->mainScreen.drawRectangle( area, Framework::Util::Color::BLACK );
  }
  
  consoleClear( );
  
  printf( "Player 1 life points: %d\n", player1.lifePoints );
  printf( "Player 2 life points: %d\n", player2.lifePoints );
}
drawRectangle method:

Code: Select all

void Screen::drawRectangle( const Geometry::Rectangle & rec  ,
                            u16                         color,
                            uint8                       layer )
{
  for ( auto column = rec.bottomLeft.x; column < rec.topRight.x; ++column )
  {
    for ( auto line = rec.bottomLeft.y; line < rec.topRight.y; ++line )
    {
      this->frameBuffer[ line * 256 + column ] = color;
    }
  }
}
As you can see, a blue and a noisy line appear.
Thanks for your time.

TiagoGomes
Posts: 5
Joined: Wed Feb 20, 2013 4:03 pm
Location: Brazil

Re: Problem Setting Up Backgrounds and VRAM

Post by TiagoGomes » Sat Mar 16, 2013 5:01 pm

Sorry for not replaying in a while, I was busy with my university.
Anyway, I actually found out what the problem was, it was caused by a call to "consoleDemoInit()", which I forgot to take out and was setting VRAM_C for text, prior to the code snippet I showed. After taking it out, all went as expected.
Thanks for the help and attention.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests