Text Mode Cursor: Difference between revisions

m
→‎Without the BIOS: Add code to get the cursor position.
[unchecked revision][unchecked revision]
m (correct typo in port number)
m (→‎Without the BIOS: Add code to get the cursor position.)
Line 159:
popfq
ret
</source>
 
===Get Cursor Data===
 
With this code, you get: <tt>pos = y * VGA_WIDTH + x</tt>. To obtain the coordinates, just calculate: <tt>y = pos/VGA_WIDTH; x = pos%VGA_WIDTH</tt>.
 
'''Source in C'''
 
<source lang="c">
uint16_t get_cursor_position(void)
{
uint16_t pos = 0;
outb(0x3D4, 0x0F);
pos |= inb(0x3D5);
outb(0x3D4, 0x0E);
pos |= ((uint16_t)inb(0x3D5)) << 8;
return pos;
}
</source>
 
16

edits