vt100_base.h revision 1.1 1 1.1 drochner /* $NetBSD: vt100_base.h,v 1.1 2010/02/10 19:39:39 drochner Exp $ */
2 1.1 drochner
3 1.1 drochner /*
4 1.1 drochner * Copyright (c) 1998
5 1.1 drochner * Matthias Drochner. All rights reserved.
6 1.1 drochner *
7 1.1 drochner * Redistribution and use in source and binary forms, with or without
8 1.1 drochner * modification, are permitted provided that the following conditions
9 1.1 drochner * are met:
10 1.1 drochner * 1. Redistributions of source code must retain the above copyright
11 1.1 drochner * notice, this list of conditions and the following disclaimer.
12 1.1 drochner * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 drochner * notice, this list of conditions and the following disclaimer in the
14 1.1 drochner * documentation and/or other materials provided with the distribution.
15 1.1 drochner *
16 1.1 drochner * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 drochner * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 drochner * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 drochner * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 drochner * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.1 drochner * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.1 drochner * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.1 drochner * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.1 drochner * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.1 drochner * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.1 drochner *
27 1.1 drochner */
28 1.1 drochner
29 1.1 drochner #define VT100_EMUL_NARGS 10 /* max # of args to a command */
30 1.1 drochner
31 1.1 drochner struct vt100base_data {
32 1.1 drochner const struct wsdisplay_emulops *emulops;
33 1.1 drochner void *emulcookie;
34 1.1 drochner int scrcapabilities;
35 1.1 drochner u_int nrows, ncols, crow, ccol;
36 1.1 drochner struct wsdisplay_msgattrs msgattrs;
37 1.1 drochner long defattr; /* default attribute */
38 1.1 drochner
39 1.1 drochner void *cbcookie;
40 1.1 drochner
41 1.1 drochner int flags;
42 1.1 drochner #define VTFL_LASTCHAR 0x001 /* printed last char on line (below cursor) */
43 1.1 drochner #define VTFL_INSERTMODE 0x002
44 1.1 drochner #define VTFL_APPLKEYPAD 0x004
45 1.1 drochner #define VTFL_APPLCURSOR 0x008
46 1.1 drochner #define VTFL_DECOM 0x010 /* origin mode */
47 1.1 drochner #define VTFL_DECAWM 0x020 /* auto wrap */
48 1.1 drochner #define VTFL_CURSORON 0x040
49 1.1 drochner #define VTFL_NATCHARSET 0x080 /* national replacement charset mode */
50 1.1 drochner #define VTFL_SAVEDCURS 0x100 /* we have a saved cursor state */
51 1.1 drochner long curattr, bkgdattr; /* currently used attribute */
52 1.1 drochner int attrflags, fgcol, bgcol; /* properties of curattr */
53 1.1 drochner u_int scrreg_startrow;
54 1.1 drochner u_int scrreg_nrows;
55 1.1 drochner char *tabs;
56 1.1 drochner char *dblwid;
57 1.1 drochner int dw;
58 1.1 drochner
59 1.1 drochner int nargs;
60 1.1 drochner u_int args[VT100_EMUL_NARGS]; /* numeric command args (CSI/DCS) */
61 1.1 drochner
62 1.1 drochner char modif1; /* {>?} in VT100_EMUL_STATE_CSI */
63 1.1 drochner char modif2; /* {!"$&} in VT100_EMUL_STATE_CSI */
64 1.1 drochner
65 1.1 drochner int dcstype; /* substate in VT100_EMUL_STATE_STRING */
66 1.1 drochner char *dcsarg;
67 1.1 drochner int dcspos;
68 1.1 drochner #define DCS_MAXLEN 256 /* ??? */
69 1.1 drochner #define DCSTYPE_TABRESTORE 1 /* DCS2$t */
70 1.1 drochner };
71 1.1 drochner
72 1.1 drochner /* some useful utility macros */
73 1.1 drochner #define ARG(d, n) ((d)->args[(n)])
74 1.1 drochner #define DEF1_ARG(d, n) (ARG(d, n) ? ARG(d, n) : 1)
75 1.1 drochner #define DEFx_ARG(d, n, x) (ARG(d, n) ? ARG(d, n) : (x))
76 1.1 drochner /* the following two can be negative if we are outside the scrolling region */
77 1.1 drochner #define ROWS_ABOVE(d) ((int)(d)->crow - (int)(d)->scrreg_startrow)
78 1.1 drochner #define ROWS_BELOW(d) ((int)((d)->scrreg_startrow + (d)->scrreg_nrows) \
79 1.1 drochner - (int)(d)->crow - 1)
80 1.1 drochner #define CHECK_DW(d) do { \
81 1.1 drochner if ((d)->dblwid && (d)->dblwid[(d)->crow]) { \
82 1.1 drochner (d)->dw = 1; \
83 1.1 drochner if ((d)->ccol > ((d)->ncols >> 1) - 1) \
84 1.1 drochner (d)->ccol = ((d)->ncols >> 1) - 1; \
85 1.1 drochner } else \
86 1.1 drochner (d)->dw = 0; \
87 1.1 drochner } while (0)
88 1.1 drochner #define NCOLS(d) ((d)->ncols >> (d)->dw)
89 1.1 drochner #define COLS_LEFT(d) (NCOLS(d) - (d)->ccol - 1)
90 1.1 drochner #define COPYCOLS(d, f, t, n) (*(d)->emulops->copycols)((d)->emulcookie, \
91 1.1 drochner (d)->crow, (f) << (d)->dw, (t) << (d)->dw, (n) << (d)->dw)
92 1.1 drochner #define ERASECOLS(d, f, n, a) (*(d)->emulops->erasecols)((d)->emulcookie, \
93 1.1 drochner (d)->crow, (f) << (d)->dw, (n) << (d)->dw, a)
94 1.1 drochner
95 1.1 drochner /*
96 1.1 drochner * response to primary DA request
97 1.1 drochner * operating level: 61 = VT100, 62 = VT200, 63 = VT300
98 1.1 drochner * extensions: 1 = 132 cols, 2 = printer port, 6 = selective erase,
99 1.1 drochner * 7 = soft charset, 8 = UDKs, 9 = NRC sets
100 1.1 drochner * VT100 = "033[?1;2c"
101 1.1 drochner */
102 1.1 drochner #define WSEMUL_VT_ID1 "\033[?62;6c"
103 1.1 drochner /*
104 1.1 drochner * response to secondary DA request
105 1.1 drochner * ident code: 24 = VT320
106 1.1 drochner * firmware version
107 1.1 drochner * hardware options: 0 = no options
108 1.1 drochner */
109 1.1 drochner #define WSEMUL_VT_ID2 "\033[>24;20;0c"
110 1.1 drochner
111 1.1 drochner void wsemul_vt100_scrollup(struct vt100base_data *, int);
112 1.1 drochner void wsemul_vt100_scrolldown(struct vt100base_data *, int);
113 1.1 drochner void wsemul_vt100_ed(struct vt100base_data *, int);
114 1.1 drochner void wsemul_vt100_el(struct vt100base_data *, int);
115 1.1 drochner void wsemul_vt100_handle_csi(struct vt100base_data *, u_char);
116 1.1 drochner void wsemul_vt100_handle_dcs(struct vt100base_data *);
117