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 > Stupid question - Vram banks?!?

#37856 - Wriggler - Thu Mar 17, 2005 11:18 pm

Code:
VRAM_A_CR = VRAM_ENABLE | VRAM_ARM9 | VRAM_CORE_A;
VRAM_B_CR = VRAM_ENABLE | VRAM_ARM9 | VRAM_CORE_A;
VRAM_C_CR = VRAM_ENABLE | VRAM_ARM9 | VRAM_CORE_B;
VRAM_D_CR = VRAM_ENABLE | VRAM_ARM9 | VRAM_CORE_B;
   vramSetMainBanks(VRAM_A_MAIN_BG,VRAM_B_MAIN_SPRITE,VRAM_C_SUB_BG,VRAM_D_SUB_SPRITE);


So, ermm... what does this actually do? This is new to me, and anything that isn't immediately familiar scares the hell out of me... ;-)

Ben

#37872 - josath - Fri Mar 18, 2005 2:49 am

it enables the first 4 vram banks, assigns the first two to core_a (the main screen), and the next two to core_b (the sub screen), as well as marking them as used by the ARM9 processor (the main one most code is written for right now)

then it sets bank A as BG data for main screen, bank B as sprite data for main screen, bank C as BG data for sub screen, and bank D as sprite data for sub screen.

#37886 - Wriggler - Fri Mar 18, 2005 8:59 am

Oh I see, so then you can write to VRAM_A (or whichever), as if it were a great big bitmap? Do you need to use this in a specific graphics mode? I assume so, as I wasn't having any joy in MODE_0_2D...

Ben

#37913 - josath - Fri Mar 18, 2005 5:31 pm

here's a snippet of code from my mines game which use bg0, with some comments:
Code:

    // Set main display to mode 0
    // Enable BG0
    DISPLAY_CR = MODE_0_2D | DISPLAY_BG0_ACTIVE;

    // Set BG0 to 256 color mode
    // Set it to screen block 0 (for map data)
    // Set it to char block 1 (for tile gfx data)
    BG0_CR = BG_COLOR_256| (0 << SCREEN_SHIFT) | (1 << CHAR_SHIFT);

    // copy our palette to the main bg palette
    COPY16((uint16*)title_pal, (uint16 *)BG_PALETTE, 256);

    // copy our tile map the screen block 0
    uint16 *map = (uint16*)SCREEN_BASE_BLOCK(0);
    COPY16((uint16*)title_map, map0, 32*24/2);
    // you may not have a pre-built tile map, in which case you would
    // not use the above copy line, and place tiles by hand using the formula:
    // map[y*32 + x] = N; // where N is the tile number. Tiles are 8x8

    // decompress our tile data to char block 1
    // (you would just use same copy function if your data is not compressed)
    aP_depack((void *)title_raw, (void *)CHAR_BASE_BLOCK(1));


to get the graphics in the correct format, i use a tool called 'gfx2gba', and the command line options are:
Code:
./gfx2gba -t8 -zt -ap tiles.pcx

