From a3d6599c6b160a445339bc4a642214340982186e Mon Sep 17 00:00:00 2001 From: jwt2706 Date: Fri, 23 Aug 2024 23:08:01 -0400 Subject: [PATCH] fix y leveling --- kernel/include/terminal.h | 2 ++ kernel/src/kernel.c | 2 +- kernel/src/terminal.c | 10 +++++----- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/kernel/include/terminal.h b/kernel/include/terminal.h index 3c6f721..7bcd4bc 100644 --- a/kernel/include/terminal.h +++ b/kernel/include/terminal.h @@ -6,6 +6,8 @@ struct terminal { struct limine_framebuffer *framebuffer; + int start_x; + int start_y; int cursor_x; int cursor_y; uint32_t color; diff --git a/kernel/src/kernel.c b/kernel/src/kernel.c index ee7d251..e312189 100644 --- a/kernel/src/kernel.c +++ b/kernel/src/kernel.c @@ -67,7 +67,7 @@ void _start(void) { struct terminal term; terminal_init(&term, framebuffer, COLOR_WHITE, 2); - terminal_write(&term, "BaboscOS booted up successfully!BaboscOS booted up successfully!BaboscOS booted up successfully!BaboscOS booted up successfully!BaboscOS booted up successfully!"); + terminal_write(&term, "BaboscOS booted up successfully!BaboscOS booted up successfully!BaboscOS booted up successfully!"); terminal_edit(&term, COLOR_RED, 3); terminal_write(&term, "red color and scalesadasdasdsads 3"); diff --git a/kernel/src/terminal.c b/kernel/src/terminal.c index 9fead74..fec1b4a 100644 --- a/kernel/src/terminal.c +++ b/kernel/src/terminal.c @@ -3,8 +3,10 @@ void terminal_init(struct terminal *term, struct limine_framebuffer *framebuffer, uint32_t color, int scale) { term->framebuffer = framebuffer; - term->cursor_x = 4; - term->cursor_y = 4; + term->start_x = 4; + term->start_y = 4; + term->cursor_x = term->start_x; + term->cursor_y = term->start_y; term->color = color; term->scale = scale; } @@ -19,12 +21,11 @@ void terminal_edit(struct terminal *term, uint32_t color, int scale) { but take into account, special things like '\n' for new lines. */ void terminal_write(struct terminal *term, const char *str) { - int start_x = term->cursor_x; int max_x = term->framebuffer->width - 8 * term->scale; // maximum x position before wrapping while (*str) { if (*str == '\n' || term->cursor_x > max_x) { // if the character is a newline or cursor exceeds max_x.. term->cursor_y += 8 * term->scale; // ..offset y - term->cursor_x = start_x; // ..and reset x + term->cursor_x = term->start_x; // ..and reset x } if (*str != '\n') { terminal_write_char(term, *str); @@ -32,7 +33,6 @@ void terminal_write(struct terminal *term, const char *str) { } str++; } - term->cursor_x = start_x; } /*