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 > Can someone plz explain vram banks???

#124350 - Diirewolf - Thu Apr 05, 2007 8:39 am

Im moving from GBA to DS and I realised this new thing.. vram banks. Now gba doesnt have these and I want to know what they are and how to use them. The tutorials ive read just say vramSetBank?(...) and dont explain what it does, ive seen a table of vram banks but dont understand it as I have no clue what they are in the first place.
some help please.
thanks

#124353 - qw3rty - Thu Apr 05, 2007 10:00 am

Vram is the video-ram of the NDS.

The GBA had videoram too ! (where you put the chars. and maps / bitmaps).

The NDS has more than 4 times the VRam of the GBA though.
You have to VramSetMainbanks(), to reserve the different VRAM-banks to screen one or two.

VramSetMainBankA(VRAM_A_MAIN_BG); (call this, to setup VRAM_A to the main-screen - check for spelling though - I wrote this from head ;))

#124354 - Lick - Thu Apr 05, 2007 10:22 am

VRAM Banks have to be mapped at a memory location before you can store graphics data to that memory location.

Imagine you have a flat table with a hole. That hole is the memory location where you want to put data, a Euro-coin for example. If you try putting the coin there, it will fall through. This is why you need to map your hand (VRAM) under the table at the hole (memory location), so the coin (data) falls on your hand (thus in the VRAM) instead.
Some VRAM banks fit some holes, others fit others, so check out the tables to see which 'hand' (VRAM) can be mapped to which 'hole' (memory location).

For example, VRAM_A to 0x6000000 (aka 'BG_GFX'):
vramSetBankA(VRAM_A_MAIN_BG);
or vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
Both are the same.
_________________
http://licklick.wordpress.com

#124358 - Diirewolf - Thu Apr 05, 2007 11:35 am

what exactly do you mean by mapped? you can explain in technical terms, you dont need to use a coin example :). you see with gba, there is just VRAM and if you want to write to it, you just use VRAM[i] = ...
why are there sooo many banks ( A - F or whatever it was).
thanks for replies

#124359 - OOPMan - Thu Apr 05, 2007 11:56 am

Try doing a search for "memory mapping". By mapping the VRAM to a memory location you make it accessible in the same fashion that normal memory is accessible, via standard memory reading and writing techniques...
_________________
"My boot, your face..." - Attributed to OOPMan, Emperor of Eroticon VI

You can find my NDS homebrew projects here...

#124361 - qw3rty - Thu Apr 05, 2007 12:09 pm

each VRAM bank can be "mapped" to different start-adresses.
vramSetBankA(VRAM_A_MAIN_BG); sets bank a to 0x06000000.
That's the normal memory area you are used to on GBA.
You can however set bankB to 0x06020000, which is right after the first 128k.
This will make charbaseblock 4...7 accesible.
On the GBA you had only 4 charbaseblocks.
(you still are limited to 32 screenbaseblocks though)

the "normal" vram of the SUBscreen is at 0x06200000.
the subscreen can be used the same way as the top screen.

However, not each bank can be used for every purpose !
And different purpose may mean a different memory adresse !

Before being able to use VRAM you HAVE to set it up, using vramSetMainBankX(<LIBNDS-DEFINE>);

Detailed info on the VRAM-managing can be found at DSTek :

http://neimod.com/dstek/

P.S. : The memory adresses etc. are for tiled backgrounds (text) - I don't know for sure what's about rotating BGs, double layering etc.
Again - look it up on dstek (you asked for technical info, this will give you technical info ;))

#124362 - Diirewolf - Thu Apr 05, 2007 12:16 pm

ok so from what I understand, if you map vram a memory to background memory, then it will be used for background memory and if you write to BG_GFX or whatever, it will write to VRAM_A?
thx

#124363 - qw3rty - Thu Apr 05, 2007 12:25 pm

look into memory.h and video.h - there are all the defines you need !

memory.h :
#define BG_GFX ((uint16*)0x6000000)
#define BG_GFX_SUB ((uint16*)0x6200000)

BG_GFX[i] will point to RAM-adresse (0x6000000 + i)- a write or read won't work if you didn't map a vrambank to that memory area before !

video.h :

typedef enum {
VRAM_A_LCD = 0,
VRAM_A_MAIN_BG = 1,
VRAM_A_MAIN_BG_0x06000000 = 1 | VRAM_OFFSET(0),
VRAM_A_MAIN_BG_0x06020000 = 1 | VRAM_OFFSET(1),
VRAM_A_MAIN_BG_0x06040000 = 1 | VRAM_OFFSET(2),
VRAM_A_MAIN_BG_0x06060000 = 1 | VRAM_OFFSET(3),
VRAM_A_MAIN_SPRITE = 2,
VRAM_A_MAIN_SPRITE_0x06400000 = 2,
VRAM_A_MAIN_SPRITE_0x06420000 = 2 | VRAM_OFFSET(1),
VRAM_A_TEXTURE = 3,
VRAM_A_TEXTURE_SLOT0 = 3 | VRAM_OFFSET(0),
VRAM_A_TEXTURE_SLOT1 = 3 | VRAM_OFFSET(1),
VRAM_A_TEXTURE_SLOT2 = 3 | VRAM_OFFSET(2),
VRAM_A_TEXTURE_SLOT3 = 3 | VRAM_OFFSET(3)
} VRAM_A_TYPE;

these are the different usages of VRAM-bank A.