master
h 95 lines 2.23 KB
Raw
1 /*
2 * SPDX-License-Identifier: MIT
3 * QEMU vt100
4 */
5 #ifndef VT100_H
6 #define VT100_H
7
8 #include "chardev/char.h"
9 #include "ui/console.h"
10 #include "qemu/fifo8.h"
11 #include "qemu/queue.h"
12
13 typedef struct TextAttributes {
14 uint8_t fgcol:4;
15 uint8_t bgcol:4;
16 uint8_t bold:1;
17 uint8_t uline:1;
18 uint8_t blink:1;
19 uint8_t invers:1;
20 uint8_t unvisible:1;
21 } TextAttributes;
22
23 #define TEXT_ATTRIBUTES_DEFAULT ((TextAttributes) { \
24 .fgcol = QEMU_COLOR_WHITE, \
25 .bgcol = QEMU_COLOR_BLACK \
26 })
27
28 typedef struct TextCell {
29 uint8_t ch;
30 TextAttributes t_attrib;
31 } TextCell;
32
33 #define MAX_ESC_PARAMS 3
34
35 enum TTYState {
36 TTY_STATE_NORM,
37 TTY_STATE_ESC,
38 TTY_STATE_CSI,
39 TTY_STATE_G0,
40 TTY_STATE_G1,
41 TTY_STATE_OSC,
42 };
43
44 typedef struct QemuVT100 QemuVT100;
45
46 struct QemuVT100 {
47 pixman_image_t *image;
48 void (*image_update)(QemuVT100 *vt, int x, int y, int width, int height);
49
50 ChardevVCEncoding encoding;
51 int width;
52 int height;
53 int total_height;
54 int backscroll_height;
55 int x, y;
56 int y_displayed;
57 int y_base;
58 TextCell *cells;
59 int text_x[2], text_y[2], cursor_invalidate;
60 int echo;
61
62 int update_x0;
63 int update_y0;
64 int update_x1;
65 int update_y1;
66
67 enum TTYState state;
68 int esc_params[MAX_ESC_PARAMS];
69 int nb_esc_params;
70 uint32_t utf8_state; /* UTF-8 DFA decoder state */
71 uint32_t utf8_codepoint; /* accumulated UTF-8 code point */
72 TextAttributes t_attrib; /* currently active text attributes */
73 TextAttributes t_attrib_saved;
74 int x_saved, y_saved;
75 /* fifo for key pressed */
76 Fifo8 out_fifo;
77 void (*out_flush)(QemuVT100 *vt);
78
79 QTAILQ_ENTRY(QemuVT100) list;
80 };
81
82 void vt100_init(QemuVT100 *vt,
83 pixman_image_t *image,
84 ChardevVCEncoding encoding,
85 void (*image_update)(QemuVT100 *vt, int x, int y, int width, int height),
86 void (*out_flush)(QemuVT100 *vt));
87 void vt100_fini(QemuVT100 *vt);
88
89 void vt100_update_cursor(void);
90 size_t vt100_input(QemuVT100 *vt, const uint8_t *buf, size_t len);
91 void vt100_keysym(QemuVT100 *vt, int keysym);
92 void vt100_set_image(QemuVT100 *vt, pixman_image_t *image);
93 void vt100_refresh(QemuVT100 *vt);
94
95 #endif