[fix] Better color?
This commit is contained in:
+3
-30
@@ -3,16 +3,7 @@
|
|||||||
#include <graphics/draw.h>
|
#include <graphics/draw.h>
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
|
|
||||||
static unsigned int pf_x = 0;
|
void pf_print_char(char c, uint16_t basex, uint16_t basey, COLOR_RGB color) {
|
||||||
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) {
|
|
||||||
for (unsigned int y = 0; y < 16; y++) {
|
for (unsigned int y = 0; y < 16; y++) {
|
||||||
unsigned char data = hankaku_pixels[c][y];
|
unsigned char data = hankaku_pixels[c][y];
|
||||||
for (int x = 7; x >= 0; x--) {
|
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++) {
|
for (unsigned int i = 0; i < strlen(text); i++) {
|
||||||
char c = text[i];
|
char c = text[i];
|
||||||
if (c == '\n') {
|
pf_print_char(c, basex + i * 8, basey, color);
|
||||||
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++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void prepare(UINT32 width, UINT32 height, COLOR_RGB color = {144, 238, 145});
|
void prepare(UINT32 width, UINT32 height, COLOR_RGB color = {34, 139, 34});
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <graphics/context.h>
|
#include <graphics/context.h>
|
||||||
#include <graphics/draw.h>
|
#include <graphics/draw.h>
|
||||||
|
|
||||||
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 打印字符
|
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_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位置
|
// void pf_reset_position(void); // 重设Pixel Font Cursor位置
|
||||||
+2
-56
@@ -94,30 +94,6 @@ extern "C" void kernel_main() {
|
|||||||
serial_write("Sylva: init heap...\n");
|
serial_write("Sylva: init heap...\n");
|
||||||
init_heap();
|
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: memory init done.\n");
|
||||||
|
|
||||||
serial_write("Sylva: FS init...\n");
|
serial_write("Sylva: FS init...\n");
|
||||||
@@ -129,10 +105,10 @@ extern "C" void kernel_main() {
|
|||||||
fs_list();
|
fs_list();
|
||||||
}
|
}
|
||||||
|
|
||||||
pf_print("Welcome to Sylva OS!\n");
|
|
||||||
serial_write(" Kernel prepared well.\n");
|
serial_write(" Kernel prepared well.\n");
|
||||||
|
|
||||||
prepare((UINT32) g_gfx.vr, (UINT32) g_gfx.hr);
|
prepare((UINT32) g_gfx.vr, (UINT32) g_gfx.hr);
|
||||||
|
pf_print("Hello from SylvaOS!", 100, 100);
|
||||||
|
|
||||||
// --- Interrupt infrastructure ---
|
// --- Interrupt infrastructure ---
|
||||||
serial_write("Sylva: init GDT...\n");
|
serial_write("Sylva: init GDT...\n");
|
||||||
@@ -155,37 +131,7 @@ extern "C" void kernel_main() {
|
|||||||
ASM("sti");
|
ASM("sti");
|
||||||
serial_write("Sylva: interrupts enabled\n");
|
serial_write("Sylva: interrupts enabled\n");
|
||||||
|
|
||||||
// --- Multitasking demo ---
|
// 现在还没有任何tasks
|
||||||
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");
|
|
||||||
});
|
|
||||||
|
|
||||||
serial_write("Sylva: starting preemptive scheduler\n");
|
serial_write("Sylva: starting preemptive scheduler\n");
|
||||||
scheduler_run(); // never returns
|
scheduler_run(); // never returns
|
||||||
|
|||||||
Reference in New Issue
Block a user