blue!
This commit is contained in:
50
kernel/lib/console.c
Normal file
50
kernel/lib/console.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <lib/console.h>
|
||||
#include <lib/font.h>
|
||||
|
||||
#include <drivers/vga/vga.h>
|
||||
|
||||
static psf_font_t* font;
|
||||
|
||||
static uint32_t console_row;
|
||||
static uint32_t console_col;
|
||||
static uint32_t console_text_color;
|
||||
static uint32_t console_backgrnd_color;
|
||||
|
||||
static void write_vga_char(char c) {
|
||||
uint32_t vga_pitch = vga_get_pitch();
|
||||
uint8_t* glyph = (uint8_t*)font->glyphs + (c * font->hdr->charsz);
|
||||
|
||||
for (uint32_t y = 0; y < font->hdr->charsz; y++) {
|
||||
uint8_t bits = glyph[y];
|
||||
uint32_t* row = (uint32_t*)((uintptr_t)VGA_FRAMEBUFFER + ((console_row + y) * vga_pitch));
|
||||
for (int x = 0; x < 8; x++) {
|
||||
if (bits & (0b10000000 >> x)) {
|
||||
row[console_col + x] = console_text_color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int set_console_font(const char* path) {
|
||||
font = load_font(path);
|
||||
return font != NULL;
|
||||
}
|
||||
|
||||
void set_console_fg(uint32_t color) {
|
||||
console_text_color = color;
|
||||
}
|
||||
|
||||
void set_console_bg(uint32_t color) {
|
||||
console_backgrnd_color = color;
|
||||
}
|
||||
|
||||
void console_init() {
|
||||
console_row = 0;
|
||||
console_col = 0;
|
||||
set_console_fg(0xFFFFFFFF);
|
||||
vga_clear_scrn(0x00000000);
|
||||
}
|
||||
|
||||
void console_putchar(char c) {
|
||||
write_vga_char(c);
|
||||
}
|
||||
13
kernel/lib/console.h
Normal file
13
kernel/lib/console.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef D_CONSOLE_H
|
||||
#define D_CONSOLE_H
|
||||
|
||||
#include <lib/font.h>
|
||||
|
||||
void console_putchar(char c);
|
||||
|
||||
int set_console_font(const char* path);
|
||||
void set_console_fg(uint32_t color);
|
||||
void set_console_bg(uint32_t color);
|
||||
void console_init();
|
||||
|
||||
#endif
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <drivers/vga/vga.h>
|
||||
#include <drivers/console/console.h>
|
||||
#include <lib/console.h>
|
||||
|
||||
spinlock_t kwrite_lock = {0};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user