Page 1 of 1

Can't access memory using arrayindexing.

Posted: Mon Sep 12, 2016 6:53 pm
by FabianB
Hello dear osdev community,
I just started getting into OS development yesterday.

I managed to do some TextMode stuff and now I want to move on to Graphics programming.
I managed to switch to the 13h VGA draw mode, but now I am facing some problems:

I can't access the Graphicsmemory using arrayindexing(?). I need to use pointerarithmetic, if I want to edit a pixel, which is pretty slow.
Also, if I try to calculate any pixel offset, and cast it to an pointer, it won't work, too. It shows either no colored pixel, or heavily offset pixel locations. Accessing them using pointerarithmetic works fine tho.

Am I missing something basic?

PS:
Sorry for the bad english, I am no native speaker :(

I attached an image of my code.

Re: Can't access memory using arrayindexing.

Posted: Mon Sep 12, 2016 11:13 pm
by stdcall
It's better to post code as snippets and not as images.

Re: Can't access memory using arrayindexing.

Posted: Mon Sep 12, 2016 11:28 pm
by Boris
Hi,
Is your colour a char, or an int ?
You have to decide and not have a pointer-to-char accepting int values .

Re: Can't access memory using arrayindexing.

Posted: Tue Sep 13, 2016 4:31 am
by MichaelFarthing
Well if your put pixel routine uses x for a row and y for a column then:

(a) you have not used y at all
(b) you have treated x as if it is a column

I'll leave it at that, because frankly progress with a project like this needs a bit* of sweat and determination to sort out things for yourself.

*I put 'a lot' originally - but hey - small beginnings.

Re: Can't access memory using arrayindexing.

Posted: Tue Sep 13, 2016 7:41 am
by Ch4ozz
The linear buffer usage is pretty easy.
You need to know the width of the screen resolution and then simply can use modulo width to calculate the x pos and divide width to get y pos in the buffer.

Re: Can't access memory using arrayindexing.

Posted: Tue Sep 13, 2016 9:55 am
by FabianB
Guys, I know how to calculate the pixel position. it is just, if I use arrayindexing or calculating the adress, it doesn't work, but if I use pointer arithmetic it does :S

Re: Can't access memory using arrayindexing.

Posted: Tue Sep 13, 2016 10:12 am
by Ch4ozz
FabianB wrote:Guys, I know how to calculate the pixel position. it is just, if I use arrayindexing or calculating the adress, it doesn't work, but if I use pointer arithmetic it does :S
Pointer arithmetic and indexing is the same after compiling to a binary file.

array[x] is just something along a macro and will be translated to *(array + x)
Therefore pointer arithmetics will produce the exact same opcodes as when using indexing and therefore it has the exact same speed.

Take a look at your binary file with a disassembler and maybe you spot something weird.