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
how to make a matrix start at a specified address
- Pype.Clicker
- 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
Code: Select all
matrix=(short*)0xb8000;
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
That should work, but I think the compiler still allocates some other memory and tries to assign 0xb8000 to the content.Pype.Clicker wrote:should work ...Code: Select all
matrix=(short*)0xb8000;
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)
My guess:
Code: Select all
unsigned short int matrix[][80] = (unsigned short int *)0xb8000;
- Pype.Clicker
- 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
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...
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
Depends on whether 'matrix' is a variable, object, or a pointer to one of those, right?Candy wrote: That should work, but I think the compiler still allocates some other memory and tries to assign 0xb8000 to the content.
Every good solution is obvious once you've found it.
Re:how to make a matrix start at a specified address
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
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
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:
in the .c file:
proxy
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;
Code: Select all
int myvar = 5;