wsemul_dumb.c revision 1.1
190792Sgshapiro/* $NetBSD: wsemul_dumb.c,v 1.1 1998/03/22 14:24:03 drochner Exp $ */ 290792Sgshapiro 390792Sgshapiro/* 490792Sgshapiro * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved. 590792Sgshapiro * 690792Sgshapiro * Redistribution and use in source and binary forms, with or without 790792Sgshapiro * modification, are permitted provided that the following conditions 890792Sgshapiro * are met: 990792Sgshapiro * 1. Redistributions of source code must retain the above copyright 1090792Sgshapiro * notice, this list of conditions and the following disclaimer. 1190792Sgshapiro * 2. Redistributions in binary form must reproduce the above copyright 1290792Sgshapiro * notice, this list of conditions and the following disclaimer in the 1390792Sgshapiro * documentation and/or other materials provided with the distribution. 1490792Sgshapiro * 3. All advertising materials mentioning features or use of this software 1590792Sgshapiro * must display the following acknowledgement: 1690792Sgshapiro * This product includes software developed by Christopher G. Demetriou 1790792Sgshapiro * for the NetBSD Project. 1890792Sgshapiro * 4. The name of the author may not be used to endorse or promote products 1990792Sgshapiro * derived from this software without specific prior written permission 2090792Sgshapiro * 2190792Sgshapiro * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2290792Sgshapiro * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2390792Sgshapiro * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2490792Sgshapiro * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2590792Sgshapiro * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2690792Sgshapiro * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2790792Sgshapiro * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2890792Sgshapiro * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2990792Sgshapiro * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 3090792Sgshapiro * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3190792Sgshapiro */ 3290792Sgshapiro 3390792Sgshapirostatic const char _copyright[] __attribute__ ((unused)) = 3490792Sgshapiro "Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved."; 3590792Sgshapirostatic const char _rcsid[] __attribute__ ((unused)) = 3690792Sgshapiro "$NetBSD: wsemul_dumb.c,v 1.1 1998/03/22 14:24:03 drochner Exp $"; 3790792Sgshapiro 3890792Sgshapiro#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/time.h> 41#include <sys/malloc.h> 42#include <sys/fcntl.h> 43 44#include <dev/wscons/wsconsio.h> 45#include <dev/wscons/wsdisplayvar.h> 46#include <dev/wscons/wsemulvar.h> 47#include <dev/wscons/ascii.h> 48 49void *wsemul_dumb_cnattach __P((const struct wsscreen_descr *, void *, 50 int, int)); 51void *wsemul_dumb_attach __P((int console, const struct wsscreen_descr *, 52 void *, int, int, void *)); 53void wsemul_dumb_output __P((void *cookie, const u_char *data, u_int count)); 54void wsemul_dumb_detach __P((void *cookie, u_int *crowp, u_int *ccolp)); 55 56const struct wsemul_ops wsemul_dumb_ops = { 57 "dumb", 58 wsemul_dumb_cnattach, 59 wsemul_dumb_attach, 60 wsemul_dumb_output, 61 wsemul_dumb_detach, 62}; 63 64struct wsemul_dumb_emuldata { 65 const struct wsdisplay_emulops *emulops; 66 void *emulcookie; 67 void *cbcookie; 68 u_int nrows, ncols, crow, ccol; 69}; 70 71struct wsemul_dumb_emuldata wsemul_dumb_console_emuldata; 72 73void * 74wsemul_dumb_cnattach(type, cookie, ccol, crow) 75 const struct wsscreen_descr *type; 76 void *cookie; 77 int ccol, crow; 78{ 79 struct wsemul_dumb_emuldata *edp; 80 81 edp = &wsemul_dumb_console_emuldata; 82 83 edp->emulops = type->textops; 84 edp->emulcookie = cookie; 85 edp->nrows = type->nrows; 86 edp->ncols = type->ncols; 87 edp->crow = crow; 88 edp->ccol = ccol; 89 edp->cbcookie = NULL; 90 91 return (edp); 92} 93 94void * 95wsemul_dumb_attach(console, type, cookie, ccol, crow, cbcookie) 96 int console; 97 const struct wsscreen_descr *type; 98 void *cookie; 99 int ccol, crow; 100 void *cbcookie; 101{ 102 struct wsemul_dumb_emuldata *edp; 103 104 if (console) 105 edp = &wsemul_dumb_console_emuldata; 106 else { 107 edp = malloc(sizeof *edp, M_DEVBUF, M_WAITOK); 108 109 edp->emulops = type->textops; 110 edp->emulcookie = cookie; 111 edp->nrows = type->nrows; 112 edp->ncols = type->ncols; 113 edp->crow = crow; 114 edp->ccol = ccol; 115 } 116 117 edp->cbcookie = cbcookie; 118 119 return (edp); 120} 121 122void 123wsemul_dumb_output(cookie, data, count) 124 void *cookie; 125 const u_char *data; 126 u_int count; 127{ 128 struct wsemul_dumb_emuldata *edp = cookie; 129 u_char c; 130 int n; 131 132 /* XXX */ 133 (*edp->emulops->cursor)(edp->emulcookie, 0, edp->crow, edp->ccol); 134 while (count-- > 0) { 135 c = *data++; 136 switch (c) { 137 case ASCII_BEL: 138 wsdisplay_emulbell(edp->cbcookie); 139 break; 140 141 case ASCII_BS: 142 if (edp->ccol > 0) 143 edp->ccol--; 144 break; 145 146 case ASCII_CR: 147 edp->ccol = 0; 148 break; 149 150 case ASCII_HT: 151 n = min(8 - (edp->ccol & 7), 152 edp->ncols - edp->ccol - 1); 153 (*edp->emulops->erasecols)(edp->emulcookie, 154 edp->crow, edp->ccol, n); 155 edp->ccol += n; 156 break; 157 158 case ASCII_NP: 159 (*edp->emulops->eraserows)(edp->emulcookie, 0, 160 edp->nrows); 161 edp->ccol = 0; 162 edp->crow = 0; 163 break; 164 165 case ASCII_VT: 166 if (edp->crow > 0) 167 edp->crow--; 168 break; 169 170 default: 171 (*edp->emulops->putstr)(edp->emulcookie, edp->crow, 172 edp->ccol, &c, 1); 173 edp->ccol++; 174 175 /* if cur col is still on cur line, done. */ 176 if (edp->ccol < edp->ncols) 177 break; 178 179 /* wrap the column around. */ 180 edp->ccol = 0; 181 182 /* FALLTHRU */ 183 184 case ASCII_LF: 185 /* if the cur line isn't the last, incr and leave. */ 186 if (edp->crow < edp->nrows - 1) { 187 edp->crow++; 188 break; 189 } 190 n = 1; /* number of lines to scroll */ 191 (*edp->emulops->copyrows)(edp->emulcookie, n, 0, 192 edp->nrows - n); 193 (*edp->emulops->eraserows)(edp->emulcookie, 194 edp->nrows - n, n); 195 edp->crow -= n - 1; 196 break; 197 } 198 } 199 /* XXX */ 200 (*edp->emulops->cursor)(edp->emulcookie, 1, edp->crow, edp->ccol); 201} 202 203void 204wsemul_dumb_detach(cookie, crowp, ccolp) 205 void *cookie; 206 u_int *crowp, *ccolp; 207{ 208 struct wsemul_dumb_emuldata *edp = cookie; 209 210 *crowp = edp->crow; 211 *ccolp = edp->ccol; 212 if (edp != &wsemul_dumb_console_emuldata) 213 free(edp, M_DEVBUF); 214} 215