Multiple Backgrounds Help

Post Reply
elnanni
Posts: 23
Joined: Sat Nov 14, 2009 1:41 am

Multiple Backgrounds Help

Post by elnanni » Sat Nov 14, 2009 2:07 am

Hi, I'm new to homebrew, I sought the answer in many places - including this forum -, but could not find it :(.

Each time I start to think that I understood how to use the backgrounds, I realize I don't, he.

I'm trying to place two backgrounds in my application, code is like this:

Code: Select all

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

#include "nanniWare.h" //256*192px
#include "mumei.h" //256*192px
#include "dracko.h" //64*64px

int main(void){

  videoSetMode(MODE_5_2D);
  videoSetModeSub(MODE_5_2D);

  PrintConsole pcTop = *consoleInit(0, 1, BgType_Text4bpp, BgSize_T_256x256, 0, 1, true, true);
  PrintConsole pcBtm = *consoleInit(0, 1, BgType_Text4bpp, BgSize_T_256x256, 0, 1, false, true);

  vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
  vramSetBankB(VRAM_B_MAIN_BG_0x06000000);
  vramSetBankC(VRAM_C_SUB_BG_0x06200000);

  int bgMainSplash = bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 2, 0);
  bgSetCenter(bgMainSplash, 128, 128);
  bgSetRotateScale(bgMainSplash, 0, 1 << 8, 1 << 8);
  bgSetScroll(bgMainSplash, 128, 128);
  bgSetPriority(bgMainSplash, 3);
  bgUpdate();
  dmaCopy(nanniWareBitmap, bgGetGfxPtr(bgMainSplash), nanniWareBitmapLen);

  int bgDracko = bgInit(2, BgType_Bmp16, BgSize_B16_256x256, 2, 0);
  bgSetCenter(bgDracko, 0, 10);
  bgSetRotateScale(bgDracko, 0, 1 << 8, 1 << 8);
  bgSetScroll(bgDracko, 0, 0);
  bgSetPriority(bgDracko, 2);
  bgUpdate();
  dmaCopy(drackoBitmap, bgGetGfxPtr(bgDracko), drackoBitmapLen);

  int bgSubSplash = bgInitSub(2, BgType_Bmp16, BgSize_B16_256x256, 2, 0);
  bgSetCenter(bgSubSplash, 0, 10);
  bgSetRotateScale(bgSubSplash, 0, 1 << 8, 1 << 8);
  bgSetScroll(bgSubSplash, 0, 0);
  bgSetPriority(bgSubSplash, 2);
  bgUpdate();
  dmaCopy(mumeiBitmap, bgGetGfxPtr(bgSubSplash), mumeiBitmapLen);

  iprintf("\x1b[%i;%iH%s", 0, 0, "Text");

  return 0;

}
If I comment this line dmaCopy(drackoBitmap, bgGetGfxPtr(bgDracko), drackoBitmapLen); I realize that bgMainSplash and bgDracko have the same data, I really don't know why, because when I use the bgInit for the first I'm using layer 3 and for the second I use layer 2, I think it's the same than doing this:

Code: Select all

  REG_BG3CNT = BG_BMP16_256x256;

  REG_BG3PA = 1 << 8;
  REG_BG3PB = 0;
  REG_BG3PC = 0;
  REG_BG3PD = 1 << 8;

  REG_BG3X = 0;
  REG_BG3Y = 0;
and:

Code: Select all

  REG_BG2CNT = BG_BMP16_256x256;

  REG_BG2PA = 1 << 8;
  REG_BG2PB = 0;
  REG_BG2PC = 0;
  REG_BG2PD = 1 << 8;

  REG_BG2X = 0;
  REG_BG2Y = 0;
