Can't access memory using arrayindexing.

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
FabianB
Posts: 2
Joined: Mon Sep 12, 2016 6:45 pm

Can't access memory using arrayindexing.

Post 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.
Attachments
Bildschirmfoto von »2016-09-13 02-45-32«.png
stdcall
Member
Member
Posts: 78
Joined: Thu Mar 14, 2013 1:30 am

Re: Can't access memory using arrayindexing.

Post by stdcall »

It's better to post code as snippets and not as images.
“Meaningless! Meaningless!”
says the Teacher.
“Utterly meaningless!
Everything is meaningless.” - Ecclesiastes 1, 2

Educational Purpose Operating System - EPOS
Boris
Member
Member
Posts: 145
Joined: Sat Nov 07, 2015 3:12 pm

Re: Can't access memory using arrayindexing.

Post 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 .
User avatar
MichaelFarthing
Member
Member
Posts: 167
Joined: Thu Mar 10, 2016 7:35 am
Location: Lancaster, England, Disunited Kingdom

Re: Can't access memory using arrayindexing.

Post 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.
User avatar
Ch4ozz
Member
Member
Posts: 170
Joined: Mon Jul 18, 2016 2:46 pm
Libera.chat IRC: esi

Re: Can't access memory using arrayindexing.

Post 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.
FabianB
Posts: 2
Joined: Mon Sep 12, 2016 6:45 pm

Re: Can't access memory using arrayindexing.

Post 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
User avatar
Ch4ozz
Member
Member
Posts: 170
Joined: Mon Jul 18, 2016 2:46 pm
Libera.chat IRC: esi

Re: Can't access memory using arrayindexing.

Post 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.
Post Reply