reading cursor pos. and cur. on/off

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
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

reading cursor pos. and cur. on/off

Post by bubach »

How do i read the cursor position and how do i turn the cursor on/off? I can?t seem to find any info on this.
All documents on the cursor is on how to move it..

/ Christoffer
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:reading cursor pos. and cur. on/off

Post by Neo »

Code: Select all

  outb(0x3D4,14);
  outb(0x3D5,0);
  outb(0x3D4,15);
  outb(0x3D5,0);
this code positions the cursor at the top,left corner of the screen.
as you can see the ports 0x3d4 and 0x3d5 are used for cursor manipulation (this is text mode isn't it?)
to read in the cursor position you can use something like this

Code: Select all

outb(0x3D4,14);
offset = inb(0x3d5) << 8;
outb(0x3D4,15);
offset |= inb(0x3d5);
to get the position into var 'offset'
to reposition the cursor you may use soemthing like this

Code: Select all

 outb(0x3D5,(unsigned char)offset);
 outb(0x3D4,14); 
 outb(0x3D5,(unsigned char)(offset >> 8));
HTH'
I think you can find more info at [url=http://www.osdever.net"]http://www.osdever.net[/url]
Only Human
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:reading cursor pos. and cur. on/off

Post by Pype.Clicker »

keep in mind that changing the cursor position is a slow operation (compared to your CPU power) and that deferring it or caching the last set position rather than reading it again and again from the VGA hardware will certainly boost your console driver.
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:reading cursor pos. and cur. on/off

Post by bubach »

Pype.Clicker: But the cursor position may have changed by a user program or something...
PS. Don?t need that much CPU power in text mode.. :-)

Neo: Thanks!
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:reading cursor pos. and cur. on/off

Post by bubach »

One more thing. What is >> or << in C?
Is it shift right/left by x bytes?

/ Christoffer
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:reading cursor pos. and cur. on/off

Post by Solar »

Shift by bits.
Every good solution is obvious once you've found it.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:reading cursor pos. and cur. on/off

Post by Pype.Clicker »

bubach wrote: But the cursor position may have changed by a user program or something...
If you're in real mode, yes ... though it would be a decent design choice to force the program that wants to move the cursor by direct hardware access to inform the driver it did so before using the driver to output text. Reading the current hardware cursor position to know where the next char is to be displayed would be (imho) confusing.

If you're in pmode, the user program will not have access to the hardware cursor anyway.
PS. Don?t need that much CPU power in text mode.. :-)
That depends on what you're doing. Imagine a kernel compilation that produces lot of output on the console (because in verbose mode), you wouldn't like the compilation to slow down because the console driver does 5 times more VGA I/O cycles, would you ?
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:reading cursor pos. and cur. on/off

Post by bubach »

Solar: Ops, sorry i mean bits.. :)
Pype.Clicker: I always forget that i am in pmode.. :-[
But i think that the driver should have the possibility to check it from the vga registers anyway.. (argh, d*mn my spelling)

/ Christoffer
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
Post Reply