aboutsummaryrefslogtreecommitdiff
path: root/devices/vga.c
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2022-11-02 09:34:31 +0200
committeraqua <aqua@iserlohn-fortress.net>2022-11-02 09:34:31 +0200
commitccaf2737f82968816c5ec962f936a593686cfb72 (patch)
tree6aa87c45c05e147c56fc4f330780386a608c33c7 /devices/vga.c
parentEnable interrupts after enabling the PIC (diff)
downloadkernel-ccaf2737f82968816c5ec962f936a593686cfb72.tar.xz
Add ps2_ctrl_8042
Diffstat (limited to 'devices/vga.c')
-rw-r--r--devices/vga.c79
1 files changed, 40 insertions, 39 deletions
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 <stdint.h>
#include <sys/io.h>
+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);
-}