From 98ea7e6280aa7656e05334ea91406147a4ee4a36 Mon Sep 17 00:00:00 2001 From: Tom-on64 Date: Mon, 29 Apr 2024 19:38:51 +0200 Subject: [PATCH] Made screen.h more generic, instead of just assuming 1920x1080 32bpp mode --- include/screen.h | 41 +++++++++++++++++++++++++++-------------- src/kernel.c | 2 +- todo.txt | 7 +++++++ 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/include/screen.h b/include/screen.h index ac1b93a..1832719 100644 --- a/include/screen.h +++ b/include/screen.h @@ -6,6 +6,8 @@ #define MODE_INFO_BLOCK 0x5000 #define BG_COLOR 0xff010b17 #define FG_COLOR 0xffebddf4 +#define CHAR_WIDTH 8 +#define CHAR_HEIGHT 16 typedef struct modeInfoBlock_s { // Required by all VBE revisions @@ -74,23 +76,29 @@ static char* font = (char*)0x6000; static struct cursor_s cursor = { 0, 0 }; static modeInfoBlock_t* gfxMode = (modeInfoBlock_t*)MODE_INFO_BLOCK; -// TODO: Probably make the font bigger in a better way, but this works for now +uint32_t bgColor = BG_COLOR; +uint32_t fgColor = FG_COLOR; + void putcAt(unsigned char c, uint32_t x, uint32_t y) { - uint32_t* vidmem = (uint32_t*)gfxMode->physicalBasePtr; - uint32_t offset = (gfxMode->xRes * y * 16 + x * 8) * 2; + uint8_t* vidmem = (uint8_t*)gfxMode->physicalBasePtr; + uint8_t bytesPerPx = (gfxMode->bpp+1) / 8; + uint32_t offset = (gfxMode->xRes * y * CHAR_HEIGHT + x * CHAR_WIDTH) * bytesPerPx; char* bitmap = &font[((c % 128) - 1) * 16]; - for (uint8_t i = 0; i < 32; i++) { // Rows (16*2 since we draw font 2x larger) - char bitmapRow = bitmap[i/2]; // Idk if this should work, because i'm scared of division + for (uint8_t i = 0; i < CHAR_HEIGHT; i++) { // Rows + char bitmapRow = bitmap[i]; - for (uint8_t j = 0; j < 16; j++) { // Cols (8*2 same as rows) - vidmem[offset + j] = (bitmapRow & 0x80) ? FG_COLOR : BG_COLOR; - if (j % 2) { + for (uint8_t j = 0; j < CHAR_WIDTH * bytesPerPx; ++j) { // Cols + uint32_t color = (bitmapRow & 0x80) ? fgColor : bgColor; + uint8_t byte = j % bytesPerPx; + vidmem[offset + j] = (uint8_t)(color >> (8 * byte)); + + if (byte == bytesPerPx - 1) { bitmapRow = bitmapRow << 1; } - } + } - offset += gfxMode->xRes; + offset += gfxMode->linearBytesPerScanline; // gfxMode->xRes * bytesPerPx } } @@ -122,13 +130,18 @@ void print(const char* str) { } } +// TODO: Optimize this, it is VERY slow void clear() { - uint32_t* vidmem = (uint32_t*)gfxMode->physicalBasePtr; + uint8_t* vidmem = (uint8_t*)gfxMode->physicalBasePtr; + uint8_t bytesPerPx = (gfxMode->bpp+1) / 8; size_t i = 0; - while (i < gfxMode->xRes * gfxMode->yRes) { - vidmem[i] = BG_COLOR; // #1f2937 - i++; + uint8_t j = 0; + while (i < gfxMode->xRes * gfxMode->yRes) { // Loop through all pixels + vidmem[i * bytesPerPx + j] = (uint8_t)(bgColor >> (j*8)); + + j = (j + 1) % bytesPerPx; + if (!j) { i++; } } cursor.x = 0; diff --git a/src/kernel.c b/src/kernel.c index cd459c7..5dfc5df 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -54,7 +54,7 @@ void main() { print("kern.\n\n"); diskRead(5, 1, filetable); // Read the filetable and store it in memory - + // Run Interactive Shell Program // TODO: Make it in another file while (1) { diff --git a/todo.txt b/todo.txt index 6324ad6..b9e3fb2 100644 --- a/todo.txt +++ b/todo.txt @@ -16,6 +16,8 @@ - [ ] Variable text size :) - [ ] Make output overflow go to next line - [ ] More fonts + - [x] Generic screen.h stuff (don't assume 1920x1080 32bpp) + - [ ] - [x] Graphics - [?] Enter/exit a "graphics" mode (idk if we need this) - [x] Pixel drawing @@ -68,6 +70,7 @@ - [ ] Malloc() - [ ] Free() - [ ] Shell + - [ ] Separate file/program - [ ] ';' separated commands - [ ] I/O Redirection with '<' '>' - [ ] Commands @@ -111,4 +114,8 @@ - [ ] Standard libs - [ ] Finish all todos - [ ] Refactoring!!! +- [ ] Can it run DOOM? +- [ ] Games + - [ ] Minesweeper + - [ ] Solitaire