[BACK]Return to qv.c CVS log [TXT][DIR] Up to [local] / sys / arch / vax / uba

Annotation of sys/arch/vax/uba/qv.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: qv.c,v 1.12 2006/01/17 20:26:16 miod Exp $    */
        !             2: /*     $NetBSD: qv.c,v 1.2 1996/09/02 06:44:28 mycroft Exp $   */
        !             3:
        !             4: /*-
        !             5:  * Copyright (c) 1988
        !             6:  *     The Regents of the University of California.  All rights reserved.
        !             7:  * (c) UNIX System Laboratories, Inc.
        !             8:  * All or some portions of this file are derived from material licensed
        !             9:  * to the University of California by American Telephone and Telegraph
        !            10:  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
        !            11:  * the permission of UNIX System Laboratories, Inc.
        !            12:  *
        !            13:  * Redistribution and use in source and binary forms, with or without
        !            14:  * modification, are permitted provided that the following conditions
        !            15:  * are met:
        !            16:  * 1. Redistributions of source code must retain the above copyright
        !            17:  *    notice, this list of conditions and the following disclaimer.
        !            18:  * 2. Redistributions in binary form must reproduce the above copyright
        !            19:  *    notice, this list of conditions and the following disclaimer in the
        !            20:  *    documentation and/or other materials provided with the distribution.
        !            21:  * 3. Neither the name of the University nor the names of its contributors
        !            22:  *    may be used to endorse or promote products derived from this software
        !            23:  *    without specific prior written permission.
        !            24:  *
        !            25:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            26:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            27:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            28:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            29:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            30:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            31:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            32:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            33:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            34:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            35:  * SUCH DAMAGE.
        !            36:  *
        !            37:  *     @(#)qv.c        7.2 (Berkeley) 1/21/94
        !            38:  */
        !            39:
        !            40: /*
        !            41:  *     derived from: @(#)qv.c  1.8 (ULTRIX) 8/21/85
        !            42:  */
        !            43:
        !            44: /************************************************************************
        !            45:  *                                                                     *
        !            46:  *                     Copyright (c) 1985 by                           *
        !            47:  *             Digital Equipment Corporation, Maynard, MA              *
        !            48:  *                     All rights reserved.                            *
        !            49:  *                                                                     *
        !            50:  *   This software is furnished under a license and may be used and    *
        !            51:  *   copied  only  in accordance with the terms of such license and    *
        !            52:  *   with the  inclusion  of  the  above  copyright  notice.   This    *
        !            53:  *   software  or  any  other copies thereof may not be provided or    *
        !            54:  *   otherwise made available to any other person.  No title to and    *
        !            55:  *   ownership of the software is hereby transferred.                  *
        !            56:  *                                                                     *
        !            57:  *   This software is  derived  from  software  received  from  the    *
        !            58:  *   University    of   California,   Berkeley,   and   from   Bell    *
        !            59:  *   Laboratories.  Use, duplication, or disclosure is  subject  to    *
        !            60:  *   restrictions  under  license  agreements  with  University  of    *
        !            61:  *   California and with AT&T.                                         *
        !            62:  *                                                                     *
        !            63:  *   The information in this software is subject to change  without    *
        !            64:  *   notice  and should not be construed as a commitment by Digital    *
        !            65:  *   Equipment Corporation.                                            *
        !            66:  *                                                                     *
        !            67:  *   Digital assumes no responsibility for the use  or  reliability    *
        !            68:  *   of its software on equipment which is not supplied by Digital.    *
        !            69:  *                                                                     *
        !            70:  ************************************************************************
        !            71:  *
        !            72:  * This driver provides glass tty functionality to the qvss. It is a strange
        !            73:  * device in that it supports three subchannels. The first being the asr,
        !            74:  * the second being a channel that intercepts the chars headed for the screen
        !            75:  * ( like a pseudo tty ) and the third being a source of mouse state changes.
        !            76:  * NOTE: the second is conditional on #ifdef CONS_HACK in this version
        !            77:  * of the driver, as it's a total crock.
        !            78:  *
        !            79:  * There may be one and only one qvss in the system.  This restriction is based
        !            80:  * on the inability to map more than one at a time.  This restriction will
        !            81:  * exist until the kernel has shared memory services. This driver therefore
        !            82:  * support a single unit. No attempt was made to have it service more.
        !            83:  *
        !            84:  * (this belongs in sccs - not here)
        !            85:  *
        !            86:  * 02 Aug 85 -- rjl
        !            87:  *     Changed the names of the special setup routines so that the system
        !            88:  *     can have a qvss or a qdss system console.
        !            89:  *
        !            90:  * 03 Jul 85 -- rjl
        !            91:  *     Added a check for virtual mode in qvputc so that the driver
        !            92:  *     doesn't crash while in a dump which is done in physical mode.
        !            93:  *
        !            94:  * 10 Apr 85 -- jg
        !            95:  *     Well, our theory about keyboard handling was wrong; most of the
        !            96:  *     keyboard is in autorepeat, down mode.  These changes are to make
        !            97:  *     the qvss work the same as the Vs100, which is not necessarily
        !            98:  *     completely correct, as some chord usage may fail.  But since we
        !            99:  *     can't easily change the Vs100, we might as well propagate the
        !           100:  *     problem to another device.  There are also changes for screen and
        !           101:  *     mouse accellaration.
        !           102:  *
        !           103:  * 27 Mar 85 -- rjl
        !           104:  *     MicroVAX-II systems have interval timers that interrupt at ipl4.
        !           105:  *     Everything else is higher and thus causes us to miss clock ticks. The
        !           106:  *     problem isn't severe except in the case of a device like this one that
        !           107:  *     generates lots of interrupts. We aren't willing to make this change to
        !           108:  *     all device drivers but it seems acceptable in this case.
        !           109:  *
        !           110:  *  3 Dec 84 -- jg
        !           111:  *     To continue the tradition of building a better mouse trap,  this
        !           112:  *     driver has been extended to form Vs100 style event queues.  If the
        !           113:  *     mouse device is open, the keyboard events are intercepted and put
        !           114:  *     into the shared memory queue.  Unfortunately, we are ending up with
        !           115:  *     one of the longest Unix device drivers.  Sigh....
        !           116:  *
        !           117:  * 20 Nov 84 -- rjl
        !           118:  *      As a further complication this driver is required to function as the
        !           119:  *      virtual system console. This code runs before and during auto-
        !           120:  *      configuration and therefore is require to have a second path for setup.
        !           121:  *      It is futher constrained to have a character output routine that
        !           122:  *      is not dependant on the interrupt system.
        !           123:  *
        !           124:  */
        !           125:
        !           126:
        !           127: #include "qv.h"
        !           128: #if NQV > 0
        !           129:
        !           130: #include <machine/pte.h>
        !           131:
        !           132: #include <sys/param.h>
        !           133: #include <sys/conf.h>
        !           134: #include <sys/user.h>
        !           135: #include <vax/uba/qvioctl.h>
        !           136: #include <sys/tty.h>
        !           137: #include <sys/map.h>
        !           138: #include <sys/buf.h>
        !           139: #include <sys/vm.h>
        !           140: #include <sys/file.h>
        !           141: #include <sys/uio.h>
        !           142: #include <sys/kernel.h>
        !           143: #include <sys/syslog.h>
        !           144: #include <sys/poll.h>
        !           145: #include <machine/cpu.h>
        !           146: #include <machine/mtpr.h>
        !           147: #include <vax/uba/ubareg.h>
        !           148: #include <vax/uba/ubavar.h>
        !           149:
        !           150: #define CONS_HACK
        !           151:
        !           152: struct uba_device *qvinfo[NQV];
        !           153:
        !           154: struct tty qv_tty[NQV*4];
        !           155:
        !           156: #define        nNQV  NQV
        !           157: int    nqv = NQV*4;
        !           158:
        !           159: /*
        !           160:  * Definition of the driver for the auto-configuration program.
        !           161:  */
        !           162: int    qvprobe(), qvattach(), qvkint(), qvvint();
        !           163: u_short        qvstd[] = { 0 };
        !           164: struct uba_driver qvdriver =
        !           165:        { qvprobe, 0, qvattach, 0, qvstd, "qv", qvinfo };
        !           166:
        !           167: extern char qvmem[][512*NBPG];
        !           168: extern pt_entry_t QVmap[][512];
        !           169:
        !           170: /*
        !           171:  * Local variables for the driver. Initialized for 15' screen
        !           172:  * so that it can be used during the boot process.
        !           173:  */
        !           174:
        !           175: #define QVWAITPRI      (PZERO+1)
        !           176: #define QVSSMAJOR      40
        !           177:
        !           178: #define QVKEYBOARD     0       /* minor 0, keyboard/glass tty */
        !           179: #define QVPCONS        1       /* minor 1, console interceptor XXX */
        !           180: #define QVMOUSECHAN    2       /* minor 2, mouse */
        !           181: #define        QVSPARE         3       /* unused */
        !           182: #define QVCHAN(unit)   ((unit) & 03)
        !           183: /*
        !           184:  * v_putc is the switch that is used to redirect the console cnputc to the
        !           185:  * virtual console vputc.  consops is used to redirect the console
        !           186:  * device to the qvss console.
        !           187:  */
        !           188: extern (*v_putc)();
        !           189: extern struct cdevsw *consops;
        !           190: /*
        !           191:  * qv_def_scrn is used to select the appropriate tables. 0=15 inch 1=19 inch,
        !           192:  * 2 = uVAXII.
        !           193:  */
        !           194: int qv_def_scrn = 2;
        !           195:
        !           196: #define QVMAXEVQ       64      /* must be power of 2 */
        !           197: #define EVROUND(x)     ((x) & (QVMAXEVQ - 1))
        !           198:
        !           199: /*
        !           200:  * Screen parameters 15 & 19 inch monitors. These determine the max size in
        !           201:  * pixel and character units for the display and cursor positions.
        !           202:  * Notice that the mouse defaults to original square algorithm, but X
        !           203:  * will change to its defaults once implemented.
        !           204:  */
        !           205: struct qv_info *qv_scn;
        !           206: struct qv_info qv_scn_defaults[] = {
        !           207:        {0, {0, 0}, 0, {0, 0}, 0, 0, 30, 80, 768, 480, 768-16, 480-16,
        !           208:         0, 0, 0, 0, 0, QVMAXEVQ, 0, 0, {0, 0}, {0, 0, 0, 0}, 2, 4},
        !           209:        {0, {0, 0}, 0, {0, 0}, 0, 0, 55, 120, 960, 864, 960-16, 864-16,
        !           210:         0, 0, 0, 0, 0, QVMAXEVQ, 0, 0, {0, 0}, {0, 0, 0, 0}, 2, 4},
        !           211:        {0, {0, 0}, 0, {0, 0}, 0, 0, 56, 120,1024, 864,1024-16, 864-16,
        !           212:         0, 0, 0, 0, 0, QVMAXEVQ, 0, 0, {0, 0}, {0, 0, 0, 0}, 2, 4}
        !           213: };
        !           214:
        !           215: /*
        !           216:  * Screen controller initialization parameters. The definations and use
        !           217:  * of these parameters can be found in the Motorola 68045 crtc specs. In
        !           218:  * essence they set the display parameters for the chip. The first set is
        !           219:  * for the 15" screen and the second is for the 19" separate sync. There
        !           220:  * is also a third set for a 19" composite sync monitor which we have not
        !           221:  * tested and which is not supported.
        !           222:  */
        !           223: static short qv_crt_parms[][16] = {
        !           224:            { 31, 25, 27, 0142, 31, 13, 30, 31, 4, 15, 040, 0, 0, 0, 0, 0 },
        !           225: /* VR100*/ { 39, 30, 32, 0262, 55, 5, 54, 54, 4, 15, 040, 0, 0, 0, 0, 0 },
        !           226: /* VR260*/ { 39, 32, 33, 0264, 56, 5, 54, 54, 4, 15, 040, 0, 0, 0, 0, 0},
        !           227: };
        !           228:
        !           229: /*
        !           230:  * Screen parameters
        !           231:  */
        !           232: struct qv_info  *qv_scn;
        !           233: int maxqvmem = 254*1024 - sizeof(struct qv_info) - QVMAXEVQ*sizeof(vsEvent);
        !           234:
        !           235: /*
        !           236:  * Keyboard state
        !           237:  */
        !           238: struct qv_keyboard {
        !           239:        int shift;                      /* state variables      */
        !           240:        int cntrl;
        !           241:        int lock;
        !           242:        char last;                      /* last character       */
        !           243: } qv_keyboard;
        !           244:
        !           245: short divdefaults[15] = { LK_DOWN,     /* 0 doesn't exist */
        !           246:        LK_AUTODOWN, LK_AUTODOWN, LK_AUTODOWN, LK_DOWN,
        !           247:        LK_UPDOWN,   LK_UPDOWN,   LK_AUTODOWN, LK_AUTODOWN,
        !           248:        LK_AUTODOWN, LK_AUTODOWN, LK_AUTODOWN, LK_AUTODOWN,
        !           249:        LK_DOWN, LK_AUTODOWN };
        !           250:
        !           251: short kbdinitstring[] = {              /* reset any random keyboard stuff */
        !           252:        LK_AR_ENABLE,                   /* we want autorepeat by default */
        !           253:        LK_CL_ENABLE,                   /* keyclick */
        !           254:        0x84,                           /* keyclick volume */
        !           255:        LK_KBD_ENABLE,                  /* the keyboard itself */
        !           256:        LK_BELL_ENABLE,                 /* keyboard bell */
        !           257:        0x84,                           /* bell volume */
        !           258:        LK_LED_DISABLE,                 /* keyboard leds */
        !           259:        LED_ALL };
        !           260: #define KBD_INIT_LENGTH        sizeof(kbdinitstring)/sizeof(short)
        !           261:
        !           262: #define TOY ((time.tv_sec * 100) + (time.tv_usec / 10000))
        !           263:
        !           264: int    qv_ipl_lo = 1;                  /* IPL low flag                 */
        !           265: int    mouseon = 0;                    /* mouse channel is enabled when 1*/
        !           266: struct proc *qvrsel;                   /* process waiting for select */
        !           267:
        !           268: int    qvstart(), qvputc();
        !           269:
        !           270: /*
        !           271:  * Keyboard translation and font tables
        !           272:  */
        !           273: extern u_short q_key[], q_shift_key[], q_cursor[];
        !           274: extern char *q_special[], q_font[];
        !           275:
        !           276: /*
        !           277:  * See if the qvss will interrupt.
        !           278:  */
        !           279:
        !           280: /*ARGSUSED*/
        !           281: qvprobe(reg, ctlr)
        !           282:        caddr_t reg;
        !           283:        int ctlr;
        !           284: {
        !           285:        register int br, cvec;          /* these are ``value-result'' */
        !           286:        register struct qvdevice *qvaddr = (struct qvdevice *)reg;
        !           287:        static int tvec, ovec;
        !           288:
        !           289: #ifdef lint
        !           290:        br = 0; cvec = br; br = cvec;
        !           291:        qvkint(0); qvvint(0);
        !           292: #endif
        !           293:        /*
        !           294:         * Allocate the next two vectors
        !           295:         */
        !           296:        tvec = 0360;
        !           297:        ovec = cvec;
        !           298:        /*
        !           299:         * Turn on the keyboard and vertical interrupt vectors.
        !           300:         */
        !           301:        qvaddr->qv_intcsr = 0;          /* init the interrupt controller */
        !           302:        qvaddr->qv_intcsr = 0x40;       /* reset irr                    */
        !           303:        qvaddr->qv_intcsr = 0x80;       /* specify individual vectors   */
        !           304:        qvaddr->qv_intcsr = 0xc0;       /* preset autoclear data        */
        !           305:        qvaddr->qv_intdata = 0xff;      /* all setup as autoclear       */
        !           306:
        !           307:        qvaddr->qv_intcsr = 0xe0;       /* preset vector address 1      */
        !           308:        qvaddr->qv_intdata = tvec;      /* give it the keyboard vector  */
        !           309:        qvaddr->qv_intcsr = 0x28;       /* enable tx/rx interrupt       */
        !           310:
        !           311:        qvaddr->qv_intcsr = 0xe1;       /* preset vector address 2      */
        !           312:        qvaddr->qv_intdata = tvec+4;    /* give it the vertical sysnc   */
        !           313:        qvaddr->qv_intcsr = 0x29;       /* enable                       */
        !           314:
        !           315:        qvaddr->qv_intcsr = 0xa1;       /* arm the interrupt ctrl       */
        !           316:
        !           317:        qvaddr->qv_uartcmd = 0x15;      /* set mode pntr/enable rx/tx   */
        !           318:        qvaddr->qv_uartmode = 0x17;     /* noparity, 8-bit              */
        !           319:        qvaddr->qv_uartmode = 0x07;     /* 1 stop bit                   */
        !           320:        qvaddr->qv_uartstatus = 0x99;   /* 4800 baud xmit/recv          */
        !           321:        qvaddr->qv_uartintstatus = 2;   /* enable recv interrupts       */
        !           322:
        !           323:        qvaddr->qv_csr |= QV_INT_ENABLE | QV_CUR_MODE;
        !           324:
        !           325:        DELAY(10000);
        !           326:
        !           327:        qvaddr->qv_csr &= ~QV_INT_ENABLE;
        !           328:
        !           329:        /*
        !           330:         * If the qvss did interrupt it was the second vector not
        !           331:         * the first so we have to return the first so that they
        !           332:         * will be setup properly
        !           333:         */
        !           334:        if( ovec == cvec ) {
        !           335:                return 0;
        !           336:        } else
        !           337:                cvec -= 4;
        !           338:        return (sizeof (struct qvdevice));
        !           339: }
        !           340:
        !           341: /*
        !           342:  * Routine called to attach a qv.
        !           343:  */
        !           344: qvattach(ui)
        !           345:         struct uba_device *ui;
        !           346: {
        !           347:
        !           348:         /*
        !           349:          * If not the console then we have to setup the screen
        !           350:          */
        !           351:         if (v_putc != qvputc || ui->ui_unit != 0)
        !           352:                 (void)qv_setup((struct qvdevice *)ui->ui_addr, ui->ui_unit, 1);
        !           353:        else
        !           354:                qv_scn->qvaddr = (struct qvdevice *)ui->ui_addr;
        !           355: }
        !           356:
        !           357:
        !           358: /*ARGSUSED*/
        !           359: qvopen(dev, flag)
        !           360:        dev_t dev;
        !           361: {
        !           362:        register struct tty *tp;
        !           363:        register int unit, qv;
        !           364:        register struct qvdevice *qvaddr;
        !           365:        register struct uba_device *ui;
        !           366:        register struct qv_info *qp = qv_scn;
        !           367:
        !           368:        unit = minor(dev);
        !           369:        qv = unit >> 2;
        !           370:        if (unit >= nqv || (ui = qvinfo[qv])== 0 || ui->ui_alive == 0)
        !           371:                return (ENXIO);
        !           372:        if (QVCHAN(unit) == QVSPARE
        !           373: #ifndef CONS_HACK
        !           374:           || QVCHAN(unit) == QVPCONS
        !           375: #endif
        !           376:           )
        !           377:                return (ENODEV);
        !           378:        tp = &qv_tty[unit];
        !           379:        if (tp->t_state&TS_XCLUDE && u.u_uid!=0)
        !           380:                return (EBUSY);
        !           381:        qvaddr = (struct qvdevice *)ui->ui_addr;
        !           382:         qv_scn->qvaddr = qvaddr;
        !           383:        tp->t_addr = (caddr_t)qvaddr;
        !           384:        tp->t_oproc = qvstart;
        !           385:
        !           386:        if ((tp->t_state&TS_ISOPEN) == 0) {
        !           387:                ttychars(tp);
        !           388:                tp->t_state = TS_ISOPEN|TS_CARR_ON;
        !           389:                tp->t_ispeed = B9600;
        !           390:                tp->t_ospeed = B9600;
        !           391:                if( QVCHAN(unit) == QVKEYBOARD ) {
        !           392:                        /* make sure keyboard is always back to default */
        !           393:                        qvkbdreset();
        !           394:                        qvaddr->qv_csr |= QV_INT_ENABLE;
        !           395:                        tp->t_iflag = TTYDEF_IFLAG;
        !           396:                        tp->t_oflag = TTYDEF_OFLAG;
        !           397:                        tp->t_lflag = TTYDEF_LFLAG;
        !           398:                        tp->t_cflag = TTYDEF_CFLAG;
        !           399:                }
        !           400:                /* XXX ?why?  else
        !           401:                        tp->t_flags = RAW;
        !           402:                */
        !           403:        }
        !           404:        /*
        !           405:         * Process line discipline specific open if its not the
        !           406:         * mouse channel. For the mouse we init the ring ptr's.
        !           407:         */
        !           408:        if( QVCHAN(unit) != QVMOUSECHAN )
        !           409:                return ((*linesw[tp->t_line].l_open)(dev, tp));
        !           410:        else {
        !           411:                mouseon = 1;
        !           412:                /* set up event queue for later */
        !           413:                qp->ibuff = (vsEvent *)qp - QVMAXEVQ;
        !           414:                qp->iqsize = QVMAXEVQ;
        !           415:                qp->ihead = qp->itail = 0;
        !           416:                return 0;
        !           417:        }
        !           418: }
        !           419:
        !           420: /*
        !           421:  * Close a QVSS line.
        !           422:  */
        !           423: /*ARGSUSED*/
        !           424: qvclose(dev, flag, mode, p)
        !           425:        dev_t dev;
        !           426:        int flag, mode;
        !           427:        struct proc *p;
        !           428: {
        !           429:        register struct tty *tp;
        !           430:        register unit;
        !           431:        register struct qvdevice *qvaddr;
        !           432:        int error;
        !           433:
        !           434:        unit = minor(dev);
        !           435:        tp = &qv_tty[unit];
        !           436:
        !           437:        /*
        !           438:         * If this is the keyboard unit (0) shutdown the
        !           439:         * interface.
        !           440:         */
        !           441:        qvaddr = (struct qvdevice *)tp->t_addr;
        !           442:        if (QVCHAN(unit) == QVKEYBOARD )
        !           443:                qvaddr->qv_csr &= ~QV_INT_ENABLE;
        !           444:
        !           445:        /*
        !           446:         * If unit is not the mouse channel call the line disc.
        !           447:         * otherwise clear the state flag, and put the keyboard into down/up.
        !           448:         */
        !           449:        if (QVCHAN(unit) != QVMOUSECHAN) {
        !           450:                (*linesw[tp->t_line].l_close)(tp, flag);
        !           451:                error = ttyclose(tp);
        !           452:        } else {
        !           453:                mouseon = 0;
        !           454:                qv_init( qvaddr );
        !           455:                error = 0;
        !           456:        }
        !           457:        tp->t_state = 0;
        !           458:        return (error);
        !           459: }
        !           460:
        !           461: qvread(dev, uio)
        !           462:        dev_t dev;
        !           463:        struct uio *uio;
        !           464: {
        !           465:        register struct tty *tp;
        !           466:        int unit = minor( dev );
        !           467:
        !           468:        if (QVCHAN(unit) != QVMOUSECHAN) {
        !           469:                tp = &qv_tty[unit];
        !           470:                return ((*linesw[tp->t_line].l_read)(tp, uio));
        !           471:        }
        !           472:        return (ENXIO);
        !           473: }
        !           474:
        !           475: qvwrite(dev, uio)
        !           476:        dev_t dev;
        !           477:        struct uio *uio;
        !           478: {
        !           479:        register struct tty *tp;
        !           480:        int unit = minor( dev );
        !           481:
        !           482:        /*
        !           483:         * If this is the mouse we simply fake the i/o, otherwise
        !           484:         * we let the line disp. handle it.
        !           485:         */
        !           486:        if (QVCHAN(unit) == QVMOUSECHAN) {
        !           487:                uio->uio_offset = uio->uio_resid;
        !           488:                uio->uio_resid = 0;
        !           489:                return 0;
        !           490:        }
        !           491:        tp = &qv_tty[unit];
        !           492:        return ((*linesw[tp->t_line].l_write)(tp, uio));
        !           493: }
        !           494:
        !           495:
        !           496: /*
        !           497:  * Mouse activity poll routine
        !           498:  */
        !           499: int
        !           500: qvpoll(dev, events, p)
        !           501:        dev_t dev;
        !           502:        int events;
        !           503:        struct proc *p;
        !           504: {
        !           505:        struct qv_info *qp = qv_scn;
        !           506:        int revents = 0;
        !           507:        int s = spl5();
        !           508:
        !           509:        if (QVCHAN(minor(dev)) != QVMOUSECHAN) {
        !           510:                splx(s);
        !           511:                return(ttpoll(dev, events, p));
        !           512:        }
        !           513:
        !           514:        if (events & (POLLIN | POLLRDNORM)) {
        !           515:                if (qp->ihead != qp->itail)
        !           516:                        revents |= events & (POLLIN | POLLRDNORM);
        !           517:                else
        !           518:                        qvrsel = u.u_procp;
        !           519:        }
        !           520:        splx(s);
        !           521:        return(revents);
        !           522: }
        !           523:
        !           524: /*
        !           525:  * QVSS keyboard interrupt.
        !           526:  */
        !           527: qvkint(qv)
        !           528:        int qv;
        !           529: {
        !           530:        struct tty *tp;
        !           531:        register c;
        !           532:        struct uba_device *ui;
        !           533:        register int key;
        !           534:        register int i;
        !           535:
        !           536:        ui = qvinfo[qv];
        !           537:        if (ui == 0 || ui->ui_alive == 0)
        !           538:                return;
        !           539:        tp = &qv_tty[qv<<2];
        !           540:        /*
        !           541:         * Get a character from the keyboard.
        !           542:         */
        !           543:        key = ((struct qvdevice *)ui->ui_addr)->qv_uartdata & 0xff;
        !           544:        if( mouseon == 0) {
        !           545:                /*
        !           546:                 * Check for various keyboard errors
        !           547:                 */
        !           548:                if( key == LK_POWER_ERROR || key == LK_KDOWN_ERROR ||
        !           549:                    key == LK_INPUT_ERROR || key == LK_OUTPUT_ERROR) {
        !           550:                        log(LOG_ERR,
        !           551:                            "qv%d: Keyboard error, code = %x\n",qv,key);
        !           552:                        return;
        !           553:                }
        !           554:                if( key < LK_LOWEST ) return;
        !           555:                /*
        !           556:                 * See if its a state change key
        !           557:                 */
        !           558:                switch ( key ) {
        !           559:                case LOCK:
        !           560:                        qv_keyboard.lock ^= 0xffff;     /* toggle */
        !           561:                        if( qv_keyboard.lock )
        !           562:                                qv_key_out( LK_LED_ENABLE );
        !           563:                        else
        !           564:                                qv_key_out( LK_LED_DISABLE );
        !           565:                        qv_key_out( LED_3 );
        !           566:                        return;
        !           567:                case SHIFT:
        !           568:                        qv_keyboard.shift ^= 0xffff;
        !           569:                        return;
        !           570:                case CNTRL:
        !           571:                        qv_keyboard.cntrl ^= 0xffff;
        !           572:                        return;
        !           573:                case ALLUP:
        !           574:                        qv_keyboard.cntrl = qv_keyboard.shift = 0;
        !           575:                        return;
        !           576:                case REPEAT:
        !           577:                        c = qv_keyboard.last;
        !           578:                        break;
        !           579:                default:
        !           580:                /*
        !           581:                 * Test for control characters. If set, see if the character
        !           582:                 * is eligible to become a control character.
        !           583:                 */
        !           584:                        if( qv_keyboard.cntrl ) {
        !           585:                                c = q_key[ key ];
        !           586:                                if( c >= ' ' && c <= '~' )
        !           587:                                        c &= 0x1f;
        !           588:                        } else if( qv_keyboard.lock || qv_keyboard.shift )
        !           589:                                c = q_shift_key[ key ];
        !           590:                                else
        !           591:                                c = q_key[ key ];
        !           592:                        break;
        !           593:                }
        !           594:
        !           595:                qv_keyboard.last = c;
        !           596:
        !           597:                /*
        !           598:                 * Check for special function keys
        !           599:                 */
        !           600:                if( c & 0x80 ) {
        !           601:                        register char *string;
        !           602:                        string = q_special[ c & 0x7f ];
        !           603:                        while( *string )
        !           604:                        (*linesw[tp->t_line].l_rint)(*string++, tp);
        !           605:                } else
        !           606:                        (*linesw[tp->t_line].l_rint)(c, tp);
        !           607:        } else {
        !           608:                /*
        !           609:                 * Mouse channel is open put it into the event queue
        !           610:                 * instead.
        !           611:                 */
        !           612:                register struct qv_info *qp = qv_scn;
        !           613:                register vsEvent *vep;
        !           614:
        !           615:                if ((i = EVROUND(qp->itail+1)) == qp->ihead)
        !           616:                        return;
        !           617:                vep = &qp->ibuff[qp->itail];
        !           618:                vep->vse_direction = VSE_KBTRAW;
        !           619:                vep->vse_type = VSE_BUTTON;
        !           620:                vep->vse_device = VSE_DKB;
        !           621:                vep->vse_x = qp->mouse.x;
        !           622:                vep->vse_y = qp->mouse.y;
        !           623:                vep->vse_time = TOY;
        !           624:                vep->vse_key = key;
        !           625:                qp->itail = i;
        !           626:                if(qvrsel) {
        !           627:                        selwakeup(qvrsel,0);
        !           628:                        qvrsel = 0;
        !           629:                }
        !           630:        }
        !           631: }
        !           632:
        !           633: /*
        !           634:  * Ioctl for QVSS.
        !           635:  */
        !           636: /*ARGSUSED*/
        !           637: qvioctl(dev, cmd, data, flag)
        !           638:        dev_t dev;
        !           639:        register caddr_t data;
        !           640: {
        !           641:        register struct tty *tp;
        !           642:        register int unit = minor(dev);
        !           643:        register struct qv_info *qp = qv_scn;
        !           644:        register struct qv_kpcmd *qk;
        !           645:        register unsigned char *cp;
        !           646:        int error;
        !           647:
        !           648:        /*
        !           649:         * Check for and process qvss specific ioctl's
        !           650:         */
        !           651:        switch( cmd ) {
        !           652:        case QIOCGINFO:                                 /* return screen info */
        !           653:                bcopy((caddr_t)qp, data, sizeof (struct qv_info));
        !           654:                break;
        !           655:
        !           656:        case QIOCSMSTATE:                               /* set mouse state */
        !           657:                qp->mouse = *((vsCursor *)data);
        !           658:                qv_pos_cur( qp->mouse.x, qp->mouse.y );
        !           659:                break;
        !           660:
        !           661:        case QIOCINIT:                                  /* init screen  */
        !           662:                qv_init( qp->qvaddr );
        !           663:                break;
        !           664:
        !           665:        case QIOCKPCMD:
        !           666:                qk = (struct qv_kpcmd *)data;
        !           667:                if(qk->nbytes == 0) qk->cmd |= 0200;
        !           668:                if(mouseon == 0) qk->cmd |= 1;  /* no mode changes */
        !           669:                qv_key_out(qk->cmd);
        !           670:                cp = &qk->par[0];
        !           671:                while(qk->nbytes-- > 0) {       /* terminate parameters */
        !           672:                        if(qk->nbytes <= 0) *cp |= 0200;
        !           673:                        qv_key_out(*cp++);
        !           674:                }
        !           675:                break;
        !           676:        case QIOCADDR:                                  /* get struct addr */
        !           677:                *(struct qv_info **) data = qp;
        !           678:                break;
        !           679:        default:                                        /* not ours ??  */
        !           680:                tp = &qv_tty[unit];
        !           681:                error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag);
        !           682:                if (error >= 0)
        !           683:                        return (error);
        !           684:                error = ttioctl(tp, cmd, data, flag);
        !           685:                if (error >= 0) {
        !           686:                        return (error);
        !           687:                }
        !           688:                break;
        !           689:        }
        !           690:        return (0);
        !           691: }
        !           692: /*
        !           693:  * Initialize the screen and the scanmap
        !           694:  */
        !           695: qv_init(qvaddr)
        !           696: struct qvdevice *qvaddr;
        !           697: {
        !           698:        register short *scanline;
        !           699:        register int i;
        !           700:        register short scan;
        !           701:        register char *ptr;
        !           702:        register struct qv_info *qp = qv_scn;
        !           703:
        !           704:        /*
        !           705:         * Clear the bit map
        !           706:         */
        !           707:        for( i=0 , ptr = qp->bitmap ; i<240 ; i += 2 , ptr += 2048)
        !           708:                bzero( ptr, 2048 );
        !           709:        /*
        !           710:         * Reinitialize the scanmap
        !           711:         */
        !           712:         scan = qvaddr->qv_csr & QV_MEM_BANK;
        !           713:         scanline = qp->scanmap;
        !           714:         for(i = 0 ; i < qp->max_y ; i++ )
        !           715:                 *scanline++ = scan++;
        !           716:
        !           717:        /*
        !           718:         * Home the cursor
        !           719:         */
        !           720:        qp->row = qp->col = 0;
        !           721:
        !           722:        /*
        !           723:         * Reset the cursor to the default type.
        !           724:         */
        !           725:        for( i=0 ; i<16 ; i++ )
        !           726:                qp->cursorbits[i] = q_cursor[i];
        !           727:        qvaddr->qv_csr |= QV_CUR_MODE;
        !           728:        /*
        !           729:         * Reset keyboard to default state.
        !           730:         */
        !           731:        qvkbdreset();
        !           732: }
        !           733:
        !           734: qvreset()
        !           735: {
        !           736: }
        !           737: qvkbdreset()
        !           738: {
        !           739:        register int i;
        !           740:        qv_key_out(LK_DEFAULTS);
        !           741:        for( i=1 ; i < 15 ; i++ )
        !           742:                qv_key_out( divdefaults[i] | (i<<3));
        !           743:        for (i = 0; i < KBD_INIT_LENGTH; i++)
        !           744:                qv_key_out(kbdinitstring[i]);
        !           745: }
        !           746:
        !           747: #define abs(x) (((x) > 0) ? (x) : (-(x)))
        !           748: /*
        !           749:  * QVSS vertical sync interrupt
        !           750:  */
        !           751: qvvint(qv)
        !           752:        int qv;
        !           753: {
        !           754:        extern int selwait;
        !           755:        register struct qvdevice *qvaddr;
        !           756:        struct uba_device *ui;
        !           757:        register struct qv_info *qp = qv_scn;
        !           758:        int unit;
        !           759:        struct tty *tp0;
        !           760:        int i;
        !           761:        register int j;
        !           762:        /*
        !           763:         * Mouse state info
        !           764:         */
        !           765:        static ushort omouse = 0, nmouse = 0;
        !           766:        static char omx=0, omy=0, mx=0, my=0, om_switch=0, m_switch=0;
        !           767:        register int dx, dy;
        !           768:
        !           769:        /*
        !           770:         * Test and set the qv_ipl_lo flag. If the result is not zero then
        !           771:         * someone else must have already gotten here.
        !           772:         */
        !           773:        if( --qv_ipl_lo )
        !           774:                return;
        !           775:        (void)spl4();
        !           776:        ui = qvinfo[qv];
        !           777:        unit = qv<<2;
        !           778:        qvaddr = (struct qvdevice *)ui->ui_addr;
        !           779:        tp0 = &qv_tty[QVCHAN(unit) + QVMOUSECHAN];
        !           780:        /*
        !           781:         * See if the mouse has moved.
        !           782:         */
        !           783:        if( omouse != (nmouse = qvaddr->qv_mouse) ) {
        !           784:                omouse = nmouse;
        !           785:                mx = nmouse & 0xff;
        !           786:                my = nmouse >> 8;
        !           787:                dy = my - omy; omy = my;
        !           788:                dx = mx - omx; omx = mx;
        !           789:                if( dy < 50 && dy > -50 && dx < 50 && dx > -50 ) {
        !           790:                        register vsEvent *vep;
        !           791:                        if( qp->mscale < 0 ) {  /* Ray Lanza's original */
        !           792:                                if( dy < 0 )
        !           793:                                        dy = -( dy * dy );
        !           794:                                else
        !           795:                                        dy *= dy;
        !           796:                                if( dx < 0 )
        !           797:                                        dx = -( dx * dx );
        !           798:                                else
        !           799:                                        dx *= dx;
        !           800:                        }
        !           801:                        else {                  /* Vs100 style, see WGA spec */
        !           802:                            int thresh = qp->mthreshold;
        !           803:                            int scale  = qp->mscale;
        !           804:                            if( abs(dx) > thresh ) {
        !           805:                                if ( dx < 0 )
        !           806:                                    dx = (dx + thresh)*scale - thresh;
        !           807:                                else
        !           808:                                    dx = (dx - thresh)*scale + thresh;
        !           809:                            }
        !           810:                            if( abs(dy) > thresh ) {
        !           811:                                if ( dy < 0 )
        !           812:                                    dy = (dy + thresh)*scale - thresh;
        !           813:                                else
        !           814:                                    dy = (dy - thresh)*scale + thresh;
        !           815:                            }
        !           816:                        }
        !           817:                        qp->mouse.x += dx;
        !           818:                        qp->mouse.y -= dy;
        !           819:                        if( qp->mouse.x < 0 )
        !           820:                                qp->mouse.x = 0;
        !           821:                        if( qp->mouse.y < 0 )
        !           822:                                qp->mouse.y = 0;
        !           823:                        if( qp->mouse.x > qp->max_cur_x )
        !           824:                                qp->mouse.x = qp->max_cur_x;
        !           825:                        if( qp->mouse.y > qp->max_cur_y )
        !           826:                                qp->mouse.y = qp->max_cur_y;
        !           827:                        if( tp0->t_state & TS_ISOPEN )
        !           828:                                qv_pos_cur( qp->mouse.x, qp->mouse.y );
        !           829:                        if (qp->mouse.y < qp->mbox.bottom &&
        !           830:                            qp->mouse.y >=  qp->mbox.top &&
        !           831:                            qp->mouse.x < qp->mbox.right &&
        !           832:                            qp->mouse.x >=  qp->mbox.left) goto switches;
        !           833:                        qp->mbox.bottom = 0;    /* trash box */
        !           834:                        if (EVROUND(qp->itail+1) == qp->ihead)
        !           835:                                goto switches;
        !           836:                        i = EVROUND(qp->itail - 1);
        !           837:                        if ((qp->itail != qp->ihead) && (i != qp->ihead)) {
        !           838:                                vep = & qp->ibuff[i];
        !           839:                                if(vep->vse_type == VSE_MMOTION) {
        !           840:                                        vep->vse_x = qp->mouse.x;
        !           841:                                        vep->vse_y = qp->mouse.y;
        !           842:                                        goto switches;
        !           843:                                }
        !           844:                        }
        !           845:                        /* put event into queue and do select */
        !           846:                        vep = & qp->ibuff[qp->itail];
        !           847:                        vep->vse_type = VSE_MMOTION;
        !           848:                        vep->vse_time = TOY;
        !           849:                        vep->vse_x = qp->mouse.x;
        !           850:                        vep->vse_y = qp->mouse.y;
        !           851:                        qp->itail = EVROUND(qp->itail+1);
        !           852:                }
        !           853:        }
        !           854:        /*
        !           855:         * See if mouse switches have changed.
        !           856:         */
        !           857: switches:if( om_switch != ( m_switch = (qvaddr->qv_csr & QV_MOUSE_ANY) >> 8 ) ) {
        !           858:                qp->mswitches = ~m_switch & 0x7;
        !           859:                for (j = 0; j < 3; j++) {       /* check each switch */
        !           860:                        register vsEvent *vep;
        !           861:                        if ( ((om_switch>>j) & 1) == ((m_switch>>j) & 1) )
        !           862:                                continue;
        !           863:                        /* check for room in the queue */
        !           864:                        if ((i = EVROUND(qp->itail+1)) == qp->ihead) return;
        !           865:                        /* put event into queue and do select */
        !           866:                        vep = &qp->ibuff[qp->itail];
        !           867:                        vep->vse_type = VSE_BUTTON;
        !           868:                        vep->vse_key = 2 - j;
        !           869:                        vep->vse_direction = VSE_KBTDOWN;
        !           870:                        if ( (m_switch >> j) & 1)
        !           871:                                vep->vse_direction = VSE_KBTUP;
        !           872:                        vep->vse_device = VSE_MOUSE;
        !           873:                        vep->vse_time = TOY;
        !           874:                        vep->vse_x = qp->mouse.x;
        !           875:                        vep->vse_y = qp->mouse.y;
        !           876:                }
        !           877:                qp->itail =  i;
        !           878:                om_switch = m_switch;
        !           879:                qp->mswitches = m_switch;
        !           880:        }
        !           881:        /* if we have proc waiting, and event has happened, wake him up */
        !           882:        if(qvrsel && (qp->ihead != qp->itail)) {
        !           883:                selwakeup(qvrsel,0);
        !           884:                qvrsel = 0;
        !           885:        }
        !           886:        /*
        !           887:         * Okay we can take another hit now
        !           888:         */
        !           889:        qv_ipl_lo = 1;
        !           890: }
        !           891:
        !           892: /*
        !           893:  * Start  transmission
        !           894:  */
        !           895: qvstart(tp)
        !           896:        register struct tty *tp;
        !           897: {
        !           898:        register int unit, c;
        !           899:        register struct tty *tp0;
        !           900:        int s;
        !           901:
        !           902:        unit = minor(tp->t_dev);
        !           903: #ifdef CONS_HACK
        !           904:        tp0 = &qv_tty[(unit&0xfc)+QVPCONS];
        !           905: #endif
        !           906:        unit = QVCHAN(unit);
        !           907:
        !           908:        s = spl5();
        !           909:        /*
        !           910:         * If it's currently active, or delaying, no need to do anything.
        !           911:         */
        !           912:        if (tp->t_state&(TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
        !           913:                goto out;
        !           914:        /*
        !           915:         * Display chars until the queue is empty, if the second subchannel
        !           916:         * is open direct them there. Drop characters from subchannels other
        !           917:         * than 0 on the floor.
        !           918:         */
        !           919:
        !           920:        while( tp->t_outq.c_cc ) {
        !           921:                c = getc(&tp->t_outq);
        !           922:                if (unit == QVKEYBOARD)
        !           923: #ifdef CONS_HACK
        !           924:                        if( tp0->t_state & TS_ISOPEN ){
        !           925:                                (*linesw[tp0->t_line].l_rint)(c, tp0);
        !           926:                        } else
        !           927: #endif
        !           928:                                qvputchar( c & 0xff );
        !           929:        }
        !           930:        /*
        !           931:         * Position the cursor to the next character location.
        !           932:         */
        !           933:        qv_pos_cur( qv_scn->col*8, qv_scn->row*15 );
        !           934:
        !           935:        /*
        !           936:         * If there are sleepers, and output has drained below low
        !           937:         * water mark, wake up the sleepers.
        !           938:         */
        !           939:        if ( tp->t_outq.c_cc<= tp->t_lowat ) {
        !           940:                if (tp->t_state&TS_ASLEEP){
        !           941:                        tp->t_state &= ~TS_ASLEEP;
        !           942:                        wakeup((caddr_t)&tp->t_outq);
        !           943:                }
        !           944:        }
        !           945:        tp->t_state &= ~TS_BUSY;
        !           946: out:
        !           947:        splx(s);
        !           948: }
        !           949:
        !           950: /*
        !           951:  * Stop output on a line, e.g. for ^S/^Q or output flush.
        !           952:  */
        !           953: /*ARGSUSED*/
        !           954: void
        !           955: qvstop(tp, flag)
        !           956:        register struct tty *tp;
        !           957:        int flag;
        !           958: {
        !           959:        register int s;
        !           960:
        !           961:        /*
        !           962:         * Block input/output interrupts while messing with state.
        !           963:         */
        !           964:        s = spl5();
        !           965:        if (tp->t_state & TS_BUSY) {
        !           966:                if ((tp->t_state&TS_TTSTOP)==0) {
        !           967:                        tp->t_state |= TS_FLUSH;
        !           968:                } else
        !           969:                        tp->t_state &= ~TS_BUSY;
        !           970:        }
        !           971:        splx(s);
        !           972: }
        !           973:
        !           974: qvputc(c)
        !           975: char c;
        !           976: {
        !           977:        qvputchar(c);
        !           978: }
        !           979:
        !           980: /*
        !           981:  * Routine to display a character on the screen.  The model used is a
        !           982:  * glass tty.  It is assumed that the user will only use this emulation
        !           983:  * during system boot and that the screen will be eventually controlled
        !           984:  * by a window manager.
        !           985:  *
        !           986:  */
        !           987: qvputchar( c )
        !           988: register char c;
        !           989: {
        !           990:
        !           991:        register char *b_row, *f_row;
        !           992:        register int i;
        !           993:        register short *scanline;
        !           994:        register int ote = 128;
        !           995:        register struct qv_info *qp = qv_scn;
        !           996:
        !           997:        /*
        !           998:         * This routine may be called in physical mode by the dump code
        !           999:         * so we check and punt if that's the case.
        !          1000:         */
        !          1001:        if( (mfpr(MAPEN) & 1) == 0 )
        !          1002:                return;
        !          1003:
        !          1004:        c &= 0x7f;
        !          1005:
        !          1006:        switch ( c ) {
        !          1007:        case '\t':                              /* tab          */
        !          1008:                for( i = 8 - (qp->col & 0x7) ; i > 0 ; i-- )
        !          1009:                        qvputchar( ' ' );
        !          1010:                break;
        !          1011:
        !          1012:        case '\r':                              /* return       */
        !          1013:                qp->col = 0;
        !          1014:                break;
        !          1015:
        !          1016:        case '\010':                            /* backspace    */
        !          1017:                if( --qp->col < 0 )
        !          1018:                        qp->col = 0;
        !          1019:                break;
        !          1020:
        !          1021:        case '\n':                              /* linefeed     */
        !          1022:                if( qp->row+1 >= qp->max_row )
        !          1023:                        qvscroll();
        !          1024:                else
        !          1025:                        qp->row++;
        !          1026:                /*
        !          1027:                * Position the cursor to the next character location.
        !          1028:                */
        !          1029:                qv_pos_cur( qp->col*8, qp->row*15 );
        !          1030:                break;
        !          1031:
        !          1032:        case '\007':                            /* bell         */
        !          1033:                 /*
        !          1034:                  * We don't do anything to the keyboard until after
        !          1035:                  * autoconfigure.
        !          1036:                  */
        !          1037:                if( qp->qvaddr )
        !          1038:                        qv_key_out( LK_RING_BELL );
        !          1039:                return;
        !          1040:
        !          1041:        default:
        !          1042:                if( c >= ' ' && c <= '~' ) {
        !          1043:                         scanline = qp->scanmap;
        !          1044:                         b_row = qp->bitmap+(scanline[qp->row*15]&0x3ff)*128+qp->col;
        !          1045:                        i = c - ' ';
        !          1046:                        if( i < 0 || i > 95 )
        !          1047:                                i = 0;
        !          1048:                        else
        !          1049:                                i *= 15;
        !          1050:                        f_row = (char *)((int)q_font + i);
        !          1051:
        !          1052: /*                     for( i=0 ; i<15 ; i++ , b_row += 128, f_row++ )
        !          1053:                                *b_row = *f_row;*/
        !          1054:                        /* inline expansion for speed */
        !          1055:                        *b_row = *f_row++; b_row += ote;
        !          1056:                        *b_row = *f_row++; b_row += ote;
        !          1057:                        *b_row = *f_row++; b_row += ote;
        !          1058:                        *b_row = *f_row++; b_row += ote;
        !          1059:                        *b_row = *f_row++; b_row += ote;
        !          1060:                        *b_row = *f_row++; b_row += ote;
        !          1061:                        *b_row = *f_row++; b_row += ote;
        !          1062:                        *b_row = *f_row++; b_row += ote;
        !          1063:                        *b_row = *f_row++; b_row += ote;
        !          1064:                        *b_row = *f_row++; b_row += ote;
        !          1065:                        *b_row = *f_row++; b_row += ote;
        !          1066:                        *b_row = *f_row++; b_row += ote;
        !          1067:                        *b_row = *f_row++; b_row += ote;
        !          1068:                        *b_row = *f_row++; b_row += ote;
        !          1069:                        *b_row = *f_row++; b_row += ote;
        !          1070:
        !          1071:                        if( ++qp->col >= qp->max_col ) {
        !          1072:                                qp->col = 0 ;
        !          1073:                                if( qp->row+1 >= qp->max_row )
        !          1074:                                        qvscroll();
        !          1075:                                else
        !          1076:                                        qp->row++;
        !          1077:                        }
        !          1078:                }
        !          1079:                break;
        !          1080:        }
        !          1081: }
        !          1082:
        !          1083: /*
        !          1084:  * Position the cursor to a particular spot.
        !          1085:  */
        !          1086: qv_pos_cur( x, y)
        !          1087: register int x,y;
        !          1088: {
        !          1089:        register struct qvdevice *qvaddr;
        !          1090:        register struct qv_info *qp = qv_scn;
        !          1091:        register index;
        !          1092:
        !          1093:        if( qvaddr = qp->qvaddr ) {
        !          1094:                if( y < 0 || y > qp->max_cur_y )
        !          1095:                        y = qp->max_cur_y;
        !          1096:                if( x < 0 || x > qp->max_cur_x )
        !          1097:                        x = qp->max_cur_x;
        !          1098:                qp->cursor.x = x;               /* keep track of real cursor*/
        !          1099:                qp->cursor.y = y;               /* position, indep. of mouse*/
        !          1100:
        !          1101:                qvaddr->qv_crtaddr = 10;        /* select cursor start reg */
        !          1102:                qvaddr->qv_crtdata = y & 0xf;
        !          1103:                qvaddr->qv_crtaddr = 11;        /* select cursor end reg */
        !          1104:                qvaddr->qv_crtdata = y & 0xf;
        !          1105:                qvaddr->qv_crtaddr = 14;        /* select cursor y pos. */
        !          1106:                qvaddr->qv_crtdata = y >> 4;
        !          1107:                qvaddr->qv_xcur = x;            /* pos x axis   */
        !          1108:                /*
        !          1109:                 * If the mouse is being used then we change the mode of
        !          1110:                 * cursor display based on the pixels under the cursor
        !          1111:                 */
        !          1112:                if( mouseon ) {
        !          1113:                        index = y*128 + x/8;
        !          1114:                        if( qp->bitmap[ index ] && qp->bitmap[ index+128 ] )
        !          1115:                                qvaddr->qv_csr &= ~QV_CUR_MODE;
        !          1116:                        else
        !          1117:                                qvaddr->qv_csr |=  QV_CUR_MODE;
        !          1118:                }
        !          1119:        }
        !          1120: }
        !          1121: /*
        !          1122:  * Scroll the bitmap by moving the scanline map words. This could
        !          1123:  * be done by moving the bitmap but it's much too slow for a full screen.
        !          1124:  * The only drawback is that the scanline map must be reset when the user
        !          1125:  * wants to do graphics.
        !          1126:  */
        !          1127: qvscroll()
        !          1128: {
        !          1129:        short tmpscanlines[15];
        !          1130:        register char *b_row;
        !          1131:        register short *scanline;
        !          1132:        register struct qv_info *qp = qv_scn;
        !          1133:
        !          1134:        /*
        !          1135:         * If the mouse is on we don't scroll so that the bit map
        !          1136:         * remains sane.
        !          1137:         */
        !          1138:        if( mouseon ) {
        !          1139:                qp->row = 0;
        !          1140:                return;
        !          1141:        }
        !          1142:        /*
        !          1143:         * Save the first 15 scanlines so that we can put them at
        !          1144:         * the bottom when done.
        !          1145:         */
        !          1146:        bcopy((caddr_t)qp->scanmap, (caddr_t)tmpscanlines, sizeof tmpscanlines);
        !          1147:
        !          1148:        /*
        !          1149:         * Clear the wrapping line so that it won't flash on the bottom
        !          1150:         * of the screen.
        !          1151:         */
        !          1152:         scanline = qp->scanmap;
        !          1153:         b_row = qp->bitmap+(*scanline&0x3ff)*128;
        !          1154:        bzero( b_row, 1920 );
        !          1155:
        !          1156:        /*
        !          1157:         * Now move the scanlines down
        !          1158:         */
        !          1159:        bcopy((caddr_t)(qp->scanmap+15), (caddr_t)qp->scanmap,
        !          1160:              (qp->row * 15) * sizeof (short) );
        !          1161:
        !          1162:        /*
        !          1163:         * Now put the other lines back
        !          1164:         */
        !          1165:        bcopy((caddr_t)tmpscanlines, (caddr_t)(qp->scanmap+(qp->row * 15)),
        !          1166:              sizeof (tmpscanlines) );
        !          1167:
        !          1168: }
        !          1169:
        !          1170: /*
        !          1171:  * Output to the keyboard. This routine status polls the transmitter on the
        !          1172:  * keyboard to output a code. The timer is to avoid hanging on a bad device.
        !          1173:  */
        !          1174: qv_key_out(c)
        !          1175:        u_short c;
        !          1176: {
        !          1177:        int timer = 30000;
        !          1178:        register struct qv_info *qp = qv_scn;
        !          1179:
        !          1180:        if (qp->qvaddr) {
        !          1181:                while ((qp->qvaddr->qv_uartstatus & 0x4) == 0  && timer--)
        !          1182:                        ;
        !          1183:                qp->qvaddr->qv_uartdata = c;
        !          1184:        }
        !          1185: }
        !          1186: /*
        !          1187:  * Virtual console initialization. This routine sets up the qvss so that it can
        !          1188:  * be used as the system console. It is invoked before autoconfig and has to do
        !          1189:  * everything necessary to allow the device to serve as the system console.
        !          1190:  * In this case it must map the q-bus and device areas and initialize the qvss
        !          1191:  * screen.
        !          1192:  */
        !          1193: qvcons_init()
        !          1194: {
        !          1195:         struct percpu *pcpu;            /* pointer to percpu structure  */
        !          1196:        register struct qbus *qb;
        !          1197:         struct qvdevice *qvaddr;        /* device pointer               */
        !          1198:         short *devptr;                  /* virtual device space         */
        !          1199:        extern cnputc();                /* standard serial console putc */
        !          1200: #define QVSSCSR 017200
        !          1201:
        !          1202:        /*
        !          1203:         * If secondary console already configured,
        !          1204:         * don't override the previous one.
        !          1205:         */
        !          1206:        if (v_putc != cnputc)
        !          1207:                return 0;
        !          1208:         /*
        !          1209:          * find the percpu entry that matches this machine.
        !          1210:          */
        !          1211:         for( pcpu = percpu ; pcpu && pcpu->pc_cputype != cpu ; pcpu++ )
        !          1212:                 ;
        !          1213:         if( pcpu == NULL )
        !          1214:                 return 0;
        !          1215:        if (pcpu->pc_io->io_type != IO_QBUS)
        !          1216:                return 0;
        !          1217:
        !          1218:         /*
        !          1219:          * Found an entry for this cpu. Because this device is Microvax specific
        !          1220:          * we assume that there is a single q-bus and don't have to worry about
        !          1221:          * multiple adapters.
        !          1222:          *
        !          1223:          * Map the device registers.
        !          1224:          */
        !          1225:        qb = (struct qbus *)pcpu->pc_io->io_details;
        !          1226:        ioaccess(qb->qb_iopage, UMEMmap[0] + qb->qb_memsize, UBAIOPAGES * NBPG);
        !          1227:
        !          1228:         /*
        !          1229:          * See if the qvss is there.
        !          1230:          */
        !          1231:         devptr = (short *)((char *)umem[0] + (qb->qb_memsize * NBPG));
        !          1232:         qvaddr = (struct qvdevice *)((u_int)devptr + ubdevreg(QVSSCSR));
        !          1233:         if (badaddr((caddr_t)qvaddr, sizeof(short)))
        !          1234:                 return 0;
        !          1235:         /*
        !          1236:          * Okay the device is there lets set it up
        !          1237:          */
        !          1238:         if (!qv_setup(qvaddr, 0, 0))
        !          1239:                return 0;
        !          1240:        v_putc = qvputc;
        !          1241:         consops = &cdevsw[QVSSMAJOR];
        !          1242:        return 1;
        !          1243: }
        !          1244: /*
        !          1245:  * Do the board specific setup
        !          1246:  */
        !          1247: qv_setup(qvaddr, unit, probed)
        !          1248: struct qvdevice *qvaddr;
        !          1249: int unit;
        !          1250: int probed;
        !          1251: {
        !          1252:         caddr_t qvssmem;               /* pointer to the display mem   */
        !          1253:         register i;                    /* simple index                 */
        !          1254:        register struct qv_info *qp;
        !          1255:         register int *pte;
        !          1256:         struct percpu *pcpu;            /* pointer to percpu structure  */
        !          1257:        register struct qbus *qb;
        !          1258:
        !          1259:         /*
        !          1260:          * find the percpu entry that matches this machine.
        !          1261:          */
        !          1262:         for( pcpu = percpu ; pcpu && pcpu->pc_cputype != cpu ; pcpu++ )
        !          1263:                 ;
        !          1264:         if( pcpu == NULL )
        !          1265:                 return(0);
        !          1266:
        !          1267:         /*
        !          1268:          * Found an entry for this cpu. Because this device is Microvax specific
        !          1269:          * we assume that there is a single q-bus and don't have to worry about
        !          1270:          * multiple adapters.
        !          1271:          *
        !          1272:          * Map the device memory.
        !          1273:          */
        !          1274:        qb = (struct qbus *)pcpu->pc_io->io_details;
        !          1275:
        !          1276:         i = (u_int)(qvaddr->qv_csr & QV_MEM_BANK) << 7;
        !          1277:        ioaccess(qb->qb_maddr + i, QVmap[unit], 512 * NBPG);
        !          1278:        qvssmem = qvmem[unit];
        !          1279:         pte = (int *)(QVmap[unit]);
        !          1280:         for (i=0; i < 512; i++, pte++)
        !          1281:                 *pte = (*pte & ~PG_PROT) | PG_UW | PG_V;
        !          1282:
        !          1283:         qv_scn = (struct qv_info *)((u_int)qvssmem + 251*1024);
        !          1284:        qp = qv_scn;
        !          1285:         if( (qvaddr->qv_csr & QV_19INCH) && qv_def_scrn == 0)
        !          1286:                 qv_def_scrn = 1;
        !          1287:         *qv_scn = qv_scn_defaults[ qv_def_scrn ];
        !          1288:        if (probed)
        !          1289:                qp->qvaddr = qvaddr;
        !          1290:        qp->bitmap = qvssmem;
        !          1291:         qp->scanmap = (short *)((u_int)qvssmem + 254*1024);
        !          1292:         qp->cursorbits = (short *)((u_int)qvssmem + 256*1024-32);
        !          1293:        /* set up event queue for later */
        !          1294:        qp->ibuff = (vsEvent *)qp - QVMAXEVQ;
        !          1295:        qp->iqsize = QVMAXEVQ;
        !          1296:        qp->ihead = qp->itail = 0;
        !          1297:
        !          1298:         /*
        !          1299:          * Setup the crt controller chip.
        !          1300:          */
        !          1301:         for( i=0 ; i<16 ; i++ ) {
        !          1302:                 qvaddr->qv_crtaddr = i;
        !          1303:                 qvaddr->qv_crtdata = qv_crt_parms[ qv_def_scrn ][ i ];
        !          1304:         }
        !          1305:         /*
        !          1306:          * Setup the display.
        !          1307:          */
        !          1308:         qv_init( qvaddr );
        !          1309:
        !          1310:         /*
        !          1311:          * Turn on the video
        !          1312:          */
        !          1313:         qvaddr->qv_csr |= QV_VIDEO_ENA ;
        !          1314:        return 1;
        !          1315: }
        !          1316: #endif

CVSweb