summaryrefslogtreecommitdiff
path: root/kernel/drivers/gpu/vga_text.c
blob: e3359c3a2e79d49dd64a94a30fb819edc6811535 (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
#include <lib.h>
#include <comus/term.h>
#include <comus/asm.h>
#include <comus/memory.h>
#include <comus/drivers/gpu/vga_text.h>

#define VGA_ADDR 0xB8000
#define VGA_WIDTH 80
#define VGA_HEIGHT 25
static volatile uint16_t *buffer = (uint16_t *)VGA_ADDR;

// color
static uint8_t fg = 15, bg = 0;

void vga_text_draw_char(char c, uint16_t x, uint16_t y)
{
	// output character
	const size_t index = y * VGA_WIDTH + x;
	buffer[index] = c | bg << 12 | fg << 8;

	// set cursor position on screen
	const uint16_t pos = y * VGA_HEIGHT + x;
	outb(0x3D4, 0x0F);
	outb(0x3D5, (uint8_t)(pos & 0xFF));
	outb(0x3D4, 0x0E);
	outb(0x3D5, (uint8_t)((pos >> 8) & 0xFF));
}