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