Syncboot/arch/i386/tty.c

62 lines
1.4 KiB
C
Raw Normal View History

2019-04-01 01:18:48 +00:00
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <kernel/tty.h>
#include "vga.h"
static const size_t TERM_WIDTH=80;
static const size_t TERM_HEIGHT=25;
static size_t terminal_row;
static size_t terminal_column;
static uint8_t current_color;
static uint16_t* term_buffer;
void screen_initialize(void) {
static uint16_t* const vga_buffer = (uint16_t*) 0xB8000;
terminal_row = 0;
terminal_column = 0;
current_color = vga_color_set(LIGHT_GREY, BLACK);
term_buffer = vga_buffer;
for (size_t y = 0; y < TERM_HEIGHT; y++) {
for(size_t x = 0; x < TERM_WIDTH; x++) {
const size_t offset = y * TERM_WIDTH + x;
term_buffer[offset] = vga_entry(' ', current_color);
}
}
}
void term_setcolor(enum vga_colors color) {
current_color = color;
}
void term_putentryat (unsigned char c, uint8_t color, size_t x, size_t y) {
const size_t offset = y * TERM_WIDTH + x;
term_buffer[offset] = vga_entry(c, color);
}
void term_putchar(char c) {
unsigned char uc = c;
term_putentryat(uc, current_color, terminal_column, terminal_row);
if(++terminal_column == TERM_WIDTH)
terminal_column = 0;
if(++terminal_row == TERM_HEIGHT){
term_scroll();
terminal_row = 0;
}
}
void term_write(const char* data, size_t size) {
for(size_t i = 0; i < size; i++)
term_putchar(data[i]);
}
void puts(const char* string) {
term_write(string + "\n", strlen(string));
}