WITHOUT BIOS: Get Cursor X and Y
Posted: Mon Jul 30, 2007 7:03 pm
How to Get Cursor X and Y without B. I. O. S.
The Place to Start for Operating System Developers
http://f.osdev.org/
Yes yes...Do you mean the blinking line that usually indicates where the next character will go?
That is a two-stroke approach. That "blinking line" does not indicate where the next character will go, but instead represents the current/next position in a properly designed CLI.matias_beretta wrote:Yes yes...Do you mean the blinking line that usually indicates where the next character will go?
Code: Select all
MOV EDX , 0x00003D4 ; CRTC Address Register
MOV EAX , 0x000000E ; (Index = Cursor Location High Register)
OUT DX , AL ; Tell the CRTC about what we need
INC EDX ; EDX = CRTC Data Register (0x03D5)
IN AL , DX ; Read the High Order Byte of the cursor
MOV EBX , EAX ; Store this value in EBX
SHL EBX , 0x00000008 ; BH = High Order Byte of the cursor
MOV EAX , 0x000000F ; (Index = Cursor Location Low Register)
DEC EDX ; EDX = CRTC Address Register
OUT DX , AL ; Tell the CRTC what value we need
INC EDX ; EDX = CRTC Data Register
IN AL , DX ; Read the Low Order Byte of the cursor
OR EAX , EBX ; AH = High Order Byte, AL = Low Order Byte
XOR EDX , EDX ; Do a simple division (EDX = 0, 32-bits Div)
MOV EBX , 80 ; Divide EDX:EAX by 80 (Number of columns per row)
DIV EBX ; Divide now
; EDX = Cursor.X
; EAX = Cursor.Y