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 > Questions about loading graphics and sprites

#99124 - Lupi - Sat Aug 19, 2006 5:19 pm

Hi, newbie here, while I was learning some libnds with the examples in devkitPro and the orange spaceship example of the pdf guide, I got myself a bit confused by NDS Hardware and the way to load sprites and bg:

1) VRAM banks... they are used to load backgrounds and sprites, but do I need to use one of the VRAM banks for one background, or I can use for several different type of data(sprites and backgrounds)?


2) When starting a background, I have seen something like this:
BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_PRIORITY(3);
I know that BG_BMP_BASE(base) is used to later load the background with BG_BMP_RAM(base) in the dmaCopy function, but what does that 'base' variable represent, I don't get it :S:S

3) To load sprites..., first I load the palette, with this:
dmaCopy(test_pal_bin, SPRITE_PALETTE, test_pal_bin_size);
Then I load the sprite with this:
dmaCopy(test_bin, &SPRITE_GFX[64 * 16], test_bin_size);

Why is it loading at 64*16, and by the way, somehow it load the sprite at the position 0 of the OAM, but what if I want to load it on a different position...
And SPRITE_GFX, what part of VRam does it represent?, what's its memory limit?

4) Last one, it's about palettes, i have read you can have 1 big palette of 256 colours or 16 palettes of 16 colours, I don't quite get this palette thing, where are they stored?, in SPRITE_PALETTE, what about the BG_MAIN_PALETTE?, if I want to load several sprites that uses several palettes (converted with git I must add), how do I load a new sprite if that SPRITE_PALETTE is covered by a different one?


Sorry, too many questions here, I just can't find what do those macros mean, or loading multiple sprites without a .pcx file. You don't have to answer all of course ^_^

Thanks in advance

#99128 - Sausage Boy - Sat Aug 19, 2006 5:46 pm

1.
Depends on how you map the VRAM banks. Look at this code
Code:

vramSetMainBanks(   VRAM_A_MAIN_BG_0x6000000,      //map A and B to main background memory
                    VRAM_B_MAIN_BG_0x6020000,      //this gives us 256KB which is a healthy amount for 16-bit gfx
...

vramSetBankE(VRAM_E_MAIN_SPRITE); //mapping E to main sprites gives us 64k for sprites


This maps banks A and B for backrounds and bank E for sprites, both for the main core.

2.
Have a look at the table at http://user.chem.tue.nl/jakvijn/tonc/regbg.htm. The charblock is your base variable. It's just a way to refer to vram. Read the section I linked on TONC, it's for GBA, but the same thing applies to the DS, only you have twice as much VRAM.

3.
The 64*16 actually means that you don't load the data at 0, but rather at 1024. Perhaps there's something else before it, such as other sprite data? SPRITE_GFX represents the vram bank you have mapped for sprites on the main core.

Don't confuse OAM and VRAM. OAM tells the DS what to load, how and where. VRAM contains the image data. Again,

TONC is good. Read and understand. Just ask if anything's unclear.

4.
You don't. Convert all the sprites that will be visible at the same time to use the same palette. I actually don't know where the palettes are stored. You can think of it as some secret palette memory :P
_________________
"no offense, but this is the gayest game ever"

#99136 - Lupi - Sat Aug 19, 2006 7:11 pm

Ok, now I'm starting to get this.

In charblocks I store the tile data and in the screen blocks I store the map data (with the tiles)

But what if the tile data surpass the 16 kb/charblock, or that's not posible? :P

I don't quite get the sprites thing.
Let's say I reserve one of the 64 kb VRAM for sprites, now I have 64.000 bytes.
every 8x8 sub-tile of every sprite is 64 bytes long(considering 8bpp), that would be 1000 sub-tiles of sprites
Now let's say I want to access the sprite that starts at the sub-tile 30 of 1000, how is that done? and what would I put in attribute[2] to tell the OAM the sprite data is there?

Thanks again, you are helping me A LOT =)

#99139 - tepples - Sat Aug 19, 2006 7:25 pm

Lupi wrote:
Ok, now I'm starting to get this.

In charblocks I store the tile data and in the screen blocks I store the map data (with the tiles)

But what if the tile data surpass the 16 kb/charblock, or that's not posible? :P

The GBA or DS will happily render tiles from the following charblock(s) if you specify a tile number greater than 256 (in 256 color mode) or 512 (in 16 color mode).

Quote:
I don't quite get the sprites thing.

Did you get it on the GBA? If you're referring to accessing tiles past the first 32 KB of your sprite cel VRAM bank, you can set bits 20-21 of DISPCNT to multiply all sprites' tile indices by 2, 4, or 8.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#99166 - Lupi - Sat Aug 19, 2006 10:09 pm

tepples wrote:
Lupi wrote:
I don't quite get the sprites thing.

Did you get it on the GBA? If you're referring to accessing tiles past the first 32 KB of your sprite cel VRAM bank, you can set bits 20-21 of DISPCNT to multiply all sprites' tile indices by 2, 4, or 8.

No, not exactly that, I'm refering what index do I have to put in SPRITE_GFX[i] and, if I load it in SPRITE_GFX[i], what do I have to put in attribute[2] of the SpriteEntry.
In other words, a element from that vector, what does it represent, a pixel?, a kb?, a sprite 8x8 sub-tile?

Thanks in advance, and excuse my english :P
Lupi

#99167 - tepples - Sat Aug 19, 2006 10:12 pm

OAM attribute 2 refers to 32-byte, 64-byte, 128-byte, or 256-byte offsets from the start of the sprite cel VRAM bank. If you're using all 8-bit sprite cels, you will want to set DISPCNT to 64-byte mode so that each OAM attribute 2 unit represents one 8x8 pixel sub-tile.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.