From 97161c0797e9aa54d66b90018dfba7a9eb39e195 Mon Sep 17 00:00:00 2001 From: pointer-to-bios Date: Sun, 14 Jan 2024 15:46:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=84=E8=8C=83tty=E5=AD=97=E4=BD=93?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/include/kernel/kernel.h | 2 +- src/include/kernel/tty.h | 12 +++++++++--- src/kernel/arch/x86_64/memm_x86_64.c | 2 +- src/kernel/tty/font.c | 14 +++++++++++++- src/kernel/tty/tty.c | 26 ++++++++++++++------------ 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/include/kernel/kernel.h b/src/include/kernel/kernel.h index 5ed0bda..b3c645c 100644 --- a/src/include/kernel/kernel.h +++ b/src/include/kernel/kernel.h @@ -7,7 +7,7 @@ #include -#define ISA_STRING "x86_64" +#define ISA_NAME "x86_64" #endif diff --git a/src/include/kernel/tty.h b/src/include/kernel/tty.h index 54c00fd..d19f5e7 100644 --- a/src/include/kernel/tty.h +++ b/src/include/kernel/tty.h @@ -113,8 +113,14 @@ void tty_text_print(tty *ttyx, char *string, u32 color, u32 bgcolor); #define gen_color(r, g, b) (((b) << 16) | ((g) << 8) | (r)) -#define TTY_FONT_SCALE 2 -extern u64 font[256][64]; -extern usize font_width, font_height; +#define TTY_FONT_SCALE 1 + +typedef struct __tty_font_t +{ + u16 char_width, char_height; + u64 **font; +} tty_font_t; + +tty_font_t tty_get_font(); #endif diff --git a/src/kernel/arch/x86_64/memm_x86_64.c b/src/kernel/arch/x86_64/memm_x86_64.c index 2eeec75..6112c03 100644 --- a/src/kernel/arch/x86_64/memm_x86_64.c +++ b/src/kernel/arch/x86_64/memm_x86_64.c @@ -123,8 +123,8 @@ bool memm_map_pageframes_to( } map_pageframe_to(target, physical, user, write, align); - usize step = min(size, (usize)align * MEMM_PAGE_SIZE); + usize step = min(size, (usize)align * MEMM_PAGE_SIZE); size -= step; target += step; physical += step; diff --git a/src/kernel/tty/font.c b/src/kernel/tty/font.c index 28bb72b..ab9dd05 100644 --- a/src/kernel/tty/font.c +++ b/src/kernel/tty/font.c @@ -1,6 +1,8 @@ #include -usize font_width = 8, font_height = 16; +#include + +u16 font_width = 8, font_height = 16; u64 font[256][64] = { // 带 ‘//' 的是基准线 @@ -1880,3 +1882,13 @@ u64 font[256][64] = { 0b00000000, }, }; + +tty_font_t tty_get_font() +{ + tty_font_t refont = { + .font = (u64 **)font, + .char_width = font_width, + .char_height = font_height, + }; + return refont; +} diff --git a/src/kernel/tty/tty.c b/src/kernel/tty/tty.c index db3cc4f..fd896b4 100644 --- a/src/kernel/tty/tty.c +++ b/src/kernel/tty/tty.c @@ -50,8 +50,8 @@ void tty_set_framebuffer(tty *ttyx, framebuffer *fb) memcpy(&ttyx->typeinfo.raw_framebuffer, fb, sizeof(framebuffer)); if (ttyx->mode == tty_mode_text) { - ttyx->text.width = fb->width / font_width; - ttyx->text.height = fb->height / font_height; + ttyx->text.width = fb->width / tty_get_font().char_width; + ttyx->text.height = fb->height / tty_get_font().char_height; } } @@ -72,11 +72,12 @@ inline static void scroll_buffer( inline static void putchar( tty *ttyx, char c, u32 color, u32 bgcolor) { - for (usize j = 0; j < font_height; ++j) + tty_font_t font = tty_get_font(); + for (usize j = 0; j < font.char_height; ++j) { - for (usize i = 0; i < font_width; ++i) + for (usize i = 0; i < font.char_width; ++i) { - bool p = font[c][j] & (1 << (font_width - 1 - i)); + bool p = font.font[c][j] & (1 << (font.char_width - 1 - i)); if (p != false) { for (usize a = 0; a < TTY_FONT_SCALE; ++a) @@ -86,8 +87,8 @@ inline static void putchar( put_pixel(ttyx->typeinfo.raw_framebuffer.pointer, ttyx->typeinfo.raw_framebuffer.width, ttyx->typeinfo.raw_framebuffer.pixsize, - ttyx->text.column * font_width * TTY_FONT_SCALE + i * TTY_FONT_SCALE + a, - ttyx->text.line * font_height * TTY_FONT_SCALE + j * TTY_FONT_SCALE + b, + ttyx->text.column * font.char_width * TTY_FONT_SCALE + i * TTY_FONT_SCALE + a, + ttyx->text.line * font.char_height * TTY_FONT_SCALE + j * TTY_FONT_SCALE + b, color); } } @@ -101,8 +102,8 @@ inline static void putchar( put_pixel(ttyx->typeinfo.raw_framebuffer.pointer, ttyx->typeinfo.raw_framebuffer.width, ttyx->typeinfo.raw_framebuffer.pixsize, - ttyx->text.column * font_width * TTY_FONT_SCALE + i * TTY_FONT_SCALE + a, - ttyx->text.line * font_height * TTY_FONT_SCALE + j * TTY_FONT_SCALE + b, + ttyx->text.column * font.char_width * TTY_FONT_SCALE + i * TTY_FONT_SCALE + a, + ttyx->text.line * font.char_height * TTY_FONT_SCALE + j * TTY_FONT_SCALE + b, bgcolor); } } @@ -121,7 +122,7 @@ inline static void newline(tty *ttyx) ttyx->typeinfo.raw_framebuffer.width, ttyx->typeinfo.raw_framebuffer.height, ttyx->typeinfo.raw_framebuffer.pixsize, - font_height * TTY_FONT_SCALE); + tty_get_font().char_height * TTY_FONT_SCALE); ttyx->text.line--; } } @@ -142,6 +143,7 @@ void tty_text_print(tty *ttyx, char *string, u32 color, u32 bgcolor) t >>= 8; } } + tty_font_t font = tty_get_font(); simple_lock_lock(ttyx->text.lock); usize len = strlen(string); for (char *str = string; string - str < len; string++) @@ -172,7 +174,7 @@ void tty_text_print(tty *ttyx, char *string, u32 color, u32 bgcolor) ttyx->typeinfo.raw_framebuffer.width, ttyx->typeinfo.raw_framebuffer.height, ttyx->typeinfo.raw_framebuffer.pixsize, - font_height * TTY_FONT_SCALE); + font.char_height * TTY_FONT_SCALE); ttyx->text.line--; } continue; @@ -191,7 +193,7 @@ void tty_text_print(tty *ttyx, char *string, u32 color, u32 bgcolor) ttyx->typeinfo.raw_framebuffer.width, ttyx->typeinfo.raw_framebuffer.height, ttyx->typeinfo.raw_framebuffer.pixsize, - font_height * TTY_FONT_SCALE); + font.char_height * TTY_FONT_SCALE); continue; } // 打印字符c