From 40b2d29b6f622e2a07257a8a4b933ab1f6559960 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 5 Dec 2019 20:32:45 +0100 Subject: Fixed mouse cursor glitching --- src/kernel/graphics/vesa.c | 32 ++++++++++++++++---------------- src/kernel/graphics/vesa.h | 2 ++ src/kernel/kernel.c | 3 --- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c index 6bc6e35..1b793a9 100644 --- a/src/kernel/graphics/vesa.c +++ b/src/kernel/graphics/vesa.c @@ -189,8 +189,11 @@ void set_optimal_resolution() vbe_set_mode(highest); uint32_t fb_size = vbe_width * vbe_height * vbe_bpl; - for (uint32_t z = 0; z < fb_size; z += 4096) + cursor_buffer = kmalloc(fb_size); + for (uint32_t z = 0; z < fb_size; z += 4096) { paging_map((uint32_t) fb + z, (uint32_t) fb + z, PT_PRESENT | PT_RW | PT_USED); + paging_map((uint32_t) cursor_buffer + z, (uint32_t) cursor_buffer + z, PT_PRESENT | PT_RW | PT_USED); + } if (vbe_height > 1440) vesa_set_font(32); else if (vbe_height > 720) vesa_set_font(24); @@ -346,31 +349,27 @@ void vesa_keyboard_char(char ch) terminal_color); } -char *prev = 0; int prev_coords[2] = {}; - void vesa_draw_cursor(int x, int y) { // Reset previous area - if (prev != 0) { - char *reset = (char *) &fb[prev_coords[0] * vbe_bpl + prev_coords[1] * vbe_pitch]; - for (int cy = 0; cy <= 19; cy++) { - for (int cx = 0; cx <= 12; cx++) { - reset[vbe_bpl * cx] = prev[vbe_bpl * cx]; - reset[vbe_bpl * cx + 1] = prev[vbe_bpl * cx + 1]; - reset[vbe_bpl * cx + 2] = prev[vbe_bpl * cx + 2]; - } - reset += vbe_pitch; + char *reset = (char *) &fb[prev_coords[0] * vbe_bpl + prev_coords[1] * vbe_pitch]; + char *prev = (char *) &cursor_buffer[prev_coords[0] * vbe_bpl + prev_coords[1] * vbe_pitch]; + for (int cy = 0; cy <= 19; cy++) { + for (int cx = 0; cx <= 12; cx++) { + reset[vbe_bpl * cx] = prev[vbe_bpl * cx]; + reset[vbe_bpl * cx + 1] = prev[vbe_bpl * cx + 1]; + reset[vbe_bpl * cx + 2] = prev[vbe_bpl * cx + 2]; } - kfree(prev); + reset += vbe_pitch; + prev += vbe_pitch; } - prev = kmalloc(19 * 12 * vbe_bpl); - // Draw cursor - char *draw = (char *) &fb[x * vbe_bpl + y * vbe_pitch]; prev_coords[0] = x; prev_coords[1] = y; + prev = (char *) &cursor_buffer[x * vbe_bpl + y * vbe_pitch]; + char *draw = (char *) &fb[x * vbe_bpl + y * vbe_pitch]; for (int cy = 0; cy <= 19; cy++) { for (int cx = 0; cx <= 12; cx++) { // Performance issue? @@ -388,6 +387,7 @@ void vesa_draw_cursor(int x, int y) } } draw += vbe_pitch; + prev += vbe_pitch; } } diff --git a/src/kernel/graphics/vesa.h b/src/kernel/graphics/vesa.h index 4ec80a4..2288760 100644 --- a/src/kernel/graphics/vesa.h +++ b/src/kernel/graphics/vesa.h @@ -255,4 +255,6 @@ int vbe_bpl; */ unsigned char *fb; +unsigned char *cursor_buffer; + #endif diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index d55fc00..69ad72a 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -70,7 +70,4 @@ void kernel_main() panic("This should NOT happen!"); // asm ("div %0" :: "r"(0)); // Exception testing x/0 - loop: - asm ("hlt"); - goto loop; } -- cgit v1.2.3