From 88217deddc314172493f9aa9192ebdca8d46c4b3 Mon Sep 17 00:00:00 2001 From: tkchia Date: Tue, 6 Sep 2022 22:30:03 +0000 Subject: [PATCH] Bare metal VGA: use bing & unbing to map between CP437 & UTF-8 --- Makefile | 4 ++-- libc/calls/calls.mk | 3 +-- libc/vga/tty.c | 19 +++---------------- libc/vga/vga.mk | 3 ++- 4 files changed, 8 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 20c2d5cc6..0a14edd6f 100644 --- a/Makefile +++ b/Makefile @@ -111,12 +111,12 @@ include libc/linux/linux.mk # │ You can manipulate arrays include libc/tinymath/tinymath.mk # │ You can issue raw system calls include third_party/compiler_rt/compiler_rt.mk # │ include libc/str/str.mk # │ -include libc/vga/vga.mk # │ include third_party/xed/xed.mk # │ include third_party/zlib/zlib.mk # │ include libc/elf/elf.mk # │ include ape/ape.mk # │ -include libc/fmt/fmt.mk #─┘ +include libc/fmt/fmt.mk # │ +include libc/vga/vga.mk #─┘ include libc/calls/calls.mk #─┐ include libc/runtime/runtime.mk # ├──SYSTEMS RUNTIME include libc/crt/crt.mk # │ You can issue system calls diff --git a/libc/calls/calls.mk b/libc/calls/calls.mk index c76919609..2708a40bd 100644 --- a/libc/calls/calls.mk +++ b/libc/calls/calls.mk @@ -51,8 +51,7 @@ LIBC_CALLS_A_DIRECTDEPS = \ LIBC_STR \ LIBC_STUBS \ LIBC_SYSV_CALLS \ - LIBC_SYSV \ - LIBC_VGA + LIBC_SYSV LIBC_CALLS_A_DEPS := \ $(call uniq,$(foreach x,$(LIBC_CALLS_A_DIRECTDEPS),$($(x)))) diff --git a/libc/vga/tty.c b/libc/vga/tty.c index f7aa808c0..68b3190e8 100644 --- a/libc/vga/tty.c +++ b/libc/vga/tty.c @@ -16,6 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/fmt/bing.internal.h" #include "libc/fmt/itoa.h" #include "libc/intrin/bits.h" #include "libc/intrin/safemacros.internal.h" @@ -107,7 +108,7 @@ void _StartTty(struct Tty *tty, unsigned short yn, unsigned short xn, if (SetWcs(tty, wcs)) { size_t n = (size_t)yn * xn, i; for (i = 0; i < n; ++i) - wcs[i] = kCp437[ccs[i].ch]; + wcs[i] = bing(ccs[i].ch, 0); } _TtyResetOutputMode(tty); } @@ -361,20 +362,6 @@ static void TtyAdvance(struct Tty *tty) { } } -/* - * FIXME(tkchia): use something more efficient and flexible like unbing(), - * but without creating a circular library dependency. - */ -static int TtyUnBing(wint_t wc) { - uint8_t c; - if (wc >= 0x20 && wc <= 0x7E) - return (int)(uint8_t)wc; - for (c = 0x7F; c != 0x20; ++c) - if (kCp437[c] == wc) - return c; - return -1; -} - static void TtyWriteGlyph(struct Tty *tty, wint_t wc, int w) { uint8_t attr = TtyGetVgaAttr(tty); size_t i; @@ -385,7 +372,7 @@ static void TtyWriteGlyph(struct Tty *tty, wint_t wc, int w) { TtyAdvance(tty); } i = tty->y * Xn(tty) + tty->x; - c = TtyUnBing(wc); + c = unbing(wc); if (c == -1) c = 0xFE; tty->ccs[i] = (struct VgaTextCharCell){ c, attr }; diff --git a/libc/vga/vga.mk b/libc/vga/vga.mk index 2ce656957..0fabf0284 100644 --- a/libc/vga/vga.mk +++ b/libc/vga/vga.mk @@ -31,7 +31,8 @@ LIBC_VGA_A_DIRECTDEPS = \ LIBC_SYSV \ LIBC_STR \ LIBC_INTRIN \ - LIBC_STUBS + LIBC_STUBS \ + LIBC_FMT LIBC_VGA_A_DEPS := \ $(call uniq,$(foreach x,$(LIBC_VGA_A_DIRECTDEPS),$($(x))))