diff --git a/.gitignore b/.gitignore index 544078c..0e18bf3 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ external/ *.o src/kernel/kernel -src/libmittos/libmittos.a \ No newline at end of file +src/libmittos/libmittos.a +src/libmittos/graphics/u_vga16.termfont.inc \ No newline at end of file diff --git a/src/libmittos/Makefile b/src/libmittos/Makefile index 943eb17..2eeca37 100644 --- a/src/libmittos/Makefile +++ b/src/libmittos/Makefile @@ -17,6 +17,9 @@ LDFLAGS := -nostdlib -r libmittos.a: $(OBJ) $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@ +graphics/graphics.o: graphics/u_vga16.termfont.inc +graphics/u_vga16.termfont.inc: + ${BUILDROOT}/toolchain/build-uni_vga.sh # Automatic dependency tracking DEP := $(OBJ:.o=.d) diff --git a/src/libmittos/graphics/graphics.c b/src/libmittos/graphics/graphics.c index 911a40f..6550dfc 100644 --- a/src/libmittos/graphics/graphics.c +++ b/src/libmittos/graphics/graphics.c @@ -5,7 +5,7 @@ #define incptr(p, n) ((void *)(((uintptr_t)(p)) + (n))) -#include "termfont.inc" +#include "u_vga16.termfont.inc" void putpixel(gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr) { @@ -52,12 +52,12 @@ void draw_rect(gfx_context *ctx, uint64_t x, uint64_t y, uint64_t width, uint64_ putpixel(ctx, x, _y, clr); putpixel(ctx, x+width, _y, clr); } + } void putCharacter(gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr_fg, uint32_t clr_bg, char c) { - - char *chr = c ? font[(int)c-0x20]: font[0]; + unsigned char *chr = c ? font[(int)c-0x20]: font[0]; if(x >= ctx->width || y >= ctx->height) return; uint64_t loc = \ y * ctx->pitch + \ diff --git a/toolchain/build-uni_vga.sh b/toolchain/build-uni_vga.sh new file mode 100755 index 0000000..a22a18e --- /dev/null +++ b/toolchain/build-uni_vga.sh @@ -0,0 +1,42 @@ +#!/bin/sh -e + +mkdir -p /opt/external && cd /opt/external +[ -f "uni-vga.tgz" ] || wget "https://www.inp.nsk.su/~bolkhov/files/fonts/univga/uni-vga.tgz" +[ -d "uni_vga" ] || tar -xf uni-vga.tgz + +cd uni_vga +python3 - << EOF + +codepoint = 0 +reading = False + +chars = {} + +with open("u_vga16.bdf") as fp: + while line := fp.readline(): + + if line.startswith("ENCODING"): + codepoint = int(line.split()[1]) + continue + + if line.startswith("BITMAP"): + values = [] + while True: + line = fp.readline() + if line.startswith("ENDCHAR"): + break + values.append(int(line, 16)) + chars[codepoint] = values + +with open("u_vga16.termfont.inc", "w") as fp: + fp.write("// THIS FILE IS GENERATED BY toolchain/build-univga-font.sh\n") + fp.write(f"unsigned char font[{127-32}][16] =") + fp.write("{\n") + + for codepoint in range(32, 127): + fp.write("\t{" + ", ".join([f"0x{v:02X}" for v in chars.get(codepoint, [])]) + "},\n") + + fp.write("};") +EOF + +cp u_vga16.termfont.inc ${BUILDROOT}/src/libmittos/graphics/. \ No newline at end of file