summaryrefslogtreecommitdiff
path: root/src/user/app/vterm/vterm.c
diff options
context:
space:
mode:
authordzwdz2022-08-06 00:12:51 +0200
committerdzwdz2022-08-06 00:12:51 +0200
commit03c6f3cf458c89df17b02557cd232f9cde73ed54 (patch)
treea89076307f32d9df6eec550f175accaa73d72408 /src/user/app/vterm/vterm.c
parent641b857dcfe1cfca625fbd75646b743142a9069c (diff)
make snprintf shared; dynamic resolution support
Diffstat (limited to 'src/user/app/vterm/vterm.c')
-rw-r--r--src/user/app/vterm/vterm.c52
1 files changed, 45 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];