But it does not work as I want :(.

a screenshot:

Image

Discostew
Posts: 103
Joined: Sun Mar 08, 2009 7:24 pm

Re: Multiple Backgrounds Help

Post by Discostew » Sat Nov 14, 2009 3:18 am

You've got a problem with conflicting vram bank allocations (bankA & bankB) because they are set up for the same position in memory. You're also gonna have a problem with your Main console (or Top in this case) because each 256x256 bmp bg take up an entire bank, and both will be filled, leaving no space for it, and will likely corrupt the bitmaps. Now, you can probably fix this issue if your BGs aren't scrolling vertically, and just set up the consoleInit function for your Main console to use that unused space of one of the BGs.

elnanni
Posts: 23
Joined: Sat Nov 14, 2009 1:41 am

Re: Multiple Backgrounds Help

Post by elnanni » Mon Nov 16, 2009 2:22 am

>>You've got a problem with conflicting vram bank allocations (bankA & bankB) because they are set up for the same position in memory.
So, I should use G or F???

>>You're also gonna have a problem with your Main console (or Top in this case) because each 256x256 bmp bg take up an entire bank, and both will be filled, leaving no space for it, and will likely corrupt the bitmaps.
An example from Jaden Amero does this successfully.

>>Now, you can probably fix this issue if your BGs aren't scrolling vertically, and just set up the consoleInit function for your Main console to use that unused space of one of the BGs.
Code :S???

I'm in a hurry now :(, but I hope in this week have more time to talk about this issue :S...

Discostew
Posts: 103
Joined: Sun Mar 08, 2009 7:24 pm

Re: Multiple Backgrounds Help

Post by Discostew » Mon Nov 16, 2009 5:00 am

elnanni wrote:So, I should use G or F???
What I meant by that is that both are enums to reference to the address 0x06000000. What you'll want to do is make them different. Also, bankF and bank G don't have enough space allocation for the bitmaps (16KB each vs the 96KB needed for a 256x192 16-bit image). Stick with bankA and bankB, but don't set them to the same position.
elnanni wrote:An example from Jaden Amero does this successfully.
That only 2 banks for the Main screen are used, but that there is 2 bitmap BGs being used along with the console on the same screen?

elnanni wrote:Code :S???
Atm, I can't. I haven't made something like that myself. I'm just speculating the way it can be done with the info that we have at places like GBATek.
Actually, I'm glad you had asked about this, because when I checked GBATek about how to do this, I believe to have found a discrepancy between that and the libnds headers.
GBATek wrote:screen base used in bitmap modes as BGxCNT.bits*16K, without DISPCNT.bits*64K
libnds wrote:// In bitmap modes, this is multiplied by 64KB and added to BG_BMP_BASE
#define DISPLAY_SCREEN_BASE(n) (((n)&7)<<27)
I believe that GBATek is correct on this, because according to that, by using solely the screen base of the BG, you'd have reference to all 512KB of main vram space, but with what libnds says, if the display screen base and bg screen base are added together, that would reference up to twice that amount, which cannot be, since there isn't even a combined amount of vram that big. That's under the assumption that the libnds version is based off of GBATek's notion of screen base changing from 2KB to 16KB increments for bitmap modes.

I'll get back to you on the idea of using only 2 main banks for 2 bitmap BGs on the main screen and a console on both screens together, but it should be as simple as shifting the screen base for your first bitmap BG by at least 1 (offsetting it by 16KB, but still within the 128KB boundary for your 256x192 16bit image), and then in your consoleInit for the main (top) screen, setting the charbase to 0 and mapbase to 7.

elnanni
Posts: 23
Joined: Sat Nov 14, 2009 1:41 am

Re: Multiple Backgrounds Help

Post by elnanni » Tue Nov 17, 2009 7:04 pm

Thanks :D, it worked with a mapBase of 8, I still don't get it 100%, why changing this value, what I think it does is an offset of the VRAM, but isn't VRAM supposed to do this by telling:

VRAM_A_MAIN_BG_0x06000000 and then VRAM_B_MAIN_BG_0x06020000.

I will be happy if you can explain me the bgInit, kind of for dummies.

Sylus101
Posts: 179
Joined: Wed Dec 24, 2008 5:08 am

Re: Multiple Backgrounds Help

Post by Sylus101 » Wed Nov 18, 2009 12:34 am

VRAM_A_MAIN_BG_0x06000000 and VRAM_B_MAIN_BG_0x06020000

I'm not going to say this quite right, but I'll try. All of VRAM actually starts at address 0x06800000. When you're using those enumerations above, you're setting up the VRAM Control Registers and defining a particular usage for them. When the hardware goes looking for graphical data for the main engine backgrounds, it's always going to start at 0x06000000 offset by the mapbase for the map (or bmp data for bmp type backgrounds) or tilebase for the tile data. To make use of another bank, it needs to be setup "behind" the first bank registered, in this case at 0x06200000 (a 128KB offset, the size of the 1st bank).
-Sylus "Not Stylus..." McFrederickson

Come visit my web site.

elnanni
Posts: 23
Joined: Sat Nov 14, 2009 1:41 am

Re: Multiple Backgrounds Help

Post by elnanni » Thu Nov 19, 2009 4:05 pm

Ok, so, I think we can close this thread :D.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest