improve VGA implementation

This commit is contained in:
Quinten Kock 2020-11-30 03:42:06 +01:00
parent 3661cc4bfb
commit e3f4038b3a
1 changed files with 24 additions and 5 deletions

View File

@ -1,14 +1,33 @@
#include <stdint.h>
#include <stddef.h>
#include "vga.h"
#define VGA_ADDRESS 0xb8000
static uint8_t current_color = VGA_WHITE;
uint16_t *vga_buffer = (uint16_t*)VGA_ADDRESS;
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 vga_putc(char c) {
*(vga_buffer++) = (uint16_t)c | (uint16_t)(current_color) << 8;
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_puts(char *c) {