Bare metal VGA: use bing & unbing to map between CP437 & UTF-8

This commit is contained in:
tkchia 2022-09-06 22:30:03 +00:00
parent d4d24482ce
commit 88217deddc
4 changed files with 8 additions and 21 deletions

View file

@ -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 libc/tinymath/tinymath.mk # │ You can issue raw system calls
include third_party/compiler_rt/compiler_rt.mk # │ include third_party/compiler_rt/compiler_rt.mk # │
include libc/str/str.mk # │ include libc/str/str.mk # │
include libc/vga/vga.mk # │
include third_party/xed/xed.mk # │ include third_party/xed/xed.mk # │
include third_party/zlib/zlib.mk # │ include third_party/zlib/zlib.mk # │
include libc/elf/elf.mk # │ include libc/elf/elf.mk # │
include ape/ape.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/calls/calls.mk #─┐
include libc/runtime/runtime.mk # ├──SYSTEMS RUNTIME include libc/runtime/runtime.mk # ├──SYSTEMS RUNTIME
include libc/crt/crt.mk # │ You can issue system calls include libc/crt/crt.mk # │ You can issue system calls

View file

@ -51,8 +51,7 @@ LIBC_CALLS_A_DIRECTDEPS = \
LIBC_STR \ LIBC_STR \
LIBC_STUBS \ LIBC_STUBS \
LIBC_SYSV_CALLS \ LIBC_SYSV_CALLS \
LIBC_SYSV \ LIBC_SYSV
LIBC_VGA
LIBC_CALLS_A_DEPS := \ LIBC_CALLS_A_DEPS := \
$(call uniq,$(foreach x,$(LIBC_CALLS_A_DIRECTDEPS),$($(x)))) $(call uniq,$(foreach x,$(LIBC_CALLS_A_DIRECTDEPS),$($(x))))

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/fmt/bing.internal.h"
#include "libc/fmt/itoa.h" #include "libc/fmt/itoa.h"
#include "libc/intrin/bits.h" #include "libc/intrin/bits.h"
#include "libc/intrin/safemacros.internal.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)) { if (SetWcs(tty, wcs)) {
size_t n = (size_t)yn * xn, i; size_t n = (size_t)yn * xn, i;
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
wcs[i] = kCp437[ccs[i].ch]; wcs[i] = bing(ccs[i].ch, 0);
} }
_TtyResetOutputMode(tty); _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) { static void TtyWriteGlyph(struct Tty *tty, wint_t wc, int w) {
uint8_t attr = TtyGetVgaAttr(tty); uint8_t attr = TtyGetVgaAttr(tty);
size_t i; size_t i;
@ -385,7 +372,7 @@ static void TtyWriteGlyph(struct Tty *tty, wint_t wc, int w) {
TtyAdvance(tty); TtyAdvance(tty);
} }
i = tty->y * Xn(tty) + tty->x; i = tty->y * Xn(tty) + tty->x;
c = TtyUnBing(wc); c = unbing(wc);
if (c == -1) if (c == -1)
c = 0xFE; c = 0xFE;
tty->ccs[i] = (struct VgaTextCharCell){ c, attr }; tty->ccs[i] = (struct VgaTextCharCell){ c, attr };

View file

@ -31,7 +31,8 @@ LIBC_VGA_A_DIRECTDEPS = \
LIBC_SYSV \ LIBC_SYSV \
LIBC_STR \ LIBC_STR \
LIBC_INTRIN \ LIBC_INTRIN \
LIBC_STUBS LIBC_STUBS \
LIBC_FMT
LIBC_VGA_A_DEPS := \ LIBC_VGA_A_DEPS := \
$(call uniq,$(foreach x,$(LIBC_VGA_A_DIRECTDEPS),$($(x)))) $(call uniq,$(foreach x,$(LIBC_VGA_A_DIRECTDEPS),$($(x))))