What's wrong with df's code snippet in his FAQ?
http://www.mega-tokyo.com/os/os-faq-console.htmlI hope df does not mind if I'll try to explain what he does and why it works...
A quick explanation:
There is a chip on your VGA card called CRTC (Cathod Ray Tube Controller), responsible for the video signal generation. It has a set of registers you can modify. To communicate with the CRTC you use 2 ports, the so called Index Port ( port no. 3D4H in color and 3B4H in monochrome display mode) and Data Port (3D5H in color and 3B5H in monochrome display mode).
To read/write the value of a single CRTC register you must first output its identifier (number) to the Index Port (outb in C) and then read/write the register value using the Data Port (inb/outb in C).
There are 2 registers controlling the cursor position in text modes, they are called Cursor Address High (register no. 0EH) and Cursor Address Low (register no. 0FH). Together they hold the LINEAR OFFSET ADDRESS of the cursor relative to the start of the the video memory (it means they do not hold the row/column values as you may have thought first
). The offset is a 16-bit value you calculate after the following formula:
? ?_offset_ = (current_row * total_columns) + current_column
Then you write the higher byte of ?_offset_ to the CRTC register no. 0EH and the lower byte to 0FH and voila. That's what df's code is doing for the 80x25 color text mode.