feat: standard vga support (mode switching, framebuffer remapping)
[lunaix-os.git] / lunaix-os / includes / hal / term.h
1 #ifndef __LUNAIX_TERM_H
2 #define __LUNAIX_TERM_H
3
4 #include <lunaix/device.h>
5
6 struct term;
7
8 struct term_lcntl
9 {
10     struct llist_header lcntls;
11     size_t (*apply)(struct term* termdev, char* line, size_t len);
12 };
13
14 struct linebuffer
15 {
16     char* current;
17     char* next;
18     size_t sz_hlf;
19     off_t ptr;
20 };
21
22 struct term
23 {
24     struct device* dev;
25     struct device* chdev;
26     struct llist_header lcntl_stack;
27     struct linebuffer line;
28     pid_t fggrp;
29 };
30
31 struct term*
32 term_create();
33
34 int
35 term_bind(struct term* tdev, struct device* chdev);
36
37 int
38 term_push_lcntl(struct term* tdev, struct term_lcntl* lcntl);
39
40 int
41 term_pop_lcntl(struct term* tdev);
42
43 struct term_lcntl*
44 term_get_lcntl(u32_t lcntl_index);
45
46 void
47 line_flip(struct linebuffer* lbf);
48
49 void
50 line_alloc(struct linebuffer* lbf, size_t sz_hlf);
51
52 void
53 line_free(struct linebuffer* lbf, size_t sz_hlf);
54
55 static inline int
56 line_put_next(struct linebuffer* lbf, char val, int delta)
57 {
58     size_t dptr = (size_t)(lbf->ptr + delta);
59     if (dptr >= lbf->sz_hlf) {
60         return 0;
61     }
62
63     lbf->next[dptr] = val;
64     lbf->ptr++;
65     return 1;
66 }
67
68 int
69 term_sendline(struct term* tdev, size_t len);
70
71 int
72 term_readline(struct term* tdev, size_t len);
73
74 #endif /* __LUNAIX_TERM_H */