the -t8 tells it to split it into 8x8 tiles, -zt tells it to compress the tile data, -ap tells it to use aPLib to compress it. (leave out the '-zt -ap' if you don't want to bother with compressing)
If you want it to generate a tile map for you (like for a static image or something), add '-m' before tiles.pcx. Make sure the width of your image is 256 pixels, otherwise you will have to fool around with it to line up correctly.
You will end up with a tiles.raw and a master.pal, rename master.pal to tiles.pal, and move the two files to the arm9/resources/ directory. in your cpp file, write:
Code:

#include "tiles_raw.h"
#include "tiles_pal.h"

and the template handles the compilation of the resources for you.

hope this helps

#37915 - Wriggler - Fri Mar 18, 2005 5:42 pm

Hey josath, thanks for the code. That's just the same as tile modes on the GBA though isn't it? It's virtually how I'm running my demos on the DS at the moment... if you comment out all the vram bank code it doesn't make any difference. For example...

Code:

void initBg(void)
{
   u16 i;

   //Setup background layers
   u16* CharBB = (u16*)CHAR_BASE_BLOCK(0);
   u16* ScreenBB0 = (u16*)SCREEN_BASE_BLOCK(31);

   u16* CharBBSub = (u16*)CHAR_BASE_BLOCK_SUB(2);
   u16* ScreenBB0Sub = (u16*)SCREEN_BASE_BLOCK_SUB(29);

   BG0_CR = TEXTBG_SIZE_256x256 | BG_COLOR_256 | (31 << SCREEN_SHIFT) | (0 << CHAR_SHIFT);
   SUB_BG0_CR = TEXTBG_SIZE_256x256 | BG_COLOR_256 | (29 << SCREEN_SHIFT) | (2 << CHAR_SHIFT);

   //Setup background (sub screen)
   for (i=0; i<=255; i++) { BG_PALETTE_SUB[i] = bg0_cmap[i]; }      //Palette
   
   //DMA Copy for character tiles (ouch!)
   *(vu32*)0x40000D4 = (u32)bg0_blockgfx;
   *(vu32*)0x40000D8 = (u32)CharBBSub;
   *(vu32*)0x40000DC = (u32)714*32 | 0x80000000;

   for (i=0; i<(32*32); i++) { ScreenBB0Sub[i] = bg0_map0[i];   }

   //Setup background (main screen)
   for (i=0; i<=255; i++) { BG_PALETTE[i] = bg1_cmap[i]; }      //Palette
   
   //DMA Copy for character tiles (ouch!)
   *(vu32*)0x40000D4 = (u32)bg1_blockgfx;
   *(vu32*)0x40000D8 = (u32)CharBB;
   *(vu32*)0x40000DC = (u32)607*32 | 0x80000000;

   for (i=0; i<(32*32); i++) { ScreenBB0[i] = bg1_map0[i];   }
}


...all of that works as you'd expect, without enabling Vram banks. So what exactly does that original bit of code do?

Ben

#37916 - josath - Fri Mar 18, 2005 6:20 pm

maybe those vram settings are the default settings, so if you don't set them, it still works?

or if you are running on an emulator, maybe the emulator doesn't emulate those settings?

#37917 - Wriggler - Fri Mar 18, 2005 6:28 pm

Yeah maybe... I can't be arsed to go find the hardware specs at the moment, but didn't Nintendo add a whole bunch of new vram to the DS over the GBA? Perhaps they just did a crap job of implementing it, allowing you to "allocate" the extra vram memory as you please?

We really need someone who knows what they're talking about in this thread, hehe :)

Ben

#37955 - dovoto - Sat Mar 19, 2005 3:03 am

The call to vramSetBanks is all that is required. ndslib is currently written with little direct register access required, mainly to make the source code easier to read.
My first tutorial will be almost entirely on vram mapping (that is the biggest difference between GBA and DS 2D cores) but i have a lot of testing to do this weekend before I start. There are 9 banks that can each be used a little differently and most can be mapped to more than one area of low vram for the 2D cores to utilize.
_________________
www.drunkencoders.com

#38293 - Wriggler - Fri Mar 25, 2005 2:20 pm

dovoto wrote:
The call to vramSetBanks is all that is required. ndslib is currently written with little direct register access required, mainly to make the source code easier to read.
My first tutorial will be almost entirely on vram mapping (that is the biggest difference between GBA and DS 2D cores) but i have a lot of testing to do this weekend before I start. There are 9 banks that can each be used a little differently and most can be mapped to more than one area of low vram for the 2D cores to utilize.


Excellent, cheers dovoto. Will wait for the tutorial with interest...

Ben

#38367 - Sausage Boy - Sat Mar 26, 2005 7:05 pm

Sorry for bothering you with a silly question, but I can't make it work.
It compiles fine, but instead of my awesome title screen it prints this:

[Images not permitted - Click here to view it]


Is there any common newbie mistake I'm making?
_________________
"no offense, but this is the gayest game ever"