aboutsummaryrefslogtreecommitdiffstats
path: root/com32/lib/sys/ansi.h
blob: 1e0342466f69910a9b313e9c1ae8b961ee8de652 (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
68
69
/*
 * ansi.h
 */

#ifndef COM32_LIB_SYS_ANSI_H
#define COM32_LIB_SYS_ANSI_H

#include <inttypes.h>

#define ANSI_MAX_PARMS	16

#define BIOS_CURXY ((struct curxy *)0x450)	/* Array for each page */
#define BIOS_ROWS (*(uint8_t *)0x484)	/* Minus one; if zero use 24 (= 25 lines) */
#define BIOS_COLS (*(uint16_t *)0x44A)	/* Number of columns on screen */
#define BIOS_PAGE (*(uint8_t *)0x462)	/* Current page number  */

enum ansi_state {
    st_init,
    st_esc,
    st_csi,
    st_tbl,
    st_tblc,
};

struct curxy {
    uint8_t x, y;
} __attribute__ ((packed));

struct term_state {
    struct curxy xy;
    int cindex;			/* SOH color index */
    int vtgraphics;		/* VT graphics on/off */
    int intensity;
    int underline;
    int blink;
    int reverse;
    int fg;
    int bg;
    int autocr;
    struct curxy saved_xy;
    int cursor;
    enum ansi_state state;
    int pvt;			/* Private code? */
    int nparms;			/* Number of parameters seen */
    int parms[ANSI_MAX_PARMS];
};

struct ansi_ops {
    void (*erase) (const struct term_state * st, int x0, int y0, int x1,
		   int y1);
    void (*write_char) (int x, int y, int page, uint8_t ch, const struct term_state * st);
    void (*showcursor) (const struct term_state * st);
    void (*scroll_up) (const struct term_state * st);
    void (*set_cursor) (int x, int y, int page, int visible);
    void (*beep) (void);
};

struct term_info {
    int rows, cols;		/* Screen size */
    int disabled;
    struct term_state *ts;
    const struct ansi_ops *op;
};

void __ansi_init(const struct term_info *ti);
void __ansi_putchar(const struct term_info *ti, uint8_t ch);
void __ansicon_beep(void);

#endif /* COM32_LIB_SYS_ANSI_H */