Text Mode Cursor: Difference between revisions

Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content deleted Content added
m correct typo in port number
Rod (talk | contribs)
m →‎Without the BIOS: Add code to get the cursor position.
Line 159: Line 159:
popfq
popfq
ret
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>
</source>