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