diff options
Diffstat (limited to 'src/user/app/vterm')
-rw-r--r-- | src/user/app/vterm/vterm.c | 52 | ||||
-rw-r--r-- | src/user/app/vterm/vterm.h | 1 |
2 files changed, 46 insertions, 7 deletions
diff --git a/src/user/app/vterm/vterm.c b/src/user/app/vterm/vterm.c index 0468477..43180b2 100644 --- a/src/user/app/vterm/vterm.c +++ b/src/user/app/vterm/vterm.c @@ -1,7 +1,10 @@ #include "vterm.h" #include <camellia/syscalls.h> #include <stdbool.h> +#include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <unistd.h> struct point cursor = {0}; @@ -26,15 +29,50 @@ void in_char(char c) { while (cursor.y * font.h >= fb.height) scroll(); } -int main(void) { - fb_fd = _syscall_open("/kdev/video/b", 13, 0); - // TODO don't hardcode size - fb.len = 640 * 480 * 4; - fb.width = 640; - fb.height = 480; - fb.pitch = 640 * 4; +int main(); + +void fb_setup(void) { + #define BASEPATH "/kdev/video/" + char path[64], *spec; + size_t pos; + FILE *f; + + f = fopen(BASEPATH, "r"); + if (!f) { + eprintf("couldn't open %s", BASEPATH); + exit(1); + } + + pos = strlen(BASEPATH); + memcpy(path, BASEPATH, pos); + spec = path + pos; + fread(spec, 1, sizeof(path) - pos, f); + /* assumes the read went correctly */ + fclose(f); + + fb_fd = _syscall_open(path, strlen(path), 0); + if (fb_fd < 0) { + eprintf("failed to open %s", path); + exit(1); + } + + fb.width = strtol(spec, &spec, 0); + if (*spec++ != 'x') { eprintf("bad filename format"); exit(1); } + fb.height = strtol(spec, &spec, 0); + if (*spec++ != 'x') { eprintf("bad filename format"); exit(1); } + fb.bpp = strtol(spec, &spec, 0); + fb.len = _syscall_getsize(fb_fd); + fb.pitch = fb.len / fb.height; fb.b = malloc(fb.len); + if (fb.bpp != 32) { + eprintf("unsupported format %ux%ux%u", fb.width, fb.height, fb.bpp); + exit(1); + } +} + +int main(void) { + fb_setup(); font_load("/init/font.psf"); static char buf[512]; diff --git a/src/user/app/vterm/vterm.h b/src/user/app/vterm/vterm.h index 5e09105..5cfc609 100644 --- a/src/user/app/vterm/vterm.h +++ b/src/user/app/vterm/vterm.h @@ -24,6 +24,7 @@ void font_blit(uint32_t glyph, int x, int y); struct framebuf { size_t len, width, height, pitch; + uint8_t bpp; char *b; }; extern struct framebuf fb; |