[feat] Desktop render color
This commit is contained in:
@@ -21,7 +21,8 @@ KERNEL_CPP = kernel/entry.cpp kernel/main.cpp kernel/serial.cpp kernel/fs.cpp \
|
||||
kernel/interrupt/gdt.cpp kernel/interrupt/idt.cpp \
|
||||
kernel/interrupt/pic.cpp kernel/interrupt/pit.cpp \
|
||||
graphics/context.cpp graphics/draw.cpp \
|
||||
fonts/pixel_font.cpp
|
||||
fonts/pixel_font.cpp \
|
||||
desktop/prepare.cpp
|
||||
KERNEL_ASM = kernel/scheduler/context_switch.S kernel/interrupt/isr.S kernel/interrupt/idt_helpers.S
|
||||
KERNEL_OBJ = $(KERNEL_CPP:%.cpp=build/%.o) $(KERNEL_ASM:%.S=build/%.o)
|
||||
|
||||
@@ -47,7 +48,8 @@ all: _bd $(EFI_OBJ) $(BOOT_OBJ) $(KERNEL_OBJ)
|
||||
@echo "Done."
|
||||
|
||||
_bd:
|
||||
@mkdir -p build/graphics build/kernel build/fonts build/kernel/memory \
|
||||
@mkdir -p build/graphics build/kernel build/fonts build/desktop \
|
||||
build/kernel/memory \
|
||||
build/kernel/scheduler build/kernel/interrupt \
|
||||
build/efi/lib build/efi/lib/x86_64 build/efi/lib/runtime build/efi/gnuefi
|
||||
|
||||
@@ -117,6 +119,10 @@ build/fonts/%.o: fonts/%.cpp | _bd
|
||||
@echo "Compile CPP $<"
|
||||
@g++ $(KERNEL_CXXFLAGS) -c $< -o $@
|
||||
|
||||
build/desktop/%.o: desktop/%.cpp | _bd
|
||||
@echo "Compile CPP $<"
|
||||
@g++ $(KERNEL_CXXFLAGS) -c $< -o $@
|
||||
|
||||
vdir: all
|
||||
@mkdir -p vdir/EFI/BOOT
|
||||
@cp build/BOOTX64.EFI vdir/EFI/BOOT
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#include <graphics/draw.h>
|
||||
|
||||
void prepare(UINT32 width, UINT32 height, COLOR_RGB color) {
|
||||
for (UINT32 i = 0; i < height; i++) {
|
||||
for (UINT32 j = 0; j < width; j++) {
|
||||
draw_pixel(i, j, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ void pf_reset_position(void) {
|
||||
pf_y = 1;
|
||||
}
|
||||
|
||||
void pf_print_char(char c, unsigned int basex, unsigned int basey, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) {
|
||||
void pf_print_char(char c, unsigned int basex, unsigned int 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,7 +31,7 @@ void pf_print_char(char c, unsigned int basex, unsigned int basey, EFI_GRAPHICS_
|
||||
}
|
||||
}
|
||||
|
||||
void pf_print(const char* text, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) {
|
||||
void pf_print(const char* text, COLOR_RGB color) {
|
||||
for (unsigned int i = 0; i < strlen(text); i++) {
|
||||
char c = text[i];
|
||||
if (c == '\n') {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <graphics/context.h>
|
||||
#include <graphics/draw.h>
|
||||
|
||||
gfx_context g_gfx;
|
||||
|
||||
@@ -6,10 +7,10 @@ void gfx_init(EFI_GRAPHICS_OUTPUT_PROTOCOL *GOP) {
|
||||
g_gfx.GOP = GOP;
|
||||
g_gfx.hr = GOP->Mode->Info->HorizontalResolution;
|
||||
g_gfx.vr = GOP->Mode->Info->VerticalResolution;
|
||||
g_gfx.base = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) GOP->Mode->FrameBufferBase;
|
||||
g_gfx.base = (COLOR_RGB *) GOP->Mode->FrameBufferBase;
|
||||
}
|
||||
|
||||
void gfx_clear(void) {
|
||||
EFI_GRAPHICS_OUTPUT_BLT_PIXEL black = {0, 0, 0, 0};
|
||||
COLOR_RGB black = {0, 0, 0, 0};
|
||||
g_gfx.GOP->Blt(g_gfx.GOP, &black, EfiBltVideoFill, 0, 0, 0, 0, g_gfx.hr, g_gfx.vr, 0);
|
||||
}
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
#include <graphics/draw.h>
|
||||
|
||||
void draw_pixel(unsigned int x, unsigned int y, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) {
|
||||
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *p = g_gfx.base + (g_gfx.hr * y) + x;
|
||||
void draw_pixel(unsigned int x, unsigned int y, COLOR_RGB color) {
|
||||
COLOR_RGB *p = g_gfx.base + (g_gfx.hr * y) + x;
|
||||
|
||||
p->Blue = color.Blue;
|
||||
p->Green = color.Green;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#define ASM asm volatile
|
||||
#define COLOR_RGB EFI_GRAPHICS_OUTPUT_BLT_PIXEL
|
||||
|
||||
static unsigned int strlen(const char* arr) { // 获取string长度
|
||||
int i = 0;
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
void prepare(UINT32 width, UINT32 height, COLOR_RGB color = {144, 238, 145});
|
||||
@@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <graphics/context.h>
|
||||
#include <graphics/draw.h>
|
||||
|
||||
void pf_print_char(char c, unsigned int basex, unsigned int basey,
|
||||
EFI_GRAPHICS_OUTPUT_BLT_PIXEL color = {255, 255, 255, 255}); // Pixel Font 打印字符
|
||||
void pf_print(const char* text, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color = {255, 255, 255, 255}); // Pixel Font 打印string
|
||||
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位置
|
||||
@@ -3,12 +3,13 @@
|
||||
// 这个文件存在的目的是让graphics的draw功能不用每次传 GOP hr vr base
|
||||
|
||||
#include <efi.h>
|
||||
#include <common.h>
|
||||
|
||||
struct gfx_context {
|
||||
EFI_GRAPHICS_OUTPUT_PROTOCOL *GOP;
|
||||
unsigned int hr;
|
||||
unsigned int vr;
|
||||
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *base;
|
||||
COLOR_RGB *base;
|
||||
};
|
||||
|
||||
extern gfx_context g_gfx;
|
||||
|
||||
@@ -3,4 +3,6 @@
|
||||
#include <efi.h>
|
||||
#include <graphics/context.h>
|
||||
|
||||
void draw_pixel(unsigned int x, unsigned int y, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color); // 画像素
|
||||
#define COLOR_RGB EFI_GRAPHICS_OUTPUT_BLT_PIXEL
|
||||
|
||||
void draw_pixel(unsigned int x, unsigned int y, COLOR_RGB color); // 画像素
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
#include <fs.h>
|
||||
#include <serial.h>
|
||||
#include <kernel/fs.h>
|
||||
#include <kernel/serial.h>
|
||||
#include <memory/heap.h>
|
||||
#include <common.h>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <gdt.h>
|
||||
#include <kernel/gdt.h>
|
||||
#include <common.h>
|
||||
#include <serial.h>
|
||||
#include <kernel/serial.h>
|
||||
|
||||
static gdt_entry g_gdt[7]; // 5 segments + TSS (2 entries)
|
||||
static gdt_ptr g_gdt_ptr;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <idt.h>
|
||||
#include <kernel/idt.h>
|
||||
#include <common.h>
|
||||
#include <pic.h>
|
||||
#include <serial.h>
|
||||
#include <kernel/pic.h>
|
||||
#include <kernel/serial.h>
|
||||
|
||||
// Defined in isr.S — 256 ISR stubs
|
||||
extern "C" void* isr_stub_table[256];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <pic.h>
|
||||
#include <kernel/pic.h>
|
||||
#include <common.h>
|
||||
#include <serial.h>
|
||||
#include <kernel/serial.h>
|
||||
|
||||
static inline void outb(UINT16 port, UINT8 val) {
|
||||
ASM("outb %0, %1" : : "a"(val), "Nd"(port));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <pit.h>
|
||||
#include <kernel/pit.h>
|
||||
#include <common.h>
|
||||
#include <pic.h>
|
||||
#include <serial.h>
|
||||
#include <kernel/pic.h>
|
||||
#include <kernel/serial.h>
|
||||
|
||||
static inline void outb(UINT16 port, UINT8 val) {
|
||||
ASM("outb %0, %1" : : "a"(val), "Nd"(port));
|
||||
|
||||
+10
-7
@@ -2,16 +2,17 @@
|
||||
#include <graphics/context.h>
|
||||
#include <graphics/draw.h>
|
||||
#include <fonts/pixel_font.h>
|
||||
#include <serial.h>
|
||||
#include <kernel/serial.h>
|
||||
#include <common.h>
|
||||
#include <memory/pmm.h>
|
||||
#include <memory/heap.h>
|
||||
#include <scheduler.h>
|
||||
#include <fs.h>
|
||||
#include <gdt.h>
|
||||
#include <idt.h>
|
||||
#include <pic.h>
|
||||
#include <pit.h>
|
||||
#include <kernel/scheduler.h>
|
||||
#include <kernel/fs.h>
|
||||
#include <kernel/gdt.h>
|
||||
#include <kernel/idt.h>
|
||||
#include <kernel/pic.h>
|
||||
#include <kernel/pit.h>
|
||||
#include <desktop/prepare.h>
|
||||
|
||||
extern EFI_SYSTEM_TABLE *ST;
|
||||
|
||||
@@ -131,6 +132,8 @@ extern "C" void kernel_main() {
|
||||
pf_print("Welcome to Sylva OS!\n");
|
||||
serial_write(" Kernel prepared well.\n");
|
||||
|
||||
prepare((UINT32) g_gfx.vr, (UINT32) g_gfx.hr);
|
||||
|
||||
// --- Interrupt infrastructure ---
|
||||
serial_write("Sylva: init GDT...\n");
|
||||
gdt_init();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <memory/heap.h>
|
||||
#include <memory/pmm.h>
|
||||
#include <serial.h>
|
||||
#include <kernel/serial.h>
|
||||
|
||||
struct heap_block {
|
||||
UINTN size; // includes header; bit 0 = 1 used, 0 free
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <memory/pmm.h>
|
||||
#include <serial.h>
|
||||
#include <kernel/serial.h>
|
||||
|
||||
extern EFI_SYSTEM_TABLE *ST;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <scheduler.h>
|
||||
#include <idt.h>
|
||||
#include <pic.h>
|
||||
#include <kernel/scheduler.h>
|
||||
#include <kernel/idt.h>
|
||||
#include <kernel/pic.h>
|
||||
#include <memory/heap.h>
|
||||
#include <memory/pmm.h>
|
||||
#include <common.h>
|
||||
#include <serial.h>
|
||||
#include <kernel/serial.h>
|
||||
|
||||
// Assembly: context_switch(UINT64* old_rsp, UINT64 new_rsp)
|
||||
extern "C" void context_switch(UINT64* old_rsp, UINT64 new_rsp);
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include <serial.h>
|
||||
#include <kernel/serial.h>
|
||||
|
||||
extern EFI_SYSTEM_TABLE *ST;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user