diff --git a/fonts/pixel_font.cpp b/fonts/pixel_font.cpp index 88e7189..fc6d69b 100644 --- a/fonts/pixel_font.cpp +++ b/fonts/pixel_font.cpp @@ -3,10 +3,10 @@ #include #include -void pf_print_char(char c, unsigned int basex, unsigned int basey, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) { - for (unsigned int y = 0; y < 16; y++) { - unsigned char data = hankaku_pixels[c][y]; - for (int x = 7; x >= 0; x--) { +void pf_print_char(char c, SUINT32 basex, SUINT32 basey, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) { + for (SUINT32 y = 0; y < 16; y++) { + SUINT8 data = hankaku_pixels[c][y]; + for (SSINT32 x = 7; x >= 0; x--) { // 解码Hankaku字体 /* 既然都在这了,就讲一下Hankaku字体是如何解码的 @@ -14,7 +14,7 @@ void pf_print_char(char c, unsigned int basex, unsigned int basey, EFI_GRAPHICS_ {0x00, 0x82, 0x82, 0x44, 0x44, 0x44, 0x28, 0x28, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00} 每一个Hex代表一行,比如0x82就是一行,转换成Bin得到10000010,1代表有像素,0代表没像素 */ - unsigned int current = data & 1; + SUINT32 current = data & 1; data >>= 1; if (current) draw_pixel(basex + x, basey + y, color); @@ -22,8 +22,8 @@ void pf_print_char(char c, unsigned int basex, unsigned int basey, EFI_GRAPHICS_ } } -void pf_print(const char* text, unsigned int basex, unsigned int basey, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) { - for (unsigned int i = 0; i < strlen(text); i++) { +void pf_print(const char* text, SUINT32 basex, SUINT32 basey, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) { + for (SUINT32 i = 0; i < strlen(text); i++) { char c = text[i]; pf_print_char(c, basex + i * 8, basey, color); // 只要 字数 * 8 + basex 不爆hr就没事 } diff --git a/graphics/context.cpp b/graphics/context.cpp index f3b9c04..86bf3db 100644 --- a/graphics/context.cpp +++ b/graphics/context.cpp @@ -24,7 +24,7 @@ void gfx_clear(void) { g_gfx.GOP->Blt(g_gfx.GOP, &black, EfiBltVideoFill, 0, 0, 0, 0, g_gfx.hr, g_gfx.vr, 0); } -void draw_set_target(EFI_GRAPHICS_OUTPUT_BLT_PIXEL *buf, unsigned int w, unsigned int h) { +void draw_set_target(EFI_GRAPHICS_OUTPUT_BLT_PIXEL *buf, SUINT32 w, SUINT32 h) { g_draw_target.buf = buf; g_draw_target.w = w; g_draw_target.h = h; diff --git a/graphics/draw.cpp b/graphics/draw.cpp index d2e7e08..1077a9e 100644 --- a/graphics/draw.cpp +++ b/graphics/draw.cpp @@ -2,7 +2,7 @@ // --- Global (framebuffer) --- -void global_draw_pixel(unsigned int x, unsigned int y, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) { +void global_draw_pixel(SUINT32 x, SUINT32 y, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) { EFI_GRAPHICS_OUTPUT_BLT_PIXEL *p = g_gfx.base + (g_gfx.hr * y) + x; p->Blue = color.Blue; p->Green = color.Green; @@ -10,16 +10,16 @@ void global_draw_pixel(unsigned int x, unsigned int y, EFI_GRAPHICS_OUTPUT_BLT_P p->Reserved = color.Reserved; } -void global_draw_rect(unsigned int bx, unsigned int by, unsigned int ex, unsigned int ey, +void global_draw_rect(SUINT32 bx, SUINT32 by, SUINT32 ex, SUINT32 ey, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) { - for (unsigned int x = bx; x <= ex; x++) - for (unsigned int y = by; y <= ey; y++) + for (SUINT32 x = bx; x <= ex; x++) + for (SUINT32 y = by; y <= ey; y++) global_draw_pixel(x, y, color); } // --- Current target buffer --- -void draw_pixel(unsigned int x, unsigned int y, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) { +void draw_pixel(SUINT32 x, SUINT32 y, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) { if (x >= g_draw_target.w || y >= g_draw_target.h) return; EFI_GRAPHICS_OUTPUT_BLT_PIXEL *p = g_draw_target.buf + (g_draw_target.w * y) + x; p->Blue = color.Blue; @@ -28,9 +28,9 @@ void draw_pixel(unsigned int x, unsigned int y, EFI_GRAPHICS_OUTPUT_BLT_PIXEL co p->Reserved = color.Reserved; } -void draw_rect(unsigned int bx, unsigned int by, unsigned int ex, unsigned int ey, +void draw_rect(SUINT32 bx, SUINT32 by, SUINT32 ex, SUINT32 ey, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) { - for (unsigned int x = bx; x <= ex; x++) - for (unsigned int y = by; y <= ey; y++) + for (SUINT32 x = bx; x <= ex; x++) + for (SUINT32 y = by; y <= ey; y++) draw_pixel(x, y, color); } diff --git a/include/common.h b/include/common.h index 11a9603..ccecc24 100644 --- a/include/common.h +++ b/include/common.h @@ -1,9 +1,10 @@ #pragma once +#include #define ASM asm volatile -static unsigned int strlen(const char* arr) { // 获取string长度 - int i = 0; +static SUINT32 strlen(const char* arr) { // 获取string长度 + SSINT32 i = 0; while (arr[i++] != '\0'); return i - 1; } \ No newline at end of file diff --git a/include/fonts/hankaku.h b/include/fonts/hankaku.h index 542e081..d4dd12a 100644 --- a/include/fonts/hankaku.h +++ b/include/fonts/hankaku.h @@ -1,7 +1,8 @@ #pragma once +#include // Hankaku 字体,不动 -static unsigned char hankaku_pixels[256][16] = { +static SUINT8 hankaku_pixels[256][16] = { {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x10, 0x10, 0x38, 0x38, 0x7c, 0x7c, 0xfe, 0xfe, 0x7c, 0x7c, 0x38, 0x38, 0x10, 0x10, 0x00, 0x00}, {0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x00, 0x00}, diff --git a/include/fonts/pixel_font.h b/include/fonts/pixel_font.h index 9008641..02faf58 100644 --- a/include/fonts/pixel_font.h +++ b/include/fonts/pixel_font.h @@ -2,6 +2,6 @@ #include -void pf_print_char(char c, unsigned int basex, unsigned int basey, +void pf_print_char(char c, SUINT32 basex, SUINT32 basey, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color = {255, 255, 255, 255}); // Pixel Font 打印字符 -void pf_print(const char* text, unsigned int basex, unsigned int basey, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color = {255, 255, 255, 255}); // Pixel Font 打印string \ No newline at end of file +void pf_print(const char* text, SUINT32 basex, SUINT32 basey, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color = {255, 255, 255, 255}); // Pixel Font 打印string \ No newline at end of file diff --git a/include/graphics/context.h b/include/graphics/context.h index 3ed58e8..218c242 100644 --- a/include/graphics/context.h +++ b/include/graphics/context.h @@ -3,11 +3,12 @@ // 这个文件存在的目的是让graphics的draw功能不用每次传 GOP hr vr base #include +#include struct gfx_context { EFI_GRAPHICS_OUTPUT_PROTOCOL *GOP; - unsigned int hr; - unsigned int vr; + SUINT32 hr; + SUINT32 vr; EFI_GRAPHICS_OUTPUT_BLT_PIXEL *base; }; @@ -15,13 +16,13 @@ extern gfx_context g_gfx; struct draw_target { EFI_GRAPHICS_OUTPUT_BLT_PIXEL *buf; - unsigned int w; - unsigned int h; + SUINT32 w; + SUINT32 h; }; extern draw_target g_draw_target; void gfx_init(EFI_GRAPHICS_OUTPUT_PROTOCOL *GOP); void gfx_clear(void); -void draw_set_target(EFI_GRAPHICS_OUTPUT_BLT_PIXEL *buf, unsigned int w, unsigned int h); +void draw_set_target(EFI_GRAPHICS_OUTPUT_BLT_PIXEL *buf, SUINT32 w, SUINT32 h); void draw_set_default_target(void); \ No newline at end of file diff --git a/include/graphics/draw.h b/include/graphics/draw.h index df9a3af..f80db3e 100644 --- a/include/graphics/draw.h +++ b/include/graphics/draw.h @@ -3,10 +3,10 @@ #include #include -void global_draw_pixel(unsigned int x, unsigned int y, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color); -void global_draw_rect(unsigned int bx, unsigned int by, unsigned int ex, unsigned int ey, +void global_draw_pixel(SUINT32 x, SUINT32 y, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color); +void global_draw_rect(SUINT32 bx, SUINT32 by, SUINT32 ex, SUINT32 ey, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color); -void draw_pixel(unsigned int x, unsigned int y, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color); -void draw_rect(unsigned int bx, unsigned int by, unsigned int ex, unsigned int ey, +void draw_pixel(SUINT32 x, SUINT32 y, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color); +void draw_rect(SUINT32 bx, SUINT32 by, SUINT32 ex, SUINT32 ey, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color); diff --git a/include/graphics/layer.h b/include/graphics/layer.h index 8c828a2..2ede234 100644 --- a/include/graphics/layer.h +++ b/include/graphics/layer.h @@ -1,6 +1,7 @@ #pragma once #include +#include #define LAYER_MAX 32 #define LAYER_NAME_LEN 32 @@ -16,9 +17,9 @@ typedef struct layer { UINT32 id; char name[LAYER_NAME_LEN]; layer_type_t type; - int x, y; + SSINT32 x, y; UINT32 w, h; - int z; + SSINT32 z; bool visible; EFI_GRAPHICS_OUTPUT_BLT_PIXEL* buffer; struct layer* next; @@ -30,8 +31,8 @@ void layer_init(void); // Layer management layer_t* layer_create(const char* name, layer_type_t type, UINT32 w, UINT32 h); void layer_destroy(layer_t* layer); -void layer_set_z(layer_t* layer, int z); -void layer_set_pos(layer_t* layer, int x, int y); +void layer_set_z(layer_t* layer, SSINT32 z); +void layer_set_pos(layer_t* layer, SSINT32 x, SSINT32 y); void layer_set_visible(layer_t* layer, bool visible); layer_t* layer_get_by_id(UINT32 id); layer_t* layer_get_focused(void); diff --git a/include/types.h b/include/types.h new file mode 100644 index 0000000..bf71c34 --- /dev/null +++ b/include/types.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +// Signed integers +#define SSINT8 int8_t +#define SSINT16 int16_t +#define SSINT32 int32_t +#define SSINT64 int64_t + +// Unsigned integers +#define SUINT8 uint8_t +#define SUINT16 uint16_t +#define SUINT32 uint32_t +#define SUINT64 uint64_t diff --git a/kernel/fs.cpp b/kernel/fs.cpp index 87eaed1..3f3e421 100644 --- a/kernel/fs.cpp +++ b/kernel/fs.cpp @@ -216,7 +216,7 @@ static EFI_STATUS find_mbr_partition(struct block_dev *dev, UINT64 *StartLBA) { struct MBRPart *Parts = (struct MBRPart*)(Buf + 446); // Verify at least one non-zero partition entry exists BOOLEAN has_part = FALSE; - for (int i = 0; i < 4; i++) { + for (SSINT32 i = 0; i < 4; i++) { if (Parts[i].Type != 0x00 && Parts[i].Type != 0xEE) { has_part = TRUE; break; @@ -224,7 +224,7 @@ static EFI_STATUS find_mbr_partition(struct block_dev *dev, UINT64 *StartLBA) { } if (!has_part) { kfree(Buf); return EFI_NOT_FOUND; } - for (int i = 0; i < 4; i++) { + for (SSINT32 i = 0; i < 4; i++) { UINT8 t = Parts[i].Type; if (t == 0x00 || t == 0xEE) continue; if (t == MBR_TYPE_FAT12 || t == MBR_TYPE_FAT16 || @@ -238,7 +238,7 @@ static EFI_STATUS find_mbr_partition(struct block_dev *dev, UINT64 *StartLBA) { } // Fallback: first non-empty partition - for (int i = 0; i < 4; i++) { + for (SSINT32 i = 0; i < 4; i++) { if (Parts[i].Type != 0x00) { *StartLBA = Parts[i].LBABegin; kfree(Buf); @@ -361,7 +361,7 @@ static EFI_STATUS fat_init(struct fat_fs *fs, struct block_dev *dev, UINT64 Part static UINT8 lfn_checksum(const UINT8 *SFN) { UINT8 sum = 0; - for (int i = 0; i < 11; i++) + for (SSINT32 i = 0; i < 11; i++) sum = ((sum & 1) ? 0x80 : 0) + (sum >> 1) + SFN[i]; return sum; } @@ -381,17 +381,17 @@ static void lfn_reset(struct lfn_state *lfn) { static void lfn_add(struct lfn_state *lfn, const UINT8 *E) { if (lfn->count >= LFN_MAX_FRAGS) return; UINTN pos = 0; - for (int i = 0; i < 5 && pos < LFN_FRAG_SIZE; i++) { + for (SSINT32 i = 0; i < 5 && pos < LFN_FRAG_SIZE; i++) { CHAR16 c = *(const UINT16*)(E + 1 + i * 2); if (c == 0x0000 || c == 0xFFFF) { lfn->frags[lfn->count][pos] = 0; return; } lfn->frags[lfn->count][pos++] = c; } - for (int i = 0; i < 6 && pos < LFN_FRAG_SIZE; i++) { + for (SSINT32 i = 0; i < 6 && pos < LFN_FRAG_SIZE; i++) { CHAR16 c = *(const UINT16*)(E + 14 + i * 2); if (c == 0x0000 || c == 0xFFFF) { lfn->frags[lfn->count][pos] = 0; return; } lfn->frags[lfn->count][pos++] = c; } - for (int i = 0; i < 2 && pos < LFN_FRAG_SIZE; i++) { + for (SSINT32 i = 0; i < 2 && pos < LFN_FRAG_SIZE; i++) { CHAR16 c = *(const UINT16*)(E + 28 + i * 2); if (c == 0x0000 || c == 0xFFFF) { lfn->frags[lfn->count][pos] = 0; return; } lfn->frags[lfn->count][pos++] = c; @@ -413,11 +413,11 @@ static void lfn_build(struct lfn_state *lfn, CHAR16 *out, UINTN out_size) { static void sfn_to_name(const UINT8 *E, CHAR16 *out, UINTN out_size) { UINTN pos = 0; - for (int i = 0; i < 8 && pos < out_size - 1; i++) + for (SSINT32 i = 0; i < 8 && pos < out_size - 1; i++) if (E[i] != ' ') out[pos++] = E[i]; UINTN ext_start = pos; BOOLEAN has_ext = FALSE; - for (int i = 8; i < 11 && pos < out_size - 1; i++) { + for (SSINT32 i = 8; i < 11 && pos < out_size - 1; i++) { if (E[i] != ' ') { if (!has_ext) { out[pos++] = '.'; has_ext = TRUE; ext_start = pos; } out[pos++] = E[i]; @@ -533,7 +533,7 @@ static BOOLEAN g_fs_inited = FALSE; struct list_ctx { struct fat_fs *fs; - int depth; + SSINT32 depth; }; static void name_to_ascii(const CHAR16 *Name, char *Ascii, UINTN ascii_sz) { @@ -550,7 +550,7 @@ static void name_to_ascii(const CHAR16 *Name, char *Ascii, UINTN ascii_sz) { static void list_callback(void *ctx, const CHAR16 *Name, UINT8 Attr, UINT32 Size, UINT32 FirstClus) { struct list_ctx *lc = (struct list_ctx*)ctx; - for (int i = 0; i < lc->depth; i++) serial_write(" "); + for (SSINT32 i = 0; i < lc->depth; i++) serial_write(" "); serial_write(Attr & 0x10 ? "[DIR] " : "[FILE] "); diff --git a/kernel/graphics/layer.cpp b/kernel/graphics/layer.cpp index 995a29e..9f3aabc 100644 --- a/kernel/graphics/layer.cpp +++ b/kernel/graphics/layer.cpp @@ -86,7 +86,7 @@ layer_t* layer_create(const char* name, layer_type_t type, UINT32 w, UINT32 h) { const char* s = name; char* d = layer->name; - for (int i = 0; i < LAYER_NAME_LEN - 1 && *s; i++) { + for (SSINT32 i = 0; i < LAYER_NAME_LEN - 1 && *s; i++) { *d++ = *s++; } *d = '\0'; @@ -149,14 +149,14 @@ layer_t* layer_get_focused(void) { return g_focused; } -void layer_set_z(layer_t* layer, int z) { +void layer_set_z(layer_t* layer, SSINT32 z) { if (!layer) return; layer_remove(layer); layer->z = z; layer_insert_sorted(layer); } -void layer_set_pos(layer_t* layer, int x, int y) { +void layer_set_pos(layer_t* layer, SSINT32 x, SSINT32 y) { if (!layer) return; layer->x = x; layer->y = y; @@ -281,14 +281,14 @@ void layer_compositor_task(void) { layer_t* cur = g_layer_list; while (cur) { if (cur->visible && cur->buffer) { - int sx = 0, sy = 0; - int dx = cur->x, dy = cur->y; + SSINT32 sx = 0, sy = 0; + SSINT32 dx = cur->x, dy = cur->y; UINT32 sw = cur->w, sh = cur->h; if (dx < 0) { sx = -dx; sw -= sx; dx = 0; } if (dy < 0) { sy = -dy; sh -= sy; dy = 0; } - if (dx + (int)sw > (int)hr) sw = hr - dx; - if (dy + (int)sh > (int)vr) sh = vr - dy; + if (dx + (SSINT32)sw > (SSINT32)hr) sw = hr - dx; + if (dy + (SSINT32)sh > (SSINT32)vr) sh = vr - dy; if (sw == 0 || sh == 0) { cur = cur->next; continue; } for (UINT32 row = 0; row < sh; row++) { diff --git a/kernel/interrupt/gdt.cpp b/kernel/interrupt/gdt.cpp index f74da9a..97c9089 100644 --- a/kernel/interrupt/gdt.cpp +++ b/kernel/interrupt/gdt.cpp @@ -41,7 +41,7 @@ static void tss_set_descriptor(UINT32 index) { void gdt_init(void) { serial_write("GDT: initializing\n"); - for (int i = 0; i < 7; i++) { + for (SSINT32 i = 0; i < 7; i++) { g_gdt[i] = {0}; } diff --git a/kernel/interrupt/idt.cpp b/kernel/interrupt/idt.cpp index 70ae035..2cbd303 100644 --- a/kernel/interrupt/idt.cpp +++ b/kernel/interrupt/idt.cpp @@ -47,13 +47,13 @@ void idt_init(void) { serial_write("IDT: initializing 256 entries\n"); // Clear IDT - for (int i = 0; i < 256; i++) { + for (SSINT32 i = 0; i < 256; i++) { g_idt[i] = {0}; g_handlers[i] = NULL; } // Install all 256 ISR stubs - for (int i = 0; i < 256; i++) { + for (SSINT32 i = 0; i < 256; i++) { idt_set_entry(i, (UINT64)isr_stub_table[i]); } diff --git a/kernel/main.cpp b/kernel/main.cpp index 8277794..457aa66 100644 --- a/kernel/main.cpp +++ b/kernel/main.cpp @@ -173,7 +173,7 @@ extern "C" void kernel_main() { // Create window 1 (centered) layer_t* win1 = layer_create("window_1", LAYER_TYPE_WINDOW, 300, 200); if (win1) { - layer_set_pos(win1, (int)(g_gfx.hr / 2) - 150, (int)(g_gfx.vr / 2) - 100); + layer_set_pos(win1, (SSINT32)(g_gfx.hr / 2) - 150, (SSINT32)(g_gfx.vr / 2) - 100); layer_set_z(win1, 1); EFI_GRAPHICS_OUTPUT_BLT_PIXEL win_color = {200, 200, 200, 0}; draw_set_target(win1->buffer, 300, 200); @@ -184,7 +184,7 @@ extern "C" void kernel_main() { // Create window 2 (offset from center) layer_t* win2 = layer_create("window_2", LAYER_TYPE_WINDOW, 250, 180); if (win2) { - layer_set_pos(win2, (int)(g_gfx.hr / 2) - 50, (int)(g_gfx.vr / 2) - 40); + layer_set_pos(win2, (SSINT32)(g_gfx.hr / 2) - 50, (SSINT32)(g_gfx.vr / 2) - 40); layer_set_z(win2, 2); EFI_GRAPHICS_OUTPUT_BLT_PIXEL win2_color = {180, 220, 140, 0}; draw_set_target(win2->buffer, 250, 180); diff --git a/kernel/scheduler/scheduler.cpp b/kernel/scheduler/scheduler.cpp index 09a8b64..9aa73ad 100644 --- a/kernel/scheduler/scheduler.cpp +++ b/kernel/scheduler/scheduler.cpp @@ -55,7 +55,7 @@ task_t* task_create(const char* name, void (*entry)(void)) { // Copy name const char* s = name; char* d = task->name; - for (int i = 0; i < TASK_NAME_LEN - 1 && *s; i++) { + for (SSINT32 i = 0; i < TASK_NAME_LEN - 1 && *s; i++) { *d++ = *s++; } *d = '\0'; diff --git a/kernel/serial.cpp b/kernel/serial.cpp index 4681623..2a00a64 100644 --- a/kernel/serial.cpp +++ b/kernel/serial.cpp @@ -1,4 +1,5 @@ #include +#include extern EFI_SYSTEM_TABLE *ST; @@ -34,7 +35,7 @@ void serial_write(const char *str) { void serial_write_hex(UINTN val) { char buf[19]; buf[0] = '0'; buf[1] = 'x'; - for (int i = 17; i >= 2; i--) { + for (SSINT32 i = 17; i >= 2; i--) { UINTN digit = val & 0xF; buf[i] = digit < 10 ? '0' + digit : 'A' + digit - 10; val >>= 4;