Flanterm integration? but page fault in flanterm_fb_double_buffer_flush

This commit is contained in:
2026-02-22 18:27:57 +01:00
parent 70f19ab299
commit 1f055ab31c
14 changed files with 4027 additions and 102 deletions

View File

@@ -17,6 +17,7 @@ because this shitty implementation will be replaced one day by Flanterm
#include "term.h"
#include "mem/misc/utils.h"
#include "config.h"
#include "flanterm.h"
extern struct boot_context boot_ctx;
@@ -30,7 +31,7 @@ uint8_t* glyphs = _binary_zap_light16_psf_start + sizeof(PSF1_Header);
#define FONT_WIDTH 8
#define FONT_HEIGHT font->characterSize
extern struct flanterm_context* ft_ctx;
// Character cursor
typedef struct
@@ -87,38 +88,6 @@ static inline void putpixel(size_t x, size_t y, uint32_t color)
fb[pos+2] = (color >> 16) & 255; // blue
}
static void draw_char(char c, size_t px, size_t py, uint32_t fg, uint32_t bg)
{
// So we cannot write past fb
if (px+FONT_WIDTH > framebuffer->width || py+FONT_HEIGHT > framebuffer->height) return;
uint8_t* glyph = glyphs + ((unsigned char)c * FONT_HEIGHT);
for (size_t y=0; y<FONT_HEIGHT; y++)
{
uint8_t row = glyph[y];
for (size_t x=0; x<FONT_WIDTH; x++)
{
uint32_t color = (row & (0x80 >> x)) ? fg : bg;
putpixel(px+x, py+y, color);
}
}
}
static void erase_char(size_t px, size_t py)
{
if (px+FONT_WIDTH > framebuffer->width || py+FONT_HEIGHT > framebuffer->height) return;
for (size_t y=0; y<FONT_HEIGHT; y++)
{
for (size_t x=0; x<FONT_WIDTH; x++)
{
// Black
putpixel(px+x, py+y, 0);
}
}
}
void term_scroll()
{
// Erase first text line
@@ -140,67 +109,10 @@ void term_scroll()
lines_length[max_lines - 1] = 0;
}
void putchar(char c)
{
const size_t max_cols = term_max_cols();
const size_t max_lines = term_max_lines();
if (c == '\n') {
lines_length[cursor.y] = cursor.x;
cursor.x = 0;
if (cursor.y + 1 >= max_lines)
{
term_scroll();
}
else
{
cursor.y++;
}
return;
}
if (c == '\b')
{
if (cursor.x > 0)
{
cursor.x--;
}
else if (cursor.y > 0)
{
cursor.y--;
cursor.x = lines_length[cursor.y];
}
else
{
return;
}
erase_char(cursor.x * FONT_WIDTH, cursor.y * FONT_HEIGHT);
return;
}
if (cursor.x >= max_cols)
{
cursor.x = 0;
if (cursor.y + 1 >= max_lines)
{
term_scroll();
}
else
{
cursor.y++;
}
}
draw_char(c, cursor.x * FONT_WIDTH, cursor.y * FONT_HEIGHT, WHITE, BLACK);
cursor.x++;
}
// Overhead that could be avoided, right? (for printf)
void _putchar(char character)
{
putchar(character);
flanterm_write(ft_ctx, &character, 1);
}
// Debug-printing
@@ -209,7 +121,7 @@ void kputs(const char* str)
size_t i=0;
while (str[i] != 0)
{
putchar(str[i]);
_putchar(str[i]);
i++;
}
}