From f1a9f84f2443daef5a659d11063ef3256d80f177 Mon Sep 17 00:00:00 2001 From: xamidev <121681048+xamidev@users.noreply.github.com> Date: Fri, 23 Aug 2024 13:05:53 +0200 Subject: [PATCH] Add: graphics mode terminal scrolling --- src/drivers/framebuffer.c | 38 ++++++++++++++++++++++++++++++++++ src/drivers/framebuffer.h | 1 + src/kernel/kmain.c | 11 +++++++--- src/kernel/system.c | 21 +++++++++++++++++++ src/kernel/system.h | 1 + src/libc/stdio.c | 43 ++++++++++++++------------------------- src/libc/stdio.h | 1 - src/programs/misc.c | 3 ++- 8 files changed, 86 insertions(+), 33 deletions(-) diff --git a/src/drivers/framebuffer.c b/src/drivers/framebuffer.c index 02687bd..922573e 100644 --- a/src/drivers/framebuffer.c +++ b/src/drivers/framebuffer.c @@ -1,6 +1,7 @@ #include "../libc/stdint.h" #include "framebuffer.h" #include "serial.h" +#include "../kernel/system.h" //extern uint32_t *g_framebuffer; @@ -53,3 +54,40 @@ void draw_char(unsigned short int c, int cx, int cy, uint32_t fg, uint32_t bg) offs += scanline; } } + +void scroll() +{ + serial_printf(3, "Scrolling...\r"); + uint32_t bg_color = 0x00000000; + PSF_font *font = (PSF_font*)&_binary_include_fonts_UniCyr_8x16_psf_start; + + int line_size = font->height * scanline; + int framebuffer_size = scanline * font->height * (1080/font->height); + + // Erasing first line + for (uint32_t y=0; yheight; y++) + { + for (uint32_t x=0; xheight; y++) + { + for (uint32_t x=0; xframebuffer_bpp); uint32_t pitch = fb_info->framebuffer_pitch; uint32_t bpp = fb_info->framebuffer_bpp; - //8x16 font padded with 1 for each char = 9px/char - VGA_WIDTH = width/9; - VGA_HEIGHT = height/9; + //8x16 font, not padded + VGA_WIDTH = width/8; + VGA_HEIGHT = height/16; scanline = width * (bpp/8); @@ -114,6 +114,11 @@ serial_printf(3, "Framebuffer BPP: %u\r\n", fb_info->framebuffer_bpp); } */ + for (int i=0; i<100; i++) + { + printf("%d\n", i); + } + //colorputs("Wow, such colorful output!", green, blue); colorputs(ascii_title, green, black); diff --git a/src/kernel/system.c b/src/kernel/system.c index 78f050e..36594da 100644 --- a/src/kernel/system.c +++ b/src/kernel/system.c @@ -8,6 +8,27 @@ void *memset(void *dest, char val, size_t count) return dest; } +void *memmove(void* dest, const void* src, size_t n) +{ + unsigned char* d = (unsigned char*)dest; + const unsigned char* s = (const unsigned char*)src; + + if (d < s) + { + for (size_t i=0; i0; i--) + { + d[i-1] = s[i-1]; + } + } + + return dest; +} + void panic() { for (;;); diff --git a/src/kernel/system.h b/src/kernel/system.h index 86749e6..874cf19 100644 --- a/src/kernel/system.h +++ b/src/kernel/system.h @@ -6,6 +6,7 @@ typedef int size_t; void *memset(void *dest, char val, size_t count); +void *memmove(void* dest, const void* src, size_t n); struct regs { diff --git a/src/libc/stdio.c b/src/libc/stdio.c index 080da3d..932af77 100644 --- a/src/libc/stdio.c +++ b/src/libc/stdio.c @@ -4,6 +4,7 @@ #include "stdint.h" #include "../kernel/system.h" #include "../drivers/framebuffer.h" +#include "../drivers/serial.h" extern uint32_t* framebuffer; extern uint32_t VGA_WIDTH; @@ -35,32 +36,6 @@ void clear(void) move_cursor(0, 0); } -void scroll(int lines) -{ - if (lines <= 0 || (unsigned int)lines >= VGA_HEIGHT) return; - - for (unsigned int y = 0; y < VGA_HEIGHT-lines; y++) - { - for (unsigned int x = 0; x < VGA_WIDTH; x++) - { - //putchar(getchar(x, y+lines), x, y, white, black); - } - } - - for (unsigned int y = VGA_HEIGHT-lines; y= VGA_HEIGHT) scroll(1); + if (VGA_Y >= VGA_HEIGHT) + { + serial_printf(3, "VGA_Y=%d, VGA_HEIGHT=%d: Scrolling...\r", VGA_Y, VGA_HEIGHT); + scroll(); + VGA_Y = VGA_HEIGHT - 1; + } move_cursor(VGA_X, VGA_Y); } @@ -131,7 +111,14 @@ void colorputc(char c, uint32_t fg, uint32_t bg) VGA_Y++; VGA_X = 0; } - if (VGA_Y >= VGA_HEIGHT) scroll(1); + + if (VGA_Y >= VGA_HEIGHT) + { + serial_printf(3, "VGA_Y=%d, VGA_HEIGHT=%d: Scrolling...\r", VGA_Y, VGA_HEIGHT); + scroll(); + VGA_Y = VGA_HEIGHT - 1; + } + move_cursor(VGA_X, VGA_Y); } diff --git a/src/libc/stdio.h b/src/libc/stdio.h index b8ac4be..0b4883e 100644 --- a/src/libc/stdio.h +++ b/src/libc/stdio.h @@ -19,7 +19,6 @@ void colorputs(const char* str, uint32_t fg, uint32_t bg); void putcolor(int x, int y, unsigned int color); char getchar(int x, int y); unsigned int getcolor(int x, int y); -void scroll(int lines); void putc(char c); void colorputc(char c, uint32_t fg, uint32_t bg); diff --git a/src/programs/misc.c b/src/programs/misc.c index 93fd47f..32b24c1 100644 --- a/src/programs/misc.c +++ b/src/programs/misc.c @@ -3,6 +3,7 @@ #include "../libc/stdio.h" #include "../kernel/system.h" #include "../libc/string.h" +#include "../drivers/framebuffer.h" // Print a rainbow colorful text for testing @@ -29,7 +30,7 @@ void program_rainbow() void program_clear() { - for (int i=0; i