From 906ce6d160fa4e89f017b40e3c5c2a726fed5b0a Mon Sep 17 00:00:00 2001 From: Tom-on64 Date: Thu, 2 May 2024 17:37:58 +0200 Subject: [PATCH] Made scrolling substantually faster --- Makefile | 2 +- include/screen.h | 12 ++++++++---- include/string.h | 15 +++++++++++---- src/kernel.c | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 8ce2faf..a3c013f 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ CFLAGS = -ffreestanding -m32 -Iinclude -Wall -Wextra SRC = ./src BUILD = ./build C_FILES = calc -FONTS = testfont term16n +FONTS = testfont term16n term18n .PHONY: os clean run diff --git a/include/screen.h b/include/screen.h index 4589c42..aad6e22 100644 --- a/include/screen.h +++ b/include/screen.h @@ -93,10 +93,14 @@ uint32_t convertColor(uint32_t color) { // TODO: Reimplement larger text // TODO: Support different bpps (and still keep the colors the same) void putcAt(unsigned char c, uint32_t x, uint32_t y) { - uint8_t* vidmem = (uint8_t*)gfxMode->physicalBasePtr; - uint8_t bytesPerPx = (gfxMode->bpp+1) / 8; + // Font info uint8_t charWidth = *(font); uint8_t charHeight = *(font + 1); + // uint8_t bitmapRowLen = (charWidth - 1) / 8 + 1; // TODO: Larger font support + + // Video stuff + uint8_t bytesPerPx = (gfxMode->bpp+1) / 8; + uint8_t* vidmem = (uint8_t*)gfxMode->physicalBasePtr; uint32_t offset = (gfxMode->xRes * y * charHeight + x * charWidth) * bytesPerPx; char* bitmap = &font[((c % 128) - 1) * charHeight]; @@ -124,7 +128,7 @@ void printAt(const char* str, uint32_t x, uint32_t y) { } } -void scroll() { // TODO: Make this fast (same as everything else, it's extremely slow) +void scroll() { // TODO: Make this faster (still kinda slow) uint8_t charHeight = *(font + 1); if ((cursor.y+1) * charHeight < gfxMode->yRes) { return; } // Check if we should scroll @@ -134,7 +138,7 @@ void scroll() { // TODO: Make this fast (same as everything else, it's extremely for (uint32_t i = 1; i < lines; i++) { uint32_t address = vidmem + i * bytesPerLine; - memcopy((char*)address, (char*)(address - bytesPerLine), bytesPerLine); + memcpy32((char*)address, (char*)(address - bytesPerLine), bytesPerLine); } uint32_t color = convertColor(bgColor); diff --git a/include/string.h b/include/string.h index cf973c2..79a60d6 100644 --- a/include/string.h +++ b/include/string.h @@ -82,16 +82,23 @@ uint32_t strlen(const char* str) { } // Memory functions -char* memcopy(char* src, char* dst, uint32_t length) { +void* memcpy(void* src, void* dst, uint32_t length) { for (uint32_t i = 0; i < length; i++) { - *(dst + i) = *(src + i); + *((uint8_t*)dst + i) = *((uint8_t*)src + i); } return dst; } -char* memset(char* dst, char value, uint32_t length) { +void* memcpy32(void* src, void* dst, uint32_t length) { + for (uint32_t i = 0; i * 4 < length; i++) { + *((uint32_t*)dst + i) = *((uint32_t*)src + i); + } + return dst; +} + +void* memset(void* dst, uint8_t value, uint32_t length) { for (uint32_t i = 0; i < length; i++) { - *(dst + i) = value; + *(uint8_t*)(dst + i) = value; } return dst; } diff --git a/src/kernel.c b/src/kernel.c index 760dffe..4f78095 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -263,7 +263,7 @@ void main() { print("Loading "); print(filename); print("...\n"); - memcopy(address, font, size * 512); + memcpy(address, font, size * 512); print("Font loaded\n"); } else { for (size_t i = 0; i < size * 512; i++) {