mirror of
https://github.com/cfenollosa/os-tutorial.git
synced 2026-03-02 03:49:21 +00:00
lesson 15, video ports
This commit is contained in:
32
15-video-ports/kernel/kernel.c
Normal file
32
15-video-ports/kernel/kernel.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "../drivers/ports.h"
|
||||
|
||||
void main() {
|
||||
/* Screen cursor position: ask VGA control register (0x3d4) for bytes
|
||||
* 14 = high byte of cursor and 15 = low byte of cursor. */
|
||||
port_byte_out(0x3d4, 14); /* Requesting byte 14: high byte of cursor pos */
|
||||
/* Data is returned in VGA data register (0x3d5) */
|
||||
int position = port_byte_in(0x3d5);
|
||||
position = position << 8; /* high byte */
|
||||
|
||||
port_byte_out(0x3d4, 15); /* requesting low byte */
|
||||
position += port_byte_in(0x3d5);
|
||||
|
||||
/* VGA 'cells' consist of the character and its control data
|
||||
* e.g. 'white on black background', 'red text on white bg', etc */
|
||||
int offset_from_vga = position * 2;
|
||||
|
||||
/* Now you can examine both variables using gdb, since we still
|
||||
* don't know how to print strings on screen. Run 'make debug' and
|
||||
* on the gdb console:
|
||||
* breakpoint kernel.c:21
|
||||
* continue
|
||||
* print position
|
||||
* print offset_from_vga
|
||||
*/
|
||||
|
||||
/* Let's write on the current cursor position, we already know how
|
||||
* to do that */
|
||||
char *vga = 0xb8000;
|
||||
vga[offset_from_vga] = 'X';
|
||||
vga[offset_from_vga+1] = 0x0f; /* White text on black background */
|
||||
}
|
||||
Reference in New Issue
Block a user