kornos/kernel/src/arch/x86/vga.c

52 lines
1.1 KiB
C

#include <stdint.h>
#include <stddef.h>
#include <print/print.h>
#include "vga.h"
static const size_t VGA_WIDTH = 80;
static const size_t VGA_HEIGHT = 25;
static volatile size_t terminal_row;
static volatile size_t terminal_column;
static volatile uint8_t current_color = VGA_WHITE;
static uint16_t *terminal_buffer = (uint16_t*)0xb8000;
void putchar(char c) {
vga_putc(c);
}
void vga_putc(char c) {
size_t index = terminal_row*VGA_WIDTH + terminal_column;
if(c == '\t') {
vga_putc(' ');
while(terminal_column % 8 != 0) {
vga_putc(' ');
}
return;
}
if(c != '\n' && c != '\t')
terminal_buffer[index] = (uint16_t)c | (uint16_t)(current_color) << 8;
if (c == '\n' || ++terminal_column == VGA_WIDTH) {
terminal_column = 0;
if (++terminal_row == VGA_HEIGHT)
terminal_row = 0;
}
}
void vga_setcolor(uint8_t new_color) {
current_color = new_color;
}
void vga_write_elsewhere(const char *c, size_t y, size_t x) {
size_t old_row = terminal_row;
size_t old_column = terminal_column;
terminal_row = y;
terminal_column = x;
puts(c);
terminal_row=old_row;
terminal_column=old_column;
}