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.

Coding > vram question

#11460 - yanos - Tue Oct 07, 2003 10:42 pm

Something weird that i dont understand. If i do:

Code:

int i, lenght=1024;

for(i=0; i<lenght; i++)
   VideoBuffer[i+0x4000] = 0xCAFE;


and then i check in vba in the memory viewer, i see the value 0xCAFE at 0x6008000 instead of 0x6004000 (where i tought it should go). i got

Code:
#define VideoBuffer      ((u16*)0x6000000)


declared.


yanos

#11461 - Burton Radons - Tue Oct 07, 2003 10:45 pm

You're indexing with u16, so the 0x4000 is multiplied to 0x8000. Use 0x2000 if you want to write to 0x06004000.

#11466 - tepples - Wed Oct 08, 2003 12:50 am

It looks like you're trying to clear a map. Here are some VRAM address macros that I'm guessing people would find extremely useful:
Code:
/* Macros for addressing maps */
typedef u16 NAMETABLE[32][32];
#define MAP ((NAMETABLE *)0x06000000)

/* Macros for addressing tile data */
#define PATRAM(x) ((u32 *)(0x06000000 | ((x) << 14)))
#define PATRAM4(x, c) ((u32 *)(0x06000000 | (((x) << 14) + ((c) << 5)) ))
#define PATRAM8(x, c) ((u32 *)(0x06000000 | (((x) << 14) + ((c) << 6)) ))
#define SPR_VRAM(x) ((u32 *)(0x06010000 | ((x) << 5)))
#define OAM ((volatile struct OAM_SPRITE *)0x07000000)

The MAP macro has two purposes. You can do MAP[8][0] to get the base address of row 0 of map 8, which equals (u16 *)0x06040000. In "text" (non-rot/scale) modes, you can also write characters to the map this way:
Code:
/* place an X at (15, 10) on map 8 */
MAP[8][10][15] = 'X';

The PATRAM macros can also be used as targets for copying tile data:
Code:
/* put tile data into Character Base Block 1 */
dma_memcpy(PATRAM(1), tile_data, tile_data_len);

/* put tile data into Character Base Block 3, starting at tile #320 for 4-bit tiles */
dma_memcpy(PATRAM4(3, 320), tile_data, tile_data_len);

/* put tile data into Character Base Block 2, starting at tile #128 for 8-bit tiles */
dma_memcpy(PATRAM8(2, 128), tile_data, tile_data_len);

/* put tile data into sprite cels, starting at tile #512 */
dma_memcpy(SPR_VRAM(512), tile_data, tile_data_len);

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#11472 - yanos - Wed Oct 08, 2003 5:02 am

thanks a lot. I just tought that each address had an 16bits value 'attached' to it. makes perfect sense now.

yanos