92 lines
2.1 KiB
C
92 lines
2.1 KiB
C
#include "drivers/serial/serial.h"
|
|
|
|
#include <lib/console.h>
|
|
#include <lib/font.h>
|
|
#include <lib/print.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_width;
|
|
static uint32_t console_height;
|
|
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);
|
|
|
|
uint32_t pixel_y_start = console_row * font->hdr->charsz;
|
|
uint32_t pixel_x_start = console_col * 8;
|
|
|
|
for (uint32_t y = 0; y < font->hdr->charsz; y++) {
|
|
uint8_t bits = glyph[y];
|
|
uint8_t* row_bytes = (uint8_t*)VGA_FRAMEBUFFER + ((pixel_y_start + y) * vga_pitch);
|
|
uint32_t* pixel_row = (uint32_t*)row_bytes;
|
|
|
|
for (int x = 0; x < 8; x++) {
|
|
if (bits & (0b10000000 >> x)) {
|
|
pixel_row[pixel_x_start + x] = console_text_color;
|
|
} else {
|
|
pixel_row[pixel_x_start + x] = console_backgrnd_color;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int set_console_font(const char* path) {
|
|
font = load_font(path);
|
|
if (!font) {
|
|
return 0;
|
|
}
|
|
|
|
console_width = vga_get_width() / 8;
|
|
console_height = vga_get_height() / font->hdr->charsz;
|
|
|
|
return 1;
|
|
}
|
|
|
|
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);
|
|
set_console_bg(0xFF6c7482);
|
|
vga_clear_scrn(console_backgrnd_color);
|
|
}
|
|
|
|
void console_putchar(char c) {
|
|
if (!font) return;
|
|
|
|
if (c == '\n') {
|
|
console_col = 0;
|
|
console_row++;
|
|
if (console_row >= console_height) {
|
|
console_row = 0;
|
|
}
|
|
return;
|
|
}
|
|
|
|
write_vga_char(c);
|
|
|
|
console_col++;
|
|
if (console_col >= console_width) {
|
|
console_col = 0;
|
|
console_row++;
|
|
}
|
|
|
|
if (console_row >= console_height) {
|
|
console_row = 0;
|
|
}
|
|
} |