1178172Simp/* $NetBSD: wsemul_vt100var.h,v 1.13 2006/10/09 11:03:43 peter Exp $ */
2178172Simp
3178172Simp/*
4178172Simp * Copyright (c) 1998
5178172Simp *	Matthias Drochner.  All rights reserved.
6178172Simp *
7178172Simp * Redistribution and use in source and binary forms, with or without
8178172Simp * modification, are permitted provided that the following conditions
9178172Simp * are met:
10178172Simp * 1. Redistributions of source code must retain the above copyright
11178172Simp *    notice, this list of conditions and the following disclaimer.
12178172Simp * 2. Redistributions in binary form must reproduce the above copyright
13178172Simp *    notice, this list of conditions and the following disclaimer in the
14178172Simp *    documentation and/or other materials provided with the distribution.
15178172Simp *
16178172Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17178172Simp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18178172Simp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19178172Simp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20178172Simp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21178172Simp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22178172Simp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23178172Simp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24178172Simp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25178172Simp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26178172Simp *
27178172Simp */
28178172Simp
29178172Simp#define	VT100_EMUL_NARGS	10	/* max # of args to a command */
30178172Simp
31178172Simpstruct vt100base_data {
32178172Simp	const struct wsdisplay_emulops *emulops;
33178172Simp	void *emulcookie;
34178172Simp	int scrcapabilities;
35178172Simp	u_int nrows, ncols, crow, ccol;
36178172Simp	struct wsdisplay_msgattrs msgattrs;
37178172Simp	long defattr;			/* default attribute */
38178172Simp
39178172Simp	void *cbcookie;
40178172Simp
41178172Simp	int flags;
42196994Sphk#define VTFL_LASTCHAR	0x001	/* printed last char on line (below cursor) */
43196994Sphk#define VTFL_INSERTMODE	0x002
44178172Simp#define VTFL_APPLKEYPAD	0x004
45196994Sphk#define VTFL_APPLCURSOR	0x008
46196994Sphk#define VTFL_DECOM	0x010	/* origin mode */
47178172Simp#define VTFL_DECAWM	0x020	/* auto wrap */
48178172Simp#define VTFL_CURSORON	0x040
49206717Sjmallett#define VTFL_NATCHARSET	0x080	/* national replacement charset mode */
50178172Simp#define VTFL_SAVEDCURS	0x100	/* we have a saved cursor state */
51178172Simp	long curattr, bkgdattr;		/* currently used attribute */
52178172Simp	int attrflags, fgcol, bgcol;	/* properties of curattr */
53178172Simp	u_int scrreg_startrow;
54178172Simp	u_int scrreg_nrows;
55178172Simp	char *tabs;
56178172Simp	char *dblwid;
57178172Simp	int dw;
58178172Simp
59178172Simp	int nargs;
60178172Simp	u_int args[VT100_EMUL_NARGS]; /* numeric command args (CSI/DCS) */
61178172Simp
62178172Simp	char modif1;	/* {>?} in VT100_EMUL_STATE_CSI */
63178172Simp	char modif2;	/* {!"$&} in VT100_EMUL_STATE_CSI */
64178172Simp
65178172Simp	int dcstype;		/* substate in VT100_EMUL_STATE_STRING */
66178172Simp	char *dcsarg;
67178172Simp	int dcspos;
68178172Simp#define DCS_MAXLEN 256 /* ??? */
69178172Simp#define DCSTYPE_TABRESTORE 1 /* DCS2$t */
70178172Simp};
71178172Simp
72178172Simp/* some useful utility macros */
73208165Srrs#define	ARG(d, n)			((d)->args[(n)])
74178172Simp#define	DEF1_ARG(d, n)		(ARG(d, n) ? ARG(d, n) : 1)
75178172Simp#define	DEFx_ARG(d, n, x)		(ARG(d, n) ? ARG(d, n) : (x))
76178172Simp/* the following two can be negative if we are outside the scrolling region */
77178172Simp#define ROWS_ABOVE(d)	((int)(d)->crow - (int)(d)->scrreg_startrow)
78178172Simp#define ROWS_BELOW(d)	((int)((d)->scrreg_startrow + (d)->scrreg_nrows) \
79178172Simp					- (int)(d)->crow - 1)
80178172Simp#define CHECK_DW(d) do { \
81178172Simp	if ((d)->dblwid && (d)->dblwid[(d)->crow]) { \
82178172Simp		(d)->dw = 1; \
83178172Simp		if ((d)->ccol > ((d)->ncols >> 1) - 1) \
84178172Simp			(d)->ccol = ((d)->ncols >> 1) - 1; \
85178172Simp	} else \
86178172Simp		(d)->dw = 0; \
87178172Simp} while (0)
88195376Ssam#define NCOLS(d)	((d)->ncols >> (d)->dw)
89195376Ssam#define	COLS_LEFT(d)	(NCOLS(d) - (d)->ccol - 1)
90195376Ssam#define COPYCOLS(d, f, t, n) (*(d)->emulops->copycols)((d)->emulcookie, \
91195376Ssam	(d)->crow, (f) << (d)->dw, (t) << (d)->dw, (n) << (d)->dw)
92195376Ssam#define ERASECOLS(d, f, n, a) (*(d)->emulops->erasecols)((d)->emulcookie, \
93195376Ssam	(d)->crow, (f) << (d)->dw, (n) << (d)->dw, a)
94202031Simp
95178172Simp/*
96191278Srwatson * response to primary DA request
97191278Srwatson * operating level: 61 = VT100, 62 = VT200, 63 = VT300
98191278Srwatson * extensions: 1 = 132 cols, 2 = printer port, 6 = selective erase,
99191278Srwatson *	7 = soft charset, 8 = UDKs, 9 = NRC sets
100191276Srwatson * VT100 = "033[?1;2c"
101191276Srwatson */
102191276Srwatson#define WSEMUL_VT_ID1 "\033[?62;6c"
103178172Simp/*
104178172Simp * response to secondary DA request
105178172Simp * ident code: 24 = VT320
106178172Simp * firmware version
107206746Sjmallett * hardware options: 0 = no options
108178172Simp */
109197316Salc#define WSEMUL_VT_ID2 "\033[>24;20;0c"
110197316Salc
111183441Simpvoid wsemul_vt100_scrollup(struct vt100base_data *, int);
112183441Simpvoid wsemul_vt100_scrolldown(struct vt100base_data *, int);
113178172Simpvoid wsemul_vt100_ed(struct vt100base_data *, int);
114178172Simpvoid wsemul_vt100_el(struct vt100base_data *, int);
115205072Sneelvoid wsemul_vt100_handle_csi(struct vt100base_data *, u_char);
116178172Simpvoid wsemul_vt100_handle_dcs(struct vt100base_data *);
117206819Sjmallett