summaryrefslogtreecommitdiff
path: root/kernel/src/arch/i686/drivers/vga.c
blob: dcf6cebb122e7b8ed35c5830f7305b5f13150833 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <arch/i686/asm.h>
#include <drivers/vga.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>

static uint16_t *buffer = (uint16_t*) 0xC03FF000;
static uint8_t start, end;

void vgatext_write(char c, enum vga_color color, uint8_t x, uint8_t y) {
	const size_t index = y * VGA_TEXT_W + x;
	buffer[index] = c | (uint16_t) color << 8;
}

void vgatext_write_data(uint16_t data, uint16_t index) {
    buffer[index] = data;
}

void vgatext_write_buf(const uint16_t *src) {
    memcpy(buffer, src, VGA_TEXT_W * VGA_TEXT_H * sizeof(uint16_t));
}

void vgatext_cur_mov(uint8_t x, uint8_t y) {
	const uint16_t pos = y * VGA_TEXT_W + x;
 
	outb(0x3D4, 0x0F);
	outb(0x3D5, (uint8_t) (pos & 0xFF));
	outb(0x3D4, 0x0E);
	outb(0x3D5, (uint8_t) ((pos >> 8) & 0xFF));
}

void vgatext_cur_resize(uint8_t s, uint8_t e) {
    start = s;
    end = e;

    outb(0x3D4, 0x0A);
    outb(0x3D5, (inb(0x3D5) & 0xC0) | start);
 
    outb(0x3D4, 0x0B);
    outb(0x3D5, (inb(0x3D5) & 0xE0) | end);
}

void vgatext_cur_visible(bool visible) {
    if (visible) {
        vgatext_cur_resize(start, end);
    } else {
        outb(0x3D4, 0x0A);
	    outb(0x3D5, 0x20);
    }
}