Page 1 of 1

how to make a matrix start at a specified address

Posted: Mon May 31, 2004 6:05 pm
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

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

Posted: Tue Jun 01, 2004 2:59 am
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)

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

Posted: Tue Jun 01, 2004 3:07 am
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.

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

Posted: Tue Jun 01, 2004 3:32 am
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...

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

Posted: Tue Jun 01, 2004 4:14 am
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?

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

Posted: Tue Jun 01, 2004 4:21 pm
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

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

Posted: Tue Jun 01, 2004 5:42 pm
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