summaryrefslogtreecommitdiff
path: root/src/user/app/vterm/vterm.c
blob: 0468477b688bd1c2a67d58b30d2d0476b716ad8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "vterm.h"
#include <camellia/syscalls.h>
#include <stdbool.h>
#include <stdlib.h>

struct point cursor = {0};

void in_char(char c) {
	switch (c) {
		case '\n':
			cursor.x = 0;
			cursor.y++;
			break;
		case '\b':
			if (cursor.x > 0) cursor.x--;
			break;
		default:
			font_blit(c, cursor.x, cursor.y);
			cursor.x++;
	}

	if (cursor.x * font.w >= fb.width) {
		cursor.x = 0;
		cursor.y++;
	}
	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;
	fb.b = malloc(fb.len);

	font_load("/init/font.psf");

	static char buf[512];
	struct fs_wait_response res;
	while (!_syscall_fs_wait(buf, sizeof buf, &res)) {
		switch (res.op) {
			case VFSOP_OPEN:
				// TODO check path
				_syscall_fs_respond(NULL, 0, 0);
				break;

			case VFSOP_WRITE:
				if (res.flags) {
					_syscall_fs_respond(NULL, -1, 0);
				} else {
					for (size_t i = 0; i < res.len; i++)
						in_char(buf[i]);
					flush();
					_syscall_fs_respond(NULL, res.len, 0);
				}
				break;

			default:
				_syscall_fs_respond(NULL, -1, 0);
				break;
		}
	}

	return 1;
}