how to make a matrix start at a specified address

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
firas981

how to make a matrix start at a specified address

Post by firas981 »

In my VGA driver , I am using this matrix :
unsigned short frame [25][80] ;
however , I want to make frame = 0xb8000 , how i can do so ?
i.e. is there a way to make a matrix start at a specified address rather than using a pointer instead ?

Note : I am using GCC
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:how to make a matrix start at a specified address

Post by Pype.Clicker »

Code: Select all

matrix=(short*)0xb8000;
should work ...

you could also try to play with linker scripts to have a special section starting at 0xB8000 and behaving like BSS, but it would really be much hassle compared to the result of saving one pointer resolution (considering, for instance, the difficulty of having an existing bootloader understand what to do with that section)
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:how to make a matrix start at a specified address

Post by Candy »

Pype.Clicker wrote:

Code: Select all

matrix=(short*)0xb8000;
should work ...

you could also try to play with linker scripts to have a special section starting at 0xB8000 and behaving like BSS, but it would really be much hassle compared to the result of saving one pointer resolution (considering, for instance, the difficulty of having an existing bootloader understand what to do with that section)
That should work, but I think the compiler still allocates some other memory and tries to assign 0xb8000 to the content.

My guess:

Code: Select all

unsigned short int matrix[][80] = (unsigned short int *)0xb8000;
PS, the columns might be swapped around, not sure... Don't like multidimensional arrays myself.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:how to make a matrix start at a specified address

Post by Pype.Clicker »

so finally, why would you like the 'matrix' appear as a 80x25 two-dimensional array ? a one-dimension array of 2000 shorts would have basically the same convenience.

You know each matrix[y][ x] is resolved into something like matrix+y*ROW_SIZE+x or something alike, which the CPU will have to compute. A one-dimension array, on the other side, allow you to save such repeated multiplication by working on the offset more directly (e.g. you only compute offset=y*80+x when performing a 'gotoxy()', and use offset=offset++ or {rowstart+=ROW_SIZE; offset=rowstart; } for all other operations...
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:how to make a matrix start at a specified address

Post by Solar »

Candy wrote: That should work, but I think the compiler still allocates some other memory and tries to assign 0xb8000 to the content.
Depends on whether 'matrix' is a variable, object, or a pointer to one of those, right?
Every good solution is obvious once you've found it.
firas981

Re:how to make a matrix start at a specified address

Post by firas981 »

frame is a const pointer , so no way to modify it at all , regardless whether it is a one or two dimensions array name .
I solve the problem by just using the subistitution mentioned in my initial question, i.e. a pointer instead of array .


BUT another problem occured , it is another topic :
linker ( ld ) decided that there are multiple declarations of
frame ...
I searched all my files , there is only one !!!!

thanks you all
proxy

Re:how to make a matrix start at a specified address

Post by proxy »

i am willing to bet that one file is a .h file :)

if this is the case, you shoudl enver define a variable's storage in a .h file, define it in a .c/.cPP file and declare it extern in the .h file if other files need to reference it.

ex:

in the .h file:

Code: Select all

extern int myvar;
in the .c file:

Code: Select all

int myvar = 5;
proxy
Post Reply