From ccaf2737f82968816c5ec962f936a593686cfb72 Mon Sep 17 00:00:00 2001 From: aqua Date: Wed, 2 Nov 2022 09:34:31 +0200 Subject: Add ps2_ctrl_8042 --- devices/vga.c | 79 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 40 insertions(+), 39 deletions(-) (limited to 'devices/vga.c') diff --git a/devices/vga.c b/devices/vga.c index 93231ea..aeda483 100644 --- a/devices/vga.c +++ b/devices/vga.c @@ -2,6 +2,15 @@ #include #include +const uint16_t cga_idx_port = 0x3d4; +const uint16_t cga_dat_port = 0x3d5; + +const uint8_t cursor_start = 0xa; +const uint8_t cursor_end = 0xb; +const uint8_t cursor_addr_h = 0xe; +const uint8_t cursor_addr_l = 0xf; +const uint8_t cursor_hide = 0x20; + struct __attribute__((packed)) VGAEntry { unsigned char text; uint8_t foreground : 4; @@ -16,6 +25,37 @@ struct VGAEntry *buffer; int col = 0; int row = 0; +// *** Cursor *** +void +vga_enable_cursor(unsigned char start, unsigned char end) +{ + outb(cga_idx_port, cursor_start); + outb(cga_dat_port, (inb(cga_dat_port) & 0xc0) | start); + + outb(cga_idx_port, cursor_end); + outb(cga_dat_port, (inb(cga_dat_port) & 0xe0) | end); +} + +void +vga_disable_cursor() +{ + outb(cga_idx_port, cursor_start); + outb(cga_dat_port, cursor_hide); +} + +void +vga_update_cursor() +{ + const uint16_t pos = row * width + col; + + outb(cga_idx_port, cursor_addr_l); + outb(cga_dat_port, pos & 0xff); + + outb(cga_idx_port, cursor_addr_h); + outb(cga_dat_port, (pos >> 8) & 0xff); +} + +// *** Text Mode *** void vga_init() { @@ -90,42 +130,3 @@ vga_puts(const char *string, int len) else for (int i = 0; i < len; ++i) { vga_putc(string[i]); } } - -// Cursor -const uint16_t cga_idx_port = 0x3d4; -const uint16_t cga_dat_port = 0x3d5; - -const uint8_t cursor_start = 0xa; -const uint8_t cursor_end = 0xb; -const uint8_t cursor_addr_h = 0xe; -const uint8_t cursor_addr_l = 0xf; -const uint8_t cursor_hide = 0x20; - -void -vga_enable_cursor(unsigned char start, unsigned char end) -{ - outb(cga_idx_port, cursor_start); - outb(cga_dat_port, (inb(cga_dat_port) & 0xc0) | start); - - outb(cga_idx_port, cursor_end); - outb(cga_dat_port, (inb(cga_dat_port) & 0xe0) | end); -} - -void -vga_disable_cursor() -{ - outb(cga_idx_port, cursor_start); - outb(cga_dat_port, cursor_hide); -} - -void -vga_update_cursor() -{ - const uint16_t pos = row * width + col; - - outb(cga_idx_port, cursor_addr_l); - outb(cga_dat_port, pos & 0xff); - - outb(cga_idx_port, cursor_addr_h); - outb(cga_dat_port, (pos >> 8) & 0xff); -} -- cgit v1.2.1