规范tty模块的字体接口
This commit is contained in:
parent
def9bc89ca
commit
843ab95aa0
|
@ -111,10 +111,16 @@ void tty_set_framebuffer(tty *ttyx, framebuffer *fb);
|
|||
*/
|
||||
void tty_text_print(tty *ttyx, char *string, u32 color, u32 bgcolor);
|
||||
|
||||
#define gen_color(r, g, b) (((b) << 16) | ((g) << 8) | (r))
|
||||
#define gen_color(r, g, b) (((r) << 16) | ((g) << 8) | (b))
|
||||
|
||||
#define TTY_FONT_SCALE 2
|
||||
extern u64 font[256][64];
|
||||
extern usize font_width, font_height;
|
||||
|
||||
typedef struct __tty_font_t
|
||||
{
|
||||
u16 char_width, char_height;
|
||||
u64 **font;
|
||||
} tty_font_t;
|
||||
|
||||
tty_font_t *tty_get_font();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <types.h>
|
||||
|
||||
usize font_width = 8, font_height = 16;
|
||||
#include <kernel/tty.h>
|
||||
|
||||
u16 font_width = 8, font_height = 16;
|
||||
|
||||
u64 font[256][64] = {
|
||||
// 带 ‘//' 的是基准线
|
||||
|
@ -1880,3 +1882,25 @@ u64 font[256][64] = {
|
|||
0b00000000,
|
||||
},
|
||||
};
|
||||
|
||||
bool initialized = false;
|
||||
|
||||
u64 *font_pointers[256];
|
||||
tty_font_t refont = {
|
||||
.font = (u64 **)font_pointers,
|
||||
.char_width = 8,
|
||||
.char_height = 16,
|
||||
};
|
||||
|
||||
tty_font_t *tty_get_font()
|
||||
{
|
||||
if (initialized == false)
|
||||
{
|
||||
for (usize i = 0; i < 256; i++)
|
||||
{
|
||||
font_pointers[i] = font[i];
|
||||
}
|
||||
initialized = true;
|
||||
}
|
||||
return &refont;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue