Wrong position to plot things.

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
Bert
Posts: 9
Joined: Mon Aug 03, 2009 8:45 am

Wrong position to plot things.

Post 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.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Wrong position to plot things.

Post 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?
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Wrong position to plot things.

Post by bluemoon »

My crystal ball says you have bug in the offset calculation or cursor positioning.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Wrong position to plot things.

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Bert
Posts: 9
Joined: Mon Aug 03, 2009 8:45 am

Re: Wrong position to plot things.

Post 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.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Wrong position to plot things.

Post 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.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Wrong position to plot things.

Post 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.
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: Wrong position to plot things.

Post 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.
Bert
Posts: 9
Joined: Mon Aug 03, 2009 8:45 am

Re: Wrong position to plot things.

Post by Bert »

Thanks for you advice.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Wrong position to plot things.

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
rdos
Member
Member
Posts: 3306
Joined: Wed Oct 01, 2008 1:55 pm

Re: Wrong position to plot things.

Post 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.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Wrong position to plot things.

Post 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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Wrong position to plot things.

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply