feature: line spacing + characters are aligned

This commit is contained in:
2024-12-19 19:04:43 +01:00
parent 61debdcb85
commit bab3069152
5 changed files with 159 additions and 22 deletions

View File

@ -42,8 +42,8 @@ void terminal_remove_last_char(void)
screen->column = VGA_WIDTH - 1;
screen->row--;
}
uint32_t pos_x = (screen->column) * FONT_SIZE;
uint32_t pos_y = screen->row * FONT_SIZE;
uint32_t pos_x = (screen->column) * FONT_WIDTH;
uint32_t pos_y = screen->row * FONT_HEIGHT;
struct font node = get_font_node(
screen->buffer[screen->row * VGA_WIDTH + screen->column]);
@ -112,7 +112,8 @@ void terminal_putentryat(struct font node, uint32_t fg_color, uint32_t bg_color,
for (size_t cy = 0; cy < node.height; cy++) {
for (size_t cx = 0; cx < node.width; cx++) {
if (glyph[cy * node.width + cx] == '#')
put_pixel(fg_color, x + cx, y + cy);
put_pixel(fg_color, x + cx,
y + cy + node.yoffset);
}
}
}
@ -127,8 +128,8 @@ static void terminal_scroll(void)
screen->row--;
memset(display.buff, 0, display.height * display.pitch);
for (size_t i = 0; i < VGA_WIDTH * (VGA_HEIGHT - 1); i++) {
const uint32_t x = (i % VGA_WIDTH) * FONT_SIZE;
const uint32_t y = (i / VGA_WIDTH) * FONT_SIZE;
const uint32_t x = (i % VGA_WIDTH) * FONT_WIDTH;
const uint32_t y = (i / VGA_WIDTH) * FONT_HEIGHT;
screen->buffer[i] = screen->buffer[i + VGA_WIDTH];
terminal_putentryat(get_font_node(screen->buffer[i]),
screen->fg_color, screen->bg_color, x, y);
@ -138,7 +139,7 @@ static void terminal_scroll(void)
static void terminal_new_line(void)
{
screen->column = 0;
if (++screen->row == VGA_HEIGHT - 1)
if (++screen->row >= VGA_HEIGHT - 1)
terminal_scroll();
}
@ -203,9 +204,9 @@ int terminal_putchar(char c)
return 1;
screen->buffer[screen->column + screen->row * VGA_WIDTH] = c;
terminal_putentryat(get_font_node(c), screen->fg_color,
screen->bg_color, screen->column * FONT_SIZE,
screen->row * FONT_SIZE);
if (++screen->column == VGA_WIDTH)
screen->bg_color, screen->column * FONT_WIDTH,
screen->row * FONT_HEIGHT);
if (++screen->column >= VGA_WIDTH)
terminal_new_line();
return 1;
}