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 > Beginner:Understanding VRAM Mapping and Memory Banks

#149481 - krozen - Sun Jan 20, 2008 10:12 pm

Hi guys,
I have some GBA experience, and have decided to make the move over to DS programming. The one thing that is holding me back at the minute is VRAM memory mapping - I just can't get my head around it, and it's placed a complete road block on my progression with DS programming.

The way I figure it is as follows: The DS doesn't tie memory to specific modes. Rather, you first choose the mode you want, and then choose which memory you would like to use for it. So, you can choose Mode 3 with extended background, and then decide to use VRAM Bank A to store the relevant bitmap data. BUT, all seems to map to 0x06000000 anyway! (from what I can make out from the #defines)

I guess my main issue is understanding why mapping is used, rather than just having dedicated parts of memory to different tasks. Would someone be able to explain the basics of it to me (perhaps using a practical example of how different memory mappings would be used in a game)?

Thanks a million for your help

#149500 - Dwedit - Mon Jan 21, 2008 5:45 am

Go to http://nocash.emubase.de/gbatek.htm#dsmemorycontrolvram (gbatek is about a megabyte of html, takes a while to load)
Scroll down to the part where it says
"There is a total of 656KB of VRAM in Blocks A-I.
Table below shows the possible configurations."

Use the table to help you assign named banks to a graphics feature.
Here you can see that there are many possible overlapping ways to do this stuff.
So let's say you wanted to assign 128KB of VRAM to Engine A Background, Engine A sprites, Engine B Background, and Engine B sprites.
You'd assign "bank A" to engine A's background, "bank B" to engine A's sprites, "bank C" to engine B's background, and "bank D" to engine B's sprites.

To use Libnds to assign the VRAM:
Look in C:\devkitpro\libnds\include\nds\arm9\video.h for reference as to what names you can use.

For the above example, we could use this:
Code:
vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
vramSetBankB(VRAM_B_MAIN_SPRITE_0x06400000);
vramSetBankC(VRAM_C_SUB_BG_0x06200000);
vramSetBankD(VRAM_D_SUB_SPRITE);   //this is mapped at 0x06600000


And then we can access bank A at 06000000, bank B at 06400000, bank C at 06200000, and bank D at 06600000.

You can also just as easily pick different addresses, such as
vramSetBankA(VRAM_A_MAIN_BG_0x06020000);
then Bank A would be mapped to 06020000, not 06000000.

Here's another example, where we assign 256k to Engine A's background, 256k to Engine A's sprites, 32k to Engine B's background, and 16k to Engine B's sprites:

Code:
vramSetBankA(VRAM_A_MAIN_SPRITE_0x06400000);
vramSetBankB(VRAM_B_MAIN_SPRITE_0x06420000);
vramSetBankC(VRAM_C_MAIN_BG_0x06000000);
vramSetBankD(VRAM_D_MAIN_BG_0x06020000);
vramSetBankH(VRAM_H_SUB_BG); //32k located at 0x06200000
vramSetBankI(VRAM_I_SUB_SPRITE); //16k located at 0x06600000

_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#149542 - krozen - Mon Jan 21, 2008 9:56 pm

Thanks for your detailed explanation, Dwedit. I think I'm finally getting a grasp on this.
So, the DS is far more flexible as regards VRAM the GBA. So, this means that if you have some application that is heavy on tiles, and only uses a few sprites, you can have more memory for tile data by reducing the amount of VRAM used for sprites. And, if you are using more sprite memory on the top screen than on the top, you can assign more sprite memory to the top screen than the bottom screen.


Quote:
You can also just as easily pick different addresses, such as
vramSetBankA(VRAM_A_MAIN_BG_0x06020000);
then Bank A would be mapped to 06020000, not 06000000.


How would this impact on your application? Why would you want to do something like this - can you then use 06000000 for storing some sprite data, for example?

Thanks again for your help!