Without access to bios calls and functions, moving the cursor requires using video hardware control. Lucky for us it is a simple procedure.

Note, this quick example ASSUMES 80x25 screen mode.

        /* void update_cursor(int row, int col)
         * by Dark Fiber
         */
        void update_cursor(int row, int col)
        {
                unsigned short position=(row*80) + col;

                // cursor LOW port to vga INDEX register
                outb(0x3D4, 0x0F);
                outb(0x3D5, (unsigned char)(position&0xFF));
                // cursor HIGH port to vga INDEX register
                outb(0x3D4, 0x0E);
                outb(0x3D5, (unsigned char )((position>>8)&0xFF));
        }

Keep in mind that in/out to VGA hardware is a sloow operation. So using the hardware registers to remember of the current character location (row, col) is bad practice -- and updating position after each displayed character is poor practice (updating it only when a line/string is complete is wiser and hiding it until a user prompt is required is wisest)


Categories: HowTo