From 2624162ad88def17deb8d209c1afbd071886a1f9 Mon Sep 17 00:00:00 2001 From: antifallobst Date: Fri, 24 Feb 2023 23:44:34 +0100 Subject: [PATCH] feature (kernel): Implemented graphics_buffer text scrolling --- kernel/inc/drivers/graphics/renderer.h | 1 + kernel/src/drivers/graphics/renderer.c | 16 ++++++++++++++++ kernel/src/kmain.c | 26 +++++++++++++++----------- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/kernel/inc/drivers/graphics/renderer.h b/kernel/inc/drivers/graphics/renderer.h index 39fdf55..cd2d8ba 100644 --- a/kernel/inc/drivers/graphics/renderer.h +++ b/kernel/inc/drivers/graphics/renderer.h @@ -58,6 +58,7 @@ graphics_buffer_T* graphics_buffer_request (uint32_t pos_x, uint32_ void graphics_buffer_show (graphics_buffer_T* graphics_buffer); void graphics_buffer_hide (graphics_buffer_T* graphics_buffer); void graphics_buffer_destruct (graphics_buffer_T* graphics_buffer); +void graphics_buffer_shift_up (graphics_buffer_T* graphics_buffer, uint16_t shift); void graphics_buffer_set_pixel (graphics_buffer_T* graphics_buffer, uint32_t x, uint32_t y, color_argb_T color); color_argb_T graphics_buffer_get_pixel (graphics_buffer_T* graphics_buffer, uint32_t x, uint32_t y); void graphics_buffer_draw_char (graphics_buffer_T* graphics_buffer, uint32_t x, uint32_t y, color_argb_T color, char chr); diff --git a/kernel/src/drivers/graphics/renderer.c b/kernel/src/drivers/graphics/renderer.c index efc3f1d..f568502 100644 --- a/kernel/src/drivers/graphics/renderer.c +++ b/kernel/src/drivers/graphics/renderer.c @@ -66,6 +66,16 @@ void graphics_buffer_destruct(graphics_buffer_T* graphics_buffer) { memory_free(graphics_buffer); } +void graphics_buffer_shift_up(graphics_buffer_T* graphics_buffer, uint16_t shift) { + memory_copy(&graphics_buffer->buffer[graphics_buffer->width * shift], + graphics_buffer->buffer, + graphics_buffer->width * (graphics_buffer->height - shift) * sizeof(color_argb_T)); + + memory_set(&graphics_buffer->buffer[graphics_buffer->width * (graphics_buffer->height - shift)], + 0, + graphics_buffer->width * shift * sizeof(color_argb_T)); +} + void graphics_buffer_set_pixel(graphics_buffer_T* graphics_buffer, uint32_t x, uint32_t y, color_argb_T color) { graphics_buffer->buffer[y * graphics_buffer->width + x] = color; } @@ -113,6 +123,10 @@ position_T graphics_buffer_draw_string(graphics_buffer_T* graphics_buffer, uint3 pos.x = 0; pos.y += g_renderer.font.height; } + if (pos.y + g_renderer.font.height >= graphics_buffer->height) { + pos.y -= g_renderer.font.height; + graphics_buffer_shift_up(graphics_buffer, g_renderer.font.height); + } graphics_buffer_draw_char(graphics_buffer, pos.x, pos.y, color, string[i]); pos.x += g_renderer.font.width; break; @@ -180,6 +194,8 @@ void graphics_renderer_update_graphics_buffer(graphics_buffer_T* graphics_buffer } void graphics_renderer_update() { + memory_set(g_renderer.back_buffer, 0, g_renderer.buffer_size); + graphics_buffer_T* graphics_buffer = g_renderer.graphics_buffer_layers[GRAPHICS_BUFFER_STANDARD]; while (graphics_buffer != NULL) { graphics_renderer_update_graphics_buffer(graphics_buffer); diff --git a/kernel/src/kmain.c b/kernel/src/kmain.c index a0a653e..56f5ecc 100644 --- a/kernel/src/kmain.c +++ b/kernel/src/kmain.c @@ -81,19 +81,23 @@ void kmain(boot_info_T boot_info) { limine_terminal_print(&boot_info, "Kernel initialized\n"); log(LOG_INFO, "!=====[ Kernel Initialized ]=====!\n"); - vfs_node_T* node_temp = vfs_node_create(g_vfs_root_node, "temp", VFS_NODE_DIRECTORY); - vfs_node_T* node_system = vfs_node_create(g_vfs_root_node, "system", VFS_NODE_DIRECTORY); - vfs_node_T* node_config = vfs_node_create(node_system, "config", VFS_NODE_DIRECTORY); - vfs_node_T* node_test = vfs_node_create(node_config, "test.conf", VFS_NODE_FILE); - - vfs_node_T* result = vfs_resolve_path("/system/config/test.conf"); - if (result == node_test) { - log(LOG_DEBUG, "resolve test passed"); - } else { - log(LOG_DEBUG, "resolve test failed 0x%x != 0x%x", result, node_test); + for (int i = 0; i < 150; i++) { + log(LOG_DEBUG, "test log %d", i); } - vfs_node_dump_info(g_vfs_root_node, 0); +// vfs_node_T* node_temp = vfs_node_create(g_vfs_root_node, "temp", VFS_NODE_DIRECTORY); +// vfs_node_T* node_system = vfs_node_create(g_vfs_root_node, "system", VFS_NODE_DIRECTORY); +// vfs_node_T* node_config = vfs_node_create(node_system, "config", VFS_NODE_DIRECTORY); +// vfs_node_T* node_test = vfs_node_create(node_config, "test.conf", VFS_NODE_FILE); +// +// vfs_node_T* result = vfs_resolve_path("/system/config/test.conf"); +// if (result == node_test) { +// log(LOG_DEBUG, "resolve test passed"); +// } else { +// log(LOG_DEBUG, "resolve test failed 0x%x != 0x%x", result, node_test); +// } + +// vfs_node_dump_info(g_vfs_root_node, 0); CORE_HALT_FOREVER }