Page 1 of 1

Text mode cursor shape

Posted: Fri Feb 20, 2015 12:43 pm
by LPeter
Hi!
I know it's not the most important part of an operating system, but I'm curious: How can I change he undernine cursor shape to something else, like a solid block? I use the simple code to update it (basically from the wiki):

Code: Select all

static void terminal_update_hw_cur(void)
{
	unsigned temp;
	temp = yp * 80 + xp;

	outb(0x3D4, 14);
	outb(0x3D5, temp >> 8);
	outb(0x3D4, 15);
	outb(0x3D5, temp);
}
Is there even a way to do it? I haven't found too much info about it.

Re: Text mode cursor shape

Posted: Fri Feb 20, 2015 12:45 pm
by Muazzam
You can modify a character from VGA font and use it as a cursor (i.e. Cursor emulation).

Re: Text mode cursor shape

Posted: Fri Feb 20, 2015 10:59 pm
by Brendan
Hi,
LPeter wrote:Is there even a way to do it? I haven't found too much info about it.
In theory the text mode cursor (at least for VGA cards) can be set to between one and N rows tall; and you can also change whether the cursor blinks or not. The most reliable way to do this (with the highest chance of avoiding compatibility problems with "not quite 100% VGA compatible" hardware) is using the "Set text mode cursor shape" BIOS function.

However, it's probably better to disable the hardware cursor during boot; then emulate a cursor in software (without using BIOS functions or diddling with "hopefully VGA compatible maybe" IO ports after boot). The simplest way to do this is to invert the attribute of the character where your cursor is.

Of course the best option is to refuse to bother with stinky old text mode in the first place, and just use graphics modes. This allows you to have a modern "vertical bar" cursor in the gap between characters (and has many other significant advantages). ;)


Cheers,

Brendan

Re: Text mode cursor shape

Posted: Sat Feb 21, 2015 3:59 am
by LPeter
Thank you all!
I managed to do it:

Code: Select all

outb(0x3d4, 0xa);
outb(0x3d5, 0x0);
Thanks for the link! :D