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 > Allocating data in vram

#4861 - funkeejeffou - Sun Apr 13, 2003 12:26 pm

Hello everyone,

I am actually coding a 3d engine for GBA, and I've been trying lately to allocate my textures(which are arrays of indexed colors from the palette) in Vram, so i wont use any ewram or iram for it.
The problem is that i couldn't make it work, the lnkscript doesn't contain any vram info so i cant use the attribute command, and when i try in my header file :

Code:
unsigned short int *texture = (unsigned short int *)0x6014000;
texture[1000] = {0, 23, 45, ..............., 666};


gcc failes to compile.
So here I have two questions for the one who will save me :
1- Are transfers between data wich are both in vram are faster then transfer from ROM(or else...) to Vram?
2- How can i allocate an array which is a global variable at any adress of my choice?

Bonus : Where can i find a good, clear and complete doc about how does gcc works with the lnkscript and crtso, and where are the definitions of my c functiuns that i use (in wich include directory of the devkitadv)?

Thank you for reading this post...

#4931 - regularkid - Tue Apr 15, 2003 6:17 am

Not sure if I can help too much, but I'll give it a shot:

Don't put anything into vram except for the actual screen data. You definately won't have enough room for all your textures in there (if you are in mode 4, then you only have two screens worth of space). Like you already said, you probably want to avoid filling your iwram and ewram up with textures and other data, so the next best thing is ROM. It is a lot slower than accessing from RAM, but you get lots and lots of space (the cart size, so 64mb, 128mb, 256mb, etc). In order to put something into ROM, just put the keyword "const" infront of the declaration like this:

Code:

const u8 texture = {0, 23, 45,......, 666};


texture will now be stored in ROM (0x08000000 and up, i think). You can add the switch:

Code:

-Wl,-Map,Memory.map


to give you a listing of all your variables and functions and where they are put into memory by the compiler. Very useful. As for a reference, the best one I have seen is Jeff Frohwein's FAQ:

http://www.devrs.com/gba/files/gbadevfaqs.php

Hope that helps!
_________________
- RegularKid

#4940 - Paul Shirley - Tue Apr 15, 2003 2:17 pm

removed

Last edited by Paul Shirley on Sun Mar 28, 2004 9:58 pm; edited 1 time in total

#4953 - funkeejeffou - Tue Apr 15, 2003 7:20 pm

Thanks guys for your reply, but i still have some questions, espcially for paul.

You talked about the 16 bit alignement, but i dont see what you mean by it...is it the fact that a pixel is represented by an unsigned char and that we must perform logical operations on the 16 bit variable to store the palette index?
By the way, does the graphic card of the GBA can perform by ITSELF logical operations (as the VGA cards on pc card can, i think we call it ALU latches...not sure); or there are always data transfers between the CPU and the graphic card?
Is there any doc on the graphic card of the GBA?
It has been a week since i'm coding on the GBA , and I'm really frustrated by the fact that allocating data to specific ram sections is a pain in the ****, and i do not feel that i "masterize" my code in detail (because i objectively don't...). Where can i find these docs or tutorials that can help me do my own linker files and understand the way of properly coding, i really want to optimise my code. MOst of the tutorials and docs i've found are not sufficient(and beleive me i ve searched).
For the allocation of my textures in vram, your idea seems to bee good, since rom space is relatively big. Can malloc allocate space at a specific adress?

Thanks again

#4954 - tepples - Tue Apr 15, 2003 7:33 pm

funkeejeffou wrote:
You talked about the 16 bit alignement, but i dont see what you mean by it...is it the fact that a pixel is represented by an unsigned char and that we must perform logical operations on the 16 bit variable to store the palette index?

The bus from the CPU to VRAM is 16 bits wide, and if you try writing a byte to VRAM, it'll be written to both the even and odd bytes in the 16-bit word.

Quote:
By the way, does the graphic card of the GBA can perform by ITSELF logical operations (as the VGA cards on pc card can, i think we call it ALU latches...not sure)

No.

Quote:
Is there any doc on the graphic card of the GBA?

Search Google for Cowbite spec.

Quote:
Where can i find these docs or tutorials

Have you checked the docs sections of devrs.com and gbadev.org?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.