1 /* $OpenBSD: wsemul_vt100var.h,v 1.14 2024/11/05 08:12:08 miod Exp $ */ 2 /* $NetBSD: wsemul_vt100var.h,v 1.5 2000/04/28 21:56:17 mycroft Exp $ */ 3 4 /* 5 * Copyright (c) 1998 6 * Matthias Drochner. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 */ 29 30 #define VT100_EMUL_NARGS 10 /* max # of args to a command */ 31 32 struct wsemul_vt100_emuldata { 33 const struct wsdisplay_emulops *emulops; 34 struct wsemul_abortstate abortstate; 35 void *emulcookie; 36 int scrcapabilities; 37 u_int nrows, ncols, crow, ccol; 38 uint32_t defattr; /* default attribute */ 39 40 uint32_t kernattr; /* attribute for kernel output */ 41 void *cbcookie; 42 #ifdef DIAGNOSTIC 43 int console; 44 #endif 45 46 u_int state; /* processing state */ 47 int flags; 48 #define VTFL_LASTCHAR 0x001 /* printed last char on line (below cursor) */ 49 #define VTFL_INSERTMODE 0x002 50 #define VTFL_APPLKEYPAD 0x004 51 #define VTFL_APPLCURSOR 0x008 52 #define VTFL_DECOM 0x010 /* origin mode */ 53 #define VTFL_DECAWM 0x020 /* auto wrap */ 54 #define VTFL_CURSORON 0x040 55 #define VTFL_NATCHARSET 0x080 /* national replacement charset mode */ 56 #define VTFL_SAVEDCURS 0x100 /* we have a saved cursor state */ 57 #define VTFL_UTF8 0x200 /* utf-8 character set */ 58 uint32_t curattr, bkgdattr; /* currently used attribute */ 59 int attrflags, fgcol, bgcol; /* properties of curattr */ 60 u_int scrreg_startrow; 61 u_int scrreg_nrows; 62 char *tabs; 63 #ifdef HAVE_DOUBLE_WIDTH_HEIGHT 64 char *dblwid; 65 int dw; 66 #endif 67 68 int chartab0, chartab1; 69 u_int *chartab_G[4]; 70 u_int *isolatin1tab, *decgraphtab, *dectechtab; 71 u_int *nrctab; 72 int sschartab; /* single shift */ 73 74 int nargs; 75 u_int args[VT100_EMUL_NARGS]; /* numeric command args (CSI/DCS) */ 76 77 char modif1; /* {>?} in VT100_EMUL_STATE_CSI */ 78 char modif2; /* {!"$&} in VT100_EMUL_STATE_CSI */ 79 80 int designating; /* substate in VT100_EMUL_STATE_SCS* */ 81 82 int dcstype; /* substate in VT100_EMUL_STATE_STRING */ 83 char *dcsarg; 84 int dcspos; 85 #define DCS_MAXLEN 256 /* ??? */ 86 #define DCSTYPE_TABRESTORE 1 /* DCS2$t */ 87 88 u_int savedcursor_row, savedcursor_col; 89 uint32_t savedattr, savedbkgdattr; 90 int savedattrflags, savedfgcol, savedbgcol; 91 int savedchartab0, savedchartab1; 92 u_int *savedchartab_G[4]; 93 94 struct wsemul_inputstate instate; /* userland input state */ 95 struct wsemul_inputstate kstate; /* kernel input state */ 96 97 #ifdef HAVE_UTF8_SUPPORT 98 u_char translatebuf[4]; 99 #else 100 u_char translatebuf[1]; 101 #endif 102 }; 103 104 /* some useful utility macros */ 105 #define ARG(n) (edp->args[(n)]) 106 #define DEF1_ARG(n) (ARG(n) ? ARG(n) : 1) 107 #define DEFx_ARG(n, x) (ARG(n) ? ARG(n) : (x)) 108 /* the following two can be negative if we are outside the scrolling region */ 109 #define ROWS_ABOVE ((int)edp->crow - (int)edp->scrreg_startrow) 110 #define ROWS_BELOW ((int)(edp->scrreg_startrow + edp->scrreg_nrows) \ 111 - (int)edp->crow - 1) 112 #ifdef HAVE_DOUBLE_WIDTH_HEIGHT 113 #define CHECK_DW do { \ 114 if (edp->dblwid && edp->dblwid[edp->crow]) { \ 115 edp->dw = 1; \ 116 if (edp->ccol > (edp->ncols >> 1) - 1) \ 117 edp->ccol = (edp->ncols >> 1) - 1; \ 118 } else \ 119 edp->dw = 0; \ 120 } while (0) 121 #define NCOLS (edp->ncols >> edp->dw) 122 #define COPYCOLS(f, t, n) (edp->emulcookie, edp->crow, (f) << edp->dw, \ 123 (t) << edp->dw, (n) << edp->dw) 124 #define ERASECOLS(f, n, a) (edp->emulcookie, edp->crow, (f) << edp->dw, \ 125 (n) << edp->dw, (a)) 126 #else 127 #define CHECK_DW do { } while (0) 128 #define NCOLS (edp->ncols) 129 #define COPYCOLS(f, t, n) (edp->emulcookie, edp->crow, (f), (t), (n)) 130 #define ERASECOLS(f, n, a) (edp->emulcookie, edp->crow, (f), (n), (a)) 131 #endif 132 #define COLS_LEFT (NCOLS - edp->ccol - 1) 133 134 /* 135 * response to primary DA request 136 * operating level: 61 = VT100, 62 = VT200, 63 = VT300 137 * extensions: 1 = 132 cols, 2 = printer port, 6 = selective erase, 138 * 7 = soft charset, 8 = UDKs, 9 = NRC sets 139 * VT100 = "033[?1;2c" 140 */ 141 #define WSEMUL_VT_ID1 "\033[?62;6c" 142 /* 143 * response to secondary DA request 144 * ident code: 24 = VT320 145 * firmware version 146 * hardware options: 0 = no options 147 */ 148 #define WSEMUL_VT_ID2 "\033[>24;20;0c" 149 150 void wsemul_vt100_reset(struct wsemul_vt100_emuldata *); 151 int wsemul_vt100_scrollup(struct wsemul_vt100_emuldata *, int); 152 int wsemul_vt100_scrolldown(struct wsemul_vt100_emuldata *, int); 153 int wsemul_vt100_ed(struct wsemul_vt100_emuldata *, int); 154 int wsemul_vt100_el(struct wsemul_vt100_emuldata *, int); 155 int wsemul_vt100_handle_csi(struct wsemul_vt100_emuldata *, 156 struct wsemul_inputstate *, int); 157 void wsemul_vt100_handle_dcs(struct wsemul_vt100_emuldata *); 158 159 int wsemul_vt100_translate(void *cookie, kbd_t, keysym_t, const u_char **); 160 161 void vt100_initchartables(struct wsemul_vt100_emuldata *); 162 int vt100_setnrc(struct wsemul_vt100_emuldata *, int); 163 164 int wsemul_vt100_output_normal(struct wsemul_vt100_emuldata *, 165 struct wsemul_inputstate *, int, int); 166