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 > multiple backgrounds

#58931 - ventilo - Thu Oct 27, 2005 11:48 am

Hi everybody,

Sorry, I'm a noob so it is probably a dumb question, but.... I cannot see the way for multiple backgrounds.... using mode 5, I set the following:

videoSetMode(MODE_5_2D | DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_ACTIVE | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE);
vramSetBankA(VRAM_A_MAIN_BG_0x6000000);
vramSetBankB(VRAM_B_MAIN_BG_0x6020000);
vramSetBankC(VRAM_C_SUB_BG);
vramSetBankD(VRAM_D_LCD);
vramSetBankE(VRAM_E_MAIN_SPRITE);
BG2_CR = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_PRIORITY(1);
BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(16 /* times 16k */) | BG_PRIORITY(2);

then if I write bitmaps to BG_GFX or to BG_BMP_RAM(0) I see them, however if I write bitmaps to BG_BMP_RAM(16) I do not see anything

Please can you explain how to write to either background ? How to display both ? which is rendered "on top" of the other ? does it depend on bg priority ?

Ventilo
_________________
Firstname's Y.A.N.N..... yet another NDS noob :o)

#58935 - strager - Thu Oct 27, 2005 12:29 pm

ventilo wrote:
then if I write bitmaps to BG_GFX or to BG_BMP_RAM(0) I see them, however if I write bitmaps to BG_BMP_RAM(16) I do not see anything

Please can you explain how to write to either background ? How to display both ? which is rendered "on top" of the other ? does it depend on bg priority ?

Ventilo


"I do not see anything"
Do you mean that the upper layer is not displayed? Or the bottom layer is not shown at all?

"does it depend on bg priority"
Yes, it does. Backgrounds with a higher priority are rendered first, thus are shown "behind" everything with a lower priority.

Make sure you are not setting the alpha bit for the top layer, so that the bottom layer is visible.

#58958 - ventilo - Thu Oct 27, 2005 4:48 pm

Thanks for the answer

I was assuming the other way for the priorities, however the problem remains.

I just write one bitmap, either at BG_BMP_RAM(0) or at BG_BMP_RAM(16), i.e. I wish to write to BG2 or to BG3. It works for the former but not for the latter ("I do not see anything"), hence I guess BG3 is not writable at BG_BMP_RAM(16) ?

Next thing will be to display both backgrounds at the same time :o)
_________________
Firstname's Y.A.N.N..... yet another NDS noob :o)

#58959 - dovoto - Thu Oct 27, 2005 4:55 pm

Quote:
BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(16 /* times 16k */) | BG_PRIORITY(2);


should it not be
Quote:
BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(8 /* times 16k */) | BG_PRIORITY(2);


size of background bmp:
256x256x2 = 128KB

bmp base:
8 x 16KB = 128 KB

you have:
16x16KB = 256KB (which is above vram bank B the way you have it mapped currently)

It is early and it is never good to do the math in my head so maybe i am just misstaken...
_________________
www.drunkencoders.com

#58961 - ventilo - Thu Oct 27, 2005 4:56 pm

How right you are, many thanks

Ventilo
_________________
Firstname's Y.A.N.N..... yet another NDS noob :o)

#67993 - Zhen - Sat Jan 21, 2006 10:43 pm

I have a similar problem, I need the mode 5 to combine a framebuffer with sprites and tile maps. But in order to get space for put in the tile data I reserve two vramBanks, the first one to tiles and the second one to put the framebuffer.

Code:

   videoSetMode( MODE_5_2D /*| DISPLAY_BG0_ACTIVE */| DISPLAY_BG2_ACTIVE );
    vramSetBankA( VRAM_A_MAIN_BG_0x6000000 );
    vramSetBankB( VRAM_B_MAIN_BG_0x6020000 );
    //BG0_CR = BG_PRIORITY(0) | BG_MAP_BASE( 31 ) | BG_TILE_BASE( 0 ) | BG_256_COLOR | BG_32x32;
    BG2_CR = BG_PRIORITY(0) | BG_BMP_BASE( 8 ) | BG_BMP16_256x256;

    m_bufferMain = (uint16*)BG_BMP_RAM( 8 );
   


The problem is that when i use BG_BMP_BASE( 0 ) as framebuffer it is well . But when i use BG_BMP_BASE( 8 ) as framebuffer I see nothing.

It's really possible to combine in mode 5 sprites + tiles + framebuffer? whats is the correct layout and cofiguration of memory banks?
I use dsemu-0.4.9 to test my code.