From bd2f08632958157e2f9d85b6a53e1826a307070d Mon Sep 17 00:00:00 2001 From: pyao12 Date: Sun, 31 May 2026 20:03:46 +0800 Subject: [PATCH] [fix] Better color? --- fonts/pixel_font.cpp | 33 ++-------------------- include/desktop/prepare.h | 2 +- include/fonts/pixel_font.h | 6 ++-- kernel/main.cpp | 58 ++------------------------------------ 4 files changed, 9 insertions(+), 90 deletions(-) diff --git a/fonts/pixel_font.cpp b/fonts/pixel_font.cpp index aac5224..b19a03c 100644 --- a/fonts/pixel_font.cpp +++ b/fonts/pixel_font.cpp @@ -3,16 +3,7 @@ #include #include -static unsigned int pf_x = 0; -static unsigned int pf_y = 1; - -void pf_reset_position(void) { - // 其实应该还要清一下屏,后面思考一个安全的做法 - pf_x = 0; - pf_y = 1; -} - -void pf_print_char(char c, unsigned int basex, unsigned int basey, COLOR_RGB color) { +void pf_print_char(char c, uint16_t basex, uint16_t basey, COLOR_RGB color) { for (unsigned int y = 0; y < 16; y++) { unsigned char data = hankaku_pixels[c][y]; for (int x = 7; x >= 0; x--) { @@ -31,27 +22,9 @@ void pf_print_char(char c, unsigned int basex, unsigned int basey, COLOR_RGB col } } -void pf_print(const char* text, COLOR_RGB color) { +void pf_print(const char* text, uint16_t basex, uint16_t basey, COLOR_RGB color) { for (unsigned int i = 0; i < strlen(text); i++) { char c = text[i]; - if (c == '\n') { - pf_x = 0; - pf_y++; - if ((pf_y - 1) * 16 >= g_gfx.vr) { - gfx_clear(); - pf_y = 1; - } - continue; - } - if (pf_x * 9 + 9 > g_gfx.hr) { - pf_x = 0; - pf_y++; - if ((pf_y - 1) * 16 >= g_gfx.vr) { - gfx_clear(); - pf_y = 1; - } - } - pf_print_char(c, pf_x * 9, (pf_y - 1) * 16, color); - pf_x++; + pf_print_char(c, basex + i * 8, basey, color); } } \ No newline at end of file diff --git a/include/desktop/prepare.h b/include/desktop/prepare.h index 4214902..c5d5efa 100644 --- a/include/desktop/prepare.h +++ b/include/desktop/prepare.h @@ -1,3 +1,3 @@ #pragma once -void prepare(UINT32 width, UINT32 height, COLOR_RGB color = {144, 238, 145}); \ No newline at end of file +void prepare(UINT32 width, UINT32 height, COLOR_RGB color = {34, 139, 34}); \ No newline at end of file diff --git a/include/fonts/pixel_font.h b/include/fonts/pixel_font.h index ca362cb..e4eb7da 100644 --- a/include/fonts/pixel_font.h +++ b/include/fonts/pixel_font.h @@ -3,7 +3,7 @@ #include #include -void pf_print_char(char c, unsigned int basex, unsigned int basey, +void pf_print_char(char c, uint16_t basex, uint16_t basey, COLOR_RGB color = {255, 255, 255, 255}); // Pixel Font 打印字符 -void pf_print(const char* text, COLOR_RGB color = {255, 255, 255, 255}); // Pixel Font 打印string -void pf_reset_position(void); // 重设Pixel Font Cursor位置 \ No newline at end of file +void pf_print(const char* text, uint16_t basex, uint16_t basey, COLOR_RGB color = {255, 255, 255, 255}); // Pixel Font 打印string +// void pf_reset_position(void); // 重设Pixel Font Cursor位置 \ No newline at end of file diff --git a/kernel/main.cpp b/kernel/main.cpp index 97af6be..c46704d 100644 --- a/kernel/main.cpp +++ b/kernel/main.cpp @@ -94,30 +94,6 @@ extern "C" void kernel_main() { serial_write("Sylva: init heap...\n"); init_heap(); - // test kmalloc/kfree - serial_write("Sylva: kmalloc test...\n"); - void* p1 = kmalloc(64); - void* p2 = kmalloc(128); - void* p3 = kmalloc(256); - serial_write("Sylva: p1 = "); - serial_write_hex((UINTN)p1); - serial_write(" p2 = "); - serial_write_hex((UINTN)p2); - serial_write(" p3 = "); - serial_write_hex((UINTN)p3); - serial_write("\n"); - - serial_write("Sylva: kfree test...\n"); - kfree(p2); - kfree(p1); - kfree(p3); - - void* p4 = kmalloc(32); - serial_write("Sylva: realloc p4 = "); - serial_write_hex((UINTN)p4); - serial_write("\n"); - kfree(p4); - serial_write("Sylva: memory init done.\n"); serial_write("Sylva: FS init...\n"); @@ -129,10 +105,10 @@ extern "C" void kernel_main() { fs_list(); } - pf_print("Welcome to Sylva OS!\n"); serial_write(" Kernel prepared well.\n"); prepare((UINT32) g_gfx.vr, (UINT32) g_gfx.hr); + pf_print("Hello from SylvaOS!", 100, 100); // --- Interrupt infrastructure --- serial_write("Sylva: init GDT...\n"); @@ -155,37 +131,7 @@ extern "C" void kernel_main() { ASM("sti"); serial_write("Sylva: interrupts enabled\n"); - // --- Multitasking demo --- - serial_write("Sylva: creating tasks...\n"); - - // Task A: prints messages — preemption handles time slicing - task_create("taskA", []() { - for (int i = 0; i < 10; i++) { - serial_write("[taskA] running iteration "); - serial_write_hex(i); - serial_write("\n"); - for (volatile int j = 0; j < 50000000; j++) {} - } - serial_write("[taskA] done\n"); - }); - - // Task B: prints messages - task_create("taskB", []() { - for (int i = 0; i < 5; i++) { - serial_write("[taskB] hello from taskB #"); - serial_write_hex(i); - serial_write("\n"); - for (volatile int j = 0; j < 50000000; j++) {} - } - serial_write("[taskB] done\n"); - }); - - // Task C: short task - task_create("taskC", []() { - serial_write("[taskC] quick task\n"); - for (volatile int j = 0; j < 50000000; j++) {} - serial_write("[taskC] finished\n"); - }); + // 现在还没有任何tasks serial_write("Sylva: starting preemptive scheduler\n"); scheduler_run(); // never returns