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

#99439 - neonext - Mon Aug 21, 2006 6:34 pm

I'm stuck on getting 2 different backgrounds to display at the same time. If I only display either one on hardware, it works fine. If I try to copy both backgrounds into memory, I get 2 black screens of death on hardware (no sprites etc, the game obviously crashes). If i copy both backgrounds and run in an emulator, it works fine. I'm still a newb with ds homebrew, so i'm probably making an obvious mistake, that hopefully someone will point out.

i'm using 8bit bitmap backgrounds. i'd actually prefer to do them tilemapped, cause i've heard if you do it right you can save a lot of memory, but i haven't found any multilayer tilemapped background tutorials that i understand. besides, if i can get these to work, they will be good enough for what i'm trying to do.

here's what i've got with the bitmap backgrounds, minus the rotation and position attributes, which i highly doubt are related to the problem
Code:

 videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D);
videoSetModeSub(MODE_5_2D | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D);

vramSetMainBanks(VRAM_A_MAIN_BG_0x6000000, VRAM_B_MAIN_BG_0x6020000, VRAM_C_LCD , VRAM_D_SUB_SPRITE);

 BG2_CR = BG_BMP8_256x256 | BG_BMP_BASE(0) | BG_WRAP_ON | BG_PRIORITY(0);
 BG3_CR = BG_BMP8_256x256 | BG_BMP_BASE(8) | BG_WRAP_ON | BG_PRIORITY(1);

dmaCopy(back1_bottom3Pal, BG_PALETTE, 256*2);
dmaCopy(back1Bitmap, (uint16*)BG_BMP_RAM(0), 256*256);
dmaCopy(back2Bitmap, (uint16*)BG_BMP_RAM(8), 256*256);


i've tried changing the BASE/RAM values, and i've tried loading without using dmaCopy, and i always get the same results. please help, this is the last thing i can think of that i would get stuck on. all other aspects of the game (sprites, sound, file loading, etc) work great

#99475 - Lick - Tue Aug 22, 2006 12:05 am

You should probably not use dmaCopy (it sucks on hardware, dun ask me why) and set the 15th bit (alphabit) to 1, for each pixel.
_________________
http://licklick.wordpress.com

#99487 - neonext - Tue Aug 22, 2006 1:07 am

i tried not using dmacopy. i get the same exact results. works as expected copying only one of the 2 backgrounds, but copying both gives 2 black screens. in all cases, it works as expected (one layer upon the other) on an emulator

also, isnt the alpha bit only for 16bit mode?

#99511 - knight0fdragon - Tue Aug 22, 2006 3:15 am

I get weird effects with BMP_RAM, try using &BG_GFX[0x10000]
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#99524 - neonext - Tue Aug 22, 2006 5:29 am

thanks for the suggestion knightOfdragon, unfortunately i got the same results. they show up as expected individually, but not when used together (except in Dualis). I don't get it, do i have to use an additional palette or something? i'm completely out of ideas

#99527 - knight0fdragon - Tue Aug 22, 2006 7:19 am

look at my sample code at http://hyperclubbingfriends.yourfreewebspace.com/Knight0fDragon/

i made one that should help you
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#99635 - neonext - Tue Aug 22, 2006 9:03 pm

sweetness. i tested the code by itself in my build environment and it works perfect on hardware. when i get a chance, i will try to incorporate my graphics and sound into it. maybe the real problem was from how i was using some of those assets. thanks for the help

#99660 - neonext - Wed Aug 23, 2006 2:04 am

using the 2 bmp's example, i manage to get my graphics to work, but i had to edit the source code you gave me. in case someone else tries to do the same, i'll let you know what lines i changed (maybe they were mistakes, because it seems like this was just a hacked version of the other example). first of all, i changed
Code:

videoSetMode(MODE_5_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG3_ACTIVE );

to
Code:

videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE );

because later in the example it sets up to rotation attributes for BG2 not BG0 (isn't BG0 strickly tile mode anyways? this is mostly what leads me to believe it was a copy and paste sort of error from the other example)

also changed
Code:

BG2_CR = BG_BMP8_256x256 | BG_BMP_BASE(8) | BG_PRIORITY(3);

to
Code:

BG2_CR = BG_BMP8_256x256 | BG_BMP_BASE(0) | BG_PRIORITY(3);

to point to the first section of background memory instead of the same as BG3

the code would not work with my included graphics without these changes. i'm a little confused about the display priorities. do the earlier backgrounds automatically get priority if equal to the later ones?

anyways, all i need to do is hook up my sprites and my sound now, and i'm all set. thank you tons for your help. if everything goes smooth and this ever gets a homebrew release, i will mention u somewhere if u dont mind

EDIT: i'm already running into problems, my interrupt handler is making it crash, it seems like while it's filling in the background data (or displaying, i dont know), because i can see the top of the picture, and it stops halfway through one of the lines of pixels

#99664 - knight0fdragon - Wed Aug 23, 2006 4:09 am

oops lol ok i fixed my stuff, i was working off the tile demo and i moved to that quickly, I now made use of the D-Pad to move BG3 without moving BG2 to show my work
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#99994 - neonext - Fri Aug 25, 2006 7:15 am

i've definitally got the hang of it now. i've got 4 different backgrounds, 2 tiled and 2 bitmapped, all scrolling at different speeds, using only one of the 4 main vram banks =) it looks pretty sweet

#100014 - Lick - Fri Aug 25, 2006 12:15 pm

Man, show us the sweetness.. :D And sorry bout not being helpful earlier..
_________________
http://licklick.wordpress.com