Page 1 of 1

Wrong position to plot things.

Posted: Mon Sep 10, 2012 6:06 am
by Bert
Hi all,
I have try to follow this tutorial http://www.osdever.net/tutorials/view/mixing-assembly-c and is working well however in vmware he print not in the upper left corner but somewhere on the screen how is this possible?
I get this http://imageshack.us/photo/my-images/65 ... boven.jpg/

How can help me? thanks a lot.

Re: Wrong position to plot things.

Posted: Mon Sep 10, 2012 6:31 am
by JamesM
How the bloody hell are we supposed to know? You haven't provided any code.

Note, that is NOT a prompt to code-dump your entire source. Have you tried debugging it at all? What have you discovered so far?

Re: Wrong position to plot things.

Posted: Mon Sep 10, 2012 6:37 am
by bluemoon
My crystal ball says you have bug in the offset calculation or cursor positioning.

Re: Wrong position to plot things.

Posted: Mon Sep 10, 2012 7:11 am
by Combuster
JamesM wrote:How the bloody hell are we supposed to know?
Nice catch, it is the tutorial from hell :wink:. The entire thing is not supposed to work at all.


@Bert: Use one of the Tutorials on the wiki.

Re: Wrong position to plot things.

Posted: Mon Sep 10, 2012 7:41 am
by Bert
there is one function out which can write in to a register to set the cursor position on the right place.
I have searching a lot but ever where I find the same
you should first

out(0x3D4,14)
then set the cursor position with
out(0x3D5,0)
and again
out(0x3D4,15)
out(0x3D5,0)

of course you should define out in assembly but because I am able to move the cursor forward I think this should be correct only the start position is wrong.
however ever where I look same thing is doing. i have also try to debug and initialise the variables by hand but nothing work at all.

Greets.

Re: Wrong position to plot things.

Posted: Mon Sep 10, 2012 7:56 am
by bluemoon
The tutorial is broken, unclear in goal, and mixed in unrelated features (why on Earth you need to set/get cursor? for hello-world it's just fine to stosb the text and focus the reader on how video memory work).

Take Combuster's advice.

Re: Wrong position to plot things.

Posted: Mon Sep 10, 2012 9:05 am
by JamesM
Bert wrote:there is one function out which can write in to a register to set the cursor position on the right place.
I have searching a lot but ever where I find the same
you should first

out(0x3D4,14)
then set the cursor position with
out(0x3D5,0)
and again
out(0x3D4,15)
out(0x3D5,0)

of course you should define out in assembly but because I am able to move the cursor forward I think this should be correct only the start position is wrong.
however ever where I look same thing is doing. i have also try to debug and initialise the variables by hand but nothing work at all.

Greets.
The cursor setting only changes where the blinky-cursor-glyph shows up. It does not set an insert point, unlike most graphical drawing environments.

Re: Wrong position to plot things.

Posted: Mon Sep 10, 2012 9:32 am
by Kazinsal
JamesM wrote:The cursor setting only changes where the blinky-cursor-glyph shows up. It does not set an insert point, unlike most graphical drawing environments.
However, the tutorial thinks it's a brilliant idea to rely on the position of said blinky-cursor-glyph to determine where on the screen one places characters.

This appears to be one of many things that are horribly, horribly wrong with it. Take this sentence for example:
Because of my lack of knowledge of the linker, I don't know how to do that.
The tutorial's a lot better if you read it in an astonished/amazed/wowwed/Slap Chop infomercial/etc. voice. It's still not a good tutorial though.

Re: Wrong position to plot things.

Posted: Mon Sep 10, 2012 9:48 am
by Bert
Thanks for you advice.

Re: Wrong position to plot things.

Posted: Mon Sep 10, 2012 10:01 am
by Brendan
Hi,
JamesM wrote:
Bert wrote:out(0x3D4,14)
then set the cursor position with
out(0x3D5,0)
and again
out(0x3D4,15)
out(0x3D5,0)
The cursor setting only changes where the blinky-cursor-glyph shows up. It does not set an insert point, unlike most graphical drawing environments.
It also assumes the video card is VGA compatible at the hardware level. The BIOS provides an abstraction to shield you from unnecessary (and potentially wrong) assumptions like this, and if you're using the BIOS (during boot, before you've setup drivers of your own) to print characters on the screen you should also use the BIOS to set the cursor.


Cheers,

Brendan

Re: Wrong position to plot things.

Posted: Mon Sep 10, 2012 11:58 am
by rdos
Brendan wrote:It also assumes the video card is VGA compatible at the hardware level. The BIOS provides an abstraction to shield you from unnecessary (and potentially wrong) assumptions like this, and if you're using the BIOS (during boot, before you've setup drivers of your own) to print characters on the screen you should also use the BIOS to set the cursor.
I find it pretty unlikely that cursor positioning could be done at boot-time. If you support console mode applications, you also need cursor movement long after boot. For a lack of better methods, using the VGA compatible way gives the best (average) result. If hardware doesn't support it, typically nothing bad happens. And calling BIOS from protected mode is not so easy, unless you have a good V86 environment.

Re: Wrong position to plot things.

Posted: Mon Sep 10, 2012 12:13 pm
by bluemoon
rdos wrote:If you support console mode applications, you also need cursor movement long after boot.
At that time you could have fully detected if there is VGA compatible hardware.
What Brendan said it is potentially dangerous to assume it exists, especially at boot time which you don't detect anything yourself yet.

Re: Wrong position to plot things.

Posted: Mon Sep 10, 2012 9:10 pm
by Brendan
Hi,
bluemoon wrote:
rdos wrote:If you support console mode applications, you also need cursor movement long after boot.
At that time you could have fully detected if there is VGA compatible hardware.
What Brendan said it is potentially dangerous to assume it exists, especially at boot time which you don't detect anything yourself yet.
Yes.

I'd also say that a sane OS should switch to a graphics video mode during boot (and that the "VGA hardware cursor" won't work in graphics video modes); and that unless an OS is sitting there waiting for user input (which is unlikely during boot) the "VGA hardware cursor" (which is like a flashing "I'm waiting for you" indicator) should be disabled.

Code: Select all

     mov ah,0x01                ;ah = BIOS function number (Set Text Mode Cursor Shape)
     mov cx,0x2D0E              ;VGA cursor settings, bits 5 and 6 of CH disables cursor
     int 0x10                   ;Call BIOS function (Set Text Mode Cursor Shape)

Cheers,

Brendan