root/dev/wscons/wsemul_dumb.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. wsemul_dumb_cnattach
  2. wsemul_dumb_attach
  3. wsemul_dumb_output
  4. wsemul_dumb_translate
  5. wsemul_dumb_detach
  6. wsemul_dumb_resetop

    1 /* $OpenBSD: wsemul_dumb.c,v 1.4 2007/03/07 06:23:04 miod Exp $ */
    2 /* $NetBSD: wsemul_dumb.c,v 1.7 2000/01/05 11:19:36 drochner Exp $ */
    3 
    4 /*
    5  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  * 3. All advertising materials mentioning features or use of this software
   16  *    must display the following acknowledgement:
   17  *      This product includes software developed by Christopher G. Demetriou
   18  *      for the NetBSD Project.
   19  * 4. The name of the author may not be used to endorse or promote products
   20  *    derived from this software without specific prior written permission
   21  *
   22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   32  */
   33 
   34 #include <sys/cdefs.h>
   35 
   36 #include <sys/param.h>
   37 #include <sys/systm.h>
   38 #include <sys/time.h>
   39 #include <sys/malloc.h>
   40 #include <sys/fcntl.h>
   41 
   42 #include <dev/wscons/wsconsio.h>
   43 #include <dev/wscons/wsdisplayvar.h>
   44 #include <dev/wscons/wsemulvar.h>
   45 #include <dev/wscons/ascii.h>
   46 
   47 void    *wsemul_dumb_cnattach(const struct wsscreen_descr *, void *,
   48                                    int, int, long);
   49 void    *wsemul_dumb_attach(int console, const struct wsscreen_descr *,
   50                                  void *, int, int, void *, long);
   51 void    wsemul_dumb_output(void *cookie, const u_char *data, u_int count,
   52                                 int);
   53 int     wsemul_dumb_translate(void *cookie, keysym_t, char **);
   54 void    wsemul_dumb_detach(void *cookie, u_int *crowp, u_int *ccolp);
   55 void    wsemul_dumb_resetop(void *, enum wsemul_resetops);
   56 
   57 const struct wsemul_ops wsemul_dumb_ops = {
   58         "dumb",
   59         wsemul_dumb_cnattach,
   60         wsemul_dumb_attach,
   61         wsemul_dumb_output,
   62         wsemul_dumb_translate,
   63         wsemul_dumb_detach,
   64         wsemul_dumb_resetop
   65 };
   66 
   67 struct wsemul_dumb_emuldata {
   68         const struct wsdisplay_emulops *emulops;
   69         void *emulcookie;
   70         void *cbcookie;
   71         int crippled;
   72         u_int nrows, ncols, crow, ccol;
   73         long defattr;
   74 };
   75 
   76 struct wsemul_dumb_emuldata wsemul_dumb_console_emuldata;
   77 
   78 void *
   79 wsemul_dumb_cnattach(type, cookie, ccol, crow, defattr)
   80         const struct wsscreen_descr *type;
   81         void *cookie;
   82         int ccol, crow;
   83         long defattr;
   84 {
   85         struct wsemul_dumb_emuldata *edp;
   86         const struct wsdisplay_emulops *emulops;
   87 
   88         edp = &wsemul_dumb_console_emuldata;
   89 
   90         edp->emulops = emulops = type->textops;
   91         edp->emulcookie = cookie;
   92         edp->nrows = type->nrows;
   93         edp->ncols = type->ncols;
   94         edp->crow = crow;
   95         edp->ccol = ccol;
   96         edp->defattr = defattr;
   97         edp->cbcookie = NULL;
   98         edp->crippled = emulops->cursor == NULL ||
   99             emulops->copycols == NULL || emulops->copyrows == NULL ||
  100             emulops->erasecols == NULL || emulops->eraserows == NULL;
  101 
  102         return (edp);
  103 }
  104 
  105 void *
  106 wsemul_dumb_attach(console, type, cookie, ccol, crow, cbcookie, defattr)
  107         int console;
  108         const struct wsscreen_descr *type;
  109         void *cookie;
  110         int ccol, crow;
  111         void *cbcookie;
  112         long defattr;
  113 {
  114         struct wsemul_dumb_emuldata *edp;
  115 
  116         if (console)
  117                 edp = &wsemul_dumb_console_emuldata;
  118         else {
  119                 edp = malloc(sizeof *edp, M_DEVBUF, M_WAITOK);
  120 
  121                 edp->emulops = type->textops;
  122                 edp->emulcookie = cookie;
  123                 edp->nrows = type->nrows;
  124                 edp->ncols = type->ncols;
  125                 edp->crow = crow;
  126                 edp->ccol = ccol;
  127                 edp->defattr = defattr;
  128         }
  129 
  130         edp->cbcookie = cbcookie;
  131 
  132         return (edp);
  133 }
  134 
  135 void
  136 wsemul_dumb_output(cookie, data, count, kernel)
  137         void *cookie;
  138         const u_char *data;
  139         u_int count;
  140         int kernel; /* ignored */
  141 {
  142         struct wsemul_dumb_emuldata *edp = cookie;
  143         u_char c;
  144         int n;
  145 
  146         if (edp->crippled) {
  147                 while (count-- > 0) {
  148                         c = *data++;
  149 
  150                         if (c == ASCII_BEL)
  151                                 wsdisplay_emulbell(edp->cbcookie);
  152                         else
  153                                 (*edp->emulops->putchar)(edp->emulcookie, 0,
  154                                     0, c, 0);
  155                 }
  156                 return;
  157         }
  158 
  159         /* XXX */
  160         (*edp->emulops->cursor)(edp->emulcookie, 0, edp->crow, edp->ccol);
  161         while (count-- > 0) {
  162                 c = *data++;
  163 
  164                 switch (c) {
  165                 case ASCII_BEL:
  166                         wsdisplay_emulbell(edp->cbcookie);
  167                         break;
  168 
  169                 case ASCII_BS:
  170                         if (edp->ccol > 0)
  171                                 edp->ccol--;
  172                         break;
  173 
  174                 case ASCII_CR:
  175                         edp->ccol = 0;
  176                         break;
  177 
  178                 case ASCII_HT:
  179                         n = min(8 - (edp->ccol & 7),
  180                             edp->ncols - edp->ccol - 1);
  181                         (*edp->emulops->erasecols)(edp->emulcookie,
  182                             edp->crow, edp->ccol, n, edp->defattr);
  183                         edp->ccol += n;
  184                         break;
  185 
  186                 case ASCII_FF:
  187                         (*edp->emulops->eraserows)(edp->emulcookie, 0,
  188                             edp->nrows, edp->defattr);
  189                         edp->ccol = 0;
  190                         edp->crow = 0;
  191                         break;
  192 
  193                 case ASCII_VT:
  194                         if (edp->crow > 0)
  195                                 edp->crow--;
  196                         break;
  197 
  198                 default:
  199                         (*edp->emulops->putchar)(edp->emulcookie, edp->crow,
  200                             edp->ccol, c, edp->defattr);
  201                         edp->ccol++;
  202 
  203                         /* if cur col is still on cur line, done. */
  204                         if (edp->ccol < edp->ncols)
  205                                 break;
  206 
  207                         /* wrap the column around. */
  208                         edp->ccol = 0;
  209 
  210                         /* FALLTHROUGH */
  211 
  212                 case ASCII_LF:
  213                         /* if the cur line isn't the last, incr and leave. */
  214                         if (edp->crow < edp->nrows - 1) {
  215                                 edp->crow++;
  216                                 break;
  217                         }
  218                         n = 1;          /* number of lines to scroll */
  219                         (*edp->emulops->copyrows)(edp->emulcookie, n, 0,
  220                             edp->nrows - n);
  221                         (*edp->emulops->eraserows)(edp->emulcookie,
  222                             edp->nrows - n, n, edp->defattr);
  223                         edp->crow -= n - 1;
  224                         break;
  225                 }       
  226         }
  227         /* XXX */
  228         (*edp->emulops->cursor)(edp->emulcookie, 1, edp->crow, edp->ccol);
  229 }
  230 
  231 int
  232 wsemul_dumb_translate(cookie, in, out)
  233         void *cookie;
  234         keysym_t in;
  235         char **out;
  236 {
  237         return (0);
  238 }
  239 
  240 void
  241 wsemul_dumb_detach(cookie, crowp, ccolp)
  242         void *cookie;
  243         u_int *crowp, *ccolp;
  244 {
  245         struct wsemul_dumb_emuldata *edp = cookie;
  246 
  247         *crowp = edp->crow;
  248         *ccolp = edp->ccol;
  249         if (edp != &wsemul_dumb_console_emuldata)
  250                 free(edp, M_DEVBUF);
  251 }
  252 
  253 void
  254 wsemul_dumb_resetop(cookie, op)
  255         void *cookie;
  256         enum wsemul_resetops op;
  257 {
  258         struct wsemul_dumb_emuldata *edp = cookie;
  259 
  260         if (edp->crippled)
  261                 return;
  262 
  263         switch (op) {
  264         case WSEMUL_CLEARSCREEN:
  265                 (*edp->emulops->eraserows)(edp->emulcookie, 0, edp->nrows,
  266                                            edp->defattr);
  267                 edp->ccol = edp->crow = 0;
  268                 (*edp->emulops->cursor)(edp->emulcookie, 1, 0, 0);
  269                 break;
  270         default:
  271                 break;
  272         }
  273 }

/* [<][>][^][v][top][bottom][index][help] */