Disable VGA Text-mode Cursor Blinking

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
mghis
Posts: 17
Joined: Wed Jun 22, 2011 1:52 pm

Disable VGA Text-mode Cursor Blinking

Post by mghis »

Hello.

This is indeed a silly idiosyncrasy of mine, but I can't stand the blinking of text-mode cursor.
I'd like to change it to get the same behaviour FreeBSD uses by default (that is, a white, non-flashing
block).

I got the block shape by changing some VGA registers, but I cannot figure out how to restrain
the cursor from blinking. A useful article on Osdever states that it's quite difficult to change
blinking rate from VGA, but I hope there is a way to disable it. As far as I know, FreeBSD boots in text
mode, but has the cursor behaviour I like. I tried to look up involved code in its kernel. It should be
somewhere around syscons.c, but I couldn't find anything useful.

Thanks for any help,

-- mghis

P.S.: please forgive me for my poor English. I am not a native speaker.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Disable VGA Text-mode Cursor Blinking

Post by Brendan »

Hi,
mghis wrote:This is indeed a silly idiosyncrasy of mine, but I can't stand the blinking of text-mode cursor.
I'd like to change it to get the same behaviour FreeBSD uses by default (that is, a white, non-flashing
block).
You can't make the cursor solid using VGA registers. Instead, disable the hardware's cursor completely and draw your own "white block" character. Ironically, the BIOS function for disabling the hardware's cursor is the same function for changing how often it flashes.

Note: I'd assume that FreeBSD doesn't draw a white solid block, but actually swaps the foreground and background colours (e.g. so you get black text on a white background where the cursor is). This would look like a solid block when the cursor is at the end of the line (or over white space), but if you move the cursor left until a (non-whitespace) character is under the cursor you'd be able to see that character.


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.
mghis
Posts: 17
Joined: Wed Jun 22, 2011 1:52 pm

Re: Disable VGA Text-mode Cursor Blinking

Post by mghis »

Brendan wrote:Hi,

You can't make the cursor solid using VGA registers. Instead, disable the hardware's cursor completely and draw your own "white block" character. Ironically, the BIOS function for disabling the hardware's cursor is the same function for changing how often it flashes.

Note: I'd assume that FreeBSD doesn't draw a white solid block, but actually swaps the foreground and background colours (e.g. so you get black text on a white background where the cursor is). This would look like a solid block when the cursor is at the end of the line (or over white space), but if you move the cursor left until a (non-whitespace) character is under the cursor you'd be able to see that character.


Cheers,

Brendan
Thank you very much for your helpful response, Brendan. Disabling the cursor and writing a white block or a space with swapped colours is indeed an useful approach. Probably FreeBSD does this way.

However, I'd like to point out that, as I said in the post before, you can get block-shaped hardware cursor by setting some VGA registers. (I just couldn't figure out how to disable the blink). The following code works for me: (I'm using pmode set by GRUB, and Bochs emulator)

Code: Select all

          /* Set a block-shaped cursor */
        mov     $0x0a, %al
        mov     $0x3d4,%dx
        outb    %al, %dx
        
        xor     %ax, %ax
        inc     %dx
        outb    %al, %dx
The ports and the offsets are taken from the interesting website I mentioned. Here are a few links:
http://www.stanford.edu/class/cs140/pro ... extcur.htm
http://www.stanford.edu/class/cs140/pro ... reg.htm#0E

I'm changing index 0x0A, that corresponds to the "Cursor Start Register". As you can see in the second link, it defines the top-most scanline of the cursor. Fifth bit of that register allows to disable the cursor.

But I will indeed use the way explained in your post, if it's not possible to disable the blink of the hardware cursor.

Thank you again! :-)

--mghis
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: Disable VGA Text-mode Cursor Blinking

Post by Combuster »

mghis wrote:if it's not possible to disable the blink of the hardware cursor.
You can only hide the hardware cursor. Blinking is fixed according to the documentation:
FreeVGA wrote:On the standard VGA, the blink rate is dependent on the vertical frame rate. The on/off state of the cursor changes every 16 vertical frames, which amounts to 1.875 blinks per second at 60 vertical frames per second. The cursor blink rate is thus fixed and cannot be software controlled on the standard VGA.
"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 ]
mghis
Posts: 17
Joined: Wed Jun 22, 2011 1:52 pm

Re: Disable VGA Text-mode Cursor Blinking

Post by mghis »

Well, then I'll disable it and I'll follow Brendan's advice.

Thank you both!
Post Reply