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 > Extrange problem with background

#105095 - Lupi - Thu Oct 05, 2006 11:11 pm

I load two backgrounds into memory and then I assign BG0_CR and BG0_X0, BG0_Y0 as well as with BG3, it works fine in a emulator but I can't see BG0 in my DS hardware.

There is nothing extrange in the code, I load a background as always, if any of you have a clue, please share it, because I have no idea :S:S...


Code:
void LoadBG_BG(){
   dmaCopy(BG_img_bin,(void*)BG_TILE_RAM(0), BG_img_bin_size);
   dmaCopy(BG_map_bin,(void*)BG_MAP_RAM(8),BG_map_bin_size );
}

void LoadBG_Overview(){
   dmaCopy(Overview_img_bin,(void*)BG_TILE_RAM(2), Overview_img_bin_size);
   dmaCopy(Overview_map_bin,(void*)BG_MAP_RAM(24),Overview_map_bin_size );
}


This is how I load both tiled bg into memory...

Thanks in advance

#105100 - Dark Knight ez - Thu Oct 05, 2006 11:15 pm

Try to use memcpy instead of dmaCopy and see if it makes a difference.
There were many situations in DS homebrew which I created, where dmaCopy failed to work.

#105101 - Lupi - Thu Oct 05, 2006 11:25 pm

Tried with memcpy

Code:
void LoadBG_BG(){
   memcpy((void*)BG_TILE_RAM(0), BG_img_bin, BG_img_bin_size);
   memcpy((void*)BG_MAP_RAM(8), BG_map_bin, BG_map_bin_size );
}

void LoadBG_Overview(){
   memcpy((void*)BG_TILE_RAM(2), Overview_img_bin, Overview_img_bin_size);
   memcpy((void*)BG_MAP_RAM(24),Overview_map_bin, Overview_map_bin_size );
}


same results :(

Maybe is in this function to inizialite video:

Code:
void IniciaVideo(){
   vramSetMainBanks(VRAM_A_MAIN_BG_0x6000000,
                VRAM_B_LCD,
                VRAM_C_SUB_BG_0x6200000,
                VRAM_D_LCD);

   videoSetMode(MODE_0_2D |
             DISPLAY_BG0_ACTIVE | DISPLAY_BG3_ACTIVE);
   videoSetModeSub(0);

}


I am also adding powerON(POWER_ALL_2D); at the very start
?What can it be hapening?

PD: Excuse my english please :P

#105107 - Dark Knight ez - Thu Oct 05, 2006 11:41 pm

You do set the seperate background registers properly, right?
Like:
Code:
BG0_CR = bla;

Where "bla" consists out of bg priority, the location of the tile base, the map base, etc.

edit:
For "bla" I have the following for example:
Code:
BG_PRIORITY_0 | BG_TILE_BASE(1) | BG_MOSAIC_OFF | BG_256_COLOR | BG_MAP_BASE(29) | BG_WRAP_ON | BG_32x32

#105108 - Lupi - Fri Oct 06, 2006 12:00 am

I don't do exactly that way...

I'm doing a Background class to manage easily all the registers, here is a piece of the constructor:

http://rafb.net/paste/results/DsnBJn64.html

Once I have the constructor, I put this code, one is the third background (the one being visible) and the Zero is the one I can't see in hardware, I can see it in a emu

Code:
Background BGThird (0,3,0,0,0,8,0,3,1);
   Background BGZero (0,0,0,0,2,24,0,0,1);

#105129 - PypeBros - Fri Oct 06, 2006 8:17 am

from previous experiments, emulators aren't very concerned by the actual mappings you're doing, e.g. if you don't map MAIN_BG to anything and still write to MAIN_BG, they will live fine with that.

The hardware _needs_ the VRAM_A_0x6xxx things to know what physical memory should appear when you read/write to MAIN_BG ...
_________________
SEDS: Sprite Edition on DS :: modplayer

#105131 - Lupi - Fri Oct 06, 2006 9:00 am

PypeBros wrote:
from previous experiments, emulators aren't very concerned by the actual mappings you're doing, e.g. if you don't map MAIN_BG to anything and still write to MAIN_BG, they will live fine with that.

The hardware _needs_ the VRAM_A_0x6xxx things to know what physical memory should appear when you read/write to MAIN_BG ...


Sorry, but I don't what you are trying to say me
If you mean VRAM banks aren't assigned, then I think you are wrong, I'm assigning them
Code:
vramSetMainBanks(VRAM_A_MAIN_BG_0x6000000,
                VRAM_B_LCD,
                VRAM_C_SUB_BG_0x6200000,
                VRAM_D_LCD);


If you mean something totally different, mapping the background, I don't have a clue of what is that or how is it done :P
Thanks anyway, I'm a bit new to this :)

#105132 - Dark Knight ez - Fri Oct 06, 2006 9:38 am

I'm surprised you created an entire function for it. Seems a bit unnecessary.
I'm not sure if background registers can be read, by the way.
This for example:
Code:
BG0_CR |= BG_PRIORITY(BG_PRIOR);

Is basicly the same as this:
Code:
BG0_CR = BG0_CR | BG_PRIORITY(BG_PRIOR);

If access to the background registers are write-only (and thus cannot be read), the effect would probably end up to be this:
Code:
BG0_CR = 0 | BG_PRIORITY(BG_PRIOR);
or
BG0_CR = BG_PRIORITY(BG_PRIOR);


Do note that I myself don't know if the registers are write-only. I have never needed to read from them myself.

#105151 - PypeBros - Fri Oct 06, 2006 12:58 pm

Dark Knight ez wrote:

I'm not sure if background registers can be read
Do note that I myself don't know if the registers are write-only. I have never needed to read from them myself.


just checked gbatek (http://nocash.emubase.de/gbatek.htm#lcdiobgcontrol), BG0_CR and friends are R/W. On the other side, registers related to scrolling/rotating are R-O.
_________________
SEDS: Sprite Edition on DS :: modplayer

#105173 - Lupi - Fri Oct 06, 2006 3:49 pm

Nothing... I have tried without using |= but using Bg0_CR = BG0_CR | blablabla

Still it will work on Dualis but not in real hardware.

I have also tried expanding MAIN_BG VRAM to Banks A and B, same results

Here is my code, it has very few lines:
http://www.megaupload.com/es/?d=WU0P9P5L

The class Background is incomplete, some of the member functions still don't use sub-screen.

I wanted to do it that way because I want easy management of the background bits and setup, and in my game I will need lots, lots of different backgrounds and tiles.

Thanks for your help :)

#105200 - Sausage Boy - Fri Oct 06, 2006 6:03 pm

Works fine on hardware for me. I suspect the problem is that your bootloader sets some register to something, and you're not resetting it (to 0, most likely).

I didn't look too much in your code, but does it set the BGx_XDX, XDY, YDX and YDY as seen in the 16bit_color_bmp demo?
_________________
"no offense, but this is the gayest game ever"

#105215 - Lupi - Fri Oct 06, 2006 8:09 pm

Ok, you were right, I tried putting this after everything:

Code:
   BG0_CR = 0;
   BG1_CR = 0;
   BG2_CR = 0;
   BG3_CR = 0;
   SUB_BG0_CR = 0;
   SUB_BG1_CR = 0;
   SUB_BG2_CR = 0;
   SUB_BG3_CR = 0;


And now it works :)

Sorry for the time wasted and thanks :D