serial Kernel panic
This commit is contained in:
@@ -9,6 +9,7 @@ because this shitty implementation will be replaced one day by Flanterm
|
||||
#include <stddef.h>
|
||||
#include <kernel.h>
|
||||
#include "term.h"
|
||||
#include "mem/misc/utils.h"
|
||||
|
||||
extern struct boot_context boot_ctx;
|
||||
|
||||
@@ -35,6 +36,8 @@ unsigned char* fb;
|
||||
|
||||
struct limine_framebuffer* framebuffer;
|
||||
|
||||
uint8_t lines_length[MAX_LINES];
|
||||
|
||||
int term_init()
|
||||
{
|
||||
// Get framebuffer address from Limine struct
|
||||
@@ -87,10 +90,51 @@ static void erase_char(int px, int py)
|
||||
}
|
||||
}
|
||||
|
||||
static inline size_t term_max_lines(void)
|
||||
{
|
||||
return framebuffer->height / FONT_HEIGHT;
|
||||
}
|
||||
|
||||
void term_scroll()
|
||||
{
|
||||
const size_t row_height = FONT_HEIGHT;
|
||||
const size_t row_bytes = framebuffer->pitch;
|
||||
const size_t screen_rows = framebuffer->height;
|
||||
|
||||
// Move framebuffer up by one text row
|
||||
memmove(fb, fb + row_height * row_bytes, (screen_rows - row_height) * row_bytes);
|
||||
|
||||
// Clear last text row
|
||||
size_t clear_start = (screen_rows - row_height) * row_bytes;
|
||||
memset(fb + clear_start, 0, row_height * row_bytes);
|
||||
|
||||
// Shift line lengths by 1 (for backspace handling)
|
||||
size_t max_lines = term_max_lines();
|
||||
for (size_t i = 1; i < max_lines; i++)
|
||||
{
|
||||
lines_length[i - 1] = lines_length[i];
|
||||
}
|
||||
|
||||
lines_length[max_lines - 1] = 0;
|
||||
|
||||
if (cursor.y > 0)
|
||||
{
|
||||
cursor.y--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void putchar(char c)
|
||||
{
|
||||
if ((c == '\n') && ((cursor.y+1)*FONT_HEIGHT >= framebuffer->height))
|
||||
{
|
||||
term_scroll();
|
||||
return;
|
||||
}
|
||||
|
||||
if (c == '\n')
|
||||
{
|
||||
lines_length[cursor.y] = cursor.x;
|
||||
cursor.x = 0;
|
||||
cursor.y++;
|
||||
return;
|
||||
@@ -110,7 +154,8 @@ void putchar(char c)
|
||||
if (cursor.x == 0)
|
||||
{
|
||||
cursor.y--;
|
||||
cursor.x = (framebuffer->width / FONT_WIDTH) -1; // here
|
||||
// cursor.x = (framebuffer->width / FONT_WIDTH) -1; // here
|
||||
cursor.x = lines_length[cursor.y];
|
||||
}
|
||||
else {
|
||||
cursor.x--;
|
||||
@@ -128,6 +173,11 @@ void putchar(char c)
|
||||
cursor.y++;
|
||||
}
|
||||
|
||||
if ((cursor.y+1)*FONT_HEIGHT >= framebuffer->height)
|
||||
{
|
||||
term_scroll();
|
||||
}
|
||||
|
||||
int px = cursor.x * FONT_WIDTH;
|
||||
int py = cursor.y * FONT_HEIGHT;
|
||||
draw_char(c, px, py, WHITE, BLACK);
|
||||
|
||||
@@ -11,6 +11,8 @@ enum TermColors
|
||||
WHITE = 0xffffff
|
||||
};
|
||||
|
||||
#define MAX_LINES 256
|
||||
|
||||
#define PSF1_FONT_MAGIC 0x0436
|
||||
|
||||
typedef struct
|
||||
|
||||
Reference in New Issue
Block a user