'How to move the cursor with x86 BIOS calls?
I'm doing some operating system tutorials from the book "Operating systems from 0 to 1". One of the exercises is to set the cursor to a position on the screen in the bootloader. However, no matter what I try, the cursor only stays in the same position, at the top left.
To make things more confusing, in the book, it mentions that the registers I need to set before raising interrupt 10h are bh
for the Y coordinate and bl
for the X coordinate. Wikipedia mentions bh
for page number, dh
and dl
for the row and column. Neither of these methods have worked for me.
Here is the function I am using (using the book method):
MovCursor:
pusha
mov ah, 0x02
mov bh, 0x1
mov bl, 0x4
int 0x10
popa
Any help to tell me what I am doing wrong would be greatly appreciated.
Solution 1:[1]
The Wikipedia register settings are correct. From your saying that "Neither of these methods have worked for me", I conclude that you have tried the Wikipedia version too. It's a pity I can't verify your code since you didn't include it in your question.
A few points to consider regarding the cursor:
- On a graphics screen the cursor is never rendered. The coordinates change but it stays invisible1. On a text screen the cursor defaults to a blinking underline.
- The coordinates (column and row) of the cursor are zero-based. The upperleft corner of the screen is at (0,0).
- The cursor will disappear if you position it off screen.
- You can change the shape of the cursor with BIOS.SetCursorType function 01h. You can also make it disappear this way!
Next code displays a string of colored A's in the middle of the screen:
mov ax, 0003h ; BIOS.SetVideoMode 80x25 16-color text
int 10h
mov dx, 0C23h ; DH is Row (12), DL is Column (35)
mov bh, 0 ; DisplayPage
mov ah, 02h ; BIOS.SetCursorPosition
int 10h
mov cx, 10 ; ReplicationCount
mov bx, 002Fh ; BH is DisplayPage (0) , BL is Attribute (BrightWhiteOnGreen)
mov ax, 0941h ; BIOS.WriteCharacterAndAttribute, AL is ASCII ("A")
int 10h
mov ah, 00h ; BIOS.WaitKeyboardKey
int 16h ; -> AX
1 For some light reading How can I add a blinking cursor to the graphics video modes?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Darshan Rivka Whittle |