Home | History | Annotate | Line # | Download | only in qbus
qd.c revision 1.15.2.2
      1  1.15.2.2  thorpej /*	$NetBSD: qd.c,v 1.15.2.2 1999/07/01 23:35:33 thorpej Exp $	*/
      2  1.15.2.2  thorpej 
      3  1.15.2.2  thorpej /*-
      4  1.15.2.2  thorpej  * Copyright (c) 1988 Regents of the University of California.
      5  1.15.2.2  thorpej  * All rights reserved.
      6  1.15.2.2  thorpej  *
      7  1.15.2.2  thorpej  * Redistribution and use in source and binary forms, with or without
      8  1.15.2.2  thorpej  * modification, are permitted provided that the following conditions
      9  1.15.2.2  thorpej  * are met:
     10  1.15.2.2  thorpej  * 1. Redistributions of source code must retain the above copyright
     11  1.15.2.2  thorpej  *    notice, this list of conditions and the following disclaimer.
     12  1.15.2.2  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.15.2.2  thorpej  *    notice, this list of conditions and the following disclaimer in the
     14  1.15.2.2  thorpej  *    documentation and/or other materials provided with the distribution.
     15  1.15.2.2  thorpej  * 3. All advertising materials mentioning features or use of this software
     16  1.15.2.2  thorpej  *    must display the following acknowledgement:
     17  1.15.2.2  thorpej  *	This product includes software developed by the University of
     18  1.15.2.2  thorpej  *	California, Berkeley and its contributors.
     19  1.15.2.2  thorpej  * 4. Neither the name of the University nor the names of its contributors
     20  1.15.2.2  thorpej  *    may be used to endorse or promote products derived from this software
     21  1.15.2.2  thorpej  *    without specific prior written permission.
     22  1.15.2.2  thorpej  *
     23  1.15.2.2  thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.15.2.2  thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.15.2.2  thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.15.2.2  thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.15.2.2  thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.15.2.2  thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.15.2.2  thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.15.2.2  thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.15.2.2  thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.15.2.2  thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.15.2.2  thorpej  * SUCH DAMAGE.
     34  1.15.2.2  thorpej  *
     35  1.15.2.2  thorpej  *	@(#)qd.c	7.1 (Berkeley) 6/28/91
     36  1.15.2.2  thorpej  */
     37  1.15.2.2  thorpej 
     38  1.15.2.2  thorpej /************************************************************************
     39  1.15.2.2  thorpej *									*
     40  1.15.2.2  thorpej *			Copyright (c) 1985-1988 by			*
     41  1.15.2.2  thorpej *		Digital Equipment Corporation, Maynard, MA		*
     42  1.15.2.2  thorpej *			All rights reserved.				*
     43  1.15.2.2  thorpej *									*
     44  1.15.2.2  thorpej *   This software is furnished under a license and may be used and	*
     45  1.15.2.2  thorpej *   copied  only  in accordance with the terms of such license and	*
     46  1.15.2.2  thorpej *   with the  inclusion  of  the  above  copyright  notice.   This	*
     47  1.15.2.2  thorpej *   software  or  any  other copies thereof may not be provided or	*
     48  1.15.2.2  thorpej *   otherwise made available to any other person.  No title to and	*
     49  1.15.2.2  thorpej *   ownership of the software is hereby transferred.			*
     50  1.15.2.2  thorpej *									*
     51  1.15.2.2  thorpej *   The information in this software is subject to change  without	*
     52  1.15.2.2  thorpej *   notice  and should not be construed as a commitment by Digital	*
     53  1.15.2.2  thorpej *   Equipment Corporation.						*
     54  1.15.2.2  thorpej *									*
     55  1.15.2.2  thorpej *   Digital assumes no responsibility for the use  or  reliability	*
     56  1.15.2.2  thorpej *   of its software on equipment which is not supplied by Digital.	*
     57  1.15.2.2  thorpej *									*
     58  1.15.2.2  thorpej *************************************************************************/
     59  1.15.2.2  thorpej 
     60  1.15.2.2  thorpej /*
     61  1.15.2.2  thorpej  * qd.c - QDSS display driver for VAXSTATION-II GPX workstation
     62  1.15.2.2  thorpej  */
     63  1.15.2.2  thorpej 
     64  1.15.2.2  thorpej #include "opt_ddb.h"
     65  1.15.2.2  thorpej 
     66  1.15.2.2  thorpej #include "qd.h"
     67  1.15.2.2  thorpej 
     68  1.15.2.2  thorpej #include <sys/param.h>
     69  1.15.2.2  thorpej #include <sys/systm.h>
     70  1.15.2.2  thorpej #include <sys/conf.h>
     71  1.15.2.2  thorpej #include <sys/tty.h>
     72  1.15.2.2  thorpej #include <sys/kernel.h>
     73  1.15.2.2  thorpej #include <sys/device.h>
     74  1.15.2.2  thorpej #include <sys/poll.h>
     75  1.15.2.2  thorpej #include <sys/buf.h>
     76  1.15.2.2  thorpej 
     77  1.15.2.2  thorpej #include <vm/vm.h>
     78  1.15.2.2  thorpej 
     79  1.15.2.2  thorpej #include <dev/cons.h>
     80  1.15.2.2  thorpej 
     81  1.15.2.2  thorpej #include <machine/bus.h>
     82  1.15.2.2  thorpej #include <machine/scb.h>
     83  1.15.2.2  thorpej 
     84  1.15.2.2  thorpej #ifdef __vax__
     85  1.15.2.2  thorpej #include <machine/sid.h>
     86  1.15.2.2  thorpej #include <machine/cpu.h>
     87  1.15.2.2  thorpej #include <machine/pte.h>
     88  1.15.2.2  thorpej #endif
     89  1.15.2.2  thorpej 
     90  1.15.2.2  thorpej #include <dev/qbus/ubavar.h>
     91  1.15.2.2  thorpej 
     92  1.15.2.2  thorpej #include <dev/qbus/qduser.h>
     93  1.15.2.2  thorpej #include <dev/qbus/qdreg.h>
     94  1.15.2.2  thorpej #include <dev/qbus/qdioctl.h>
     95  1.15.2.2  thorpej 
     96  1.15.2.2  thorpej #include "ioconf.h"
     97  1.15.2.2  thorpej 
     98  1.15.2.2  thorpej /*
     99  1.15.2.2  thorpej  * QDSS driver status flags for tracking operational state
    100  1.15.2.2  thorpej  */
    101  1.15.2.2  thorpej struct qdflags {
    102  1.15.2.2  thorpej 	u_int inuse;		/* which minor dev's are in use now */
    103  1.15.2.2  thorpej 	u_int config;		/* I/O page register content */
    104  1.15.2.2  thorpej 	u_int mapped;		/* user mapping status word */
    105  1.15.2.2  thorpej 	u_int kernel_loop;	/* if kernel console is redirected */
    106  1.15.2.2  thorpej 	u_int user_dma;		/* DMA from user space in progress */
    107  1.15.2.2  thorpej 	u_short pntr_id;	/* type code of pointing device */
    108  1.15.2.2  thorpej 	u_short duart_imask;	/* shadowing for duart intrpt mask reg */
    109  1.15.2.2  thorpej 	u_short adder_ie;	/* shadowing for adder intrpt enbl reg */
    110  1.15.2.2  thorpej 	u_short curs_acc;	/* cursor acceleration factor */
    111  1.15.2.2  thorpej 	u_short curs_thr;	/* cursor acceleration threshold level */
    112  1.15.2.2  thorpej 	u_short tab_res;	/* tablet resolution factor */
    113  1.15.2.2  thorpej 	u_short selmask;	/* mask for active qd select entries */
    114  1.15.2.2  thorpej };
    115  1.15.2.2  thorpej 
    116  1.15.2.2  thorpej /*
    117  1.15.2.2  thorpej  * Softc struct to keep track of all states in this driver.
    118  1.15.2.2  thorpej  */
    119  1.15.2.2  thorpej struct	qd_softc {
    120  1.15.2.2  thorpej 	struct	device sc_dev;
    121  1.15.2.2  thorpej 	bus_space_tag_t	sc_iot;
    122  1.15.2.2  thorpej 	bus_space_handle_t sc_ioh;
    123  1.15.2.2  thorpej 	bus_dma_tag_t	sc_dmat;
    124  1.15.2.2  thorpej };
    125  1.15.2.2  thorpej 
    126  1.15.2.2  thorpej /*
    127  1.15.2.2  thorpej  * bit definitions for 'inuse' entry
    128  1.15.2.2  thorpej  */
    129  1.15.2.2  thorpej #define CONS_DEV	0x01
    130  1.15.2.2  thorpej #define GRAPHIC_DEV	0x04
    131  1.15.2.2  thorpej 
    132  1.15.2.2  thorpej /*
    133  1.15.2.2  thorpej  * bit definitions for 'mapped' member of flag structure
    134  1.15.2.2  thorpej  */
    135  1.15.2.2  thorpej #define MAPDEV		0x01		/* hardware is mapped */
    136  1.15.2.2  thorpej #define MAPDMA		0x02		/* DMA buffer mapped */
    137  1.15.2.2  thorpej #define MAPEQ		0x04		/* event queue buffer mapped */
    138  1.15.2.2  thorpej #define MAPSCR		0x08		/* scroll param area mapped */
    139  1.15.2.2  thorpej #define MAPCOLOR	0x10		/* color map writing buffer mapped */
    140  1.15.2.2  thorpej 
    141  1.15.2.2  thorpej /*
    142  1.15.2.2  thorpej  * bit definitions for 'selmask' member of qdflag structure
    143  1.15.2.2  thorpej  */
    144  1.15.2.2  thorpej #define SEL_READ	0x01		/* read select is active */
    145  1.15.2.2  thorpej #define SEL_WRITE	0x02		/* write select is active */
    146  1.15.2.2  thorpej 
    147  1.15.2.2  thorpej /*
    148  1.15.2.2  thorpej  * constants used in shared memory operations
    149  1.15.2.2  thorpej  */
    150  1.15.2.2  thorpej #define EVENT_BUFSIZE  1024	/* # of bytes per device's event buffer */
    151  1.15.2.2  thorpej #define MAXEVENTS  ( (EVENT_BUFSIZE - sizeof(struct qdinput))	 \
    152  1.15.2.2  thorpej 	/ sizeof(struct _vs_event) )
    153  1.15.2.2  thorpej #define DMA_BUFSIZ	(1024 * 10)
    154  1.15.2.2  thorpej #define COLOR_BUFSIZ  ((sizeof(struct color_buf) + 512) & ~0x01FF)
    155  1.15.2.2  thorpej 
    156  1.15.2.2  thorpej /*
    157  1.15.2.2  thorpej  * reference to an array of "uba_device" structures built by the auto
    158  1.15.2.2  thorpej  * configuration program.  The uba_device structure decribes the device
    159  1.15.2.2  thorpej  * sufficiently for the driver to talk to it.  The auto configuration code
    160  1.15.2.2  thorpej  * fills in the uba_device structures (located in ioconf.c) from user
    161  1.15.2.2  thorpej  * maintained info.
    162  1.15.2.2  thorpej  */
    163  1.15.2.2  thorpej struct uba_device *qdinfo[NQD];  /* array of pntrs to each QDSS's */
    164  1.15.2.2  thorpej struct tty *qd_tty[NQD*4];	/* teletype structures for each.. */
    165  1.15.2.2  thorpej volatile char *qvmem[NQD];
    166  1.15.2.2  thorpej volatile struct pte *QVmap[NQD];
    167  1.15.2.2  thorpej #define CHUNK	  (64 * 1024)
    168  1.15.2.2  thorpej #define QMEMSIZE  (1024 * 1024 * 4)	/* 4 meg */
    169  1.15.2.2  thorpej 
    170  1.15.2.2  thorpej /*
    171  1.15.2.2  thorpej  * static storage used by multiple functions in this code
    172  1.15.2.2  thorpej  */
    173  1.15.2.2  thorpej int Qbus_unmap[NQD];		/* Qbus mapper release code */
    174  1.15.2.2  thorpej struct qdmap qdmap[NQD];	/* QDSS register map structure */
    175  1.15.2.2  thorpej struct qdflags qdflags[NQD];	/* QDSS register map structure */
    176  1.15.2.2  thorpej caddr_t qdbase[NQD];		/* base address of each QDSS unit */
    177  1.15.2.2  thorpej struct buf qdbuf[NQD];		/* buf structs used by strategy */
    178  1.15.2.2  thorpej short qdopened[NQD];		/* graphics device is open exclusive use */
    179  1.15.2.2  thorpej 
    180  1.15.2.2  thorpej /*
    181  1.15.2.2  thorpej  * the array "event_shared[]" is made up of a number of event queue buffers
    182  1.15.2.2  thorpej  * equal to the number of QDSS's configured into the running kernel (NQD).
    183  1.15.2.2  thorpej  * Each event queue buffer begins with an event queue header (struct qdinput)
    184  1.15.2.2  thorpej  * followed by a group of event queue entries (struct _vs_event).  The array
    185  1.15.2.2  thorpej  * "*eq_header[]" is an array of pointers to the start of each event queue
    186  1.15.2.2  thorpej  * buffer in "event_shared[]".
    187  1.15.2.2  thorpej  */
    188  1.15.2.2  thorpej #define EQSIZE ((EVENT_BUFSIZE * NQD) + 512)
    189  1.15.2.2  thorpej 
    190  1.15.2.2  thorpej char event_shared[EQSIZE];	    /* reserve space for event bufs */
    191  1.15.2.2  thorpej struct qdinput *eq_header[NQD];     /* event queue header pntrs */
    192  1.15.2.2  thorpej 
    193  1.15.2.2  thorpej /*
    194  1.15.2.2  thorpej  * This allocation method reserves enough memory pages for NQD shared DMA I/O
    195  1.15.2.2  thorpej  * buffers.  Each buffer must consume an integral number of memory pages to
    196  1.15.2.2  thorpej  * guarantee that a following buffer will begin on a page boundary.  Also,
    197  1.15.2.2  thorpej  * enough space is allocated so that the FIRST I/O buffer can start at the
    198  1.15.2.2  thorpej  * 1st page boundary after "&DMA_shared".  Page boundaries are used so that
    199  1.15.2.2  thorpej  * memory protections can be turned on/off for individual buffers.
    200  1.15.2.2  thorpej  */
    201  1.15.2.2  thorpej #define IOBUFSIZE  ((DMA_BUFSIZ * NQD) + 512)
    202  1.15.2.2  thorpej 
    203  1.15.2.2  thorpej char DMA_shared[IOBUFSIZE];	    /* reserve I/O buffer space */
    204  1.15.2.2  thorpej struct DMAreq_header *DMAheader[NQD];  /* DMA buffer header pntrs */
    205  1.15.2.2  thorpej 
    206  1.15.2.2  thorpej /*
    207  1.15.2.2  thorpej  * The driver assists a client in scroll operations by loading dragon
    208  1.15.2.2  thorpej  * registers from an interrupt service routine.	The loading is done using
    209  1.15.2.2  thorpej  * parameters found in memory shrade between the driver and it's client.
    210  1.15.2.2  thorpej  * The scroll parameter structures are ALL loacted in the same memory page
    211  1.15.2.2  thorpej  * for reasons of memory economy.
    212  1.15.2.2  thorpej  */
    213  1.15.2.2  thorpej char scroll_shared[2 * 512];	/* reserve space for scroll structs */
    214  1.15.2.2  thorpej struct scroll *scroll[NQD];	/* pointers to scroll structures */
    215  1.15.2.2  thorpej 
    216  1.15.2.2  thorpej /*
    217  1.15.2.2  thorpej  * the driver is programmable to provide the user with color map write
    218  1.15.2.2  thorpej  * services at VSYNC interrupt time.  At interrupt time the driver loads
    219  1.15.2.2  thorpej  * the color map with any user-requested load data found in shared memory
    220  1.15.2.2  thorpej  */
    221  1.15.2.2  thorpej #define COLOR_SHARED  ((COLOR_BUFSIZ * NQD) + 512)
    222  1.15.2.2  thorpej 
    223  1.15.2.2  thorpej char color_shared[COLOR_SHARED];      /* reserve space: color bufs */
    224  1.15.2.2  thorpej struct color_buf *color_buf[NQD];     /* pointers to color bufs */
    225  1.15.2.2  thorpej 
    226  1.15.2.2  thorpej /*
    227  1.15.2.2  thorpej  * mouse input event structures
    228  1.15.2.2  thorpej  */
    229  1.15.2.2  thorpej struct mouse_report last_rep[NQD];
    230  1.15.2.2  thorpej struct mouse_report current_rep[NQD];
    231  1.15.2.2  thorpej 
    232  1.15.2.2  thorpej struct selinfo qdrsel[NQD]; 	/* process waiting for select */
    233  1.15.2.2  thorpej struct _vs_cursor cursor[NQD];	/* console cursor */
    234  1.15.2.2  thorpej int qdcount = 0;		/* count of successfully probed qd's */
    235  1.15.2.2  thorpej int nNQD = NQD;
    236  1.15.2.2  thorpej int DMAbuf_size = DMA_BUFSIZ;
    237  1.15.2.2  thorpej int QDlast_DMAtype;             /* type of the last DMA operation */
    238  1.15.2.2  thorpej 
    239  1.15.2.2  thorpej /* #define QDSSMAJOR	41 */	/* QDSS major device number.  We don't care! */
    240  1.15.2.2  thorpej 
    241  1.15.2.2  thorpej /*
    242  1.15.2.2  thorpej  * macro to get system time.  Used to time stamp event queue entries
    243  1.15.2.2  thorpej  */
    244  1.15.2.2  thorpej #define TOY ((time.tv_sec * 100) + (time.tv_usec / 10000))
    245  1.15.2.2  thorpej 
    246  1.15.2.2  thorpej void qd_attach __P((struct device *, struct device *, void *));
    247  1.15.2.2  thorpej static int qd_match __P((struct device *, struct cfdata *, void *));
    248  1.15.2.2  thorpej 
    249  1.15.2.2  thorpej static void qddint(int);			/* DMA gate array intrpt service */
    250  1.15.2.2  thorpej static void qdaint(int);			/* Dragon ADDER intrpt service */
    251  1.15.2.2  thorpej static void qdiint(int);
    252  1.15.2.2  thorpej 
    253  1.15.2.2  thorpej #define QDPRIOR (PZERO-1)		/* must be negative */
    254  1.15.2.2  thorpej #define FALSE	0
    255  1.15.2.2  thorpej #ifdef TRUE
    256  1.15.2.2  thorpej #undef TRUE
    257  1.15.2.2  thorpej #endif
    258  1.15.2.2  thorpej #define TRUE	~FALSE
    259  1.15.2.2  thorpej #define BAD	-1
    260  1.15.2.2  thorpej #define GOOD	0
    261  1.15.2.2  thorpej 
    262  1.15.2.2  thorpej /*
    263  1.15.2.2  thorpej  * macro to create a system virtual page number from system virtual adrs
    264  1.15.2.2  thorpej  */
    265  1.15.2.2  thorpej #define VTOP(x)  (((int)x & ~0xC0000000) >> VAX_PGSHIFT)
    266  1.15.2.2  thorpej 
    267  1.15.2.2  thorpej /*
    268  1.15.2.2  thorpej  * QDSS register address offsets from start of QDSS address space
    269  1.15.2.2  thorpej  */
    270  1.15.2.2  thorpej #define QDSIZE	 (52 * 1024)	/* size of entire QDSS foot print */
    271  1.15.2.2  thorpej #define TMPSIZE  (16 * 1024)	/* template RAM is 8k SHORT WORDS */
    272  1.15.2.2  thorpej #define TMPSTART 0x8000 	/* offset of template RAM from base adrs */
    273  1.15.2.2  thorpej #define REGSIZE  (5 * 512)	/* regs touch 2.5k (5 pages) of addr space */
    274  1.15.2.2  thorpej #define REGSTART 0xC000 	/* offset of reg pages from base adrs */
    275  1.15.2.2  thorpej #define ADDER	(REGSTART+0x000)
    276  1.15.2.2  thorpej #define DGA	(REGSTART+0x200)
    277  1.15.2.2  thorpej #define DUART	(REGSTART+0x400)
    278  1.15.2.2  thorpej #define MEMCSR	(REGSTART+0x800)
    279  1.15.2.2  thorpej #define CLRSIZE  (3 * 512)		/* color map size */
    280  1.15.2.2  thorpej #define CLRSTART (REGSTART+0xA00)	/* color map start offset from base */
    281  1.15.2.2  thorpej /*  0x0C00 really */
    282  1.15.2.2  thorpej #define RED	(CLRSTART+0x000)
    283  1.15.2.2  thorpej #define BLUE	(CLRSTART+0x200)
    284  1.15.2.2  thorpej #define GREEN	(CLRSTART+0x400)
    285  1.15.2.2  thorpej 
    286  1.15.2.2  thorpej 
    287  1.15.2.2  thorpej /*
    288  1.15.2.2  thorpej  * QDSS minor device numbers.  The *real* minor device numbers are in
    289  1.15.2.2  thorpej  * the bottom two bits of the major/minor device spec.  Bits 2 and up are
    290  1.15.2.2  thorpej  * used to specify the QDSS device number (ie: which one?)
    291  1.15.2.2  thorpej  */
    292  1.15.2.2  thorpej 
    293  1.15.2.2  thorpej #define CONS		0
    294  1.15.2.2  thorpej #define GRAPHIC 	2
    295  1.15.2.2  thorpej 
    296  1.15.2.2  thorpej /*
    297  1.15.2.2  thorpej  * console cursor bitmap (white block cursor)
    298  1.15.2.2  thorpej  */
    299  1.15.2.2  thorpej short cons_cursor[32] = {
    300  1.15.2.2  thorpej 	/* A */ 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF,
    301  1.15.2.2  thorpej 	0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF,
    302  1.15.2.2  thorpej 	/* B */ 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF,
    303  1.15.2.2  thorpej 	0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF
    304  1.15.2.2  thorpej };
    305  1.15.2.2  thorpej 
    306  1.15.2.2  thorpej /*
    307  1.15.2.2  thorpej  * constants used in font operations
    308  1.15.2.2  thorpej  */
    309  1.15.2.2  thorpej #define CHARS		190 			/* # of chars in the font */
    310  1.15.2.2  thorpej #define CHAR_HEIGHT	15			/* char height in pixels */
    311  1.15.2.2  thorpej #define CHAR_WIDTH	8			/* char width in pixels*/
    312  1.15.2.2  thorpej #define FONT_WIDTH	(CHAR_WIDTH * CHARS)	/* font width in pixels */
    313  1.15.2.2  thorpej #define ROWS		CHAR_HEIGHT
    314  1.15.2.2  thorpej #define FONT_X		0			/* font's off screen adrs */
    315  1.15.2.2  thorpej #define FONT_Y		(2048 - CHAR_HEIGHT)
    316  1.15.2.2  thorpej 
    317  1.15.2.2  thorpej /* Offset to second row characters (XXX - should remove) */
    318  1.15.2.2  thorpej #define FONT_OFFSET	((MAX_SCREEN_X/CHAR_WIDTH)*CHAR_HEIGHT)
    319  1.15.2.2  thorpej 
    320  1.15.2.2  thorpej extern char q_font[];		/* reference font object code */
    321  1.15.2.2  thorpej extern	u_short q_key[];	/* reference key xlation tables */
    322  1.15.2.2  thorpej extern	u_short q_shift_key[];
    323  1.15.2.2  thorpej extern	char *q_special[];
    324  1.15.2.2  thorpej 
    325  1.15.2.2  thorpej /*
    326  1.15.2.2  thorpej  * definitions for cursor acceleration reporting
    327  1.15.2.2  thorpej  */
    328  1.15.2.2  thorpej #define ACC_OFF 	0x01		/* acceleration is inactive */
    329  1.15.2.2  thorpej 
    330  1.15.2.2  thorpej /*
    331  1.15.2.2  thorpej  * virtual console support.
    332  1.15.2.2  thorpej  */
    333  1.15.2.2  thorpej extern struct cdevsw *consops;
    334  1.15.2.2  thorpej cons_decl(qd);
    335  1.15.2.2  thorpej cdev_decl(qd);
    336  1.15.2.2  thorpej void setup_dragon __P((int));
    337  1.15.2.2  thorpej void init_shared __P((int));
    338  1.15.2.2  thorpej void clear_qd_screen __P((int));
    339  1.15.2.2  thorpej void ldfont __P((int));
    340  1.15.2.2  thorpej void ldcursor __P((int, short *));
    341  1.15.2.2  thorpej void setup_input __P((int));
    342  1.15.2.2  thorpej void blitc __P((int, u_char));
    343  1.15.2.2  thorpej void scroll_up __P((volatile struct adder *));
    344  1.15.2.2  thorpej void write_ID __P((volatile struct adder *, short, short));
    345  1.15.2.2  thorpej int wait_status __P((volatile struct adder *, int));
    346  1.15.2.2  thorpej void led_control __P((int, int, int));
    347  1.15.2.2  thorpej void qdstart(struct tty *);
    348  1.15.2.2  thorpej void qdearly(void);
    349  1.15.2.2  thorpej int qdpolling = 0;
    350  1.15.2.2  thorpej 
    351  1.15.2.2  thorpej /*
    352  1.15.2.2  thorpej  * LK-201 state storage for input console keyboard conversion to ASCII
    353  1.15.2.2  thorpej  */
    354  1.15.2.2  thorpej struct q_keyboard {
    355  1.15.2.2  thorpej 	int shift;			/* state variables	*/
    356  1.15.2.2  thorpej 	int cntrl;
    357  1.15.2.2  thorpej 	int lock;
    358  1.15.2.2  thorpej 	int lastcode;			/* last keycode typed	*/
    359  1.15.2.2  thorpej 	unsigned kup[8];		/* bits for each keycode*/
    360  1.15.2.2  thorpej 	unsigned dkeys[8];		/* down/up mode keys	*/
    361  1.15.2.2  thorpej 	char last;			/* last character	*/
    362  1.15.2.2  thorpej } q_keyboard;
    363  1.15.2.2  thorpej 
    364  1.15.2.2  thorpej /*
    365  1.15.2.2  thorpej  * tty settings on first open
    366  1.15.2.2  thorpej  */
    367  1.15.2.2  thorpej #define IFLAG (BRKINT|ISTRIP|IXON|IXANY|ICRNL|IMAXBEL)
    368  1.15.2.2  thorpej #define OFLAG (OPOST|OXTABS|ONLCR)
    369  1.15.2.2  thorpej #define LFLAG (ISIG|ICANON|ECHO|IEXTEN)
    370  1.15.2.2  thorpej #define CFLAG (PARENB|CREAD|CS7|CLOCAL)
    371  1.15.2.2  thorpej 
    372  1.15.2.2  thorpej /*
    373  1.15.2.2  thorpej  * Kernel virtual addresses where we can map in the QBUS io page and the
    374  1.15.2.2  thorpej  * QDSS memory during qdcninit.  pmap_bootstrap fills this in.
    375  1.15.2.2  thorpej  */
    376  1.15.2.2  thorpej void *qd_ubaio;
    377  1.15.2.2  thorpej 
    378  1.15.2.2  thorpej /* This is the QDSS unit 0 CSR.  It is hard-coded in here so that the
    379  1.15.2.2  thorpej  * QDSS can be used as the console.  The console routines don't get
    380  1.15.2.2  thorpej  * any config info.  The ROM also autodetects at this address, so
    381  1.15.2.2  thorpej  * the console QDSS should be at this address.  Furthermore, nothing
    382  1.15.2.2  thorpej  * else shuld be at this address instead because that would confuse the
    383  1.15.2.2  thorpej  * ROM and this driver.
    384  1.15.2.2  thorpej  */
    385  1.15.2.2  thorpej #define QDSSCSR 0x1F00
    386  1.15.2.2  thorpej 
    387  1.15.2.2  thorpej volatile u_short *qdaddr;         /* Virtual address for QDSS CSR */
    388  1.15.2.2  thorpej 
    389  1.15.2.2  thorpej /*
    390  1.15.2.2  thorpej  * This flag is set to 1 if the console initialization (qdcninit)
    391  1.15.2.2  thorpej  * has been performed on qd0.  That initialization is required and must
    392  1.15.2.2  thorpej  * be done before the device probe routine.
    393  1.15.2.2  thorpej  */
    394  1.15.2.2  thorpej int qd0cninited = 0, qd0iscons = 0;
    395  1.15.2.2  thorpej 
    396  1.15.2.2  thorpej /*
    397  1.15.2.2  thorpej  * Do early check if the qdss is console. If not; don't allocate
    398  1.15.2.2  thorpej  * any memory for it in bootstrap.
    399  1.15.2.2  thorpej  */
    400  1.15.2.2  thorpej void
    401  1.15.2.2  thorpej qdearly()
    402  1.15.2.2  thorpej {
    403  1.15.2.2  thorpej 	extern vaddr_t virtual_avail;
    404  1.15.2.2  thorpej 	int tmp;
    405  1.15.2.2  thorpej 
    406  1.15.2.2  thorpej 	/* Make sure we're running on a system that can have a QDSS */
    407  1.15.2.2  thorpej 	if (vax_boardtype == VAX_BTYP_630)  {
    408  1.15.2.2  thorpej 		/* Now check some undocumented flag */
    409  1.15.2.2  thorpej 		if ((*(int *)(0x200B801E) & 0x60) == 0)
    410  1.15.2.2  thorpej 			/* The KA630 isn't using a QDSS as the console,
    411  1.15.2.2  thorpej 			 * so we won't either */
    412  1.15.2.2  thorpej 			return;
    413  1.15.2.2  thorpej 	} else if (vax_boardtype != VAX_BTYP_650)
    414  1.15.2.2  thorpej 		return;
    415  1.15.2.2  thorpej 
    416  1.15.2.2  thorpej 	/* How to check for console on KA650? We assume that if there is a
    417  1.15.2.2  thorpej 	 * QDSS, it is console.
    418  1.15.2.2  thorpej 	 */
    419  1.15.2.2  thorpej #define	QIOPAGE	0x20000000	/* XXX */
    420  1.15.2.2  thorpej #define	UBAIOPAGES 16
    421  1.15.2.2  thorpej 	tmp = QIOPAGE + ubdevreg(QDSSCSR);
    422  1.15.2.2  thorpej 	if (badaddr((caddr_t)tmp, sizeof(short)))
    423  1.15.2.2  thorpej 		return;
    424  1.15.2.2  thorpej 
    425  1.15.2.2  thorpej 	MAPVIRT(qvmem[0], 64 * 1024 * NQD / VAX_NBPG);
    426  1.15.2.2  thorpej 	MAPVIRT(qd_ubaio, 16);
    427  1.15.2.2  thorpej 	pmap_map((int)qd_ubaio, QIOPAGE, QIOPAGE + UBAIOPAGES * VAX_NBPG,
    428  1.15.2.2  thorpej 	    VM_PROT_READ|VM_PROT_WRITE);
    429  1.15.2.2  thorpej 	qdaddr = (u_short *)((u_int)qd_ubaio + ubdevreg(QDSSCSR));
    430  1.15.2.2  thorpej 	qd0iscons = 1;
    431  1.15.2.2  thorpej }
    432  1.15.2.2  thorpej 
    433  1.15.2.2  thorpej void
    434  1.15.2.2  thorpej qdcnprobe(cndev)
    435  1.15.2.2  thorpej 	struct  consdev *cndev;
    436  1.15.2.2  thorpej {
    437  1.15.2.2  thorpej 	int i;
    438  1.15.2.2  thorpej 
    439  1.15.2.2  thorpej 	cndev->cn_pri = CN_DEAD;
    440  1.15.2.2  thorpej 
    441  1.15.2.2  thorpej 	if (mfpr(PR_MAPEN) == 0)
    442  1.15.2.2  thorpej 		return; /* Cannot use qd if vm system is OFF */
    443  1.15.2.2  thorpej 
    444  1.15.2.2  thorpej 	if (!qd0iscons)
    445  1.15.2.2  thorpej 		return;
    446  1.15.2.2  thorpej 
    447  1.15.2.2  thorpej 	/* Find the console device corresponding to the console QDSS */
    448  1.15.2.2  thorpej 	for (i = 0; i < nchrdev; i++)
    449  1.15.2.2  thorpej 		if (cdevsw[i].d_open == qdopen)  {
    450  1.15.2.2  thorpej 			      cndev->cn_dev = makedev(i,0);
    451  1.15.2.2  thorpej 			      cndev->cn_pri = CN_INTERNAL;
    452  1.15.2.2  thorpej 			      return;
    453  1.15.2.2  thorpej 		 }
    454  1.15.2.2  thorpej 	return;
    455  1.15.2.2  thorpej }
    456  1.15.2.2  thorpej 
    457  1.15.2.2  thorpej 
    458  1.15.2.2  thorpej /*
    459  1.15.2.2  thorpej  * Init QDSS as console (before probe routine)
    460  1.15.2.2  thorpej  */
    461  1.15.2.2  thorpej void
    462  1.15.2.2  thorpej qdcninit(cndev)
    463  1.15.2.2  thorpej 	struct  consdev *cndev;
    464  1.15.2.2  thorpej {
    465  1.15.2.2  thorpej 	caddr_t phys_adr;		/* physical QDSS base adrs */
    466  1.15.2.2  thorpej 	u_int mapix;			/* index into QVmap[] array */
    467  1.15.2.2  thorpej 	int unit;
    468  1.15.2.2  thorpej 
    469  1.15.2.2  thorpej 	/* qdaddr must point to CSR for this unit! */
    470  1.15.2.2  thorpej 
    471  1.15.2.2  thorpej 	/* The console QDSS is QDSS unit 0 */
    472  1.15.2.2  thorpej 	unit = 0;
    473  1.15.2.2  thorpej 
    474  1.15.2.2  thorpej 	/*
    475  1.15.2.2  thorpej 	 * Map q-bus memory used by qdss. (separate map)
    476  1.15.2.2  thorpej 	 */
    477  1.15.2.2  thorpej 	mapix = QMEMSIZE - (CHUNK * (unit + 1));
    478  1.15.2.2  thorpej #define	QMEM 0x30000000
    479  1.15.2.2  thorpej 	(int)phys_adr = QMEM + mapix;
    480  1.15.2.2  thorpej 	pmap_map((int)(qvmem[0]), (int)phys_adr, (int)(phys_adr + (CHUNK*NQD)),
    481  1.15.2.2  thorpej 				    VM_PROT_READ|VM_PROT_WRITE);
    482  1.15.2.2  thorpej 
    483  1.15.2.2  thorpej 	/*
    484  1.15.2.2  thorpej 	 * Set QVmap to point to page table entries for what we just
    485  1.15.2.2  thorpej 	 * mapped.
    486  1.15.2.2  thorpej 	 */
    487  1.15.2.2  thorpej 	QVmap[0] = (struct pte *)kvtopte(qvmem[0]);
    488  1.15.2.2  thorpej 
    489  1.15.2.2  thorpej 	/*
    490  1.15.2.2  thorpej 	 * tell QDSS which Q memory address base to decode
    491  1.15.2.2  thorpej 	 * (shifted right 16 bits - its in 64K units)
    492  1.15.2.2  thorpej 	 */
    493  1.15.2.2  thorpej 	*qdaddr = (u_short)((int)mapix >> 16);
    494  1.15.2.2  thorpej 	qdflags[unit].config = *(u_short *)qdaddr;
    495  1.15.2.2  thorpej 
    496  1.15.2.2  thorpej 	/*
    497  1.15.2.2  thorpej 	 * load qdmap struct with the virtual addresses of the QDSS elements
    498  1.15.2.2  thorpej 	 */
    499  1.15.2.2  thorpej 	qdbase[unit] = (caddr_t) (qvmem[0]);
    500  1.15.2.2  thorpej 	qdmap[unit].template = qdbase[unit] + TMPSTART;
    501  1.15.2.2  thorpej 	qdmap[unit].adder = qdbase[unit] + ADDER;
    502  1.15.2.2  thorpej 	qdmap[unit].dga = qdbase[unit] + DGA;
    503  1.15.2.2  thorpej 	qdmap[unit].duart = qdbase[unit] + DUART;
    504  1.15.2.2  thorpej 	qdmap[unit].memcsr = qdbase[unit] + MEMCSR;
    505  1.15.2.2  thorpej 	qdmap[unit].red = qdbase[unit] + RED;
    506  1.15.2.2  thorpej 	qdmap[unit].blue = qdbase[unit] + BLUE;
    507  1.15.2.2  thorpej 	qdmap[unit].green = qdbase[unit] + GREEN;
    508  1.15.2.2  thorpej 
    509  1.15.2.2  thorpej 	qdflags[unit].duart_imask = 0;	/* init shadow variables */
    510  1.15.2.2  thorpej 
    511  1.15.2.2  thorpej 	/*
    512  1.15.2.2  thorpej 	 * init the QDSS
    513  1.15.2.2  thorpej 	 */
    514  1.15.2.2  thorpej 
    515  1.15.2.2  thorpej 	*(short *)qdmap[unit].memcsr |= SYNC_ON; /* once only: turn on sync */
    516  1.15.2.2  thorpej 
    517  1.15.2.2  thorpej 	cursor[unit].x = 0;
    518  1.15.2.2  thorpej 	cursor[unit].y = 0;
    519  1.15.2.2  thorpej 	init_shared(unit);		/* init shared memory */
    520  1.15.2.2  thorpej 	setup_dragon(unit);		/* init the ADDER/VIPER stuff */
    521  1.15.2.2  thorpej 	clear_qd_screen(unit);		/* clear the screen */
    522  1.15.2.2  thorpej 	ldfont(unit);			/* load the console font */
    523  1.15.2.2  thorpej 	ldcursor(unit, cons_cursor);	/* load default cursor map */
    524  1.15.2.2  thorpej 	setup_input(unit);		/* init the DUART */
    525  1.15.2.2  thorpej 
    526  1.15.2.2  thorpej 	/* Set flag so probe knows */
    527  1.15.2.2  thorpej 	qd0cninited = 1;
    528  1.15.2.2  thorpej } /* qdcninit */
    529  1.15.2.2  thorpej 
    530  1.15.2.2  thorpej /* see <sys/device.h> */
    531  1.15.2.2  thorpej struct cfattach qd_ca = {
    532  1.15.2.2  thorpej 	sizeof(struct qd_softc), qd_match, qd_attach
    533  1.15.2.2  thorpej };
    534  1.15.2.2  thorpej 
    535  1.15.2.2  thorpej #define	QD_RCSR(reg) \
    536  1.15.2.2  thorpej 	bus_space_read_2(sc->sc_iot, sc->sc_ioh, reg)
    537  1.15.2.2  thorpej #define	QD_WCSR(reg, val) \
    538  1.15.2.2  thorpej 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, reg, val)
    539  1.15.2.2  thorpej 
    540  1.15.2.2  thorpej /*
    541  1.15.2.2  thorpej  *  Configure QDSS into Q memory and make it intrpt.
    542  1.15.2.2  thorpej  *
    543  1.15.2.2  thorpej  *  side effects: QDSS gets mapped into Qbus memory space at the first
    544  1.15.2.2  thorpej  *		 vacant 64kb boundary counting back from the top of
    545  1.15.2.2  thorpej  *		 Qbus memory space (qvmem+4mb)
    546  1.15.2.2  thorpej  *
    547  1.15.2.2  thorpej  *  return: QDSS bus request level and vector address returned in
    548  1.15.2.2  thorpej  *	   registers by UNIX convention.
    549  1.15.2.2  thorpej  *
    550  1.15.2.2  thorpej  */
    551  1.15.2.2  thorpej static int
    552  1.15.2.2  thorpej qd_match(parent, match, aux)
    553  1.15.2.2  thorpej 	struct device *parent;
    554  1.15.2.2  thorpej 	struct cfdata *match;
    555  1.15.2.2  thorpej 	void *aux;
    556  1.15.2.2  thorpej {
    557  1.15.2.2  thorpej 	struct qd_softc ssc;
    558  1.15.2.2  thorpej 	struct qd_softc *sc = &ssc;
    559  1.15.2.2  thorpej 	struct uba_attach_args *ua = aux;
    560  1.15.2.2  thorpej 	struct uba_softc *uh = (void *)parent;
    561  1.15.2.2  thorpej 	register int unit;
    562  1.15.2.2  thorpej 	volatile struct dga *dga;       /* pointer to gate array structure */
    563  1.15.2.2  thorpej 	int vector;
    564  1.15.2.2  thorpej #ifdef notdef
    565  1.15.2.2  thorpej 	int *ptep;			/* page table entry pointer */
    566  1.15.2.2  thorpej 	caddr_t phys_adr;		/* physical QDSS base adrs */
    567  1.15.2.2  thorpej 	u_int mapix;
    568  1.15.2.2  thorpej #endif
    569  1.15.2.2  thorpej 
    570  1.15.2.2  thorpej 	/* Create a "fake" softc with only a few fields used. */
    571  1.15.2.2  thorpej 	sc->sc_iot = ua->ua_iot;
    572  1.15.2.2  thorpej 	sc->sc_ioh = ua->ua_ioh;
    573  1.15.2.2  thorpej 	sc->sc_dmat = ua->ua_dmat;
    574  1.15.2.2  thorpej 	/*
    575  1.15.2.2  thorpej 	 * calculate board unit number from I/O page register address
    576  1.15.2.2  thorpej 	 */
    577  1.15.2.2  thorpej 	unit = (int) (((int)sc->sc_ioh >> 1) & 0x0007);
    578  1.15.2.2  thorpej 
    579  1.15.2.2  thorpej 	/*
    580  1.15.2.2  thorpej 	 * QDSS regs must be mapped to Qbus memory space at a 64kb
    581  1.15.2.2  thorpej 	 * physical boundary.  The Qbus memory space is mapped into
    582  1.15.2.2  thorpej 	 * the system memory space at config time.  After config
    583  1.15.2.2  thorpej 	 * runs, "qvmem[0]" (ubavar.h) holds the system virtual adrs
    584  1.15.2.2  thorpej 	 * of the start of Qbus memory.   The Qbus memory page table
    585  1.15.2.2  thorpej 	 * is found via an array of pte ptrs called "QVmap[]" (ubavar.h)
    586  1.15.2.2  thorpej 	 * which is also loaded at config time.   These are the
    587  1.15.2.2  thorpej 	 * variables used below to find a vacant 64kb boundary in
    588  1.15.2.2  thorpej 	 * Qbus memory, and load it's corresponding physical adrs
    589  1.15.2.2  thorpej 	 * into the QDSS's I/O page CSR.
    590  1.15.2.2  thorpej 	 */
    591  1.15.2.2  thorpej 
    592  1.15.2.2  thorpej 	/*
    593  1.15.2.2  thorpej 	 * Only if QD is the graphics device.
    594  1.15.2.2  thorpej 	 */
    595  1.15.2.2  thorpej 
    596  1.15.2.2  thorpej 	/* if this QDSS is NOT the console, then do init here.. */
    597  1.15.2.2  thorpej 
    598  1.15.2.2  thorpej 	if (unit != 0) {
    599  1.15.2.2  thorpej 		printf("qd: can't support two qdss's (yet)\n");
    600  1.15.2.2  thorpej #ifdef notdef	/* can't test */
    601  1.15.2.2  thorpej 		if (v_consputc != qdputc  ||  unit != 0) {
    602  1.15.2.2  thorpej 
    603  1.15.2.2  thorpej 			/*
    604  1.15.2.2  thorpej 			* read QDSS config info
    605  1.15.2.2  thorpej 			*/
    606  1.15.2.2  thorpej 			qdflags[unit].config = *(u_short *)reg;
    607  1.15.2.2  thorpej 
    608  1.15.2.2  thorpej 			/*
    609  1.15.2.2  thorpej 			* find an empty 64kb adrs boundary
    610  1.15.2.2  thorpej 			*/
    611  1.15.2.2  thorpej 
    612  1.15.2.2  thorpej 			qdbase[unit] = (caddr_t) (qvmem[0] + QMEMSIZE - CHUNK);
    613  1.15.2.2  thorpej 
    614  1.15.2.2  thorpej 			/*
    615  1.15.2.2  thorpej 			* find the cpusw entry that matches this machine.
    616  1.15.2.2  thorpej 			*/
    617  1.15.2.2  thorpej 			cpup = &cpusw[cpu];
    618  1.15.2.2  thorpej 			while (!(BADADDR(qdbase[unit], sizeof(short))))
    619  1.15.2.2  thorpej 				qdbase[unit] -= CHUNK;
    620  1.15.2.2  thorpej 
    621  1.15.2.2  thorpej 			/*
    622  1.15.2.2  thorpej 			* tell QDSS which Q memory address base to decode
    623  1.15.2.2  thorpej 			*/
    624  1.15.2.2  thorpej 			mapix = (int) (VTOP(qdbase[unit]) - VTOP(qvmem[0]));
    625  1.15.2.2  thorpej 			ptep = (int *) QVmap[0] + mapix;
    626  1.15.2.2  thorpej 			phys_adr = (caddr_t)(((int)*ptep&0x001FFFFF)<<VAX_PGSHIFT);
    627  1.15.2.2  thorpej 			*(u_short *)reg = (u_short) ((int)phys_adr >> 16);
    628  1.15.2.2  thorpej 
    629  1.15.2.2  thorpej 			/*
    630  1.15.2.2  thorpej 			* load QDSS adrs map with system addresses
    631  1.15.2.2  thorpej 			* of device regs
    632  1.15.2.2  thorpej 			*/
    633  1.15.2.2  thorpej 			qdmap[unit].template = qdbase[unit] + TMPSTART;
    634  1.15.2.2  thorpej 			qdmap[unit].adder = qdbase[unit] + ADDER;
    635  1.15.2.2  thorpej 			qdmap[unit].dga = qdbase[unit] + DGA;
    636  1.15.2.2  thorpej 			qdmap[unit].duart = qdbase[unit] + DUART;
    637  1.15.2.2  thorpej 			qdmap[unit].memcsr = qdbase[unit] + MEMCSR;
    638  1.15.2.2  thorpej 			qdmap[unit].red = qdbase[unit] + RED;
    639  1.15.2.2  thorpej 			qdmap[unit].blue = qdbase[unit] + BLUE;
    640  1.15.2.2  thorpej 			qdmap[unit].green = qdbase[unit] + GREEN;
    641  1.15.2.2  thorpej 
    642  1.15.2.2  thorpej 			/* device init */
    643  1.15.2.2  thorpej 
    644  1.15.2.2  thorpej 			cursor[unit].x = 0;
    645  1.15.2.2  thorpej 			cursor[unit].y = 0;
    646  1.15.2.2  thorpej 			init_shared(unit);		/* init shared memory */
    647  1.15.2.2  thorpej 			setup_dragon(unit); 	/* init the ADDER/VIPER stuff */
    648  1.15.2.2  thorpej 			ldcursor(unit, cons_cursor);	/* load default cursor map */
    649  1.15.2.2  thorpej 			setup_input(unit);		/* init the DUART */
    650  1.15.2.2  thorpej 			clear_qd_screen(unit);
    651  1.15.2.2  thorpej 			ldfont(unit);			/* load the console font */
    652  1.15.2.2  thorpej 
    653  1.15.2.2  thorpej 			/* once only: turn on sync */
    654  1.15.2.2  thorpej 
    655  1.15.2.2  thorpej 			*(short *)qdmap[unit].memcsr |= SYNC_ON;
    656  1.15.2.2  thorpej 		}
    657  1.15.2.2  thorpej #endif /*notdef*/
    658  1.15.2.2  thorpej 	} else {
    659  1.15.2.2  thorpej 		/* We are dealing with qd0 */
    660  1.15.2.2  thorpej 
    661  1.15.2.2  thorpej 		if (!qd0cninited) {
    662  1.15.2.2  thorpej 			/*
    663  1.15.2.2  thorpej 			 * qd0 has not been initiallized as the console.
    664  1.15.2.2  thorpej 			 * We need to do some initialization now
    665  1.15.2.2  thorpej 			 *
    666  1.15.2.2  thorpej 			 * XXX
    667  1.15.2.2  thorpej 			 * However, if the QDSS is not the console then
    668  1.15.2.2  thorpej 			 * that stupid undocumented bit (see qdcnprobe)
    669  1.15.2.2  thorpej 			 * is cleared.  Then the QDSS refuses to work.
    670  1.15.2.2  thorpej 			 * (What did the ROM do to it!?)
    671  1.15.2.2  thorpej 			 * XXX
    672  1.15.2.2  thorpej 			 */
    673  1.15.2.2  thorpej 			 return 0;
    674  1.15.2.2  thorpej 
    675  1.15.2.2  thorpej #if 0
    676  1.15.2.2  thorpej 			 qdaddr = (void *)reg;
    677  1.15.2.2  thorpej 
    678  1.15.2.2  thorpej 			 /* Lame probe for QDSS.  Should be ok for qd0 */
    679  1.15.2.2  thorpej 			 if (badaddr((caddr_t)qdaddr, sizeof(short)))
    680  1.15.2.2  thorpej 				 return 0;
    681  1.15.2.2  thorpej 
    682  1.15.2.2  thorpej 			 qdcninit(NULL);
    683  1.15.2.2  thorpej #endif
    684  1.15.2.2  thorpej 		}
    685  1.15.2.2  thorpej 	}
    686  1.15.2.2  thorpej 
    687  1.15.2.2  thorpej 
    688  1.15.2.2  thorpej 	/*
    689  1.15.2.2  thorpej 	* The QDSS interrupts at HEX vectors xx0 (DMA) xx4
    690  1.15.2.2  thorpej 	* (ADDER) and xx8 (DUART).  Therefore, we take three
    691  1.15.2.2  thorpej 	* vectors from the vector pool, and then continue
    692  1.15.2.2  thorpej 	* to take them until we get a xx0 HEX vector.  The
    693  1.15.2.2  thorpej 	* pool provides vectors in contiguous decending
    694  1.15.2.2  thorpej 	* order.
    695  1.15.2.2  thorpej 	*/
    696  1.15.2.2  thorpej 
    697  1.15.2.2  thorpej 	vector = (uh->uh_lastiv -= 4*3);	/* take three vectors */
    698  1.15.2.2  thorpej 
    699  1.15.2.2  thorpej 	while (vector & 0x0F) {		   /* if lo nibble != 0.. */
    700  1.15.2.2  thorpej 		/* ..take another vector */
    701  1.15.2.2  thorpej 		vector = (uh->uh_lastiv -= 4);
    702  1.15.2.2  thorpej 	}
    703  1.15.2.2  thorpej 
    704  1.15.2.2  thorpej 	/*
    705  1.15.2.2  thorpej 	* setup DGA to do a DMA interrupt (transfer count = 0)
    706  1.15.2.2  thorpej 	*/
    707  1.15.2.2  thorpej 	dga = (struct dga *) qdmap[unit].dga;
    708  1.15.2.2  thorpej 	dga->csr = (short) HALT;	/* disable everything */
    709  1.15.2.2  thorpej 	dga->ivr = (short) vector;	/* load intrpt base vector */
    710  1.15.2.2  thorpej 	dga->bytcnt_lo = (short) 0;	/* DMA xfer count = 0 */
    711  1.15.2.2  thorpej 	dga->bytcnt_hi = (short) 0;
    712  1.15.2.2  thorpej 
    713  1.15.2.2  thorpej 	/*
    714  1.15.2.2  thorpej 	* turn on DMA interrupts
    715  1.15.2.2  thorpej 	*/
    716  1.15.2.2  thorpej 	dga->csr &= ~SET_DONE_FIFO;
    717  1.15.2.2  thorpej 	dga->csr |= DMA_IE | DL_ENB;
    718  1.15.2.2  thorpej 
    719  1.15.2.2  thorpej 	DELAY(20000);			/* wait for the intrpt */
    720  1.15.2.2  thorpej 	dga->csr = HALT;		/* stop the wheels */
    721  1.15.2.2  thorpej 
    722  1.15.2.2  thorpej 	/* Set interrupt vector for DMA service routine */
    723  1.15.2.2  thorpej 	ua->ua_ivec = qddint;
    724  1.15.2.2  thorpej 
    725  1.15.2.2  thorpej 	/*
    726  1.15.2.2  thorpej 	* score this as an existing qdss
    727  1.15.2.2  thorpej 	*/
    728  1.15.2.2  thorpej 	qdcount++;
    729  1.15.2.2  thorpej 
    730  1.15.2.2  thorpej 	return 1;
    731  1.15.2.2  thorpej } /* qdprobe */
    732  1.15.2.2  thorpej 
    733  1.15.2.2  thorpej 
    734  1.15.2.2  thorpej void qd_attach(parent, self, aux)
    735  1.15.2.2  thorpej 	   struct device *parent, *self;
    736  1.15.2.2  thorpej 	   void *aux;
    737  1.15.2.2  thorpej      {
    738  1.15.2.2  thorpej 	register struct uba_attach_args *ua = aux;
    739  1.15.2.2  thorpej 
    740  1.15.2.2  thorpej 	register int unit;	/* QDSS module # for this call */
    741  1.15.2.2  thorpej 
    742  1.15.2.2  thorpej 	printf("\n");
    743  1.15.2.2  thorpej 
    744  1.15.2.2  thorpej 	unit = self->dv_unit;		/* get QDSS number */
    745  1.15.2.2  thorpej 
    746  1.15.2.2  thorpej 	/* Grab the other two interrupt vectors */
    747  1.15.2.2  thorpej 	scb_vecalloc(ua->ua_cvec + 4, qdaint, self->dv_unit, SCB_ISTACK);
    748  1.15.2.2  thorpej 	scb_vecalloc(ua->ua_cvec + 8, qdiint, self->dv_unit, SCB_ISTACK);
    749  1.15.2.2  thorpej 
    750  1.15.2.2  thorpej 	/*
    751  1.15.2.2  thorpej 	* init "qdflags[]" for this QDSS
    752  1.15.2.2  thorpej 	*/
    753  1.15.2.2  thorpej 	qdflags[unit].inuse = 0;	/* init inuse variable EARLY! */
    754  1.15.2.2  thorpej 	qdflags[unit].mapped = 0;
    755  1.15.2.2  thorpej 	qdflags[unit].kernel_loop = -1;
    756  1.15.2.2  thorpej 	qdflags[unit].user_dma = 0;
    757  1.15.2.2  thorpej 	qdflags[unit].curs_acc = ACC_OFF;
    758  1.15.2.2  thorpej 	qdflags[unit].curs_thr = 128;
    759  1.15.2.2  thorpej 	qdflags[unit].tab_res = 2;	/* default tablet resolution factor */
    760  1.15.2.2  thorpej 	qdflags[unit].duart_imask = 0;	/* init shadow variables */
    761  1.15.2.2  thorpej 	qdflags[unit].adder_ie = 0;
    762  1.15.2.2  thorpej 
    763  1.15.2.2  thorpej 	/*
    764  1.15.2.2  thorpej 	* init structures used in kbd/mouse interrupt service.	This code must
    765  1.15.2.2  thorpej 	* come after the "init_shared()" routine has run since that routine
    766  1.15.2.2  thorpej 	* inits the eq_header[unit] structure used here.
    767  1.15.2.2  thorpej 	*/
    768  1.15.2.2  thorpej 
    769  1.15.2.2  thorpej 	/*
    770  1.15.2.2  thorpej 	* init the "latest mouse report" structure
    771  1.15.2.2  thorpej 	*/
    772  1.15.2.2  thorpej 	last_rep[unit].state = 0;
    773  1.15.2.2  thorpej 	last_rep[unit].dx = 0;
    774  1.15.2.2  thorpej 	last_rep[unit].dy = 0;
    775  1.15.2.2  thorpej 	last_rep[unit].bytcnt = 0;
    776  1.15.2.2  thorpej 
    777  1.15.2.2  thorpej 	/*
    778  1.15.2.2  thorpej 	* init the event queue (except mouse position)
    779  1.15.2.2  thorpej 	*/
    780  1.15.2.2  thorpej 	eq_header[unit]->header.events =
    781  1.15.2.2  thorpej 	    (struct _vs_event *)((int)eq_header[unit] + sizeof(struct qdinput));
    782  1.15.2.2  thorpej 
    783  1.15.2.2  thorpej 	eq_header[unit]->header.size = MAXEVENTS;
    784  1.15.2.2  thorpej 	eq_header[unit]->header.head = 0;
    785  1.15.2.2  thorpej 	eq_header[unit]->header.tail = 0;
    786  1.15.2.2  thorpej 
    787  1.15.2.2  thorpej 	/*
    788  1.15.2.2  thorpej 	 * open exclusive for graphics device.
    789  1.15.2.2  thorpej 	 */
    790  1.15.2.2  thorpej 	qdopened[unit] = 0;
    791  1.15.2.2  thorpej 
    792  1.15.2.2  thorpej } /* qdattach */
    793  1.15.2.2  thorpej 
    794  1.15.2.2  thorpej 
    795  1.15.2.2  thorpej /*ARGSUSED*/
    796  1.15.2.2  thorpej int
    797  1.15.2.2  thorpej qdopen(dev, flag, mode, p)
    798  1.15.2.2  thorpej 	dev_t dev;
    799  1.15.2.2  thorpej 	int flag, mode;
    800  1.15.2.2  thorpej 	struct proc *p;
    801  1.15.2.2  thorpej {
    802  1.15.2.2  thorpej 	volatile register struct dga *dga;	/* ptr to gate array struct */
    803  1.15.2.2  thorpej 	register struct tty *tp;
    804  1.15.2.2  thorpej 	volatile struct duart *duart;
    805  1.15.2.2  thorpej 	int unit;
    806  1.15.2.2  thorpej 	int minor_dev;
    807  1.15.2.2  thorpej 
    808  1.15.2.2  thorpej 	minor_dev = minor(dev); /* get QDSS minor device number */
    809  1.15.2.2  thorpej 	unit = minor_dev >> 2;
    810  1.15.2.2  thorpej 
    811  1.15.2.2  thorpej 	/*
    812  1.15.2.2  thorpej 	* check for illegal conditions
    813  1.15.2.2  thorpej 	*/
    814  1.15.2.2  thorpej 	if (unit >= qd_cd.cd_ndevs || qd_cd.cd_devs[unit] == NULL)
    815  1.15.2.2  thorpej 		return (ENXIO);		/* no such device or address */
    816  1.15.2.2  thorpej 
    817  1.15.2.2  thorpej 	duart = (struct duart *) qdmap[unit].duart;
    818  1.15.2.2  thorpej 	dga = (struct dga *) qdmap[unit].dga;
    819  1.15.2.2  thorpej 
    820  1.15.2.2  thorpej 	if ((minor_dev & 0x03) == 2) {
    821  1.15.2.2  thorpej 		/*
    822  1.15.2.2  thorpej 		* this is the graphic device...
    823  1.15.2.2  thorpej 		*/
    824  1.15.2.2  thorpej 		if (qdopened[unit] != 0)
    825  1.15.2.2  thorpej 			return(EBUSY);
    826  1.15.2.2  thorpej 		else
    827  1.15.2.2  thorpej 			qdopened[unit] = 1;
    828  1.15.2.2  thorpej 		qdflags[unit].inuse |= GRAPHIC_DEV;  /* graphics dev is open */
    829  1.15.2.2  thorpej 		/*
    830  1.15.2.2  thorpej 		 * enble kbd & mouse intrpts in DUART mask reg
    831  1.15.2.2  thorpej 		 */
    832  1.15.2.2  thorpej 		qdflags[unit].duart_imask |= 0x22;
    833  1.15.2.2  thorpej 		duart->imask = qdflags[unit].duart_imask;
    834  1.15.2.2  thorpej 	} else {
    835  1.15.2.2  thorpej 	       /* Only one console */
    836  1.15.2.2  thorpej 	       if (minor_dev) return ENXIO;
    837  1.15.2.2  thorpej 
    838  1.15.2.2  thorpej 	       /* If not done already, allocate tty structure */
    839  1.15.2.2  thorpej 	       if (qd_tty[minor_dev] == NULL)
    840  1.15.2.2  thorpej 		       qd_tty[minor_dev] = ttymalloc();
    841  1.15.2.2  thorpej 
    842  1.15.2.2  thorpej 	       if (qd_tty[minor_dev] == NULL)
    843  1.15.2.2  thorpej 		       return ENXIO;
    844  1.15.2.2  thorpej 
    845  1.15.2.2  thorpej 	       /*
    846  1.15.2.2  thorpej 		* this is the console
    847  1.15.2.2  thorpej 		*/
    848  1.15.2.2  thorpej 		qdflags[unit].inuse |= CONS_DEV;  /* mark console as open */
    849  1.15.2.2  thorpej 		dga->csr |= CURS_ENB;
    850  1.15.2.2  thorpej 		qdflags[unit].duart_imask |= 0x02;
    851  1.15.2.2  thorpej 		duart->imask = qdflags[unit].duart_imask;
    852  1.15.2.2  thorpej 		/*
    853  1.15.2.2  thorpej 		* some setup for tty handling
    854  1.15.2.2  thorpej 		*/
    855  1.15.2.2  thorpej 		tp = qd_tty[minor_dev];
    856  1.15.2.2  thorpej 		/* tp->t_addr = ui->ui_addr; */
    857  1.15.2.2  thorpej 		tp->t_oproc = qdstart;
    858  1.15.2.2  thorpej 		tp->t_dev = dev;
    859  1.15.2.2  thorpej 		if ((tp->t_state & TS_ISOPEN) == 0) {
    860  1.15.2.2  thorpej 			ttychars(tp);
    861  1.15.2.2  thorpej 			tp->t_ispeed = B9600;
    862  1.15.2.2  thorpej 			tp->t_ospeed = B9600;
    863  1.15.2.2  thorpej 			tp->t_state = TS_ISOPEN | TS_CARR_ON;
    864  1.15.2.2  thorpej 			tp->t_iflag = TTYDEF_IFLAG;
    865  1.15.2.2  thorpej 			tp->t_oflag = TTYDEF_OFLAG;
    866  1.15.2.2  thorpej 			tp->t_lflag = TTYDEF_LFLAG;
    867  1.15.2.2  thorpej 			tp->t_cflag = TTYDEF_CFLAG;
    868  1.15.2.2  thorpej 			ttsetwater(tp);
    869  1.15.2.2  thorpej 		}
    870  1.15.2.2  thorpej 		/*
    871  1.15.2.2  thorpej 		* enable intrpts, open line discipline
    872  1.15.2.2  thorpej 		*/
    873  1.15.2.2  thorpej 		dga->csr |= GLOBAL_IE;	/* turn on the interrupts */
    874  1.15.2.2  thorpej 		return ((*linesw[tp->t_line].l_open)(dev, tp));
    875  1.15.2.2  thorpej 	}
    876  1.15.2.2  thorpej 	dga->csr |= GLOBAL_IE;	/* turn on the interrupts */
    877  1.15.2.2  thorpej 	return(0);
    878  1.15.2.2  thorpej 
    879  1.15.2.2  thorpej } /* qdopen */
    880  1.15.2.2  thorpej 
    881  1.15.2.2  thorpej /*ARGSUSED*/
    882  1.15.2.2  thorpej int
    883  1.15.2.2  thorpej qdclose(dev, flag, mode, p)
    884  1.15.2.2  thorpej 	dev_t dev;
    885  1.15.2.2  thorpej 	int flag, mode;
    886  1.15.2.2  thorpej 	struct proc *p;
    887  1.15.2.2  thorpej {
    888  1.15.2.2  thorpej 	register struct tty *tp;
    889  1.15.2.2  thorpej 	register struct qdmap *qd;
    890  1.15.2.2  thorpej 	volatile register int *ptep;
    891  1.15.2.2  thorpej 	volatile struct dga *dga;      	/* gate array register map pointer */
    892  1.15.2.2  thorpej 	volatile struct duart *duart;
    893  1.15.2.2  thorpej 	volatile struct adder *adder;
    894  1.15.2.2  thorpej 	int unit;
    895  1.15.2.2  thorpej 	int minor_dev;
    896  1.15.2.2  thorpej 	u_int mapix;
    897  1.15.2.2  thorpej 	int i;				/* SIGNED index */
    898  1.15.2.2  thorpej 	struct uba_softc *uh;
    899  1.15.2.2  thorpej 
    900  1.15.2.2  thorpej 	minor_dev = minor(dev); 	/* get minor device number */
    901  1.15.2.2  thorpej 	unit = minor_dev >> 2;		/* get QDSS number */
    902  1.15.2.2  thorpej 	qd = &qdmap[unit];
    903  1.15.2.2  thorpej 
    904  1.15.2.2  thorpej 	uh = (struct uba_softc *)
    905  1.15.2.2  thorpej 	     (((struct device *)(qd_cd.cd_devs[unit]))->dv_parent);
    906  1.15.2.2  thorpej 
    907  1.15.2.2  thorpej 
    908  1.15.2.2  thorpej 	if ((minor_dev & 0x03) == 2) {
    909  1.15.2.2  thorpej 		/*
    910  1.15.2.2  thorpej 		* this is the graphic device...
    911  1.15.2.2  thorpej 		*/
    912  1.15.2.2  thorpej 		if (qdopened[unit] != 1)
    913  1.15.2.2  thorpej 			return(EBUSY);
    914  1.15.2.2  thorpej 		else
    915  1.15.2.2  thorpej 			qdopened[unit] = 0;	/* allow it to be re-opened */
    916  1.15.2.2  thorpej 		/*
    917  1.15.2.2  thorpej 		* re-protect device memory
    918  1.15.2.2  thorpej 		*/
    919  1.15.2.2  thorpej 		if (qdflags[unit].mapped & MAPDEV) {
    920  1.15.2.2  thorpej 			/*
    921  1.15.2.2  thorpej 			* TEMPLATE RAM
    922  1.15.2.2  thorpej 			*/
    923  1.15.2.2  thorpej 			mapix = VTOP((int)qd->template) - VTOP(qvmem[0]);
    924  1.15.2.2  thorpej 			ptep = (int *)(QVmap[0] + mapix);
    925  1.15.2.2  thorpej 			for (i = 0; i < vax_btop(TMPSIZE); i++, ptep++)
    926  1.15.2.2  thorpej 				*ptep = (*ptep & ~PG_PROT) | PG_V | PG_KW;
    927  1.15.2.2  thorpej 			/*
    928  1.15.2.2  thorpej 			* ADDER
    929  1.15.2.2  thorpej 			*/
    930  1.15.2.2  thorpej 			mapix = VTOP((int)qd->adder) - VTOP(qvmem[0]);
    931  1.15.2.2  thorpej 			ptep = (int *)(QVmap[0] + mapix);
    932  1.15.2.2  thorpej 			for (i = 0; i < vax_btop(REGSIZE); i++, ptep++)
    933  1.15.2.2  thorpej 				*ptep = (*ptep & ~PG_PROT) | PG_V | PG_KW;
    934  1.15.2.2  thorpej 			/*
    935  1.15.2.2  thorpej 			* COLOR MAPS
    936  1.15.2.2  thorpej 			*/
    937  1.15.2.2  thorpej 			mapix = VTOP((int)qd->red) - VTOP(qvmem[0]);
    938  1.15.2.2  thorpej 			ptep = (int *)(QVmap[0] + mapix);
    939  1.15.2.2  thorpej 			for (i = 0; i < vax_btop(CLRSIZE); i++, ptep++)
    940  1.15.2.2  thorpej 				*ptep = (*ptep & ~PG_PROT) | PG_V | PG_KW;
    941  1.15.2.2  thorpej 		}
    942  1.15.2.2  thorpej 
    943  1.15.2.2  thorpej 		/*
    944  1.15.2.2  thorpej 		* re-protect DMA buffer and free the map registers
    945  1.15.2.2  thorpej 		*/
    946  1.15.2.2  thorpej 		if (qdflags[unit].mapped & MAPDMA) {
    947  1.15.2.2  thorpej 			panic("Unmapping unmapped buffer");
    948  1.15.2.2  thorpej #ifdef notyet
    949  1.15.2.2  thorpej /*
    950  1.15.2.2  thorpej  * Ragge 990620:
    951  1.15.2.2  thorpej  * Can't happen because the buffer can't be mapped.
    952  1.15.2.2  thorpej  */
    953  1.15.2.2  thorpej 			dga = (struct dga *) qdmap[unit].dga;
    954  1.15.2.2  thorpej 			adder = (struct adder *) qdmap[unit].adder;
    955  1.15.2.2  thorpej 			dga->csr &= ~DMA_IE;
    956  1.15.2.2  thorpej 			dga->csr &= ~0x0600;	     /* kill DMA */
    957  1.15.2.2  thorpej 			adder->command = CANCEL;
    958  1.15.2.2  thorpej 			/*
    959  1.15.2.2  thorpej 			 * if DMA was running, flush spurious intrpt
    960  1.15.2.2  thorpej 			 */
    961  1.15.2.2  thorpej 			if (dga->bytcnt_lo != 0) {
    962  1.15.2.2  thorpej 				dga->bytcnt_lo = 0;
    963  1.15.2.2  thorpej 				dga->bytcnt_hi = 0;
    964  1.15.2.2  thorpej 				DMA_SETIGNORE(DMAheader[unit]);
    965  1.15.2.2  thorpej 				dga->csr |= DMA_IE;
    966  1.15.2.2  thorpej 				dga->csr &= ~DMA_IE;
    967  1.15.2.2  thorpej 			}
    968  1.15.2.2  thorpej 			ptep = (int *)
    969  1.15.2.2  thorpej 			   ((VTOP(DMAheader[unit]*4)) + (mfpr(PR_SBR)|0x80000000));
    970  1.15.2.2  thorpej 			for (i = 0; i < vax_btop(DMAbuf_size); i++, ptep++)
    971  1.15.2.2  thorpej 				*ptep = (*ptep & ~PG_PROT) | PG_V | PG_KW;
    972  1.15.2.2  thorpej 			ubarelse(uh, &Qbus_unmap[unit]);
    973  1.15.2.2  thorpej #endif
    974  1.15.2.2  thorpej 		}
    975  1.15.2.2  thorpej 
    976  1.15.2.2  thorpej 		/*
    977  1.15.2.2  thorpej 		* re-protect 1K (2 pages) event queue
    978  1.15.2.2  thorpej 		*/
    979  1.15.2.2  thorpej 		if (qdflags[unit].mapped & MAPEQ) {
    980  1.15.2.2  thorpej 			ptep = (int *)
    981  1.15.2.2  thorpej 			   ((VTOP(eq_header[unit])*4) + (mfpr(PR_SBR)|0x80000000));
    982  1.15.2.2  thorpej 			*ptep = (*ptep & ~PG_PROT) | PG_KW | PG_V; ptep++;
    983  1.15.2.2  thorpej 			*ptep = (*ptep & ~PG_PROT) | PG_KW | PG_V;
    984  1.15.2.2  thorpej 		}
    985  1.15.2.2  thorpej 		/*
    986  1.15.2.2  thorpej 		* re-protect scroll param area and disable scroll intrpts
    987  1.15.2.2  thorpej 		*/
    988  1.15.2.2  thorpej 		if (qdflags[unit].mapped & MAPSCR) {
    989  1.15.2.2  thorpej 			ptep = (int *) ((VTOP(scroll[unit]) * 4)
    990  1.15.2.2  thorpej 				+ (mfpr(PR_SBR) | 0x80000000));
    991  1.15.2.2  thorpej 			/*
    992  1.15.2.2  thorpej 			 * re-protect 512 scroll param area
    993  1.15.2.2  thorpej 			 */
    994  1.15.2.2  thorpej 			*ptep = (*ptep & ~PG_PROT) | PG_KW | PG_V;
    995  1.15.2.2  thorpej 			adder = (struct adder *) qdmap[unit].adder;
    996  1.15.2.2  thorpej 			qdflags[unit].adder_ie &= ~FRAME_SYNC;
    997  1.15.2.2  thorpej 			adder->interrupt_enable = qdflags[unit].adder_ie;
    998  1.15.2.2  thorpej 		}
    999  1.15.2.2  thorpej 		/*
   1000  1.15.2.2  thorpej 		* re-protect color map write buffer area and kill intrpts
   1001  1.15.2.2  thorpej 		*/
   1002  1.15.2.2  thorpej 		if (qdflags[unit].mapped & MAPCOLOR) {
   1003  1.15.2.2  thorpej 			ptep = (int *) ((VTOP(color_buf[unit]) * 4)
   1004  1.15.2.2  thorpej 				+ (mfpr(PR_SBR) | 0x80000000));
   1005  1.15.2.2  thorpej 			*ptep = (*ptep & ~PG_PROT) | PG_KW | PG_V; ptep++;
   1006  1.15.2.2  thorpej 			*ptep = (*ptep & ~PG_PROT) | PG_KW | PG_V;
   1007  1.15.2.2  thorpej 			color_buf[unit]->status = 0;
   1008  1.15.2.2  thorpej 			adder = (struct adder *) qdmap[unit].adder;
   1009  1.15.2.2  thorpej 			qdflags[unit].adder_ie &= ~VSYNC;
   1010  1.15.2.2  thorpej 			adder->interrupt_enable = qdflags[unit].adder_ie;
   1011  1.15.2.2  thorpej 		}
   1012  1.15.2.2  thorpej 		mtpr(0, PR_TBIA);
   1013  1.15.2.2  thorpej 		/* flag everything now unmapped */
   1014  1.15.2.2  thorpej 		qdflags[unit].mapped = 0;
   1015  1.15.2.2  thorpej 		qdflags[unit].inuse &= ~GRAPHIC_DEV;
   1016  1.15.2.2  thorpej 		qdflags[unit].curs_acc = ACC_OFF;
   1017  1.15.2.2  thorpej 		qdflags[unit].curs_thr = 128;
   1018  1.15.2.2  thorpej 		/*
   1019  1.15.2.2  thorpej 		* restore the console
   1020  1.15.2.2  thorpej 		*/
   1021  1.15.2.2  thorpej 		dga = (struct dga *) qdmap[unit].dga;
   1022  1.15.2.2  thorpej 		adder = (struct adder *) qdmap[unit].adder;
   1023  1.15.2.2  thorpej 		dga->csr &= ~DMA_IE;
   1024  1.15.2.2  thorpej 		dga->csr &= ~0x0600;	/* halt the DMA! (just in case...) */
   1025  1.15.2.2  thorpej 		dga->csr |= DMA_ERR;	/* clear error condition */
   1026  1.15.2.2  thorpej 		adder->command = CANCEL;
   1027  1.15.2.2  thorpej 		/*
   1028  1.15.2.2  thorpej 		 * if DMA was running, flush spurious intrpt
   1029  1.15.2.2  thorpej 		 */
   1030  1.15.2.2  thorpej 		if (dga->bytcnt_lo != 0) {
   1031  1.15.2.2  thorpej 			dga->bytcnt_lo = 0;
   1032  1.15.2.2  thorpej 			dga->bytcnt_hi = 0;
   1033  1.15.2.2  thorpej 			DMA_SETIGNORE(DMAheader[unit]);
   1034  1.15.2.2  thorpej 			dga->csr |= DMA_IE;
   1035  1.15.2.2  thorpej 			dga->csr &= ~DMA_IE;
   1036  1.15.2.2  thorpej 		}
   1037  1.15.2.2  thorpej 		init_shared(unit);		/* init shared memory */
   1038  1.15.2.2  thorpej 		setup_dragon(unit);		/* init ADDER/VIPER */
   1039  1.15.2.2  thorpej 		ldcursor(unit, cons_cursor);	/* load default cursor map */
   1040  1.15.2.2  thorpej 		setup_input(unit);		/* init the DUART */
   1041  1.15.2.2  thorpej 		ldfont(unit);
   1042  1.15.2.2  thorpej 		cursor[unit].x = 0;
   1043  1.15.2.2  thorpej 		cursor[unit].y = 0;
   1044  1.15.2.2  thorpej 		/*
   1045  1.15.2.2  thorpej 		 * shut off the mouse rcv intrpt and turn on kbd intrpts
   1046  1.15.2.2  thorpej 		 */
   1047  1.15.2.2  thorpej 		duart = (struct duart *) qdmap[unit].duart;
   1048  1.15.2.2  thorpej 		qdflags[unit].duart_imask &= ~(0x20);
   1049  1.15.2.2  thorpej 		qdflags[unit].duart_imask |= 0x02;
   1050  1.15.2.2  thorpej 		duart->imask = qdflags[unit].duart_imask;
   1051  1.15.2.2  thorpej 		/*
   1052  1.15.2.2  thorpej 		* shut off interrupts if all is closed
   1053  1.15.2.2  thorpej 		*/
   1054  1.15.2.2  thorpej 		if (!(qdflags[unit].inuse & CONS_DEV)) {
   1055  1.15.2.2  thorpej 			dga = (struct dga *) qdmap[unit].dga;
   1056  1.15.2.2  thorpej 			dga->csr &= ~(GLOBAL_IE | DMA_IE);
   1057  1.15.2.2  thorpej 		}
   1058  1.15.2.2  thorpej 	} else {
   1059  1.15.2.2  thorpej 		/*
   1060  1.15.2.2  thorpej 		* this is the console
   1061  1.15.2.2  thorpej 		*/
   1062  1.15.2.2  thorpej 		tp = qd_tty[minor_dev];
   1063  1.15.2.2  thorpej 		(*linesw[tp->t_line].l_close)(tp, flag);
   1064  1.15.2.2  thorpej 		ttyclose(tp);
   1065  1.15.2.2  thorpej 		tp->t_state = 0;
   1066  1.15.2.2  thorpej 		qdflags[unit].inuse &= ~CONS_DEV;
   1067  1.15.2.2  thorpej 		/*
   1068  1.15.2.2  thorpej 		* if graphics device is closed, kill interrupts
   1069  1.15.2.2  thorpej 		*/
   1070  1.15.2.2  thorpej 		if (!(qdflags[unit].inuse & GRAPHIC_DEV)) {
   1071  1.15.2.2  thorpej 			dga = (struct dga *) qdmap[unit].dga;
   1072  1.15.2.2  thorpej 			dga->csr &= ~(GLOBAL_IE | DMA_IE);
   1073  1.15.2.2  thorpej 		}
   1074  1.15.2.2  thorpej 	}
   1075  1.15.2.2  thorpej 
   1076  1.15.2.2  thorpej 	return(0);
   1077  1.15.2.2  thorpej 
   1078  1.15.2.2  thorpej } /* qdclose */
   1079  1.15.2.2  thorpej 
   1080  1.15.2.2  thorpej int
   1081  1.15.2.2  thorpej qdioctl(dev, cmd, datap, flags, p)
   1082  1.15.2.2  thorpej 	dev_t dev;
   1083  1.15.2.2  thorpej 	u_long cmd;
   1084  1.15.2.2  thorpej 	caddr_t datap;
   1085  1.15.2.2  thorpej 	int flags;
   1086  1.15.2.2  thorpej 	struct proc *p;
   1087  1.15.2.2  thorpej {
   1088  1.15.2.2  thorpej 	volatile register int *ptep;	/* page table entry pointer */
   1089  1.15.2.2  thorpej 	register int mapix;		/* QVmap[] page table index */
   1090  1.15.2.2  thorpej 	register struct _vs_event *event;
   1091  1.15.2.2  thorpej 	register struct tty *tp;
   1092  1.15.2.2  thorpej 	register int i;
   1093  1.15.2.2  thorpej 	struct qdmap *qd;		/* pointer to device map struct */
   1094  1.15.2.2  thorpej 	volatile struct dga *dga;	/* Gate Array reg structure pntr */
   1095  1.15.2.2  thorpej 	volatile struct duart *duart;	/* DUART reg structure pointer */
   1096  1.15.2.2  thorpej 	volatile struct adder *adder;	/* ADDER reg structure pointer */
   1097  1.15.2.2  thorpej 	struct prgkbd *cmdbuf;
   1098  1.15.2.2  thorpej 	struct prg_cursor *curs;
   1099  1.15.2.2  thorpej 	struct _vs_cursor *pos;
   1100  1.15.2.2  thorpej 	int unit = minor(dev) >> 2;	/* number of caller's QDSS */
   1101  1.15.2.2  thorpej 	u_int minor_dev = minor(dev);
   1102  1.15.2.2  thorpej 	int error;
   1103  1.15.2.2  thorpej 	int s;
   1104  1.15.2.2  thorpej 	short *temp;			/* a pointer to template RAM */
   1105  1.15.2.2  thorpej 	struct uba_softc *uh;
   1106  1.15.2.2  thorpej 
   1107  1.15.2.2  thorpej 	uh = (struct uba_softc *)
   1108  1.15.2.2  thorpej 	     (((struct device *)(qd_cd.cd_devs[unit]))->dv_parent);
   1109  1.15.2.2  thorpej 
   1110  1.15.2.2  thorpej 	/*
   1111  1.15.2.2  thorpej 	* service graphic device ioctl commands
   1112  1.15.2.2  thorpej 	*/
   1113  1.15.2.2  thorpej 	switch (cmd) {
   1114  1.15.2.2  thorpej 
   1115  1.15.2.2  thorpej 	case QD_GETEVENT:
   1116  1.15.2.2  thorpej 		/*
   1117  1.15.2.2  thorpej 		* extract the oldest event from the event queue
   1118  1.15.2.2  thorpej 		*/
   1119  1.15.2.2  thorpej 		if (ISEMPTY(eq_header[unit])) {
   1120  1.15.2.2  thorpej 			event = (struct _vs_event *) datap;
   1121  1.15.2.2  thorpej 			event->vse_device = VSE_NULL;
   1122  1.15.2.2  thorpej 			break;
   1123  1.15.2.2  thorpej 		}
   1124  1.15.2.2  thorpej 		event = (struct _vs_event *) GETBEGIN(eq_header[unit]);
   1125  1.15.2.2  thorpej 		s = spl5();
   1126  1.15.2.2  thorpej 		GETEND(eq_header[unit]);
   1127  1.15.2.2  thorpej 		splx(s);
   1128  1.15.2.2  thorpej 		bcopy((caddr_t)event, datap, sizeof(struct _vs_event));
   1129  1.15.2.2  thorpej 		break;
   1130  1.15.2.2  thorpej 
   1131  1.15.2.2  thorpej 	case QD_RESET:
   1132  1.15.2.2  thorpej 		/*
   1133  1.15.2.2  thorpej 		* init the dragon stuff, DUART, and driver variables
   1134  1.15.2.2  thorpej 		*/
   1135  1.15.2.2  thorpej 		init_shared(unit);		/* init shared memory */
   1136  1.15.2.2  thorpej 		setup_dragon(unit);	      /* init the ADDER/VIPER stuff */
   1137  1.15.2.2  thorpej 		clear_qd_screen(unit);
   1138  1.15.2.2  thorpej 		ldcursor(unit, cons_cursor);	/* load default cursor map */
   1139  1.15.2.2  thorpej 		ldfont(unit);			/* load the console font */
   1140  1.15.2.2  thorpej 		setup_input(unit);		/* init the DUART */
   1141  1.15.2.2  thorpej 		break;
   1142  1.15.2.2  thorpej 
   1143  1.15.2.2  thorpej 	case QD_SET:
   1144  1.15.2.2  thorpej 		/*
   1145  1.15.2.2  thorpej 		* init the DUART and driver variables
   1146  1.15.2.2  thorpej 		*/
   1147  1.15.2.2  thorpej 		init_shared(unit);
   1148  1.15.2.2  thorpej 		setup_input(unit);
   1149  1.15.2.2  thorpej 		break;
   1150  1.15.2.2  thorpej 
   1151  1.15.2.2  thorpej 	case QD_CLRSCRN:
   1152  1.15.2.2  thorpej 		/*
   1153  1.15.2.2  thorpej 		* clear the QDSS screen.  (NOTE that this reinits the dragon)
   1154  1.15.2.2  thorpej 		*/
   1155  1.15.2.2  thorpej #ifdef notdef	/* has caused problems and isn't necessary */
   1156  1.15.2.2  thorpej 		setup_dragon(unit);
   1157  1.15.2.2  thorpej 		clear_qd_screen(unit);
   1158  1.15.2.2  thorpej #endif
   1159  1.15.2.2  thorpej 		break;
   1160  1.15.2.2  thorpej 
   1161  1.15.2.2  thorpej 	case QD_WTCURSOR:
   1162  1.15.2.2  thorpej 		/*
   1163  1.15.2.2  thorpej 		* load a cursor into template RAM
   1164  1.15.2.2  thorpej 		*/
   1165  1.15.2.2  thorpej 		ldcursor(unit, (short *)datap);
   1166  1.15.2.2  thorpej 		break;
   1167  1.15.2.2  thorpej 
   1168  1.15.2.2  thorpej 	case QD_RDCURSOR:
   1169  1.15.2.2  thorpej 
   1170  1.15.2.2  thorpej 		temp = (short *) qdmap[unit].template;
   1171  1.15.2.2  thorpej 		/*
   1172  1.15.2.2  thorpej 		 * cursor is 32 WORDS from the end of the 8k WORD...
   1173  1.15.2.2  thorpej 		 *  ...template space
   1174  1.15.2.2  thorpej 		 */
   1175  1.15.2.2  thorpej 		temp += (8 * 1024) - 32;
   1176  1.15.2.2  thorpej 		for (i = 0; i < 32; ++i, datap += sizeof(short))
   1177  1.15.2.2  thorpej 			*(short *)datap = *temp++;
   1178  1.15.2.2  thorpej 		break;
   1179  1.15.2.2  thorpej 
   1180  1.15.2.2  thorpej 	case QD_POSCURSOR:
   1181  1.15.2.2  thorpej 		/*
   1182  1.15.2.2  thorpej 		* position the mouse cursor
   1183  1.15.2.2  thorpej 		*/
   1184  1.15.2.2  thorpej 		dga = (struct dga *) qdmap[unit].dga;
   1185  1.15.2.2  thorpej 		pos = (struct _vs_cursor *) datap;
   1186  1.15.2.2  thorpej 		s = spl5();
   1187  1.15.2.2  thorpej 		dga->x_cursor = TRANX(pos->x);
   1188  1.15.2.2  thorpej 		dga->y_cursor = TRANY(pos->y);
   1189  1.15.2.2  thorpej 		eq_header[unit]->curs_pos.x = pos->x;
   1190  1.15.2.2  thorpej 		eq_header[unit]->curs_pos.y = pos->y;
   1191  1.15.2.2  thorpej 		splx(s);
   1192  1.15.2.2  thorpej 		break;
   1193  1.15.2.2  thorpej 
   1194  1.15.2.2  thorpej 	case QD_PRGCURSOR:
   1195  1.15.2.2  thorpej 		/*
   1196  1.15.2.2  thorpej 		* set the cursor acceleration factor
   1197  1.15.2.2  thorpej 		*/
   1198  1.15.2.2  thorpej 		curs = (struct prg_cursor *) datap;
   1199  1.15.2.2  thorpej 		s = spl5();
   1200  1.15.2.2  thorpej 		qdflags[unit].curs_acc = curs->acc_factor;
   1201  1.15.2.2  thorpej 		qdflags[unit].curs_thr = curs->threshold;
   1202  1.15.2.2  thorpej 		splx(s);
   1203  1.15.2.2  thorpej 		break;
   1204  1.15.2.2  thorpej 
   1205  1.15.2.2  thorpej 	case QD_MAPDEVICE:
   1206  1.15.2.2  thorpej 	       /*
   1207  1.15.2.2  thorpej 		* enable 'user write' to device pages
   1208  1.15.2.2  thorpej 		*/
   1209  1.15.2.2  thorpej 		qdflags[unit].mapped |= MAPDEV;
   1210  1.15.2.2  thorpej 		qd = (struct qdmap *) &qdmap[unit];
   1211  1.15.2.2  thorpej 		/*
   1212  1.15.2.2  thorpej 		* enable user write to template RAM
   1213  1.15.2.2  thorpej 		*/
   1214  1.15.2.2  thorpej 		mapix = VTOP((int)qd->template) - VTOP(qvmem[0]);
   1215  1.15.2.2  thorpej 		ptep = (int *)(QVmap[0] + mapix);
   1216  1.15.2.2  thorpej 		for (i = 0; i < vax_btop(TMPSIZE); i++, ptep++)
   1217  1.15.2.2  thorpej 			*ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V;
   1218  1.15.2.2  thorpej 
   1219  1.15.2.2  thorpej 	       /*
   1220  1.15.2.2  thorpej 		* enable user write to registers
   1221  1.15.2.2  thorpej 		*/
   1222  1.15.2.2  thorpej 		mapix = VTOP((int)qd->adder) - VTOP(qvmem[0]);
   1223  1.15.2.2  thorpej 		ptep = (int *)(QVmap[0] + mapix);
   1224  1.15.2.2  thorpej 		for (i = 0; i < vax_btop(REGSIZE); i++, ptep++)
   1225  1.15.2.2  thorpej 			*ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V;
   1226  1.15.2.2  thorpej 
   1227  1.15.2.2  thorpej 		/*
   1228  1.15.2.2  thorpej 		* enable user write to color maps
   1229  1.15.2.2  thorpej 		*/
   1230  1.15.2.2  thorpej 		mapix = VTOP((int)qd->red) - VTOP(qvmem[0]);
   1231  1.15.2.2  thorpej 		ptep = (int *)(QVmap[0] + mapix);
   1232  1.15.2.2  thorpej 		for (i = 0; i < vax_btop(CLRSIZE); i++, ptep++)
   1233  1.15.2.2  thorpej 			*ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V;
   1234  1.15.2.2  thorpej 
   1235  1.15.2.2  thorpej 	       /*
   1236  1.15.2.2  thorpej 		* enable user write to DUART
   1237  1.15.2.2  thorpej 		*/
   1238  1.15.2.2  thorpej 		mapix = VTOP((int)qd->duart) - VTOP(qvmem[0]);
   1239  1.15.2.2  thorpej 		ptep = (int *)(QVmap[0] + mapix);
   1240  1.15.2.2  thorpej 		*ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V; /* duart page */
   1241  1.15.2.2  thorpej 
   1242  1.15.2.2  thorpej 		mtpr(0, PR_TBIA);		/* invalidate translation buffer */
   1243  1.15.2.2  thorpej 
   1244  1.15.2.2  thorpej 		/*
   1245  1.15.2.2  thorpej 		 * stuff qdmap structure in return buffer
   1246  1.15.2.2  thorpej 		 */
   1247  1.15.2.2  thorpej 		bcopy((caddr_t)qd, datap, sizeof(struct qdmap));
   1248  1.15.2.2  thorpej 
   1249  1.15.2.2  thorpej 		break;
   1250  1.15.2.2  thorpej 
   1251  1.15.2.2  thorpej #ifdef notyet
   1252  1.15.2.2  thorpej /*
   1253  1.15.2.2  thorpej  * Ragge 999620:
   1254  1.15.2.2  thorpej  * Can't map in the graphic buffer into user space for now.
   1255  1.15.2.2  thorpej  * The best way to fix this is to convert this driver to wscons.
   1256  1.15.2.2  thorpej  */
   1257  1.15.2.2  thorpej 	case QD_MAPIOBUF:
   1258  1.15.2.2  thorpej 		/*
   1259  1.15.2.2  thorpej 		 * do setup for DMA by user process
   1260  1.15.2.2  thorpej 		 *
   1261  1.15.2.2  thorpej 		 * set 'user write enable' bits for DMA buffer
   1262  1.15.2.2  thorpej 		 */
   1263  1.15.2.2  thorpej 		qdflags[unit].mapped |= MAPDMA;
   1264  1.15.2.2  thorpej 		ptep = (int *) ((VTOP(DMAheader[unit]) * 4)
   1265  1.15.2.2  thorpej 			+ (mfpr(PR_SBR) | 0x80000000));
   1266  1.15.2.2  thorpej 		for (i = 0; i < vax_btop(DMAbuf_size); i++, ptep++)
   1267  1.15.2.2  thorpej 			*ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V;
   1268  1.15.2.2  thorpej 		mtpr(0, PR_TBIA);	/* invalidate translation buffer */
   1269  1.15.2.2  thorpej 		/*
   1270  1.15.2.2  thorpej 		* set up QBUS map registers for DMA
   1271  1.15.2.2  thorpej 		*/
   1272  1.15.2.2  thorpej 		DMAheader[unit]->QBAreg =
   1273  1.15.2.2  thorpej 		    uballoc(uh, (caddr_t)DMAheader[unit], DMAbuf_size, 0);
   1274  1.15.2.2  thorpej 		if (DMAheader[unit]->QBAreg == 0)
   1275  1.15.2.2  thorpej 		    printf("qd%d: qdioctl: QBA setup error\n", unit);
   1276  1.15.2.2  thorpej 		Qbus_unmap[unit] = DMAheader[unit]->QBAreg;
   1277  1.15.2.2  thorpej 		DMAheader[unit]->QBAreg &= 0x3FFFF;
   1278  1.15.2.2  thorpej 		/*
   1279  1.15.2.2  thorpej 		* return I/O buf adr
   1280  1.15.2.2  thorpej 		*/
   1281  1.15.2.2  thorpej 		*(int *)datap = (int) DMAheader[unit];
   1282  1.15.2.2  thorpej 		break;
   1283  1.15.2.2  thorpej #endif
   1284  1.15.2.2  thorpej 
   1285  1.15.2.2  thorpej 	case QD_MAPSCROLL:
   1286  1.15.2.2  thorpej 		/*
   1287  1.15.2.2  thorpej 		* map the shared scroll param area and enable scroll interpts
   1288  1.15.2.2  thorpej 		*/
   1289  1.15.2.2  thorpej 		qdflags[unit].mapped |= MAPSCR;
   1290  1.15.2.2  thorpej 		ptep = (int *) ((VTOP(scroll[unit]) * 4)
   1291  1.15.2.2  thorpej 			+ (mfpr(PR_SBR) | 0x80000000));
   1292  1.15.2.2  thorpej 		/*
   1293  1.15.2.2  thorpej 		 * allow user write to scroll area
   1294  1.15.2.2  thorpej 		 */
   1295  1.15.2.2  thorpej 		*ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V;
   1296  1.15.2.2  thorpej 		mtpr(0, PR_TBIA);			/* invalidate translation buf */
   1297  1.15.2.2  thorpej 		scroll[unit]->status = 0;
   1298  1.15.2.2  thorpej 		adder = (struct adder *) qdmap[unit].adder;
   1299  1.15.2.2  thorpej 		qdflags[unit].adder_ie |= FRAME_SYNC;
   1300  1.15.2.2  thorpej 		adder->interrupt_enable = qdflags[unit].adder_ie;
   1301  1.15.2.2  thorpej 		*(int *)datap = (int) scroll[unit]; /* return scroll area */
   1302  1.15.2.2  thorpej 		break;
   1303  1.15.2.2  thorpej 
   1304  1.15.2.2  thorpej 	case QD_UNMAPSCROLL:
   1305  1.15.2.2  thorpej 		/*
   1306  1.15.2.2  thorpej 		* unmap shared scroll param area and disable scroll intrpts
   1307  1.15.2.2  thorpej 		*/
   1308  1.15.2.2  thorpej 		if (qdflags[unit].mapped & MAPSCR) {
   1309  1.15.2.2  thorpej 			qdflags[unit].mapped &= ~MAPSCR;
   1310  1.15.2.2  thorpej 			ptep = (int *) ((VTOP(scroll[unit]) * 4)
   1311  1.15.2.2  thorpej 				+ (mfpr(PR_SBR) | 0x80000000));
   1312  1.15.2.2  thorpej 			/*
   1313  1.15.2.2  thorpej 			 * re-protect 512 scroll param area
   1314  1.15.2.2  thorpej 			 */
   1315  1.15.2.2  thorpej 			*ptep = (*ptep & ~PG_PROT) | PG_KW | PG_V;
   1316  1.15.2.2  thorpej 			mtpr(0, PR_TBIA);	/* smash CPU's translation buf */
   1317  1.15.2.2  thorpej 			adder = (struct adder *) qdmap[unit].adder;
   1318  1.15.2.2  thorpej 			qdflags[unit].adder_ie &= ~FRAME_SYNC;
   1319  1.15.2.2  thorpej 			adder->interrupt_enable = qdflags[unit].adder_ie;
   1320  1.15.2.2  thorpej 		}
   1321  1.15.2.2  thorpej 		break;
   1322  1.15.2.2  thorpej 
   1323  1.15.2.2  thorpej 	case QD_MAPCOLOR:
   1324  1.15.2.2  thorpej 		/*
   1325  1.15.2.2  thorpej 		* map shared color map write buf and turn on vsync intrpt
   1326  1.15.2.2  thorpej 		*/
   1327  1.15.2.2  thorpej 		qdflags[unit].mapped |= MAPCOLOR;
   1328  1.15.2.2  thorpej 		ptep = (int *) ((VTOP(color_buf[unit]) * 4)
   1329  1.15.2.2  thorpej 			+ (mfpr(PR_SBR) | 0x80000000));
   1330  1.15.2.2  thorpej 		/*
   1331  1.15.2.2  thorpej 		 * allow user write to color map write buffer
   1332  1.15.2.2  thorpej 		 */
   1333  1.15.2.2  thorpej 		*ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V; ptep++;
   1334  1.15.2.2  thorpej 		*ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V;
   1335  1.15.2.2  thorpej 		mtpr(0, PR_TBIA);			/* clr CPU translation buf */
   1336  1.15.2.2  thorpej 		adder = (struct adder *) qdmap[unit].adder;
   1337  1.15.2.2  thorpej 		qdflags[unit].adder_ie |= VSYNC;
   1338  1.15.2.2  thorpej 		adder->interrupt_enable = qdflags[unit].adder_ie;
   1339  1.15.2.2  thorpej 		/*
   1340  1.15.2.2  thorpej 		 * return color area address
   1341  1.15.2.2  thorpej 		 */
   1342  1.15.2.2  thorpej 		*(int *)datap = (int) color_buf[unit];
   1343  1.15.2.2  thorpej 		break;
   1344  1.15.2.2  thorpej 
   1345  1.15.2.2  thorpej 	case QD_UNMAPCOLOR:
   1346  1.15.2.2  thorpej 		/*
   1347  1.15.2.2  thorpej 		 * unmap shared color map write buffer and kill VSYNC intrpts
   1348  1.15.2.2  thorpej 		 */
   1349  1.15.2.2  thorpej 		if (qdflags[unit].mapped & MAPCOLOR) {
   1350  1.15.2.2  thorpej 			qdflags[unit].mapped &= ~MAPCOLOR;
   1351  1.15.2.2  thorpej 			ptep = (int *) ((VTOP(color_buf[unit]) * 4)
   1352  1.15.2.2  thorpej 				+ (mfpr(PR_SBR) | 0x80000000));
   1353  1.15.2.2  thorpej 			/*
   1354  1.15.2.2  thorpej 			 * re-protect color map write buffer
   1355  1.15.2.2  thorpej 			 */
   1356  1.15.2.2  thorpej 			*ptep = (*ptep & ~PG_PROT) | PG_KW | PG_V; ptep++;
   1357  1.15.2.2  thorpej 			*ptep = (*ptep & ~PG_PROT) | PG_KW | PG_V;
   1358  1.15.2.2  thorpej 			mtpr(0, PR_TBIA);
   1359  1.15.2.2  thorpej 			adder = (struct adder *) qdmap[unit].adder;
   1360  1.15.2.2  thorpej 			qdflags[unit].adder_ie &= ~VSYNC;
   1361  1.15.2.2  thorpej 			adder->interrupt_enable = qdflags[unit].adder_ie;
   1362  1.15.2.2  thorpej 		}
   1363  1.15.2.2  thorpej 		break;
   1364  1.15.2.2  thorpej 
   1365  1.15.2.2  thorpej 	case QD_MAPEVENT:
   1366  1.15.2.2  thorpej 		/*
   1367  1.15.2.2  thorpej 		* give user write access to the event queue
   1368  1.15.2.2  thorpej 		*/
   1369  1.15.2.2  thorpej 		qdflags[unit].mapped |= MAPEQ;
   1370  1.15.2.2  thorpej 		ptep = (int *) ((VTOP(eq_header[unit]) * 4)
   1371  1.15.2.2  thorpej 			+ (mfpr(PR_SBR) | 0x80000000));
   1372  1.15.2.2  thorpej 		/*
   1373  1.15.2.2  thorpej 		 * allow user write to 1K event queue
   1374  1.15.2.2  thorpej 		 */
   1375  1.15.2.2  thorpej 		*ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V; ptep++;
   1376  1.15.2.2  thorpej 		*ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V;
   1377  1.15.2.2  thorpej 		mtpr(0, PR_TBIA);			/* clr CPU translation buf */
   1378  1.15.2.2  thorpej 		/*
   1379  1.15.2.2  thorpej 		 * return event queue address
   1380  1.15.2.2  thorpej 		 */
   1381  1.15.2.2  thorpej 		*(int *)datap = (int)eq_header[unit];
   1382  1.15.2.2  thorpej 		break;
   1383  1.15.2.2  thorpej 
   1384  1.15.2.2  thorpej 	case QD_PRGKBD:
   1385  1.15.2.2  thorpej 		/*
   1386  1.15.2.2  thorpej 		* pass caller's programming commands to LK201
   1387  1.15.2.2  thorpej 		*/
   1388  1.15.2.2  thorpej 		duart = (struct duart *)qdmap[unit].duart;
   1389  1.15.2.2  thorpej 		cmdbuf = (struct prgkbd *)datap;    /* pnt to kbd cmd buf */
   1390  1.15.2.2  thorpej 		/*
   1391  1.15.2.2  thorpej 		* send command
   1392  1.15.2.2  thorpej 		*/
   1393  1.15.2.2  thorpej 		for (i = 1000; i > 0; --i) {
   1394  1.15.2.2  thorpej 			if (duart->statusA&XMT_RDY) {
   1395  1.15.2.2  thorpej 				duart->dataA = cmdbuf->cmd;
   1396  1.15.2.2  thorpej 				break;
   1397  1.15.2.2  thorpej 			}
   1398  1.15.2.2  thorpej 		}
   1399  1.15.2.2  thorpej 		if (i == 0) {
   1400  1.15.2.2  thorpej 			printf("qd%d: qdioctl: timeout on XMT_RDY [1]\n", unit);
   1401  1.15.2.2  thorpej 			break;
   1402  1.15.2.2  thorpej 		}
   1403  1.15.2.2  thorpej 		/*
   1404  1.15.2.2  thorpej 		* send param1?
   1405  1.15.2.2  thorpej 		*/
   1406  1.15.2.2  thorpej 		if (cmdbuf->cmd & LAST_PARAM)
   1407  1.15.2.2  thorpej 			break;
   1408  1.15.2.2  thorpej 		for (i = 1000; i > 0; --i) {
   1409  1.15.2.2  thorpej 			if (duart->statusA&XMT_RDY) {
   1410  1.15.2.2  thorpej 				duart->dataA = cmdbuf->param1;
   1411  1.15.2.2  thorpej 				break;
   1412  1.15.2.2  thorpej 			}
   1413  1.15.2.2  thorpej 		}
   1414  1.15.2.2  thorpej 		if (i == 0) {
   1415  1.15.2.2  thorpej 			printf("qd%d: qdioctl: timeout on XMT_RDY [2]\n", unit);
   1416  1.15.2.2  thorpej 			break;
   1417  1.15.2.2  thorpej 		}
   1418  1.15.2.2  thorpej 		/*
   1419  1.15.2.2  thorpej 		* send param2?
   1420  1.15.2.2  thorpej 		*/
   1421  1.15.2.2  thorpej 		if (cmdbuf->param1 & LAST_PARAM)
   1422  1.15.2.2  thorpej 		    break;
   1423  1.15.2.2  thorpej 		for (i = 1000; i > 0; --i) {
   1424  1.15.2.2  thorpej 			if (duart->statusA&XMT_RDY) {
   1425  1.15.2.2  thorpej 				duart->dataA = cmdbuf->param2;
   1426  1.15.2.2  thorpej 				break;
   1427  1.15.2.2  thorpej 			}
   1428  1.15.2.2  thorpej 		}
   1429  1.15.2.2  thorpej 		if (i == 0) {
   1430  1.15.2.2  thorpej 			printf("qd%d: qdioctl: timeout on XMT_RDY [3]\n", unit);
   1431  1.15.2.2  thorpej 			break;
   1432  1.15.2.2  thorpej 		}
   1433  1.15.2.2  thorpej 		break;
   1434  1.15.2.2  thorpej 
   1435  1.15.2.2  thorpej 	case QD_PRGMOUSE:
   1436  1.15.2.2  thorpej 		/*
   1437  1.15.2.2  thorpej 		* pass caller's programming commands to the mouse
   1438  1.15.2.2  thorpej 		*/
   1439  1.15.2.2  thorpej 		duart = (struct duart *) qdmap[unit].duart;
   1440  1.15.2.2  thorpej 		for (i = 1000; i > 0; --i) {
   1441  1.15.2.2  thorpej 			if (duart->statusB&XMT_RDY) {
   1442  1.15.2.2  thorpej 				duart->dataB = *datap;
   1443  1.15.2.2  thorpej 				break;
   1444  1.15.2.2  thorpej 			}
   1445  1.15.2.2  thorpej 		}
   1446  1.15.2.2  thorpej 		if (i == 0) {
   1447  1.15.2.2  thorpej 			printf("qd%d: qdioctl: timeout on XMT_RDY [4]\n", unit);
   1448  1.15.2.2  thorpej 		}
   1449  1.15.2.2  thorpej 		break;
   1450  1.15.2.2  thorpej 
   1451  1.15.2.2  thorpej 	case QD_RDCONFIG:
   1452  1.15.2.2  thorpej 		/*
   1453  1.15.2.2  thorpej 		* get QDSS configuration word and return it
   1454  1.15.2.2  thorpej 		*/
   1455  1.15.2.2  thorpej 		*(short *)datap = qdflags[unit].config;
   1456  1.15.2.2  thorpej 		break;
   1457  1.15.2.2  thorpej 
   1458  1.15.2.2  thorpej 	case QD_KERN_LOOP:
   1459  1.15.2.2  thorpej 	case QD_KERN_UNLOOP:
   1460  1.15.2.2  thorpej 		/*
   1461  1.15.2.2  thorpej 		 * vestige from ultrix.  BSD uses TIOCCONS to redirect
   1462  1.15.2.2  thorpej 		 * kernel console output.
   1463  1.15.2.2  thorpej 		 */
   1464  1.15.2.2  thorpej 		break;
   1465  1.15.2.2  thorpej 
   1466  1.15.2.2  thorpej 	case QD_PRGTABLET:
   1467  1.15.2.2  thorpej 		/*
   1468  1.15.2.2  thorpej 		* program the tablet
   1469  1.15.2.2  thorpej 		*/
   1470  1.15.2.2  thorpej 		duart = (struct duart *) qdmap[unit].duart;
   1471  1.15.2.2  thorpej 		for (i = 1000; i > 0; --i) {
   1472  1.15.2.2  thorpej 			if (duart->statusB&XMT_RDY) {
   1473  1.15.2.2  thorpej 				duart->dataB = *datap;
   1474  1.15.2.2  thorpej 				break;
   1475  1.15.2.2  thorpej 			}
   1476  1.15.2.2  thorpej 		}
   1477  1.15.2.2  thorpej 		if (i == 0) {
   1478  1.15.2.2  thorpej 			printf("qd%d: qdioctl: timeout on XMT_RDY [5]\n", unit);
   1479  1.15.2.2  thorpej 		}
   1480  1.15.2.2  thorpej 		break;
   1481  1.15.2.2  thorpej 
   1482  1.15.2.2  thorpej 	case QD_PRGTABRES:
   1483  1.15.2.2  thorpej 		/*
   1484  1.15.2.2  thorpej 		* program the tablet report resolution factor
   1485  1.15.2.2  thorpej 		*/
   1486  1.15.2.2  thorpej 		qdflags[unit].tab_res = *(short *)datap;
   1487  1.15.2.2  thorpej 		break;
   1488  1.15.2.2  thorpej 
   1489  1.15.2.2  thorpej 	default:
   1490  1.15.2.2  thorpej 		/*
   1491  1.15.2.2  thorpej 		* service tty ioctl's
   1492  1.15.2.2  thorpej 		*/
   1493  1.15.2.2  thorpej 		if (!(minor_dev & 0x02)) {
   1494  1.15.2.2  thorpej 			tp = qd_tty[minor_dev];
   1495  1.15.2.2  thorpej 			error =
   1496  1.15.2.2  thorpej 
   1497  1.15.2.2  thorpej 		   (*linesw[tp->t_line].l_ioctl)(tp, cmd, datap, flags, p);
   1498  1.15.2.2  thorpej 			if (error >= 0) {
   1499  1.15.2.2  thorpej 				return(error);
   1500  1.15.2.2  thorpej 			}
   1501  1.15.2.2  thorpej 			error = ttioctl(tp, cmd, datap, flags, p);
   1502  1.15.2.2  thorpej 			if (error >= 0) {
   1503  1.15.2.2  thorpej 				return(error);
   1504  1.15.2.2  thorpej 			}
   1505  1.15.2.2  thorpej 		}
   1506  1.15.2.2  thorpej 		break;
   1507  1.15.2.2  thorpej 	}
   1508  1.15.2.2  thorpej 
   1509  1.15.2.2  thorpej 	return(0);
   1510  1.15.2.2  thorpej 
   1511  1.15.2.2  thorpej } /* qdioctl */
   1512  1.15.2.2  thorpej 
   1513  1.15.2.2  thorpej 
   1514  1.15.2.2  thorpej int
   1515  1.15.2.2  thorpej qdpoll(dev, events, p)
   1516  1.15.2.2  thorpej 	dev_t dev;
   1517  1.15.2.2  thorpej 	int events;
   1518  1.15.2.2  thorpej 	struct proc *p;
   1519  1.15.2.2  thorpej {
   1520  1.15.2.2  thorpej 	register int s;
   1521  1.15.2.2  thorpej 	register int unit;
   1522  1.15.2.2  thorpej 	register struct tty *tp;
   1523  1.15.2.2  thorpej 	u_int minor_dev = minor(dev);
   1524  1.15.2.2  thorpej 	int revents = 0;
   1525  1.15.2.2  thorpej 
   1526  1.15.2.2  thorpej 	s = spl5();
   1527  1.15.2.2  thorpej 	unit = minor_dev >> 2;
   1528  1.15.2.2  thorpej 
   1529  1.15.2.2  thorpej 	if ((minor_dev & 0x03) == 2)  {
   1530  1.15.2.2  thorpej 		/*
   1531  1.15.2.2  thorpej 		 * This is a graphics device, so check for events.
   1532  1.15.2.2  thorpej 		 */
   1533  1.15.2.2  thorpej 
   1534  1.15.2.2  thorpej 		if (events & (POLLIN | POLLRDNORM))
   1535  1.15.2.2  thorpej 			if(!(ISEMPTY(eq_header[unit])))
   1536  1.15.2.2  thorpej 				revents |= events & (POLLIN | POLLRDNORM);
   1537  1.15.2.2  thorpej 
   1538  1.15.2.2  thorpej 		if (events & (POLLOUT | POLLWRNORM))
   1539  1.15.2.2  thorpej 			if (DMA_ISEMPTY(DMAheader[unit]))
   1540  1.15.2.2  thorpej 				revents |= events & (POLLOUT | POLLWRNORM);
   1541  1.15.2.2  thorpej 
   1542  1.15.2.2  thorpej 		if (revents == 0)  {
   1543  1.15.2.2  thorpej 			if (events & (POLLIN | POLLRDNORM))  {
   1544  1.15.2.2  thorpej 				selrecord(p, &qdrsel[unit]);
   1545  1.15.2.2  thorpej 				qdflags[unit].selmask |= SEL_READ;
   1546  1.15.2.2  thorpej 			}
   1547  1.15.2.2  thorpej 
   1548  1.15.2.2  thorpej 			if (events & (POLLOUT | POLLWRNORM))  {
   1549  1.15.2.2  thorpej 				selrecord(p, &qdrsel[unit]);
   1550  1.15.2.2  thorpej 				qdflags[unit].selmask |= SEL_WRITE;
   1551  1.15.2.2  thorpej 			}
   1552  1.15.2.2  thorpej 		}
   1553  1.15.2.2  thorpej 	} else  {
   1554  1.15.2.2  thorpej 		/*
   1555  1.15.2.2  thorpej 		* this is a tty device
   1556  1.15.2.2  thorpej 		*/
   1557  1.15.2.2  thorpej 		tp = qd_tty[minor_dev];
   1558  1.15.2.2  thorpej 
   1559  1.15.2.2  thorpej 		if (events & (POLLIN | POLLRDNORM))  {
   1560  1.15.2.2  thorpej 		     /* This is ttnread.  It's static and I don't feel
   1561  1.15.2.2  thorpej 		      * like altering platform independant parts of NetBSD
   1562  1.15.2.2  thorpej 		      */
   1563  1.15.2.2  thorpej 		     int nread;
   1564  1.15.2.2  thorpej 		     /* if (tp->t_lflag & PENDIN)
   1565  1.15.2.2  thorpej 				     ttypend(tp); */
   1566  1.15.2.2  thorpej 		     nread = tp->t_canq.c_cc;
   1567  1.15.2.2  thorpej 		     if (!(tp->t_lflag & ICANON))  {
   1568  1.15.2.2  thorpej 			     nread += tp->t_rawq.c_cc;
   1569  1.15.2.2  thorpej 			     if (nread < tp->t_cc[VMIN] && !tp->t_cc[VTIME])
   1570  1.15.2.2  thorpej 				     nread = 0;
   1571  1.15.2.2  thorpej 		     }
   1572  1.15.2.2  thorpej 		     if (nread > 0)
   1573  1.15.2.2  thorpej 			     revents |= events & (POLLIN | POLLRDNORM);
   1574  1.15.2.2  thorpej 		}
   1575  1.15.2.2  thorpej 
   1576  1.15.2.2  thorpej 		if (events & (POLLOUT | POLLWRNORM))
   1577  1.15.2.2  thorpej 			if (tp->t_outq.c_cc <= tp->t_lowat)
   1578  1.15.2.2  thorpej 				revents |= events & (POLLOUT | POLLWRNORM);
   1579  1.15.2.2  thorpej 
   1580  1.15.2.2  thorpej 		if (revents == 0)  {
   1581  1.15.2.2  thorpej 			if (events & (POLLIN | POLLRDNORM))
   1582  1.15.2.2  thorpej 				selrecord(p, &tp->t_rsel);
   1583  1.15.2.2  thorpej 
   1584  1.15.2.2  thorpej 			if (events & (POLLOUT | POLLWRNORM))
   1585  1.15.2.2  thorpej 				selrecord(p, &tp->t_wsel);
   1586  1.15.2.2  thorpej 		}
   1587  1.15.2.2  thorpej 	}
   1588  1.15.2.2  thorpej 
   1589  1.15.2.2  thorpej 	splx(s);
   1590  1.15.2.2  thorpej 	return (revents);
   1591  1.15.2.2  thorpej } /* qdpoll() */
   1592  1.15.2.2  thorpej 
   1593  1.15.2.2  thorpej 
   1594  1.15.2.2  thorpej void qd_strategy(struct buf *bp);
   1595  1.15.2.2  thorpej 
   1596  1.15.2.2  thorpej /*ARGSUSED*/
   1597  1.15.2.2  thorpej int
   1598  1.15.2.2  thorpej qdwrite(dev, uio, flag)
   1599  1.15.2.2  thorpej 	dev_t dev;
   1600  1.15.2.2  thorpej 	struct uio *uio;
   1601  1.15.2.2  thorpej {
   1602  1.15.2.2  thorpej 	register struct tty *tp;
   1603  1.15.2.2  thorpej 	register int minor_dev;
   1604  1.15.2.2  thorpej 	register int unit;
   1605  1.15.2.2  thorpej 
   1606  1.15.2.2  thorpej 	minor_dev = minor(dev);
   1607  1.15.2.2  thorpej 	unit = (minor_dev >> 2) & 0x07;
   1608  1.15.2.2  thorpej 
   1609  1.15.2.2  thorpej 	if (((minor_dev&0x03) != 0x02) && (qdflags[unit].inuse&CONS_DEV)) {
   1610  1.15.2.2  thorpej 	       /*
   1611  1.15.2.2  thorpej 		* this is the console...
   1612  1.15.2.2  thorpej 		*/
   1613  1.15.2.2  thorpej 		tp = qd_tty[minor_dev];
   1614  1.15.2.2  thorpej 		return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
   1615  1.15.2.2  thorpej 	} else if (qdflags[unit].inuse & GRAPHIC_DEV) {
   1616  1.15.2.2  thorpej 	       /*
   1617  1.15.2.2  thorpej 		* this is a DMA xfer from user space
   1618  1.15.2.2  thorpej 		*/
   1619  1.15.2.2  thorpej 		return (physio(qd_strategy, &qdbuf[unit],
   1620  1.15.2.2  thorpej 		dev, B_WRITE, minphys, uio));
   1621  1.15.2.2  thorpej 	}
   1622  1.15.2.2  thorpej 	return (ENXIO);
   1623  1.15.2.2  thorpej }
   1624  1.15.2.2  thorpej 
   1625  1.15.2.2  thorpej /*ARGSUSED*/
   1626  1.15.2.2  thorpej int
   1627  1.15.2.2  thorpej qdread(dev, uio, flag)
   1628  1.15.2.2  thorpej 	dev_t dev;
   1629  1.15.2.2  thorpej 	struct uio *uio;
   1630  1.15.2.2  thorpej {
   1631  1.15.2.2  thorpej 	register struct tty *tp;
   1632  1.15.2.2  thorpej 	register int minor_dev;
   1633  1.15.2.2  thorpej 	register int unit;
   1634  1.15.2.2  thorpej 
   1635  1.15.2.2  thorpej 	minor_dev = minor(dev);
   1636  1.15.2.2  thorpej 	unit = (minor_dev >> 2) & 0x07;
   1637  1.15.2.2  thorpej 
   1638  1.15.2.2  thorpej 	if ((minor_dev & 0x03) != 0x02 && qdflags[unit].inuse & CONS_DEV) {
   1639  1.15.2.2  thorpej 	       /*
   1640  1.15.2.2  thorpej 		* this is the console
   1641  1.15.2.2  thorpej 		*/
   1642  1.15.2.2  thorpej 		tp = qd_tty[minor_dev];
   1643  1.15.2.2  thorpej 		return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
   1644  1.15.2.2  thorpej 	} else if (qdflags[unit].inuse & GRAPHIC_DEV) {
   1645  1.15.2.2  thorpej 	       /*
   1646  1.15.2.2  thorpej 		* this is a bitmap-to-processor xfer
   1647  1.15.2.2  thorpej 		*/
   1648  1.15.2.2  thorpej 		return (physio(qd_strategy, &qdbuf[unit],
   1649  1.15.2.2  thorpej 		dev, B_READ, minphys, uio));
   1650  1.15.2.2  thorpej 	}
   1651  1.15.2.2  thorpej 	return (ENXIO);
   1652  1.15.2.2  thorpej }
   1653  1.15.2.2  thorpej 
   1654  1.15.2.2  thorpej /***************************************************************
   1655  1.15.2.2  thorpej *
   1656  1.15.2.2  thorpej *	qd_strategy()... strategy routine to do DMA
   1657  1.15.2.2  thorpej *
   1658  1.15.2.2  thorpej ***************************************************************/
   1659  1.15.2.2  thorpej 
   1660  1.15.2.2  thorpej void
   1661  1.15.2.2  thorpej qd_strategy(bp)
   1662  1.15.2.2  thorpej 	register struct buf *bp;
   1663  1.15.2.2  thorpej {
   1664  1.15.2.2  thorpej 	volatile register struct dga *dga;
   1665  1.15.2.2  thorpej 	volatile register struct adder *adder;
   1666  1.15.2.2  thorpej 	register int unit;
   1667  1.15.2.2  thorpej 	int QBAreg;
   1668  1.15.2.2  thorpej 	int s;
   1669  1.15.2.2  thorpej 	int cookie;
   1670  1.15.2.2  thorpej 	struct uba_softc *uh;
   1671  1.15.2.2  thorpej 
   1672  1.15.2.2  thorpej 	unit = (minor(bp->b_dev) >> 2) & 0x07;
   1673  1.15.2.2  thorpej 
   1674  1.15.2.2  thorpej 	uh = (struct uba_softc *)
   1675  1.15.2.2  thorpej 	     (((struct device *)(qd_cd.cd_devs[unit]))->dv_parent);
   1676  1.15.2.2  thorpej 
   1677  1.15.2.2  thorpej 	/*
   1678  1.15.2.2  thorpej 	* init pointers
   1679  1.15.2.2  thorpej 	*/
   1680  1.15.2.2  thorpej 	dga = (struct dga *) qdmap[unit].dga;
   1681  1.15.2.2  thorpej panic("qd_strategy");
   1682  1.15.2.2  thorpej #ifdef notyet
   1683  1.15.2.2  thorpej 	if ((QBAreg = ubasetup(uh, bp, 0)) == 0) {
   1684  1.15.2.2  thorpej 		printf("qd%d: qd_strategy: QBA setup error\n", unit);
   1685  1.15.2.2  thorpej 		goto STRAT_ERR;
   1686  1.15.2.2  thorpej 	}
   1687  1.15.2.2  thorpej #endif
   1688  1.15.2.2  thorpej 	s = spl5();
   1689  1.15.2.2  thorpej 	qdflags[unit].user_dma = -1;
   1690  1.15.2.2  thorpej 	dga->csr |= DMA_IE;
   1691  1.15.2.2  thorpej 	cookie = QBAreg & 0x3FFFF;
   1692  1.15.2.2  thorpej 	dga->adrs_lo = (short) cookie;
   1693  1.15.2.2  thorpej 	dga->adrs_hi = (short) (cookie >> 16);
   1694  1.15.2.2  thorpej 	dga->bytcnt_lo = (short) bp->b_bcount;
   1695  1.15.2.2  thorpej 	dga->bytcnt_hi = (short) (bp->b_bcount >> 16);
   1696  1.15.2.2  thorpej 
   1697  1.15.2.2  thorpej 	while (qdflags[unit].user_dma) {
   1698  1.15.2.2  thorpej 		sleep((caddr_t)&qdflags[unit].user_dma, QDPRIOR);
   1699  1.15.2.2  thorpej 	}
   1700  1.15.2.2  thorpej 	splx(s);
   1701  1.15.2.2  thorpej #ifdef notyet
   1702  1.15.2.2  thorpej 	ubarelse(uh, &QBAreg);
   1703  1.15.2.2  thorpej #endif
   1704  1.15.2.2  thorpej 	if (!(dga->csr & DMA_ERR)) {
   1705  1.15.2.2  thorpej 		iodone(bp);
   1706  1.15.2.2  thorpej 		return;
   1707  1.15.2.2  thorpej 	}
   1708  1.15.2.2  thorpej 
   1709  1.15.2.2  thorpej /* STRAT_ERR: */
   1710  1.15.2.2  thorpej 	adder = (struct adder *) qdmap[unit].adder;
   1711  1.15.2.2  thorpej 	adder->command = CANCEL;	/* cancel adder activity */
   1712  1.15.2.2  thorpej 	dga->csr &= ~DMA_IE;
   1713  1.15.2.2  thorpej 	dga->csr &= ~0x0600;		/* halt DMA (reset fifo) */
   1714  1.15.2.2  thorpej 	dga->csr |= DMA_ERR;		/* clear error condition */
   1715  1.15.2.2  thorpej 	bp->b_flags |= B_ERROR; 	/* flag an error to physio() */
   1716  1.15.2.2  thorpej 
   1717  1.15.2.2  thorpej 	/*
   1718  1.15.2.2  thorpej 	 * if DMA was running, flush spurious intrpt
   1719  1.15.2.2  thorpej 	 */
   1720  1.15.2.2  thorpej 	if (dga->bytcnt_lo != 0) {
   1721  1.15.2.2  thorpej 		dga->bytcnt_lo = 0;
   1722  1.15.2.2  thorpej 		dga->bytcnt_hi = 0;
   1723  1.15.2.2  thorpej 		DMA_SETIGNORE(DMAheader[unit]);
   1724  1.15.2.2  thorpej 		dga->csr |= DMA_IE;
   1725  1.15.2.2  thorpej 	}
   1726  1.15.2.2  thorpej 	iodone(bp);
   1727  1.15.2.2  thorpej } /* qd_strategy */
   1728  1.15.2.2  thorpej 
   1729  1.15.2.2  thorpej 
   1730  1.15.2.2  thorpej /*
   1731  1.15.2.2  thorpej  *  Start output to the console screen
   1732  1.15.2.2  thorpej  */
   1733  1.15.2.2  thorpej void qdstart(tp)
   1734  1.15.2.2  thorpej 	struct tty *tp;
   1735  1.15.2.2  thorpej {
   1736  1.15.2.2  thorpej 	register int which_unit, unit, c;
   1737  1.15.2.2  thorpej 	int s;
   1738  1.15.2.2  thorpej 
   1739  1.15.2.2  thorpej 	unit = minor(tp->t_dev);
   1740  1.15.2.2  thorpej 	which_unit = (unit >> 2) & 0x3;
   1741  1.15.2.2  thorpej 	unit &= 0x03;
   1742  1.15.2.2  thorpej 
   1743  1.15.2.2  thorpej 	s = spl5();
   1744  1.15.2.2  thorpej 
   1745  1.15.2.2  thorpej 	/*
   1746  1.15.2.2  thorpej 	* If it's currently active, or delaying, no need to do anything.
   1747  1.15.2.2  thorpej 	*/
   1748  1.15.2.2  thorpej 	if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
   1749  1.15.2.2  thorpej 		goto out;
   1750  1.15.2.2  thorpej 
   1751  1.15.2.2  thorpej 	/*
   1752  1.15.2.2  thorpej 	* Display chars until the queue is empty.
   1753  1.15.2.2  thorpej 	* Drop input from anything but the console
   1754  1.15.2.2  thorpej 	* device on the floor.
   1755  1.15.2.2  thorpej 	*
   1756  1.15.2.2  thorpej 	* XXX - this loop is done at spltty.
   1757  1.15.2.2  thorpej 	*
   1758  1.15.2.2  thorpej 	*/
   1759  1.15.2.2  thorpej 	while (tp->t_outq.c_cc) {
   1760  1.15.2.2  thorpej 		c = getc(&tp->t_outq);
   1761  1.15.2.2  thorpej 		if (unit == 0)
   1762  1.15.2.2  thorpej 			blitc(which_unit, (u_char)c);
   1763  1.15.2.2  thorpej 	}
   1764  1.15.2.2  thorpej 	/*
   1765  1.15.2.2  thorpej 	* If there are sleepers, and output has drained below low
   1766  1.15.2.2  thorpej 	* water mark, wake up the sleepers.
   1767  1.15.2.2  thorpej 	*/
   1768  1.15.2.2  thorpej 	if (tp->t_outq.c_cc <= tp->t_lowat) {
   1769  1.15.2.2  thorpej 		if (tp->t_state & TS_ASLEEP){
   1770  1.15.2.2  thorpej 			tp->t_state &= ~TS_ASLEEP;
   1771  1.15.2.2  thorpej 			wakeup((caddr_t) &tp->t_outq);
   1772  1.15.2.2  thorpej 		}
   1773  1.15.2.2  thorpej 	}
   1774  1.15.2.2  thorpej 
   1775  1.15.2.2  thorpej 	tp->t_state &= ~TS_BUSY;
   1776  1.15.2.2  thorpej 
   1777  1.15.2.2  thorpej out:
   1778  1.15.2.2  thorpej 	splx(s);
   1779  1.15.2.2  thorpej 
   1780  1.15.2.2  thorpej } /* qdstart */
   1781  1.15.2.2  thorpej 
   1782  1.15.2.2  thorpej /*ARGSUSED*/
   1783  1.15.2.2  thorpej void
   1784  1.15.2.2  thorpej qdstop(tp, flag)
   1785  1.15.2.2  thorpej 	struct tty *tp;
   1786  1.15.2.2  thorpej 	int flag;
   1787  1.15.2.2  thorpej {
   1788  1.15.2.2  thorpej 	register int s;
   1789  1.15.2.2  thorpej 
   1790  1.15.2.2  thorpej 	s = spl5();	/* block intrpts during state modification */
   1791  1.15.2.2  thorpej 	if (tp->t_state & TS_BUSY) {
   1792  1.15.2.2  thorpej 		if ((tp->t_state & TS_TTSTOP) == 0)
   1793  1.15.2.2  thorpej 			tp->t_state |= TS_FLUSH;
   1794  1.15.2.2  thorpej 		else
   1795  1.15.2.2  thorpej 			tp->t_state &= ~TS_BUSY;
   1796  1.15.2.2  thorpej 	}
   1797  1.15.2.2  thorpej 	splx(s);
   1798  1.15.2.2  thorpej }
   1799  1.15.2.2  thorpej 
   1800  1.15.2.2  thorpej /*
   1801  1.15.2.2  thorpej  *  Output a character to the QDSS screen
   1802  1.15.2.2  thorpej  */
   1803  1.15.2.2  thorpej void
   1804  1.15.2.2  thorpej blitc(unit, chr)
   1805  1.15.2.2  thorpej 	int unit;
   1806  1.15.2.2  thorpej 	u_char chr;
   1807  1.15.2.2  thorpej {
   1808  1.15.2.2  thorpej 	volatile register struct adder *adder;
   1809  1.15.2.2  thorpej 	volatile register struct dga *dga;
   1810  1.15.2.2  thorpej 	register int i;
   1811  1.15.2.2  thorpej 	int nograph = !(qdflags[unit].inuse&GRAPHIC_DEV);
   1812  1.15.2.2  thorpej 	static short inescape[NQD];
   1813  1.15.2.2  thorpej 
   1814  1.15.2.2  thorpej 	adder = (struct adder *)qdmap[unit].adder;
   1815  1.15.2.2  thorpej 	dga = (struct dga *) qdmap[unit].dga;
   1816  1.15.2.2  thorpej 	/*
   1817  1.15.2.2  thorpej 	 * BSD comment: this (&=0177) defeats the extended character
   1818  1.15.2.2  thorpej 	 * set code for the glass tty, but if i had the time i would
   1819  1.15.2.2  thorpej 	 * spend it ripping out the code completely.  This driver
   1820  1.15.2.2  thorpej 	 * is too big for its own good.
   1821  1.15.2.2  thorpej 	 */
   1822  1.15.2.2  thorpej 	chr &= 0177;
   1823  1.15.2.2  thorpej 	/*
   1824  1.15.2.2  thorpej 	 * Cursor addressing (so vi will work).
   1825  1.15.2.2  thorpej 	 * Decode for "\E=%.%." cursor motion description.
   1826  1.15.2.2  thorpej 	 * Corresponds to type "qdcons" in /etc/termcap:
   1827  1.15.2.2  thorpej 	 *
   1828  1.15.2.2  thorpej 	 *    qd|qdss|qdcons|qdss glass tty (4.4 BSD):\
   1829  1.15.2.2  thorpej 	 *      :am:do=^J:le=^H:bs:cm=\E=%.%.:cl=1^Z:co#128:li#57::nd=^L:up=^K:
   1830  1.15.2.2  thorpej 	 *
   1831  1.15.2.2  thorpej 	 */
   1832  1.15.2.2  thorpej 	if (inescape[unit] && nograph) {
   1833  1.15.2.2  thorpej 		switch (inescape[unit]++) {
   1834  1.15.2.2  thorpej 		case 1:
   1835  1.15.2.2  thorpej 			if (chr != '=') {
   1836  1.15.2.2  thorpej 				/* abort escape sequence */
   1837  1.15.2.2  thorpej 				inescape[unit] = 0;
   1838  1.15.2.2  thorpej 				blitc(unit, chr);
   1839  1.15.2.2  thorpej 			}
   1840  1.15.2.2  thorpej 			return;
   1841  1.15.2.2  thorpej 		case 2:
   1842  1.15.2.2  thorpej 			/* position row */
   1843  1.15.2.2  thorpej 			cursor[unit].y = CHAR_HEIGHT * chr;
   1844  1.15.2.2  thorpej 			if (cursor[unit].y > 863 - CHAR_HEIGHT)
   1845  1.15.2.2  thorpej 				cursor[unit].y = 863 - CHAR_HEIGHT;
   1846  1.15.2.2  thorpej 			dga->y_cursor = TRANY(cursor[unit].y);
   1847  1.15.2.2  thorpej 			return;
   1848  1.15.2.2  thorpej 		case 3:
   1849  1.15.2.2  thorpej 			/* position column */
   1850  1.15.2.2  thorpej 			cursor[unit].x = CHAR_WIDTH * chr;
   1851  1.15.2.2  thorpej 			if (cursor[unit].x > 1024 - CHAR_WIDTH)
   1852  1.15.2.2  thorpej 				cursor[unit].x = 1023 - CHAR_WIDTH;
   1853  1.15.2.2  thorpej 			dga->x_cursor = TRANX(cursor[unit].x);
   1854  1.15.2.2  thorpej 			inescape[unit] = 0;
   1855  1.15.2.2  thorpej 			return;
   1856  1.15.2.2  thorpej 		default:
   1857  1.15.2.2  thorpej 			inescape[unit] = 0;
   1858  1.15.2.2  thorpej 			blitc(unit, chr);
   1859  1.15.2.2  thorpej 		}
   1860  1.15.2.2  thorpej 	}
   1861  1.15.2.2  thorpej 
   1862  1.15.2.2  thorpej 	switch (chr) {
   1863  1.15.2.2  thorpej 	case '\r':			/* return char */
   1864  1.15.2.2  thorpej 		cursor[unit].x = 0;
   1865  1.15.2.2  thorpej 		if (nograph)
   1866  1.15.2.2  thorpej 			dga->x_cursor = TRANX(cursor[unit].x);
   1867  1.15.2.2  thorpej 		return;
   1868  1.15.2.2  thorpej 
   1869  1.15.2.2  thorpej 	case '\t':			/* tab char */
   1870  1.15.2.2  thorpej 		for (i = 8 - ((cursor[unit].x >> 3) & 0x07); i > 0; --i) {
   1871  1.15.2.2  thorpej 			blitc(unit, ' ');
   1872  1.15.2.2  thorpej 		}
   1873  1.15.2.2  thorpej 		return;
   1874  1.15.2.2  thorpej 
   1875  1.15.2.2  thorpej 	case '\n':			/* line feed char */
   1876  1.15.2.2  thorpej 		if ((cursor[unit].y += CHAR_HEIGHT) > (863 - CHAR_HEIGHT)) {
   1877  1.15.2.2  thorpej 			if (nograph) {
   1878  1.15.2.2  thorpej 				cursor[unit].y -= CHAR_HEIGHT;
   1879  1.15.2.2  thorpej 				scroll_up(adder);
   1880  1.15.2.2  thorpej 			} else
   1881  1.15.2.2  thorpej 				cursor[unit].y = 0;
   1882  1.15.2.2  thorpej 		}
   1883  1.15.2.2  thorpej 		if (nograph)
   1884  1.15.2.2  thorpej 			dga->y_cursor = TRANY(cursor[unit].y);
   1885  1.15.2.2  thorpej 		return;
   1886  1.15.2.2  thorpej 
   1887  1.15.2.2  thorpej 	case '\b':			/* backspace char */
   1888  1.15.2.2  thorpej 		if (cursor[unit].x > 0) {
   1889  1.15.2.2  thorpej 			cursor[unit].x -= CHAR_WIDTH;
   1890  1.15.2.2  thorpej 			if (nograph)
   1891  1.15.2.2  thorpej 				dga->x_cursor = TRANX(cursor[unit].x);
   1892  1.15.2.2  thorpej 		}
   1893  1.15.2.2  thorpej 		return;
   1894  1.15.2.2  thorpej 	case CTRL('k'):		/* cursor up */
   1895  1.15.2.2  thorpej 		if (nograph && cursor[unit].y > 0) {
   1896  1.15.2.2  thorpej 			cursor[unit].y -= CHAR_HEIGHT;
   1897  1.15.2.2  thorpej 			dga->y_cursor = TRANY(cursor[unit].y);
   1898  1.15.2.2  thorpej 		}
   1899  1.15.2.2  thorpej 		return;
   1900  1.15.2.2  thorpej 
   1901  1.15.2.2  thorpej 	case CTRL('^'):		/* home cursor */
   1902  1.15.2.2  thorpej 		if (nograph) {
   1903  1.15.2.2  thorpej 			cursor[unit].x = 0;
   1904  1.15.2.2  thorpej 			dga->x_cursor = TRANX(cursor[unit].x);
   1905  1.15.2.2  thorpej 			cursor[unit].y = 0;
   1906  1.15.2.2  thorpej 			dga->y_cursor = TRANY(cursor[unit].y);
   1907  1.15.2.2  thorpej 		}
   1908  1.15.2.2  thorpej 		return;
   1909  1.15.2.2  thorpej 
   1910  1.15.2.2  thorpej 	case CTRL('l'):		/* cursor right */
   1911  1.15.2.2  thorpej 		if (nograph && cursor[unit].x < 1023 - CHAR_WIDTH) {
   1912  1.15.2.2  thorpej 			cursor[unit].x += CHAR_WIDTH;
   1913  1.15.2.2  thorpej 			dga->x_cursor = TRANX(cursor[unit].x);
   1914  1.15.2.2  thorpej 		}
   1915  1.15.2.2  thorpej 		return;
   1916  1.15.2.2  thorpej 
   1917  1.15.2.2  thorpej 	case CTRL('z'):		/* clear screen */
   1918  1.15.2.2  thorpej 		if (nograph) {
   1919  1.15.2.2  thorpej 			setup_dragon(unit);
   1920  1.15.2.2  thorpej 			clear_qd_screen(unit);
   1921  1.15.2.2  thorpej 			/* home cursor - termcap seems to assume this */
   1922  1.15.2.2  thorpej 			cursor[unit].x = 0;
   1923  1.15.2.2  thorpej 			dga->x_cursor = TRANX(cursor[unit].x);
   1924  1.15.2.2  thorpej 			cursor[unit].y = 0;
   1925  1.15.2.2  thorpej 			dga->y_cursor = TRANY(cursor[unit].y);
   1926  1.15.2.2  thorpej 		}
   1927  1.15.2.2  thorpej 		return;
   1928  1.15.2.2  thorpej 
   1929  1.15.2.2  thorpej 	case '\033':		/* start escape sequence */
   1930  1.15.2.2  thorpej 		if (nograph)
   1931  1.15.2.2  thorpej 			inescape[unit] = 1;
   1932  1.15.2.2  thorpej 		return;
   1933  1.15.2.2  thorpej 
   1934  1.15.2.2  thorpej 	default:
   1935  1.15.2.2  thorpej 		if ((chr < ' ') || (chr > '~'))
   1936  1.15.2.2  thorpej 			return;
   1937  1.15.2.2  thorpej 	}
   1938  1.15.2.2  thorpej 	/*
   1939  1.15.2.2  thorpej 	 * setup VIPER operand control registers
   1940  1.15.2.2  thorpej 	 */
   1941  1.15.2.2  thorpej 	write_ID(adder, CS_UPDATE_MASK, 0x0001);  /* select plane #0 */
   1942  1.15.2.2  thorpej 	write_ID(adder, SRC1_OCR_B,
   1943  1.15.2.2  thorpej 	EXT_NONE | INT_SOURCE | ID | BAR_SHIFT_DELAY);
   1944  1.15.2.2  thorpej 	write_ID(adder, CS_UPDATE_MASK, 0x00FE);  /* select other planes */
   1945  1.15.2.2  thorpej 	write_ID(adder, SRC1_OCR_B,
   1946  1.15.2.2  thorpej 	EXT_SOURCE | INT_NONE | NO_ID | BAR_SHIFT_DELAY);
   1947  1.15.2.2  thorpej 	write_ID(adder, CS_UPDATE_MASK, 0x00FF);  /* select all planes */
   1948  1.15.2.2  thorpej 	write_ID(adder, DST_OCR_B,
   1949  1.15.2.2  thorpej 	EXT_NONE | INT_NONE | NO_ID | NO_BAR_SHIFT_DELAY);
   1950  1.15.2.2  thorpej 	write_ID(adder, MASK_1, 0xFFFF);
   1951  1.15.2.2  thorpej 	write_ID(adder, VIPER_Z_LOAD | FOREGROUND_COLOR_Z, 1);
   1952  1.15.2.2  thorpej 	write_ID(adder, VIPER_Z_LOAD | BACKGROUND_COLOR_Z, 0);
   1953  1.15.2.2  thorpej 	adder->x_clip_min = 0;
   1954  1.15.2.2  thorpej 	adder->x_clip_max = 1024;
   1955  1.15.2.2  thorpej 	adder->y_clip_min = 0;
   1956  1.15.2.2  thorpej 	adder->y_clip_max = 864;
   1957  1.15.2.2  thorpej 	/*
   1958  1.15.2.2  thorpej 	 * load DESTINATION origin and vectors
   1959  1.15.2.2  thorpej 	 */
   1960  1.15.2.2  thorpej 	adder->fast_dest_dy = 0;
   1961  1.15.2.2  thorpej 	adder->slow_dest_dx = 0;
   1962  1.15.2.2  thorpej 	adder->error_1 = 0;
   1963  1.15.2.2  thorpej 	adder->error_2 = 0;
   1964  1.15.2.2  thorpej 	adder->rasterop_mode = DST_WRITE_ENABLE | NORMAL;
   1965  1.15.2.2  thorpej 	(void)wait_status(adder, RASTEROP_COMPLETE);
   1966  1.15.2.2  thorpej 	adder->destination_x = cursor[unit].x;
   1967  1.15.2.2  thorpej 	adder->fast_dest_dx = CHAR_WIDTH;
   1968  1.15.2.2  thorpej 	adder->destination_y = cursor[unit].y;
   1969  1.15.2.2  thorpej 	adder->slow_dest_dy = CHAR_HEIGHT;
   1970  1.15.2.2  thorpej 	/*
   1971  1.15.2.2  thorpej 	 * load SOURCE origin and vectors
   1972  1.15.2.2  thorpej 	 */
   1973  1.15.2.2  thorpej 	if ((chr - ' ') > (CHARS - 1))  {
   1974  1.15.2.2  thorpej 		printf("Invalid character (x)%x in blitc\n",chr);
   1975  1.15.2.2  thorpej 		chr = ' ';
   1976  1.15.2.2  thorpej 	}
   1977  1.15.2.2  thorpej 	/*
   1978  1.15.2.2  thorpej 	 * X position is modulo the number of characters per line
   1979  1.15.2.2  thorpej 	 */
   1980  1.15.2.2  thorpej 	adder->source_1_x = FONT_X +
   1981  1.15.2.2  thorpej 	    (((chr - ' ') % (MAX_SCREEN_X/CHAR_WIDTH)) * CHAR_WIDTH);
   1982  1.15.2.2  thorpej 	/*
   1983  1.15.2.2  thorpej 	 * Point to either first or second row
   1984  1.15.2.2  thorpej 	 */
   1985  1.15.2.2  thorpej 	adder->source_1_y = 2048 - 15 *
   1986  1.15.2.2  thorpej 	    (((chr - ' ')/(MAX_SCREEN_X/CHAR_WIDTH)) + 1);
   1987  1.15.2.2  thorpej 	adder->source_1_dx = CHAR_WIDTH;
   1988  1.15.2.2  thorpej 	adder->source_1_dy = CHAR_HEIGHT;
   1989  1.15.2.2  thorpej 	write_ID(adder, LU_FUNCTION_R1, FULL_SRC_RESOLUTION | LF_SOURCE);
   1990  1.15.2.2  thorpej 	adder->cmd = RASTEROP | OCRB | 0 | S1E | DTE;
   1991  1.15.2.2  thorpej 	/*
   1992  1.15.2.2  thorpej 	 * update console cursor coordinates
   1993  1.15.2.2  thorpej 	 */
   1994  1.15.2.2  thorpej 	cursor[unit].x += CHAR_WIDTH;
   1995  1.15.2.2  thorpej 	if (nograph)
   1996  1.15.2.2  thorpej 		dga->x_cursor = TRANX(cursor[unit].x);
   1997  1.15.2.2  thorpej 	if (cursor[unit].x > (1024 - CHAR_WIDTH)) {
   1998  1.15.2.2  thorpej 		blitc(unit, '\r');
   1999  1.15.2.2  thorpej 		blitc(unit, '\n');
   2000  1.15.2.2  thorpej 	}
   2001  1.15.2.2  thorpej 
   2002  1.15.2.2  thorpej } /* blitc */
   2003  1.15.2.2  thorpej 
   2004  1.15.2.2  thorpej /*
   2005  1.15.2.2  thorpej  *  INTERRUPT SERVICE ROUTINES
   2006  1.15.2.2  thorpej  */
   2007  1.15.2.2  thorpej 
   2008  1.15.2.2  thorpej /*
   2009  1.15.2.2  thorpej  *  Service "DMA DONE" interrupt condition
   2010  1.15.2.2  thorpej  */
   2011  1.15.2.2  thorpej 
   2012  1.15.2.2  thorpej static void
   2013  1.15.2.2  thorpej qddint(qd)
   2014  1.15.2.2  thorpej 	int qd;
   2015  1.15.2.2  thorpej {
   2016  1.15.2.2  thorpej 	register struct DMAreq_header *header;
   2017  1.15.2.2  thorpej 	register struct DMAreq *request;
   2018  1.15.2.2  thorpej 	volatile register struct dga *dga;
   2019  1.15.2.2  thorpej 	volatile struct adder *adder;
   2020  1.15.2.2  thorpej 	int cookie;			/* DMA adrs for QDSS */
   2021  1.15.2.2  thorpej 
   2022  1.15.2.2  thorpej 	(void)spl4(); 			/* allow interval timer in */
   2023  1.15.2.2  thorpej 
   2024  1.15.2.2  thorpej 	/*
   2025  1.15.2.2  thorpej 	* init pointers
   2026  1.15.2.2  thorpej 	*/
   2027  1.15.2.2  thorpej 	header = DMAheader[qd]; 	    /* register for optimization */
   2028  1.15.2.2  thorpej 	dga = (struct dga *) qdmap[qd].dga;
   2029  1.15.2.2  thorpej 	adder = (struct adder *) qdmap[qd].adder;
   2030  1.15.2.2  thorpej 
   2031  1.15.2.2  thorpej 	/*
   2032  1.15.2.2  thorpej 	* if this interrupt flagged as bogus for interrupt flushing purposes..
   2033  1.15.2.2  thorpej 	*/
   2034  1.15.2.2  thorpej 	if (DMA_ISIGNORE(header)) {
   2035  1.15.2.2  thorpej 	   DMA_CLRIGNORE(header);
   2036  1.15.2.2  thorpej 		return;
   2037  1.15.2.2  thorpej 	}
   2038  1.15.2.2  thorpej 
   2039  1.15.2.2  thorpej 	/*
   2040  1.15.2.2  thorpej 	* dump a DMA hardware error message if appropriate
   2041  1.15.2.2  thorpej 	*/
   2042  1.15.2.2  thorpej 	if (dga->csr & DMA_ERR) {
   2043  1.15.2.2  thorpej 
   2044  1.15.2.2  thorpej 		if (dga->csr & PARITY_ERR)
   2045  1.15.2.2  thorpej 		    printf("qd%d: qddint: DMA hardware parity fault.\n", qd);
   2046  1.15.2.2  thorpej 
   2047  1.15.2.2  thorpej 		if (dga->csr & BUS_ERR)
   2048  1.15.2.2  thorpej 		    printf("qd%d: qddint: DMA hardware bus error.\n", qd);
   2049  1.15.2.2  thorpej 	}
   2050  1.15.2.2  thorpej 
   2051  1.15.2.2  thorpej 	/*
   2052  1.15.2.2  thorpej 	* if this was a DMA from user space...
   2053  1.15.2.2  thorpej 	*/
   2054  1.15.2.2  thorpej 	if (qdflags[qd].user_dma) {
   2055  1.15.2.2  thorpej 		qdflags[qd].user_dma = 0;
   2056  1.15.2.2  thorpej 		wakeup((caddr_t)&qdflags[qd].user_dma);
   2057  1.15.2.2  thorpej 		return;
   2058  1.15.2.2  thorpej 	}
   2059  1.15.2.2  thorpej 
   2060  1.15.2.2  thorpej 	/*
   2061  1.15.2.2  thorpej 	* if we're doing DMA request queue services, field the error condition
   2062  1.15.2.2  thorpej 	*/
   2063  1.15.2.2  thorpej 	if (dga->csr & DMA_ERR) {
   2064  1.15.2.2  thorpej 
   2065  1.15.2.2  thorpej 		dga->csr &= ~0x0600;		/* halt DMA (reset fifo) */
   2066  1.15.2.2  thorpej 		dga->csr |= DMA_ERR;		/* clear error condition */
   2067  1.15.2.2  thorpej 		adder->command = CANCEL;	/* cancel adder activity */
   2068  1.15.2.2  thorpej 
   2069  1.15.2.2  thorpej 		DMA_SETERROR(header);	/* flag error in header status word */
   2070  1.15.2.2  thorpej 		DMA_CLRACTIVE(header);
   2071  1.15.2.2  thorpej 		header->DMAreq[header->oldest].DMAdone |= HARD_ERROR;
   2072  1.15.2.2  thorpej 		header->newest = header->oldest;
   2073  1.15.2.2  thorpej 		header->used = 0;
   2074  1.15.2.2  thorpej 
   2075  1.15.2.2  thorpej 		if (qdrsel[qd].si_pid && qdflags[qd].selmask & SEL_WRITE) {
   2076  1.15.2.2  thorpej 			selwakeup(&qdrsel[qd]);
   2077  1.15.2.2  thorpej 			qdrsel[qd].si_pid = 0;
   2078  1.15.2.2  thorpej 			qdflags[qd].selmask &= ~SEL_WRITE;
   2079  1.15.2.2  thorpej 		}
   2080  1.15.2.2  thorpej 
   2081  1.15.2.2  thorpej 		if (dga->bytcnt_lo != 0) {
   2082  1.15.2.2  thorpej 			dga->bytcnt_lo = 0;
   2083  1.15.2.2  thorpej 			dga->bytcnt_hi = 0;
   2084  1.15.2.2  thorpej 			DMA_SETIGNORE(header);
   2085  1.15.2.2  thorpej 		}
   2086  1.15.2.2  thorpej 		return;
   2087  1.15.2.2  thorpej 	}
   2088  1.15.2.2  thorpej 
   2089  1.15.2.2  thorpej 	/*
   2090  1.15.2.2  thorpej 	* if the DMA request queue is now becoming non-full,
   2091  1.15.2.2  thorpej 	* wakeup "select" client.
   2092  1.15.2.2  thorpej 	*/
   2093  1.15.2.2  thorpej 	if (DMA_ISFULL(header)) {
   2094  1.15.2.2  thorpej 		if (qdrsel[qd].si_pid && qdflags[qd].selmask & SEL_WRITE) {
   2095  1.15.2.2  thorpej 			selwakeup(&qdrsel[qd]);
   2096  1.15.2.2  thorpej 			qdrsel[qd].si_pid = 0;
   2097  1.15.2.2  thorpej 			qdflags[qd].selmask &= ~SEL_WRITE;
   2098  1.15.2.2  thorpej 		}
   2099  1.15.2.2  thorpej 	}
   2100  1.15.2.2  thorpej 
   2101  1.15.2.2  thorpej 	header->DMAreq[header->oldest].DMAdone |= REQUEST_DONE;
   2102  1.15.2.2  thorpej 	QDlast_DMAtype = header->DMAreq[header->oldest].DMAtype;
   2103  1.15.2.2  thorpej 
   2104  1.15.2.2  thorpej 	/* check for unexpected interrupt */
   2105  1.15.2.2  thorpej 	if (DMA_ISEMPTY(header))
   2106  1.15.2.2  thorpej 	    return;
   2107  1.15.2.2  thorpej 
   2108  1.15.2.2  thorpej 	DMA_GETEND(header);	/* update request queue indices */
   2109  1.15.2.2  thorpej 
   2110  1.15.2.2  thorpej 	/*
   2111  1.15.2.2  thorpej 	* if no more DMA pending, wake up "select" client and exit
   2112  1.15.2.2  thorpej 	*/
   2113  1.15.2.2  thorpej 	if (DMA_ISEMPTY(header)) {
   2114  1.15.2.2  thorpej 		if (qdrsel[qd].si_pid && qdflags[qd].selmask & SEL_WRITE) {
   2115  1.15.2.2  thorpej 			selwakeup(&qdrsel[qd]);
   2116  1.15.2.2  thorpej 			qdrsel[qd].si_pid = 0;
   2117  1.15.2.2  thorpej 			qdflags[qd].selmask &= ~SEL_WRITE;
   2118  1.15.2.2  thorpej 		}
   2119  1.15.2.2  thorpej 		DMA_CLRACTIVE(header);  /* flag DMA done */
   2120  1.15.2.2  thorpej 		return;
   2121  1.15.2.2  thorpej 	}
   2122  1.15.2.2  thorpej 
   2123  1.15.2.2  thorpej 	/*
   2124  1.15.2.2  thorpej 	* initiate next DMA xfer
   2125  1.15.2.2  thorpej 	*/
   2126  1.15.2.2  thorpej 	request = DMA_GETBEGIN(header);
   2127  1.15.2.2  thorpej 	if (request->DMAtype != QDlast_DMAtype) {
   2128  1.15.2.2  thorpej 		dga->csr &= ~0x0600;	  /* halt DMA (reset fifo) */
   2129  1.15.2.2  thorpej 		adder->command = CANCEL;  /* cancel adder activity */
   2130  1.15.2.2  thorpej 	}
   2131  1.15.2.2  thorpej 
   2132  1.15.2.2  thorpej 
   2133  1.15.2.2  thorpej 	switch (request->DMAtype) {
   2134  1.15.2.2  thorpej 
   2135  1.15.2.2  thorpej 	case DISPLIST:
   2136  1.15.2.2  thorpej 		if (request->DMAtype != QDlast_DMAtype) {
   2137  1.15.2.2  thorpej 			dga->csr |= DL_ENB;
   2138  1.15.2.2  thorpej 			dga->csr &= ~(BTOP_ENB | BYTE_DMA);
   2139  1.15.2.2  thorpej 		}
   2140  1.15.2.2  thorpej 		break;
   2141  1.15.2.2  thorpej 
   2142  1.15.2.2  thorpej 	case PTOB:
   2143  1.15.2.2  thorpej 		if (request->DMAtype != QDlast_DMAtype) {
   2144  1.15.2.2  thorpej 			if (request->DMAdone & BYTE_PACK)
   2145  1.15.2.2  thorpej 			    dga->csr |= (PTOB_ENB | BYTE_DMA);
   2146  1.15.2.2  thorpej 			else {
   2147  1.15.2.2  thorpej 				dga->csr |= PTOB_ENB;
   2148  1.15.2.2  thorpej 				dga->csr &= ~BYTE_DMA;
   2149  1.15.2.2  thorpej 			}
   2150  1.15.2.2  thorpej 		}
   2151  1.15.2.2  thorpej 		break;
   2152  1.15.2.2  thorpej 
   2153  1.15.2.2  thorpej 	case BTOP:
   2154  1.15.2.2  thorpej 		if (request->DMAtype != QDlast_DMAtype) {
   2155  1.15.2.2  thorpej 			if (request->DMAdone & BYTE_PACK) {
   2156  1.15.2.2  thorpej 				dga->csr &= ~DL_ENB;
   2157  1.15.2.2  thorpej 				dga->csr |= (BTOP_ENB | BYTE_DMA);
   2158  1.15.2.2  thorpej 			}
   2159  1.15.2.2  thorpej 			else {
   2160  1.15.2.2  thorpej 				dga->csr |= BTOP_ENB;
   2161  1.15.2.2  thorpej 				dga->csr &= ~(BYTE_DMA | DL_ENB);
   2162  1.15.2.2  thorpej 			}
   2163  1.15.2.2  thorpej 		}
   2164  1.15.2.2  thorpej 		break;
   2165  1.15.2.2  thorpej 	default:
   2166  1.15.2.2  thorpej 		printf("qd%d: qddint: illegal DMAtype parameter.\n", qd);
   2167  1.15.2.2  thorpej 		DMA_CLRACTIVE(header);	/* flag DMA done */
   2168  1.15.2.2  thorpej 		return;
   2169  1.15.2.2  thorpej 	}
   2170  1.15.2.2  thorpej 
   2171  1.15.2.2  thorpej 	if (request->DMAdone & COUNT_ZERO) {
   2172  1.15.2.2  thorpej 		dga->csr &= ~SET_DONE_FIFO;
   2173  1.15.2.2  thorpej 	}
   2174  1.15.2.2  thorpej 	else if (request->DMAdone & FIFO_EMPTY) {
   2175  1.15.2.2  thorpej 		dga->csr |= SET_DONE_FIFO;
   2176  1.15.2.2  thorpej 	}
   2177  1.15.2.2  thorpej 
   2178  1.15.2.2  thorpej 	if (request->DMAdone & WORD_PACK)
   2179  1.15.2.2  thorpej 	    dga->csr &= ~BYTE_DMA;
   2180  1.15.2.2  thorpej 	else if (request->DMAdone & BYTE_PACK)
   2181  1.15.2.2  thorpej 	    dga->csr |= BYTE_DMA;
   2182  1.15.2.2  thorpej 
   2183  1.15.2.2  thorpej 	dga->csr |= DMA_IE;
   2184  1.15.2.2  thorpej 	QDlast_DMAtype = request->DMAtype;
   2185  1.15.2.2  thorpej 
   2186  1.15.2.2  thorpej 	cookie = ((int)request->bufp - (int)header) + (int)header->QBAreg;
   2187  1.15.2.2  thorpej 
   2188  1.15.2.2  thorpej 	dga->adrs_lo = (short) cookie;
   2189  1.15.2.2  thorpej 	dga->adrs_hi = (short) (cookie >> 16);
   2190  1.15.2.2  thorpej 
   2191  1.15.2.2  thorpej 	dga->bytcnt_lo = (short) request->length;
   2192  1.15.2.2  thorpej 	dga->bytcnt_hi = (short) (request->length >> 16);
   2193  1.15.2.2  thorpej 
   2194  1.15.2.2  thorpej 	return;
   2195  1.15.2.2  thorpej }
   2196  1.15.2.2  thorpej 
   2197  1.15.2.2  thorpej /*
   2198  1.15.2.2  thorpej  * ADDER interrupt service routine
   2199  1.15.2.2  thorpej  */
   2200  1.15.2.2  thorpej static void
   2201  1.15.2.2  thorpej qdaint(qd)
   2202  1.15.2.2  thorpej 	int qd;
   2203  1.15.2.2  thorpej {
   2204  1.15.2.2  thorpej 	volatile register struct adder *adder;
   2205  1.15.2.2  thorpej 	struct color_buf *cbuf;
   2206  1.15.2.2  thorpej 	int i;
   2207  1.15.2.2  thorpej 	register struct rgb *rgbp;
   2208  1.15.2.2  thorpej 	volatile register short *red;
   2209  1.15.2.2  thorpej 	volatile register short *green;
   2210  1.15.2.2  thorpej 	volatile register short *blue;
   2211  1.15.2.2  thorpej 
   2212  1.15.2.2  thorpej 	(void)spl4(); 			/* allow interval timer in */
   2213  1.15.2.2  thorpej 
   2214  1.15.2.2  thorpej 	adder = (struct adder *) qdmap[qd].adder;
   2215  1.15.2.2  thorpej 
   2216  1.15.2.2  thorpej 	/*
   2217  1.15.2.2  thorpej 	* service the vertical blank interrupt (VSYNC bit) by loading
   2218  1.15.2.2  thorpej 	* any pending color map load request
   2219  1.15.2.2  thorpej 	*/
   2220  1.15.2.2  thorpej 	if (adder->status & VSYNC) {
   2221  1.15.2.2  thorpej 		adder->status &= ~VSYNC;	/* clear the interrupt */
   2222  1.15.2.2  thorpej 		cbuf = color_buf[qd];
   2223  1.15.2.2  thorpej 		if (cbuf->status & LOAD_COLOR_MAP) {
   2224  1.15.2.2  thorpej 
   2225  1.15.2.2  thorpej 			red = (short *) qdmap[qd].red;
   2226  1.15.2.2  thorpej 			green = (short *) qdmap[qd].green;
   2227  1.15.2.2  thorpej 			blue = (short *) qdmap[qd].blue;
   2228  1.15.2.2  thorpej 
   2229  1.15.2.2  thorpej 			for (i = cbuf->count, rgbp = cbuf->rgb;
   2230  1.15.2.2  thorpej 			     --i >= 0; rgbp++) {
   2231  1.15.2.2  thorpej 				red[rgbp->offset] = (short) rgbp->red;
   2232  1.15.2.2  thorpej 				green[rgbp->offset] = (short) rgbp->green;
   2233  1.15.2.2  thorpej 				blue[rgbp->offset] = (short) rgbp->blue;
   2234  1.15.2.2  thorpej 			}
   2235  1.15.2.2  thorpej 
   2236  1.15.2.2  thorpej 			cbuf->status &= ~LOAD_COLOR_MAP;
   2237  1.15.2.2  thorpej 		}
   2238  1.15.2.2  thorpej 	}
   2239  1.15.2.2  thorpej 
   2240  1.15.2.2  thorpej 	/*
   2241  1.15.2.2  thorpej 	* service the scroll interrupt (FRAME_SYNC bit)
   2242  1.15.2.2  thorpej 	*/
   2243  1.15.2.2  thorpej 	if (adder->status & FRAME_SYNC) {
   2244  1.15.2.2  thorpej 		adder->status &= ~FRAME_SYNC;	/* clear the interrupt */
   2245  1.15.2.2  thorpej 
   2246  1.15.2.2  thorpej 		if (scroll[qd]->status & LOAD_REGS) {
   2247  1.15.2.2  thorpej 
   2248  1.15.2.2  thorpej 			for (i = 1000, adder->status = 0; i > 0 &&
   2249  1.15.2.2  thorpej 			     !(adder->status&ID_SCROLL_READY); --i)
   2250  1.15.2.2  thorpej 			      ;
   2251  1.15.2.2  thorpej 
   2252  1.15.2.2  thorpej 			if (i == 0) {
   2253  1.15.2.2  thorpej 			    printf("qd%d: qdaint: timeout on ID_SCROLL_READY\n",
   2254  1.15.2.2  thorpej 				qd);
   2255  1.15.2.2  thorpej 				return;
   2256  1.15.2.2  thorpej 			}
   2257  1.15.2.2  thorpej 
   2258  1.15.2.2  thorpej 			adder->ID_scroll_data = scroll[qd]->viper_constant;
   2259  1.15.2.2  thorpej 			adder->ID_scroll_command = ID_LOAD | SCROLL_CONSTANT;
   2260  1.15.2.2  thorpej 
   2261  1.15.2.2  thorpej 			adder->y_scroll_constant =
   2262  1.15.2.2  thorpej 				scroll[qd]->y_scroll_constant;
   2263  1.15.2.2  thorpej 			adder->y_offset_pending = scroll[qd]->y_offset;
   2264  1.15.2.2  thorpej 
   2265  1.15.2.2  thorpej 			if (scroll[qd]->status & LOAD_INDEX) {
   2266  1.15.2.2  thorpej 
   2267  1.15.2.2  thorpej 				adder->x_index_pending =
   2268  1.15.2.2  thorpej 					scroll[qd]->x_index_pending;
   2269  1.15.2.2  thorpej 				adder->y_index_pending =
   2270  1.15.2.2  thorpej 					scroll[qd]->y_index_pending;
   2271  1.15.2.2  thorpej 			}
   2272  1.15.2.2  thorpej 
   2273  1.15.2.2  thorpej 			scroll[qd]->status = 0x00;
   2274  1.15.2.2  thorpej 		}
   2275  1.15.2.2  thorpej 	}
   2276  1.15.2.2  thorpej }
   2277  1.15.2.2  thorpej 
   2278  1.15.2.2  thorpej /*
   2279  1.15.2.2  thorpej  *  DUART input interrupt service routine
   2280  1.15.2.2  thorpej  *
   2281  1.15.2.2  thorpej  *  XXX - this routine should be broken out - it is essentially
   2282  1.15.2.2  thorpej  *	      straight line code.
   2283  1.15.2.2  thorpej  */
   2284  1.15.2.2  thorpej 
   2285  1.15.2.2  thorpej static void
   2286  1.15.2.2  thorpej qdiint(qd)
   2287  1.15.2.2  thorpej 	int qd;
   2288  1.15.2.2  thorpej {
   2289  1.15.2.2  thorpej 	register struct _vs_event *event;
   2290  1.15.2.2  thorpej 	register struct qdinput *eqh;
   2291  1.15.2.2  thorpej 	volatile struct dga *dga;
   2292  1.15.2.2  thorpej 	volatile struct duart *duart;
   2293  1.15.2.2  thorpej 	struct mouse_report *new_rep;
   2294  1.15.2.2  thorpej 	struct tty *tp;
   2295  1.15.2.2  thorpej 	u_short chr;
   2296  1.15.2.2  thorpej 	u_short status;
   2297  1.15.2.2  thorpej 	u_short data;
   2298  1.15.2.2  thorpej 	u_short key;
   2299  1.15.2.2  thorpej 	char do_wakeup = 0;		/* flag to do a select wakeup call */
   2300  1.15.2.2  thorpej 	char a, b, c;			/* mouse button test variables */
   2301  1.15.2.2  thorpej 
   2302  1.15.2.2  thorpej 	(void)spl4(); 			/* allow interval timer in */
   2303  1.15.2.2  thorpej 
   2304  1.15.2.2  thorpej 	eqh = eq_header[qd];		/* optimized as a register */
   2305  1.15.2.2  thorpej 	new_rep = &current_rep[qd];
   2306  1.15.2.2  thorpej 	duart = (struct duart *) qdmap[qd].duart;
   2307  1.15.2.2  thorpej 
   2308  1.15.2.2  thorpej 	/*
   2309  1.15.2.2  thorpej 	* if the graphic device is turned on..
   2310  1.15.2.2  thorpej 	*/
   2311  1.15.2.2  thorpej 	if (qdflags[qd].inuse & GRAPHIC_DEV) {
   2312  1.15.2.2  thorpej 		/*
   2313  1.15.2.2  thorpej 		* empty DUART
   2314  1.15.2.2  thorpej 		*/
   2315  1.15.2.2  thorpej 		while (duart->statusA&RCV_RDY || duart->statusB&RCV_RDY) {
   2316  1.15.2.2  thorpej 			/*
   2317  1.15.2.2  thorpej 			 * pick up LK-201 input (if any)
   2318  1.15.2.2  thorpej 			 */
   2319  1.15.2.2  thorpej 			if (duart->statusA&RCV_RDY) {
   2320  1.15.2.2  thorpej 
   2321  1.15.2.2  thorpej 				/* if error condition, then reset it */
   2322  1.15.2.2  thorpej 
   2323  1.15.2.2  thorpej 				if (duart->statusA&0x70) {
   2324  1.15.2.2  thorpej 					duart->cmdA = 0x40;
   2325  1.15.2.2  thorpej 					continue;
   2326  1.15.2.2  thorpej 				}
   2327  1.15.2.2  thorpej 
   2328  1.15.2.2  thorpej 				/* event queue full now? (overflow condition) */
   2329  1.15.2.2  thorpej 
   2330  1.15.2.2  thorpej 				if (ISFULL(eqh) == TRUE) {
   2331  1.15.2.2  thorpej 					printf(
   2332  1.15.2.2  thorpej 					 "qd%d: qdiint: event queue overflow\n",
   2333  1.15.2.2  thorpej 					   qd);
   2334  1.15.2.2  thorpej 					break;
   2335  1.15.2.2  thorpej 				}
   2336  1.15.2.2  thorpej 
   2337  1.15.2.2  thorpej 				/*
   2338  1.15.2.2  thorpej 				* Check for various keyboard errors  */
   2339  1.15.2.2  thorpej 
   2340  1.15.2.2  thorpej 				key = duart->dataA & 0xFF;
   2341  1.15.2.2  thorpej 
   2342  1.15.2.2  thorpej 				if (key==LK_POWER_ERROR ||
   2343  1.15.2.2  thorpej 				    key==LK_KDOWN_ERROR ||
   2344  1.15.2.2  thorpej 				    key == LK_INPUT_ERROR ||
   2345  1.15.2.2  thorpej 				    key == LK_OUTPUT_ERROR) {
   2346  1.15.2.2  thorpej 					printf(
   2347  1.15.2.2  thorpej 				    "qd%d: qdiint: keyboard error, code = %x\n",
   2348  1.15.2.2  thorpej 					qd,key);
   2349  1.15.2.2  thorpej 					return;
   2350  1.15.2.2  thorpej 				}
   2351  1.15.2.2  thorpej 
   2352  1.15.2.2  thorpej 				if (key < LK_LOWEST)
   2353  1.15.2.2  thorpej 				    return;
   2354  1.15.2.2  thorpej 
   2355  1.15.2.2  thorpej 				++do_wakeup;  /* request a select wakeup call */
   2356  1.15.2.2  thorpej 
   2357  1.15.2.2  thorpej 				event = PUTBEGIN(eqh);
   2358  1.15.2.2  thorpej 				PUTEND(eqh);
   2359  1.15.2.2  thorpej 
   2360  1.15.2.2  thorpej 				event->vse_key = key;
   2361  1.15.2.2  thorpej 				event->vse_key &= 0x00FF;
   2362  1.15.2.2  thorpej 				event->vse_x = eqh->curs_pos.x;
   2363  1.15.2.2  thorpej 				event->vse_y = eqh->curs_pos.y;
   2364  1.15.2.2  thorpej 				event->vse_time = TOY;
   2365  1.15.2.2  thorpej 				event->vse_type = VSE_BUTTON;
   2366  1.15.2.2  thorpej 				event->vse_direction = VSE_KBTRAW;
   2367  1.15.2.2  thorpej 				event->vse_device = VSE_DKB;
   2368  1.15.2.2  thorpej 			}
   2369  1.15.2.2  thorpej 
   2370  1.15.2.2  thorpej 			/*
   2371  1.15.2.2  thorpej 			* pick up the mouse input (if any)  */
   2372  1.15.2.2  thorpej 
   2373  1.15.2.2  thorpej 			if ((status = duart->statusB) & RCV_RDY  &&
   2374  1.15.2.2  thorpej 			    qdflags[qd].pntr_id == MOUSE_ID) {
   2375  1.15.2.2  thorpej 
   2376  1.15.2.2  thorpej 				if (status & 0x70) {
   2377  1.15.2.2  thorpej 					duart->cmdB = 0x40;
   2378  1.15.2.2  thorpej 					continue;
   2379  1.15.2.2  thorpej 				}
   2380  1.15.2.2  thorpej 
   2381  1.15.2.2  thorpej 				/* event queue full now? (overflow condition) */
   2382  1.15.2.2  thorpej 
   2383  1.15.2.2  thorpej 				if (ISFULL(eqh) == TRUE) {
   2384  1.15.2.2  thorpej 					printf(
   2385  1.15.2.2  thorpej 					"qd%d: qdiint: event queue overflow\n",
   2386  1.15.2.2  thorpej 					     qd);
   2387  1.15.2.2  thorpej 					break;
   2388  1.15.2.2  thorpej 				}
   2389  1.15.2.2  thorpej 
   2390  1.15.2.2  thorpej 				data = duart->dataB;      /* get report byte */
   2391  1.15.2.2  thorpej 				++new_rep->bytcnt; /* bump report byte count */
   2392  1.15.2.2  thorpej 
   2393  1.15.2.2  thorpej 				/*
   2394  1.15.2.2  thorpej 				* if 1st byte of report.. */
   2395  1.15.2.2  thorpej 
   2396  1.15.2.2  thorpej 				if ( data & START_FRAME) {
   2397  1.15.2.2  thorpej 					new_rep->state = data;
   2398  1.15.2.2  thorpej 					if (new_rep->bytcnt > 1) {
   2399  1.15.2.2  thorpej 						/* start of new frame */
   2400  1.15.2.2  thorpej 						new_rep->bytcnt = 1;
   2401  1.15.2.2  thorpej 						/* ..continue looking */
   2402  1.15.2.2  thorpej 						continue;
   2403  1.15.2.2  thorpej 					}
   2404  1.15.2.2  thorpej 				}
   2405  1.15.2.2  thorpej 
   2406  1.15.2.2  thorpej 				/*
   2407  1.15.2.2  thorpej 				* if 2nd byte of report.. */
   2408  1.15.2.2  thorpej 
   2409  1.15.2.2  thorpej 				else if (new_rep->bytcnt == 2) {
   2410  1.15.2.2  thorpej 					new_rep->dx = data & 0x00FF;
   2411  1.15.2.2  thorpej 				}
   2412  1.15.2.2  thorpej 
   2413  1.15.2.2  thorpej 				/*
   2414  1.15.2.2  thorpej 				* if 3rd byte of report, load input event queue */
   2415  1.15.2.2  thorpej 
   2416  1.15.2.2  thorpej 				else if (new_rep->bytcnt == 3) {
   2417  1.15.2.2  thorpej 
   2418  1.15.2.2  thorpej 					new_rep->dy = data & 0x00FF;
   2419  1.15.2.2  thorpej 					new_rep->bytcnt = 0;
   2420  1.15.2.2  thorpej 
   2421  1.15.2.2  thorpej 					/*
   2422  1.15.2.2  thorpej 					* if mouse position has changed.. */
   2423  1.15.2.2  thorpej 
   2424  1.15.2.2  thorpej 					if (new_rep->dx != 0  ||  new_rep->dy != 0) {
   2425  1.15.2.2  thorpej 
   2426  1.15.2.2  thorpej 						/*
   2427  1.15.2.2  thorpej 						* calculate acceleration factor, if needed	*/
   2428  1.15.2.2  thorpej 
   2429  1.15.2.2  thorpej 						if (qdflags[qd].curs_acc > ACC_OFF) {
   2430  1.15.2.2  thorpej 
   2431  1.15.2.2  thorpej 							if (qdflags[qd].curs_thr <= new_rep->dx)
   2432  1.15.2.2  thorpej 							    new_rep->dx +=
   2433  1.15.2.2  thorpej 							    (new_rep->dx - qdflags[qd].curs_thr)
   2434  1.15.2.2  thorpej 							    * qdflags[qd].curs_acc;
   2435  1.15.2.2  thorpej 
   2436  1.15.2.2  thorpej 							if (qdflags[qd].curs_thr <= new_rep->dy)
   2437  1.15.2.2  thorpej 							    new_rep->dy +=
   2438  1.15.2.2  thorpej 							    (new_rep->dy - qdflags[qd].curs_thr)
   2439  1.15.2.2  thorpej 							    * qdflags[qd].curs_acc;
   2440  1.15.2.2  thorpej 						}
   2441  1.15.2.2  thorpej 
   2442  1.15.2.2  thorpej 						/*
   2443  1.15.2.2  thorpej 						* update cursor position coordinates */
   2444  1.15.2.2  thorpej 
   2445  1.15.2.2  thorpej 						if (new_rep->state & X_SIGN) {
   2446  1.15.2.2  thorpej 							eqh->curs_pos.x += new_rep->dx;
   2447  1.15.2.2  thorpej 							if (eqh->curs_pos.x > 1023)
   2448  1.15.2.2  thorpej 							    eqh->curs_pos.x = 1023;
   2449  1.15.2.2  thorpej 						}
   2450  1.15.2.2  thorpej 						else {
   2451  1.15.2.2  thorpej 							eqh->curs_pos.x -= new_rep->dx;
   2452  1.15.2.2  thorpej 							if (eqh->curs_pos.x < -15)
   2453  1.15.2.2  thorpej 							    eqh->curs_pos.x = -15;
   2454  1.15.2.2  thorpej 						}
   2455  1.15.2.2  thorpej 
   2456  1.15.2.2  thorpej 						if (new_rep->state & Y_SIGN) {
   2457  1.15.2.2  thorpej 							eqh->curs_pos.y -= new_rep->dy;
   2458  1.15.2.2  thorpej 							if (eqh->curs_pos.y < -15)
   2459  1.15.2.2  thorpej 							    eqh->curs_pos.y = -15;
   2460  1.15.2.2  thorpej 						}
   2461  1.15.2.2  thorpej 						else {
   2462  1.15.2.2  thorpej 							eqh->curs_pos.y += new_rep->dy;
   2463  1.15.2.2  thorpej 							if (eqh->curs_pos.y > 863)
   2464  1.15.2.2  thorpej 							    eqh->curs_pos.y = 863;
   2465  1.15.2.2  thorpej 						}
   2466  1.15.2.2  thorpej 
   2467  1.15.2.2  thorpej 						/*
   2468  1.15.2.2  thorpej 						* update cursor screen position */
   2469  1.15.2.2  thorpej 
   2470  1.15.2.2  thorpej 						dga = (struct dga *) qdmap[qd].dga;
   2471  1.15.2.2  thorpej 						dga->x_cursor = TRANX(eqh->curs_pos.x);
   2472  1.15.2.2  thorpej 						dga->y_cursor = TRANY(eqh->curs_pos.y);
   2473  1.15.2.2  thorpej 
   2474  1.15.2.2  thorpej 						/*
   2475  1.15.2.2  thorpej 						* if cursor is in the box, no event report */
   2476  1.15.2.2  thorpej 
   2477  1.15.2.2  thorpej 						if (eqh->curs_pos.x <= eqh->curs_box.right	&&
   2478  1.15.2.2  thorpej 						    eqh->curs_pos.x >= eqh->curs_box.left  &&
   2479  1.15.2.2  thorpej 						    eqh->curs_pos.y >= eqh->curs_box.top  &&
   2480  1.15.2.2  thorpej 						    eqh->curs_pos.y <= eqh->curs_box.bottom ) {
   2481  1.15.2.2  thorpej 							goto GET_MBUTTON;
   2482  1.15.2.2  thorpej 						}
   2483  1.15.2.2  thorpej 
   2484  1.15.2.2  thorpej 						/*
   2485  1.15.2.2  thorpej 						* report the mouse motion event */
   2486  1.15.2.2  thorpej 
   2487  1.15.2.2  thorpej 						event = PUTBEGIN(eqh);
   2488  1.15.2.2  thorpej 						PUTEND(eqh);
   2489  1.15.2.2  thorpej 
   2490  1.15.2.2  thorpej 						++do_wakeup;   /* request a select wakeup call */
   2491  1.15.2.2  thorpej 
   2492  1.15.2.2  thorpej 						event->vse_x = eqh->curs_pos.x;
   2493  1.15.2.2  thorpej 						event->vse_y = eqh->curs_pos.y;
   2494  1.15.2.2  thorpej 
   2495  1.15.2.2  thorpej 						event->vse_device = VSE_MOUSE;  /* mouse */
   2496  1.15.2.2  thorpej 						event->vse_type = VSE_MMOTION;  /* pos changed */
   2497  1.15.2.2  thorpej 						event->vse_key = 0;
   2498  1.15.2.2  thorpej 						event->vse_direction = 0;
   2499  1.15.2.2  thorpej 						event->vse_time = TOY;	/* time stamp */
   2500  1.15.2.2  thorpej 					}
   2501  1.15.2.2  thorpej 
   2502  1.15.2.2  thorpej GET_MBUTTON:
   2503  1.15.2.2  thorpej 					/*
   2504  1.15.2.2  thorpej 					* if button state has changed */
   2505  1.15.2.2  thorpej 
   2506  1.15.2.2  thorpej 					a = new_rep->state & 0x07;    /*mask nonbutton bits */
   2507  1.15.2.2  thorpej 					b = last_rep[qd].state & 0x07;
   2508  1.15.2.2  thorpej 
   2509  1.15.2.2  thorpej 					if (a ^ b) {
   2510  1.15.2.2  thorpej 
   2511  1.15.2.2  thorpej 						for ( c = 1;  c < 8; c <<= 1) {
   2512  1.15.2.2  thorpej 
   2513  1.15.2.2  thorpej 							if (!( c & (a ^ b))) /* this button change? */
   2514  1.15.2.2  thorpej 							    continue;
   2515  1.15.2.2  thorpej 
   2516  1.15.2.2  thorpej 							/* event queue full? (overflow condition) */
   2517  1.15.2.2  thorpej 
   2518  1.15.2.2  thorpej 							if (ISFULL(eqh) == TRUE) {
   2519  1.15.2.2  thorpej 								printf("qd%d: qdiint: event queue overflow\n", qd);
   2520  1.15.2.2  thorpej 								break;
   2521  1.15.2.2  thorpej 							}
   2522  1.15.2.2  thorpej 
   2523  1.15.2.2  thorpej 							event = PUTBEGIN(eqh);	/* get new event */
   2524  1.15.2.2  thorpej 							PUTEND(eqh);
   2525  1.15.2.2  thorpej 
   2526  1.15.2.2  thorpej 							++do_wakeup;   /* request select wakeup */
   2527  1.15.2.2  thorpej 
   2528  1.15.2.2  thorpej 							event->vse_x = eqh->curs_pos.x;
   2529  1.15.2.2  thorpej 							event->vse_y = eqh->curs_pos.y;
   2530  1.15.2.2  thorpej 
   2531  1.15.2.2  thorpej 							event->vse_device = VSE_MOUSE;	/* mouse */
   2532  1.15.2.2  thorpej 							event->vse_type = VSE_BUTTON; /* new button */
   2533  1.15.2.2  thorpej 							event->vse_time = TOY;	      /* time stamp */
   2534  1.15.2.2  thorpej 
   2535  1.15.2.2  thorpej 							/* flag changed button and if up or down */
   2536  1.15.2.2  thorpej 
   2537  1.15.2.2  thorpej 							if (c == RIGHT_BUTTON)
   2538  1.15.2.2  thorpej 							    event->vse_key = VSE_RIGHT_BUTTON;
   2539  1.15.2.2  thorpej 							else if (c == MIDDLE_BUTTON)
   2540  1.15.2.2  thorpej 							    event->vse_key = VSE_MIDDLE_BUTTON;
   2541  1.15.2.2  thorpej 							else if (c == LEFT_BUTTON)
   2542  1.15.2.2  thorpej 							    event->vse_key = VSE_LEFT_BUTTON;
   2543  1.15.2.2  thorpej 
   2544  1.15.2.2  thorpej 							/* set bit = button depressed */
   2545  1.15.2.2  thorpej 
   2546  1.15.2.2  thorpej 							if (c & a)
   2547  1.15.2.2  thorpej 							    event->vse_direction = VSE_KBTDOWN;
   2548  1.15.2.2  thorpej 							else
   2549  1.15.2.2  thorpej 								event->vse_direction = VSE_KBTUP;
   2550  1.15.2.2  thorpej 						}
   2551  1.15.2.2  thorpej 					}
   2552  1.15.2.2  thorpej 
   2553  1.15.2.2  thorpej 					/* refresh last report */
   2554  1.15.2.2  thorpej 
   2555  1.15.2.2  thorpej 					last_rep[qd] = current_rep[qd];
   2556  1.15.2.2  thorpej 
   2557  1.15.2.2  thorpej 				}  /* get last byte of report */
   2558  1.15.2.2  thorpej 			} else if ((status = duart->statusB)&RCV_RDY &&
   2559  1.15.2.2  thorpej 				   qdflags[qd].pntr_id == TABLET_ID) {
   2560  1.15.2.2  thorpej 				/*
   2561  1.15.2.2  thorpej 				* pickup tablet input, if any
   2562  1.15.2.2  thorpej 				*/
   2563  1.15.2.2  thorpej 				if (status&0x70) {
   2564  1.15.2.2  thorpej 					duart->cmdB = 0x40;
   2565  1.15.2.2  thorpej 					continue;
   2566  1.15.2.2  thorpej 				}
   2567  1.15.2.2  thorpej 				/*
   2568  1.15.2.2  thorpej 				 * event queue full now? (overflow condition)
   2569  1.15.2.2  thorpej 				 */
   2570  1.15.2.2  thorpej 				if (ISFULL(eqh) == TRUE) {
   2571  1.15.2.2  thorpej 					printf("qd%d: qdiint: event queue overflow\n", qd);
   2572  1.15.2.2  thorpej 					break;
   2573  1.15.2.2  thorpej 				}
   2574  1.15.2.2  thorpej 
   2575  1.15.2.2  thorpej 				data = duart->dataB;      /* get report byte */
   2576  1.15.2.2  thorpej 				++new_rep->bytcnt;	      /* bump report byte count */
   2577  1.15.2.2  thorpej 
   2578  1.15.2.2  thorpej 				/*
   2579  1.15.2.2  thorpej 				* if 1st byte of report.. */
   2580  1.15.2.2  thorpej 
   2581  1.15.2.2  thorpej 				if (data & START_FRAME) {
   2582  1.15.2.2  thorpej 					new_rep->state = data;
   2583  1.15.2.2  thorpej 					if (new_rep->bytcnt > 1) {
   2584  1.15.2.2  thorpej 						new_rep->bytcnt = 1;    /* start of new frame */
   2585  1.15.2.2  thorpej 						continue;		    /* ..continue looking */
   2586  1.15.2.2  thorpej 					}
   2587  1.15.2.2  thorpej 				}
   2588  1.15.2.2  thorpej 
   2589  1.15.2.2  thorpej 				/*
   2590  1.15.2.2  thorpej 				* if 2nd byte of report.. */
   2591  1.15.2.2  thorpej 
   2592  1.15.2.2  thorpej 				else if (new_rep->bytcnt == 2) {
   2593  1.15.2.2  thorpej 					new_rep->dx = data & 0x3F;
   2594  1.15.2.2  thorpej 				}
   2595  1.15.2.2  thorpej 
   2596  1.15.2.2  thorpej 				/*
   2597  1.15.2.2  thorpej 				* if 3rd byte of report.. */
   2598  1.15.2.2  thorpej 
   2599  1.15.2.2  thorpej 				else if (new_rep->bytcnt == 3) {
   2600  1.15.2.2  thorpej 					new_rep->dx |= (data & 0x3F) << 6;
   2601  1.15.2.2  thorpej 				}
   2602  1.15.2.2  thorpej 
   2603  1.15.2.2  thorpej 				/*
   2604  1.15.2.2  thorpej 				* if 4th byte of report.. */
   2605  1.15.2.2  thorpej 
   2606  1.15.2.2  thorpej 				else if (new_rep->bytcnt == 4) {
   2607  1.15.2.2  thorpej 					new_rep->dy = data & 0x3F;
   2608  1.15.2.2  thorpej 				}
   2609  1.15.2.2  thorpej 
   2610  1.15.2.2  thorpej 				/*
   2611  1.15.2.2  thorpej 				* if 5th byte of report, load input event queue */
   2612  1.15.2.2  thorpej 
   2613  1.15.2.2  thorpej 				else if (new_rep->bytcnt == 5) {
   2614  1.15.2.2  thorpej 
   2615  1.15.2.2  thorpej 					new_rep->dy |= (data & 0x3F) << 6;
   2616  1.15.2.2  thorpej 					new_rep->bytcnt = 0;
   2617  1.15.2.2  thorpej 
   2618  1.15.2.2  thorpej 					/*
   2619  1.15.2.2  thorpej 					* update cursor position coordinates */
   2620  1.15.2.2  thorpej 
   2621  1.15.2.2  thorpej 					new_rep->dx /= qdflags[qd].tab_res;
   2622  1.15.2.2  thorpej 					new_rep->dy = (2200 - new_rep->dy)
   2623  1.15.2.2  thorpej 					    / qdflags[qd].tab_res;
   2624  1.15.2.2  thorpej 
   2625  1.15.2.2  thorpej 					if (new_rep->dx > 1023) {
   2626  1.15.2.2  thorpej 						new_rep->dx = 1023;
   2627  1.15.2.2  thorpej 					}
   2628  1.15.2.2  thorpej 					if (new_rep->dy > 863) {
   2629  1.15.2.2  thorpej 						new_rep->dy = 863;
   2630  1.15.2.2  thorpej 					}
   2631  1.15.2.2  thorpej 
   2632  1.15.2.2  thorpej 					/*
   2633  1.15.2.2  thorpej 					* report an event if the puck/stylus has moved
   2634  1.15.2.2  thorpej 					*/
   2635  1.15.2.2  thorpej 
   2636  1.15.2.2  thorpej 					if (eqh->curs_pos.x != new_rep->dx ||
   2637  1.15.2.2  thorpej 					    eqh->curs_pos.y != new_rep->dy) {
   2638  1.15.2.2  thorpej 
   2639  1.15.2.2  thorpej 						eqh->curs_pos.x = new_rep->dx;
   2640  1.15.2.2  thorpej 						eqh->curs_pos.y = new_rep->dy;
   2641  1.15.2.2  thorpej 
   2642  1.15.2.2  thorpej 						/*
   2643  1.15.2.2  thorpej 						* update cursor screen position */
   2644  1.15.2.2  thorpej 
   2645  1.15.2.2  thorpej 						dga = (struct dga *) qdmap[qd].dga;
   2646  1.15.2.2  thorpej 						dga->x_cursor = TRANX(eqh->curs_pos.x);
   2647  1.15.2.2  thorpej 						dga->y_cursor = TRANY(eqh->curs_pos.y);
   2648  1.15.2.2  thorpej 
   2649  1.15.2.2  thorpej 						/*
   2650  1.15.2.2  thorpej 						* if cursor is in the box, no event report
   2651  1.15.2.2  thorpej 						*/
   2652  1.15.2.2  thorpej 
   2653  1.15.2.2  thorpej 						if (eqh->curs_pos.x <= eqh->curs_box.right	&&
   2654  1.15.2.2  thorpej 						    eqh->curs_pos.x >= eqh->curs_box.left  &&
   2655  1.15.2.2  thorpej 						    eqh->curs_pos.y >= eqh->curs_box.top  &&
   2656  1.15.2.2  thorpej 						    eqh->curs_pos.y <= eqh->curs_box.bottom ) {
   2657  1.15.2.2  thorpej 							goto GET_TBUTTON;
   2658  1.15.2.2  thorpej 						}
   2659  1.15.2.2  thorpej 
   2660  1.15.2.2  thorpej 						/*
   2661  1.15.2.2  thorpej 						* report the tablet motion event */
   2662  1.15.2.2  thorpej 
   2663  1.15.2.2  thorpej 						event = PUTBEGIN(eqh);
   2664  1.15.2.2  thorpej 						PUTEND(eqh);
   2665  1.15.2.2  thorpej 
   2666  1.15.2.2  thorpej 						++do_wakeup;   /* request a select wakeup call */
   2667  1.15.2.2  thorpej 
   2668  1.15.2.2  thorpej 						event->vse_x = eqh->curs_pos.x;
   2669  1.15.2.2  thorpej 						event->vse_y = eqh->curs_pos.y;
   2670  1.15.2.2  thorpej 
   2671  1.15.2.2  thorpej 						event->vse_device = VSE_TABLET;  /* tablet */
   2672  1.15.2.2  thorpej 						/*
   2673  1.15.2.2  thorpej 						* right now, X handles tablet motion the same
   2674  1.15.2.2  thorpej 						* as mouse motion
   2675  1.15.2.2  thorpej 						*/
   2676  1.15.2.2  thorpej 						event->vse_type = VSE_MMOTION;   /* pos changed */
   2677  1.15.2.2  thorpej 						event->vse_key = 0;
   2678  1.15.2.2  thorpej 						event->vse_direction = 0;
   2679  1.15.2.2  thorpej 						event->vse_time = TOY;	/* time stamp */
   2680  1.15.2.2  thorpej 					}
   2681  1.15.2.2  thorpej GET_TBUTTON:
   2682  1.15.2.2  thorpej 					/*
   2683  1.15.2.2  thorpej 					* if button state has changed */
   2684  1.15.2.2  thorpej 
   2685  1.15.2.2  thorpej 					a = new_rep->state & 0x1E;   /* mask nonbutton bits */
   2686  1.15.2.2  thorpej 					b = last_rep[qd].state & 0x1E;
   2687  1.15.2.2  thorpej 
   2688  1.15.2.2  thorpej 					if (a ^ b) {
   2689  1.15.2.2  thorpej 
   2690  1.15.2.2  thorpej 						/* event queue full now? (overflow condition) */
   2691  1.15.2.2  thorpej 
   2692  1.15.2.2  thorpej 						if (ISFULL(eqh) == TRUE) {
   2693  1.15.2.2  thorpej 							printf("qd%d: qdiint: event queue overflow\n",qd);
   2694  1.15.2.2  thorpej 							break;
   2695  1.15.2.2  thorpej 						}
   2696  1.15.2.2  thorpej 
   2697  1.15.2.2  thorpej 						event = PUTBEGIN(eqh);  /* get new event */
   2698  1.15.2.2  thorpej 						PUTEND(eqh);
   2699  1.15.2.2  thorpej 
   2700  1.15.2.2  thorpej 						++do_wakeup;   /* request a select wakeup call */
   2701  1.15.2.2  thorpej 
   2702  1.15.2.2  thorpej 						event->vse_x = eqh->curs_pos.x;
   2703  1.15.2.2  thorpej 						event->vse_y = eqh->curs_pos.y;
   2704  1.15.2.2  thorpej 
   2705  1.15.2.2  thorpej 						event->vse_device = VSE_TABLET;  /* tablet */
   2706  1.15.2.2  thorpej 						event->vse_type = VSE_BUTTON; /* button changed */
   2707  1.15.2.2  thorpej 						event->vse_time = TOY;	   /* time stamp */
   2708  1.15.2.2  thorpej 
   2709  1.15.2.2  thorpej 						/* define the changed button and if up or down */
   2710  1.15.2.2  thorpej 
   2711  1.15.2.2  thorpej 						for ( c = 1;  c <= 0x10; c <<= 1) {
   2712  1.15.2.2  thorpej 							if (c & (a ^ b)) {
   2713  1.15.2.2  thorpej 								if (c == T_LEFT_BUTTON)
   2714  1.15.2.2  thorpej 								    event->vse_key = VSE_T_LEFT_BUTTON;
   2715  1.15.2.2  thorpej 								else if (c == T_FRONT_BUTTON)
   2716  1.15.2.2  thorpej 								    event->vse_key = VSE_T_FRONT_BUTTON;
   2717  1.15.2.2  thorpej 								else if (c == T_RIGHT_BUTTON)
   2718  1.15.2.2  thorpej 								    event->vse_key = VSE_T_RIGHT_BUTTON;
   2719  1.15.2.2  thorpej 								else if (c == T_BACK_BUTTON)
   2720  1.15.2.2  thorpej 								    event->vse_key = VSE_T_BACK_BUTTON;
   2721  1.15.2.2  thorpej 								break;
   2722  1.15.2.2  thorpej 							}
   2723  1.15.2.2  thorpej 						}
   2724  1.15.2.2  thorpej 
   2725  1.15.2.2  thorpej 						/* set bit = button depressed */
   2726  1.15.2.2  thorpej 
   2727  1.15.2.2  thorpej 						if (c & a)
   2728  1.15.2.2  thorpej 						    event->vse_direction = VSE_KBTDOWN;
   2729  1.15.2.2  thorpej 						else
   2730  1.15.2.2  thorpej 							event->vse_direction = VSE_KBTUP;
   2731  1.15.2.2  thorpej 					}
   2732  1.15.2.2  thorpej 
   2733  1.15.2.2  thorpej 					/* refresh last report */
   2734  1.15.2.2  thorpej 
   2735  1.15.2.2  thorpej 					last_rep[qd] = current_rep[qd];
   2736  1.15.2.2  thorpej 
   2737  1.15.2.2  thorpej 				} /* get last byte of report */
   2738  1.15.2.2  thorpej 			} /* pick up tablet input */
   2739  1.15.2.2  thorpej 
   2740  1.15.2.2  thorpej 		} /* while input available.. */
   2741  1.15.2.2  thorpej 
   2742  1.15.2.2  thorpej 		/*
   2743  1.15.2.2  thorpej 		* do select wakeup
   2744  1.15.2.2  thorpej 		*/
   2745  1.15.2.2  thorpej 		if (qdrsel[qd].si_pid && do_wakeup && qdflags[qd].selmask & SEL_READ) {
   2746  1.15.2.2  thorpej 			selwakeup(&qdrsel[qd]);
   2747  1.15.2.2  thorpej 			qdrsel[qd].si_pid = 0;
   2748  1.15.2.2  thorpej 			qdflags[qd].selmask &= ~SEL_READ;
   2749  1.15.2.2  thorpej 			do_wakeup = 0;
   2750  1.15.2.2  thorpej 		}
   2751  1.15.2.2  thorpej 	} else {
   2752  1.15.2.2  thorpej 		/*
   2753  1.15.2.2  thorpej 		 * if the graphic device is not turned on, this is console input
   2754  1.15.2.2  thorpej 		 */
   2755  1.15.2.2  thorpej 		if (qdpolling)
   2756  1.15.2.2  thorpej 			return;
   2757  1.15.2.2  thorpej 
   2758  1.15.2.2  thorpej 		if (qd >= qd_cd.cd_ndevs || qd_cd.cd_devs[qd] == NULL)
   2759  1.15.2.2  thorpej 			return;		/* no such device or address */
   2760  1.15.2.2  thorpej 
   2761  1.15.2.2  thorpej 		tp = qd_tty[qd << 2];
   2762  1.15.2.2  thorpej 
   2763  1.15.2.2  thorpej 		/*
   2764  1.15.2.2  thorpej 		 * Get a character from the keyboard.
   2765  1.15.2.2  thorpej 		 */
   2766  1.15.2.2  thorpej 		while (duart->statusA&RCV_RDY) {
   2767  1.15.2.2  thorpej 			key = duart->dataA;
   2768  1.15.2.2  thorpej 			key &= 0xFF;
   2769  1.15.2.2  thorpej 			/*
   2770  1.15.2.2  thorpej 			* Check for various keyboard errors
   2771  1.15.2.2  thorpej 			*/
   2772  1.15.2.2  thorpej 			if (key == LK_POWER_ERROR || key == LK_KDOWN_ERROR ||
   2773  1.15.2.2  thorpej 			    key == LK_INPUT_ERROR || key == LK_OUTPUT_ERROR) {
   2774  1.15.2.2  thorpej 				printf("qd%d: qdiint: Keyboard error, code = %x\n",qd,key);
   2775  1.15.2.2  thorpej 				return;
   2776  1.15.2.2  thorpej 			}
   2777  1.15.2.2  thorpej 
   2778  1.15.2.2  thorpej 			if (key < LK_LOWEST)
   2779  1.15.2.2  thorpej 			    return;
   2780  1.15.2.2  thorpej 
   2781  1.15.2.2  thorpej 			/*
   2782  1.15.2.2  thorpej 			* See if its a state change key */
   2783  1.15.2.2  thorpej 
   2784  1.15.2.2  thorpej 			switch (key) {
   2785  1.15.2.2  thorpej 
   2786  1.15.2.2  thorpej 			case LOCK:
   2787  1.15.2.2  thorpej 				q_keyboard.lock ^= 0xffff;	/* toggle */
   2788  1.15.2.2  thorpej 				if (q_keyboard.lock)
   2789  1.15.2.2  thorpej 					led_control(qd, LK_LED_ENABLE,
   2790  1.15.2.2  thorpej 							  LK_LED_LOCK);
   2791  1.15.2.2  thorpej 				else
   2792  1.15.2.2  thorpej 					led_control(qd, LK_LED_DISABLE,
   2793  1.15.2.2  thorpej 							  LK_LED_LOCK);
   2794  1.15.2.2  thorpej 				return;
   2795  1.15.2.2  thorpej 
   2796  1.15.2.2  thorpej 			case SHIFT:
   2797  1.15.2.2  thorpej 				q_keyboard.shift ^= 0xFFFF;
   2798  1.15.2.2  thorpej 				return;
   2799  1.15.2.2  thorpej 
   2800  1.15.2.2  thorpej 			case CNTRL:
   2801  1.15.2.2  thorpej 				q_keyboard.cntrl ^= 0xFFFF;
   2802  1.15.2.2  thorpej 				return;
   2803  1.15.2.2  thorpej 
   2804  1.15.2.2  thorpej 			case ALLUP:
   2805  1.15.2.2  thorpej 				q_keyboard.cntrl = 0;
   2806  1.15.2.2  thorpej 				q_keyboard.shift = 0;
   2807  1.15.2.2  thorpej 				return;
   2808  1.15.2.2  thorpej 
   2809  1.15.2.2  thorpej 			case REPEAT:
   2810  1.15.2.2  thorpej 				chr = q_keyboard.last;
   2811  1.15.2.2  thorpej 				break;
   2812  1.15.2.2  thorpej 
   2813  1.15.2.2  thorpej 				/*
   2814  1.15.2.2  thorpej 				* Test for cntrl characters. If set, see if the character
   2815  1.15.2.2  thorpej 				* is elligible to become a control character. */
   2816  1.15.2.2  thorpej 
   2817  1.15.2.2  thorpej 			default:
   2818  1.15.2.2  thorpej 
   2819  1.15.2.2  thorpej 				if (q_keyboard.cntrl) {
   2820  1.15.2.2  thorpej 					chr = q_key[key];
   2821  1.15.2.2  thorpej 					if (chr >= ' ' && chr <= '~')
   2822  1.15.2.2  thorpej 					    chr &= 0x1F;
   2823  1.15.2.2  thorpej 					else if (chr >= 0xA1 && chr <= 0xFE)
   2824  1.15.2.2  thorpej 					    chr &= 0x9F;
   2825  1.15.2.2  thorpej 				}
   2826  1.15.2.2  thorpej 				else if( q_keyboard.lock || q_keyboard.shift )
   2827  1.15.2.2  thorpej 				    chr = q_shift_key[key];
   2828  1.15.2.2  thorpej 				else
   2829  1.15.2.2  thorpej 					chr = q_key[key];
   2830  1.15.2.2  thorpej 				break;
   2831  1.15.2.2  thorpej 			}
   2832  1.15.2.2  thorpej 
   2833  1.15.2.2  thorpej 			q_keyboard.last = chr;
   2834  1.15.2.2  thorpej 
   2835  1.15.2.2  thorpej 			/*
   2836  1.15.2.2  thorpej 			* Check for special function keys */
   2837  1.15.2.2  thorpej 
   2838  1.15.2.2  thorpej 			if (chr & 0x100) {
   2839  1.15.2.2  thorpej 				char *string;
   2840  1.15.2.2  thorpej 				string = q_special[chr & 0x7F];
   2841  1.15.2.2  thorpej 				while(*string)
   2842  1.15.2.2  thorpej 				    (*linesw[tp->t_line].l_rint)(*string++, tp);
   2843  1.15.2.2  thorpej 			}
   2844  1.15.2.2  thorpej 			else {
   2845  1.15.2.2  thorpej #ifdef DDB
   2846  1.15.2.2  thorpej 				/* Check for kernel debugger escape here */
   2847  1.15.2.2  thorpej 				int j;
   2848  1.15.2.2  thorpej 
   2849  1.15.2.2  thorpej 				j = kdbrint(chr&0177);
   2850  1.15.2.2  thorpej 
   2851  1.15.2.2  thorpej 				if (j == 1)  /* Escape received, just return */
   2852  1.15.2.2  thorpej 				    return;
   2853  1.15.2.2  thorpej 
   2854  1.15.2.2  thorpej 				if (j == 2)  /* Second char wasn't 'D' */
   2855  1.15.2.2  thorpej 				    (*linesw[tp->t_line].l_rint)(27, tp);
   2856  1.15.2.2  thorpej #endif
   2857  1.15.2.2  thorpej 				(*linesw[tp->t_line].l_rint)(chr&0177, tp);
   2858  1.15.2.2  thorpej 			}
   2859  1.15.2.2  thorpej 		}
   2860  1.15.2.2  thorpej 	}
   2861  1.15.2.2  thorpej } /* qdiint */
   2862  1.15.2.2  thorpej 
   2863  1.15.2.2  thorpej /*
   2864  1.15.2.2  thorpej  *
   2865  1.15.2.2  thorpej  * Clear the QDSS screen
   2866  1.15.2.2  thorpej  *
   2867  1.15.2.2  thorpej  *			     >>> NOTE <<<
   2868  1.15.2.2  thorpej  *
   2869  1.15.2.2  thorpej  *   This code requires that certain adder initialization be valid.  To
   2870  1.15.2.2  thorpej  *   assure that this requirement is satisfied, this routine should be
   2871  1.15.2.2  thorpej  *   called only after calling the "setup_dragon()" function.
   2872  1.15.2.2  thorpej  *
   2873  1.15.2.2  thorpej  *   Clear the bitmap a piece at a time. Since the fast scroll clear
   2874  1.15.2.2  thorpej  *   only clears the current displayed portion of the bitmap put a
   2875  1.15.2.2  thorpej  *   temporary value in the y limit register so we can access whole
   2876  1.15.2.2  thorpej  *   bitmap
   2877  1.15.2.2  thorpej  *
   2878  1.15.2.2  thorpej  */
   2879  1.15.2.2  thorpej void
   2880  1.15.2.2  thorpej clear_qd_screen(unit)
   2881  1.15.2.2  thorpej 	int unit;
   2882  1.15.2.2  thorpej {
   2883  1.15.2.2  thorpej 	volatile register struct adder *adder;
   2884  1.15.2.2  thorpej 	adder = (struct adder *) qdmap[unit].adder;
   2885  1.15.2.2  thorpej 
   2886  1.15.2.2  thorpej 	adder->x_limit = 1024;
   2887  1.15.2.2  thorpej 	adder->y_limit = 2048 - CHAR_HEIGHT;
   2888  1.15.2.2  thorpej 	adder->y_offset_pending = 0;
   2889  1.15.2.2  thorpej #define WSV  (void)wait_status(adder, VSYNC); (void)wait_status(adder, VSYNC)
   2890  1.15.2.2  thorpej 	WSV;
   2891  1.15.2.2  thorpej 	adder->y_scroll_constant = SCROLL_ERASE;
   2892  1.15.2.2  thorpej 	WSV;
   2893  1.15.2.2  thorpej 	adder->y_offset_pending = 864;
   2894  1.15.2.2  thorpej 	WSV;
   2895  1.15.2.2  thorpej 	adder->y_scroll_constant = SCROLL_ERASE;
   2896  1.15.2.2  thorpej 	WSV;
   2897  1.15.2.2  thorpej 	adder->y_offset_pending = 1728;
   2898  1.15.2.2  thorpej 	WSV;
   2899  1.15.2.2  thorpej 	adder->y_scroll_constant = SCROLL_ERASE;
   2900  1.15.2.2  thorpej 	WSV;
   2901  1.15.2.2  thorpej 	adder->y_offset_pending = 0;	 /* back to normal */
   2902  1.15.2.2  thorpej 	WSV;
   2903  1.15.2.2  thorpej 	adder->x_limit = MAX_SCREEN_X;
   2904  1.15.2.2  thorpej 	adder->y_limit = MAX_SCREEN_Y + FONT_HEIGHT;
   2905  1.15.2.2  thorpej #undef WSV
   2906  1.15.2.2  thorpej 
   2907  1.15.2.2  thorpej } /* clear_qd_screen */
   2908  1.15.2.2  thorpej 
   2909  1.15.2.2  thorpej /*
   2910  1.15.2.2  thorpej  *  kernel console output to the glass tty
   2911  1.15.2.2  thorpej  */
   2912  1.15.2.2  thorpej void
   2913  1.15.2.2  thorpej qdcnputc(dev, chr)
   2914  1.15.2.2  thorpej 	dev_t dev;
   2915  1.15.2.2  thorpej 	int chr;
   2916  1.15.2.2  thorpej {
   2917  1.15.2.2  thorpej 
   2918  1.15.2.2  thorpej 	/*
   2919  1.15.2.2  thorpej 	 * if system is now physical, forget it (ie: crash DUMP)
   2920  1.15.2.2  thorpej 	 */
   2921  1.15.2.2  thorpej 	if ((mfpr(PR_MAPEN) & 1) == 0)
   2922  1.15.2.2  thorpej 		return;
   2923  1.15.2.2  thorpej 
   2924  1.15.2.2  thorpej 	blitc(0, (u_char)(chr & 0xff));
   2925  1.15.2.2  thorpej 	if ((chr & 0177) == '\n')
   2926  1.15.2.2  thorpej 		blitc(0, '\r');
   2927  1.15.2.2  thorpej 
   2928  1.15.2.2  thorpej } /* qdputc */
   2929  1.15.2.2  thorpej 
   2930  1.15.2.2  thorpej /*
   2931  1.15.2.2  thorpej  *  load the mouse cursor's template RAM bitmap
   2932  1.15.2.2  thorpej  */
   2933  1.15.2.2  thorpej void
   2934  1.15.2.2  thorpej ldcursor(unit, bitmap)
   2935  1.15.2.2  thorpej 	int unit;
   2936  1.15.2.2  thorpej 	short *bitmap;
   2937  1.15.2.2  thorpej {
   2938  1.15.2.2  thorpej 	volatile register struct dga *dga;
   2939  1.15.2.2  thorpej 	volatile register short *temp;
   2940  1.15.2.2  thorpej 	register int i;
   2941  1.15.2.2  thorpej 	int curs;
   2942  1.15.2.2  thorpej 
   2943  1.15.2.2  thorpej 	dga = (struct dga *) qdmap[unit].dga;
   2944  1.15.2.2  thorpej 	temp = (short *) qdmap[unit].template;
   2945  1.15.2.2  thorpej 
   2946  1.15.2.2  thorpej 	if (dga->csr & CURS_ENB) {	/* if the cursor is enabled.. */
   2947  1.15.2.2  thorpej 		curs = -1;		/* ..note that.. */
   2948  1.15.2.2  thorpej 		dga->csr &= ~CURS_ENB;	/* ..and shut it off */
   2949  1.15.2.2  thorpej 	} else
   2950  1.15.2.2  thorpej 		curs = 0;
   2951  1.15.2.2  thorpej 
   2952  1.15.2.2  thorpej 	dga->csr &= ~CURS_ENB;		/* shut off the cursor */
   2953  1.15.2.2  thorpej 
   2954  1.15.2.2  thorpej 	temp += (8 * 1024) - 32;	/* cursor is 32 WORDS from the end */
   2955  1.15.2.2  thorpej 	/* ..of the 8k WORD template space */
   2956  1.15.2.2  thorpej 	for (i = 0; i < 32; ++i)
   2957  1.15.2.2  thorpej 		*temp++ = *bitmap++;
   2958  1.15.2.2  thorpej 
   2959  1.15.2.2  thorpej 	if (curs) {			/* if cursor was enabled.. */
   2960  1.15.2.2  thorpej 		dga->csr |= CURS_ENB;	/* ..turn it back on */
   2961  1.15.2.2  thorpej 	}
   2962  1.15.2.2  thorpej 
   2963  1.15.2.2  thorpej } /* ldcursor */
   2964  1.15.2.2  thorpej 
   2965  1.15.2.2  thorpej /*
   2966  1.15.2.2  thorpej  *  Put the console font in the QDSS off-screen memory
   2967  1.15.2.2  thorpej  */
   2968  1.15.2.2  thorpej void
   2969  1.15.2.2  thorpej ldfont(unit)
   2970  1.15.2.2  thorpej 	int unit;
   2971  1.15.2.2  thorpej {
   2972  1.15.2.2  thorpej 	volatile register struct adder *adder;
   2973  1.15.2.2  thorpej 
   2974  1.15.2.2  thorpej 	register int i, j, k, max_chars_line;
   2975  1.15.2.2  thorpej 	register short packed;
   2976  1.15.2.2  thorpej 
   2977  1.15.2.2  thorpej 	adder = (struct adder *) qdmap[unit].adder;
   2978  1.15.2.2  thorpej 
   2979  1.15.2.2  thorpej 	/*
   2980  1.15.2.2  thorpej 	* setup VIPER operand control registers
   2981  1.15.2.2  thorpej 	*/
   2982  1.15.2.2  thorpej 	write_ID(adder, MASK_1, 0xFFFF);
   2983  1.15.2.2  thorpej 	write_ID(adder, VIPER_Z_LOAD | FOREGROUND_COLOR_Z, 255);
   2984  1.15.2.2  thorpej 	write_ID(adder, VIPER_Z_LOAD | BACKGROUND_COLOR_Z, 0);
   2985  1.15.2.2  thorpej 
   2986  1.15.2.2  thorpej 	write_ID(adder, SRC1_OCR_B,
   2987  1.15.2.2  thorpej 	EXT_NONE | INT_NONE | ID | BAR_SHIFT_DELAY);
   2988  1.15.2.2  thorpej 	write_ID(adder, SRC2_OCR_B,
   2989  1.15.2.2  thorpej 	EXT_NONE | INT_NONE | ID | BAR_SHIFT_DELAY);
   2990  1.15.2.2  thorpej 	write_ID(adder, DST_OCR_B,
   2991  1.15.2.2  thorpej 	EXT_SOURCE | INT_NONE | NO_ID | NO_BAR_SHIFT_DELAY);
   2992  1.15.2.2  thorpej 
   2993  1.15.2.2  thorpej 	adder->rasterop_mode = DST_WRITE_ENABLE | DST_INDEX_ENABLE | NORMAL;
   2994  1.15.2.2  thorpej 
   2995  1.15.2.2  thorpej 	/*
   2996  1.15.2.2  thorpej 	* load destination data
   2997  1.15.2.2  thorpej 	*/
   2998  1.15.2.2  thorpej 	(void)wait_status(adder, RASTEROP_COMPLETE);
   2999  1.15.2.2  thorpej 
   3000  1.15.2.2  thorpej 	adder->destination_x = FONT_X;
   3001  1.15.2.2  thorpej 	adder->destination_y = FONT_Y;
   3002  1.15.2.2  thorpej #if FONT_WIDTH > MAX_SCREEN_X
   3003  1.15.2.2  thorpej 	adder->fast_dest_dx = MAX_SCREEN_X;
   3004  1.15.2.2  thorpej #else
   3005  1.15.2.2  thorpej 	adder->fast_dest_dx = FONT_WIDTH;
   3006  1.15.2.2  thorpej #endif
   3007  1.15.2.2  thorpej 	adder->slow_dest_dy = CHAR_HEIGHT;
   3008  1.15.2.2  thorpej 
   3009  1.15.2.2  thorpej 	/*
   3010  1.15.2.2  thorpej 	* setup for processor to bitmap xfer  */
   3011  1.15.2.2  thorpej 
   3012  1.15.2.2  thorpej 	write_ID(adder, CS_UPDATE_MASK, 0x0001);
   3013  1.15.2.2  thorpej 	adder->cmd = PBT | OCRB | 2 | DTE | 2;
   3014  1.15.2.2  thorpej 
   3015  1.15.2.2  thorpej 	/*
   3016  1.15.2.2  thorpej 	* Figure out how many characters can be stored on one "line" of
   3017  1.15.2.2  thorpej 	* offscreen memory.
   3018  1.15.2.2  thorpej 	*/
   3019  1.15.2.2  thorpej 	max_chars_line = MAX_SCREEN_X/(CHAR_WIDTH*2);
   3020  1.15.2.2  thorpej 	if ((CHARS/2 + CHARS%2) < max_chars_line)
   3021  1.15.2.2  thorpej 	    max_chars_line = CHARS/2 + CHARS%2;
   3022  1.15.2.2  thorpej 
   3023  1.15.2.2  thorpej 	/*
   3024  1.15.2.2  thorpej 	* iteratively do the processor to bitmap xfer */
   3025  1.15.2.2  thorpej 
   3026  1.15.2.2  thorpej 	for (i = 0; i < ROWS; ++i) {
   3027  1.15.2.2  thorpej 
   3028  1.15.2.2  thorpej 		/* PTOB a scan line */
   3029  1.15.2.2  thorpej 
   3030  1.15.2.2  thorpej 		for (j = 0, k = i; j < max_chars_line; ++j) {
   3031  1.15.2.2  thorpej 			/* PTOB one scan of a char cell */
   3032  1.15.2.2  thorpej 
   3033  1.15.2.2  thorpej 			packed = q_font[k];
   3034  1.15.2.2  thorpej 			k += ROWS;
   3035  1.15.2.2  thorpej 			packed |= ((short)q_font[k] << 8);
   3036  1.15.2.2  thorpej 			k += ROWS;
   3037  1.15.2.2  thorpej 
   3038  1.15.2.2  thorpej 			(void)wait_status(adder, TX_READY);
   3039  1.15.2.2  thorpej 			adder->id_data = packed;
   3040  1.15.2.2  thorpej 		}
   3041  1.15.2.2  thorpej 	}
   3042  1.15.2.2  thorpej 
   3043  1.15.2.2  thorpej 	/*
   3044  1.15.2.2  thorpej 	 * (XXX XXX XXX - should remove)
   3045  1.15.2.2  thorpej 	 *
   3046  1.15.2.2  thorpej 	 * Copy the second row of characters.  Subtract the first
   3047  1.15.2.2  thorpej 	 * row from the total number.  Divide this quantity by 2
   3048  1.15.2.2  thorpej 	 * because 2 chars are stored in a short in the PTOB loop
   3049  1.15.2.2  thorpej 	 * below.  Figure out how many characters can be stored on
   3050  1.15.2.2  thorpej 	 * one "line" of offscreen memory
   3051  1.15.2.2  thorpej 	 */
   3052  1.15.2.2  thorpej 
   3053  1.15.2.2  thorpej 	max_chars_line = MAX_SCREEN_X/(CHAR_WIDTH*2);
   3054  1.15.2.2  thorpej 	if ((CHARS/2 + CHARS%2) < max_chars_line)
   3055  1.15.2.2  thorpej 	    return;
   3056  1.15.2.2  thorpej 	max_chars_line = (CHARS/2 + CHARS%2) - max_chars_line; /* 95 - 64 */
   3057  1.15.2.2  thorpej 	/* Paranoia check to see if 3rd row may be needed */
   3058  1.15.2.2  thorpej 	if (max_chars_line > (MAX_SCREEN_X/(CHAR_WIDTH*2)))
   3059  1.15.2.2  thorpej 	    max_chars_line = MAX_SCREEN_X/(CHAR_WIDTH*2);
   3060  1.15.2.2  thorpej 
   3061  1.15.2.2  thorpej 	adder->destination_x = FONT_X;
   3062  1.15.2.2  thorpej 	adder->destination_y = FONT_Y - CHAR_HEIGHT;
   3063  1.15.2.2  thorpej 	adder->fast_dest_dx = max_chars_line * CHAR_WIDTH * 2;
   3064  1.15.2.2  thorpej 	adder->slow_dest_dy = CHAR_HEIGHT;
   3065  1.15.2.2  thorpej 
   3066  1.15.2.2  thorpej 	/*
   3067  1.15.2.2  thorpej 	* setup for processor to bitmap xfer
   3068  1.15.2.2  thorpej 	*/
   3069  1.15.2.2  thorpej 	write_ID(adder, CS_UPDATE_MASK, 0x0001);
   3070  1.15.2.2  thorpej 	adder->cmd = PBT | OCRB | 2 | DTE | 2;
   3071  1.15.2.2  thorpej 
   3072  1.15.2.2  thorpej 	/*
   3073  1.15.2.2  thorpej 	* iteratively do the processor to bitmap xfer
   3074  1.15.2.2  thorpej 	*/
   3075  1.15.2.2  thorpej 	for (i = 0; i < ROWS; ++i) {
   3076  1.15.2.2  thorpej 		/*
   3077  1.15.2.2  thorpej 		 * PTOB a scan line
   3078  1.15.2.2  thorpej 		 */
   3079  1.15.2.2  thorpej 		for (j = 0, k = i; j < max_chars_line; ++j) {
   3080  1.15.2.2  thorpej 			/*
   3081  1.15.2.2  thorpej 			 * PTOB one scan of a char cell
   3082  1.15.2.2  thorpej 			 */
   3083  1.15.2.2  thorpej 			packed = q_font[k + FONT_OFFSET];
   3084  1.15.2.2  thorpej 			k += ROWS;
   3085  1.15.2.2  thorpej 			packed |= ((short)q_font[k + FONT_OFFSET] << 8);
   3086  1.15.2.2  thorpej 			k += ROWS;
   3087  1.15.2.2  thorpej 			(void)wait_status(adder, TX_READY);
   3088  1.15.2.2  thorpej 			adder->id_data = packed;
   3089  1.15.2.2  thorpej 		}
   3090  1.15.2.2  thorpej 	}
   3091  1.15.2.2  thorpej 
   3092  1.15.2.2  thorpej }  /* ldfont */
   3093  1.15.2.2  thorpej 
   3094  1.15.2.2  thorpej 
   3095  1.15.2.2  thorpej /*
   3096  1.15.2.2  thorpej  * Disable or enable polling.  This is used when entering or leaving the
   3097  1.15.2.2  thorpej  * kernel debugger.
   3098  1.15.2.2  thorpej  */
   3099  1.15.2.2  thorpej void
   3100  1.15.2.2  thorpej qdcnpollc(dev, onoff)
   3101  1.15.2.2  thorpej 	dev_t dev;
   3102  1.15.2.2  thorpej 	int onoff;
   3103  1.15.2.2  thorpej {
   3104  1.15.2.2  thorpej      qdpolling = onoff;
   3105  1.15.2.2  thorpej }
   3106  1.15.2.2  thorpej 
   3107  1.15.2.2  thorpej 
   3108  1.15.2.2  thorpej /*
   3109  1.15.2.2  thorpej  *  Get a character from the LK201 (polled)
   3110  1.15.2.2  thorpej  */
   3111  1.15.2.2  thorpej int
   3112  1.15.2.2  thorpej qdcngetc(dev)
   3113  1.15.2.2  thorpej 	dev_t dev;
   3114  1.15.2.2  thorpej {
   3115  1.15.2.2  thorpej 	register short key;
   3116  1.15.2.2  thorpej 	register char chr;
   3117  1.15.2.2  thorpej 	volatile register struct duart *duart;
   3118  1.15.2.2  thorpej 
   3119  1.15.2.2  thorpej 	duart = (struct duart *) qdmap[0].duart;
   3120  1.15.2.2  thorpej 
   3121  1.15.2.2  thorpej 	/*
   3122  1.15.2.2  thorpej 	* Get a character from the keyboard.
   3123  1.15.2.2  thorpej 	*/
   3124  1.15.2.2  thorpej LOOP:
   3125  1.15.2.2  thorpej 	while (!(duart->statusA&RCV_RDY))
   3126  1.15.2.2  thorpej 		;
   3127  1.15.2.2  thorpej 
   3128  1.15.2.2  thorpej 	key = duart->dataA;
   3129  1.15.2.2  thorpej 	key &= 0xFF;
   3130  1.15.2.2  thorpej 
   3131  1.15.2.2  thorpej 	/*
   3132  1.15.2.2  thorpej 	* Check for various keyboard errors  */
   3133  1.15.2.2  thorpej 
   3134  1.15.2.2  thorpej 	if (key == LK_POWER_ERROR || key == LK_KDOWN_ERROR ||
   3135  1.15.2.2  thorpej 	    key == LK_INPUT_ERROR || key == LK_OUTPUT_ERROR) {
   3136  1.15.2.2  thorpej 		printf("Keyboard error, code = %x\n", key);
   3137  1.15.2.2  thorpej 		return(0);
   3138  1.15.2.2  thorpej 	}
   3139  1.15.2.2  thorpej 
   3140  1.15.2.2  thorpej 	if (key < LK_LOWEST)
   3141  1.15.2.2  thorpej 		return(0);
   3142  1.15.2.2  thorpej 
   3143  1.15.2.2  thorpej 	/*
   3144  1.15.2.2  thorpej 	 * See if its a state change key
   3145  1.15.2.2  thorpej 	 */
   3146  1.15.2.2  thorpej 	switch (key) {
   3147  1.15.2.2  thorpej 
   3148  1.15.2.2  thorpej 	case LOCK:
   3149  1.15.2.2  thorpej 		q_keyboard.lock ^= 0xffff;	/* toggle */
   3150  1.15.2.2  thorpej 		if (q_keyboard.lock)
   3151  1.15.2.2  thorpej 			led_control(0, LK_LED_ENABLE, LK_LED_LOCK);
   3152  1.15.2.2  thorpej 		else
   3153  1.15.2.2  thorpej 			led_control(0, LK_LED_DISABLE, LK_LED_LOCK);
   3154  1.15.2.2  thorpej 		goto LOOP;
   3155  1.15.2.2  thorpej 
   3156  1.15.2.2  thorpej 	case SHIFT:
   3157  1.15.2.2  thorpej 		q_keyboard.shift ^= 0xFFFF;
   3158  1.15.2.2  thorpej 		goto LOOP;
   3159  1.15.2.2  thorpej 
   3160  1.15.2.2  thorpej 	case CNTRL:
   3161  1.15.2.2  thorpej 		q_keyboard.cntrl ^= 0xFFFF;
   3162  1.15.2.2  thorpej 		goto LOOP;
   3163  1.15.2.2  thorpej 
   3164  1.15.2.2  thorpej 	case ALLUP:
   3165  1.15.2.2  thorpej 		q_keyboard.cntrl = 0;
   3166  1.15.2.2  thorpej 		q_keyboard.shift = 0;
   3167  1.15.2.2  thorpej 		goto LOOP;
   3168  1.15.2.2  thorpej 
   3169  1.15.2.2  thorpej 	case REPEAT:
   3170  1.15.2.2  thorpej 		chr = q_keyboard.last;
   3171  1.15.2.2  thorpej 		break;
   3172  1.15.2.2  thorpej 
   3173  1.15.2.2  thorpej 		/*
   3174  1.15.2.2  thorpej 		* Test for cntrl characters. If set, see if the character
   3175  1.15.2.2  thorpej 		* is elligible to become a control character.
   3176  1.15.2.2  thorpej 		*/
   3177  1.15.2.2  thorpej 	default:
   3178  1.15.2.2  thorpej 
   3179  1.15.2.2  thorpej 		if (q_keyboard.cntrl) {
   3180  1.15.2.2  thorpej 			chr = q_key[key];
   3181  1.15.2.2  thorpej 			if (chr >= ' ' && chr <= '~')
   3182  1.15.2.2  thorpej 			    chr &= 0x1F;
   3183  1.15.2.2  thorpej 		}
   3184  1.15.2.2  thorpej 		else if ( q_keyboard.lock || q_keyboard.shift )
   3185  1.15.2.2  thorpej 		    chr = q_shift_key[key];
   3186  1.15.2.2  thorpej 		else
   3187  1.15.2.2  thorpej 			chr = q_key[key];
   3188  1.15.2.2  thorpej 		break;
   3189  1.15.2.2  thorpej 	}
   3190  1.15.2.2  thorpej 
   3191  1.15.2.2  thorpej 	if (chr < ' ' && chr > '~')	/* if input is non-displayable */
   3192  1.15.2.2  thorpej 		return(0);		/* ..then pitch it! */
   3193  1.15.2.2  thorpej 
   3194  1.15.2.2  thorpej 	q_keyboard.last = chr;
   3195  1.15.2.2  thorpej 
   3196  1.15.2.2  thorpej 	/*
   3197  1.15.2.2  thorpej 	* Check for special function keys */
   3198  1.15.2.2  thorpej 
   3199  1.15.2.2  thorpej 	if (chr & 0x80) 		/* pitch the function keys */
   3200  1.15.2.2  thorpej 		return(0);
   3201  1.15.2.2  thorpej 	else
   3202  1.15.2.2  thorpej 		return(chr);
   3203  1.15.2.2  thorpej 
   3204  1.15.2.2  thorpej } /* qdgetc */
   3205  1.15.2.2  thorpej 
   3206  1.15.2.2  thorpej /*
   3207  1.15.2.2  thorpej  *  led_control()... twiddle LK-201 LED's
   3208  1.15.2.2  thorpej  */
   3209  1.15.2.2  thorpej void
   3210  1.15.2.2  thorpej led_control(unit, cmd, led_mask)
   3211  1.15.2.2  thorpej 	int unit, cmd, led_mask;
   3212  1.15.2.2  thorpej {
   3213  1.15.2.2  thorpej 	register int i;
   3214  1.15.2.2  thorpej 	volatile register struct duart *duart;
   3215  1.15.2.2  thorpej 
   3216  1.15.2.2  thorpej 	duart = (struct duart *)qdmap[unit].duart;
   3217  1.15.2.2  thorpej 
   3218  1.15.2.2  thorpej 	for (i = 1000; i > 0; --i) {
   3219  1.15.2.2  thorpej 		if (duart->statusA&XMT_RDY) {
   3220  1.15.2.2  thorpej 			duart->dataA = cmd;
   3221  1.15.2.2  thorpej 			break;
   3222  1.15.2.2  thorpej 		}
   3223  1.15.2.2  thorpej 	}
   3224  1.15.2.2  thorpej 	for (i = 1000; i > 0; --i) {
   3225  1.15.2.2  thorpej 		if (duart->statusA&XMT_RDY) {
   3226  1.15.2.2  thorpej 			duart->dataA = led_mask;
   3227  1.15.2.2  thorpej 			break;
   3228  1.15.2.2  thorpej 		}
   3229  1.15.2.2  thorpej 	}
   3230  1.15.2.2  thorpej 	return;
   3231  1.15.2.2  thorpej 
   3232  1.15.2.2  thorpej } /* led_control */
   3233  1.15.2.2  thorpej 
   3234  1.15.2.2  thorpej /*
   3235  1.15.2.2  thorpej  *  scroll_up()... move the screen up one character height
   3236  1.15.2.2  thorpej  */
   3237  1.15.2.2  thorpej void
   3238  1.15.2.2  thorpej scroll_up(adder)
   3239  1.15.2.2  thorpej 	volatile struct adder *adder;
   3240  1.15.2.2  thorpej {
   3241  1.15.2.2  thorpej 	/*
   3242  1.15.2.2  thorpej 	* setup VIPER operand control registers
   3243  1.15.2.2  thorpej 	*/
   3244  1.15.2.2  thorpej 	(void)wait_status(adder, ADDRESS_COMPLETE);
   3245  1.15.2.2  thorpej 	write_ID(adder, CS_UPDATE_MASK, 0x00FF);  /* select all planes */
   3246  1.15.2.2  thorpej 	write_ID(adder, MASK_1, 0xFFFF);
   3247  1.15.2.2  thorpej 	write_ID(adder, VIPER_Z_LOAD | FOREGROUND_COLOR_Z, 255);
   3248  1.15.2.2  thorpej 	write_ID(adder, VIPER_Z_LOAD | BACKGROUND_COLOR_Z, 0);
   3249  1.15.2.2  thorpej 	write_ID(adder, SRC1_OCR_B,
   3250  1.15.2.2  thorpej 	EXT_NONE | INT_SOURCE | ID | BAR_SHIFT_DELAY);
   3251  1.15.2.2  thorpej 	write_ID(adder, DST_OCR_B,
   3252  1.15.2.2  thorpej 	EXT_NONE | INT_NONE | NO_ID | NO_BAR_SHIFT_DELAY);
   3253  1.15.2.2  thorpej 	/*
   3254  1.15.2.2  thorpej 	 * load DESTINATION origin and vectors
   3255  1.15.2.2  thorpej 	 */
   3256  1.15.2.2  thorpej 	adder->fast_dest_dy = 0;
   3257  1.15.2.2  thorpej 	adder->slow_dest_dx = 0;
   3258  1.15.2.2  thorpej 	adder->error_1 = 0;
   3259  1.15.2.2  thorpej 	adder->error_2 = 0;
   3260  1.15.2.2  thorpej 	adder->rasterop_mode = DST_WRITE_ENABLE | NORMAL;
   3261  1.15.2.2  thorpej 	adder->destination_x = 0;
   3262  1.15.2.2  thorpej 	adder->fast_dest_dx = 1024;
   3263  1.15.2.2  thorpej 	adder->destination_y = 0;
   3264  1.15.2.2  thorpej 	adder->slow_dest_dy = 864 - CHAR_HEIGHT;
   3265  1.15.2.2  thorpej 	/*
   3266  1.15.2.2  thorpej 	 * load SOURCE origin and vectors
   3267  1.15.2.2  thorpej 	 */
   3268  1.15.2.2  thorpej 	adder->source_1_x = 0;
   3269  1.15.2.2  thorpej 	adder->source_1_dx = 1024;
   3270  1.15.2.2  thorpej 	adder->source_1_y = 0 + CHAR_HEIGHT;
   3271  1.15.2.2  thorpej 	adder->source_1_dy = 864 - CHAR_HEIGHT;
   3272  1.15.2.2  thorpej 	write_ID(adder, LU_FUNCTION_R1, FULL_SRC_RESOLUTION | LF_SOURCE);
   3273  1.15.2.2  thorpej 	adder->cmd = RASTEROP | OCRB | 0 | S1E | DTE;
   3274  1.15.2.2  thorpej 	/*
   3275  1.15.2.2  thorpej 	 * do a rectangle clear of last screen line
   3276  1.15.2.2  thorpej 	 */
   3277  1.15.2.2  thorpej 	write_ID(adder, MASK_1, 0xffff);
   3278  1.15.2.2  thorpej 	write_ID(adder, SOURCE, 0xffff);
   3279  1.15.2.2  thorpej 	write_ID(adder,DST_OCR_B,
   3280  1.15.2.2  thorpej 	(EXT_NONE | INT_NONE | NO_ID | NO_BAR_SHIFT_DELAY));
   3281  1.15.2.2  thorpej 	write_ID(adder, VIPER_Z_LOAD | FOREGROUND_COLOR_Z, 0);
   3282  1.15.2.2  thorpej 	adder->error_1 = 0;
   3283  1.15.2.2  thorpej 	adder->error_2 = 0;
   3284  1.15.2.2  thorpej 	adder->slow_dest_dx = 0;		/* set up the width of	*/
   3285  1.15.2.2  thorpej 	adder->slow_dest_dy = CHAR_HEIGHT;	/* rectangle */
   3286  1.15.2.2  thorpej 	adder->rasterop_mode = (NORMAL | DST_WRITE_ENABLE) ;
   3287  1.15.2.2  thorpej 	(void)wait_status(adder, RASTEROP_COMPLETE);
   3288  1.15.2.2  thorpej 	adder->destination_x = 0;
   3289  1.15.2.2  thorpej 	adder->destination_y = 864 - CHAR_HEIGHT;
   3290  1.15.2.2  thorpej 	adder->fast_dest_dx = 1024;	/* set up the height	*/
   3291  1.15.2.2  thorpej 	adder->fast_dest_dy = 0;	/* of rectangle 	*/
   3292  1.15.2.2  thorpej 	write_ID(adder, LU_FUNCTION_R2, (FULL_SRC_RESOLUTION | LF_SOURCE));
   3293  1.15.2.2  thorpej 	adder->cmd = (RASTEROP | OCRB | LF_R2 | DTE ) ;
   3294  1.15.2.2  thorpej 
   3295  1.15.2.2  thorpej } /* scroll_up */
   3296  1.15.2.2  thorpej 
   3297  1.15.2.2  thorpej /*
   3298  1.15.2.2  thorpej  *  init shared memory pointers and structures
   3299  1.15.2.2  thorpej  */
   3300  1.15.2.2  thorpej void
   3301  1.15.2.2  thorpej init_shared(unit)
   3302  1.15.2.2  thorpej 	int unit;
   3303  1.15.2.2  thorpej {
   3304  1.15.2.2  thorpej 	volatile register struct dga *dga;
   3305  1.15.2.2  thorpej 
   3306  1.15.2.2  thorpej 	dga = (struct dga *) qdmap[unit].dga;
   3307  1.15.2.2  thorpej 
   3308  1.15.2.2  thorpej 	/*
   3309  1.15.2.2  thorpej 	* initialize the event queue pointers and header */
   3310  1.15.2.2  thorpej 
   3311  1.15.2.2  thorpej 	eq_header[unit] = (struct qdinput *)
   3312  1.15.2.2  thorpej 	    ((((int)event_shared & ~(0x01FF)) + 512)
   3313  1.15.2.2  thorpej 		+ (EVENT_BUFSIZE * unit));
   3314  1.15.2.2  thorpej 	eq_header[unit]->curs_pos.x = 0;
   3315  1.15.2.2  thorpej 	eq_header[unit]->curs_pos.y = 0;
   3316  1.15.2.2  thorpej 	dga->x_cursor = TRANX(eq_header[unit]->curs_pos.x);
   3317  1.15.2.2  thorpej 	dga->y_cursor = TRANY(eq_header[unit]->curs_pos.y);
   3318  1.15.2.2  thorpej 	eq_header[unit]->curs_box.left = 0;
   3319  1.15.2.2  thorpej 	eq_header[unit]->curs_box.right = 0;
   3320  1.15.2.2  thorpej 	eq_header[unit]->curs_box.top = 0;
   3321  1.15.2.2  thorpej 	eq_header[unit]->curs_box.bottom = 0;
   3322  1.15.2.2  thorpej 	/*
   3323  1.15.2.2  thorpej 	 * assign a pointer to the DMA I/O buffer for this QDSS.
   3324  1.15.2.2  thorpej 	 */
   3325  1.15.2.2  thorpej 	DMAheader[unit] = (struct DMAreq_header *)
   3326  1.15.2.2  thorpej 	    (((int)(&DMA_shared[0] + 512) & ~0x1FF)
   3327  1.15.2.2  thorpej 		+ (DMAbuf_size * unit));
   3328  1.15.2.2  thorpej 	DMAheader[unit]->DMAreq = (struct DMAreq *) ((int)DMAheader[unit]
   3329  1.15.2.2  thorpej 	    + sizeof(struct DMAreq_header));
   3330  1.15.2.2  thorpej 	DMAheader[unit]->QBAreg = 0;
   3331  1.15.2.2  thorpej 	DMAheader[unit]->status = 0;
   3332  1.15.2.2  thorpej 	DMAheader[unit]->shared_size = DMAbuf_size;
   3333  1.15.2.2  thorpej 	DMAheader[unit]->used = 0;
   3334  1.15.2.2  thorpej 	DMAheader[unit]->size = 10;	/* default = 10 requests */
   3335  1.15.2.2  thorpej 	DMAheader[unit]->oldest = 0;
   3336  1.15.2.2  thorpej 	DMAheader[unit]->newest = 0;
   3337  1.15.2.2  thorpej 	/*
   3338  1.15.2.2  thorpej 	* assign a pointer to the scroll structure for this QDSS.
   3339  1.15.2.2  thorpej 	*/
   3340  1.15.2.2  thorpej 	scroll[unit] = (struct scroll *)
   3341  1.15.2.2  thorpej 	    (((int)(&scroll_shared[0] + 512) & ~0x1FF)
   3342  1.15.2.2  thorpej 		+ (sizeof(struct scroll) * unit));
   3343  1.15.2.2  thorpej 	scroll[unit]->status = 0;
   3344  1.15.2.2  thorpej 	scroll[unit]->viper_constant = 0;
   3345  1.15.2.2  thorpej 	scroll[unit]->y_scroll_constant = 0;
   3346  1.15.2.2  thorpej 	scroll[unit]->y_offset = 0;
   3347  1.15.2.2  thorpej 	scroll[unit]->x_index_pending = 0;
   3348  1.15.2.2  thorpej 	scroll[unit]->y_index_pending = 0;
   3349  1.15.2.2  thorpej 	/*
   3350  1.15.2.2  thorpej 	* assign a pointer to the color map write buffer for this QDSS
   3351  1.15.2.2  thorpej 	*/
   3352  1.15.2.2  thorpej 	color_buf[unit] = (struct color_buf *)
   3353  1.15.2.2  thorpej 	    (((int)(&color_shared[0] + 512) & ~0x1FF)
   3354  1.15.2.2  thorpej 		+ (COLOR_BUFSIZ * unit));
   3355  1.15.2.2  thorpej 	color_buf[unit]->status = 0;
   3356  1.15.2.2  thorpej 	color_buf[unit]->count = 0;
   3357  1.15.2.2  thorpej 
   3358  1.15.2.2  thorpej } /* init_shared */
   3359  1.15.2.2  thorpej 
   3360  1.15.2.2  thorpej /*
   3361  1.15.2.2  thorpej  * init the ADDER, VIPER, bitmaps, & color map
   3362  1.15.2.2  thorpej  */
   3363  1.15.2.2  thorpej void
   3364  1.15.2.2  thorpej setup_dragon(unit)
   3365  1.15.2.2  thorpej 	int unit;
   3366  1.15.2.2  thorpej {
   3367  1.15.2.2  thorpej 
   3368  1.15.2.2  thorpej 	volatile register struct adder *adder;
   3369  1.15.2.2  thorpej 	volatile register struct dga *dga;
   3370  1.15.2.2  thorpej 	volatile short *memcsr;
   3371  1.15.2.2  thorpej 	register int i;
   3372  1.15.2.2  thorpej 	short top;		/* clipping/scrolling boundaries */
   3373  1.15.2.2  thorpej 	short bottom;
   3374  1.15.2.2  thorpej 	short right;
   3375  1.15.2.2  thorpej 	short left;
   3376  1.15.2.2  thorpej 	volatile short *red;		/* color map pointers */
   3377  1.15.2.2  thorpej 	volatile short *green;
   3378  1.15.2.2  thorpej 	volatile short *blue;
   3379  1.15.2.2  thorpej 
   3380  1.15.2.2  thorpej 	/*
   3381  1.15.2.2  thorpej 	* init for setup
   3382  1.15.2.2  thorpej 	*/
   3383  1.15.2.2  thorpej 	adder = (struct adder *) qdmap[unit].adder;
   3384  1.15.2.2  thorpej 	dga = (struct dga *) qdmap[unit].dga;
   3385  1.15.2.2  thorpej 	memcsr = (short *) qdmap[unit].memcsr;
   3386  1.15.2.2  thorpej 	dga->csr &= ~(DMA_IE | 0x700);	/* halt DMA and kill the intrpts */
   3387  1.15.2.2  thorpej 	*memcsr = SYNC_ON;		/* blank screen and turn off LED's */
   3388  1.15.2.2  thorpej 	adder->command = CANCEL;
   3389  1.15.2.2  thorpej 	/*
   3390  1.15.2.2  thorpej 	* set monitor timing
   3391  1.15.2.2  thorpej 	*/
   3392  1.15.2.2  thorpej 	adder->x_scan_count_0 = 0x2800;
   3393  1.15.2.2  thorpej 	adder->x_scan_count_1 = 0x1020;
   3394  1.15.2.2  thorpej 	adder->x_scan_count_2 = 0x003A;
   3395  1.15.2.2  thorpej 	adder->x_scan_count_3 = 0x38F0;
   3396  1.15.2.2  thorpej 	adder->x_scan_count_4 = 0x6128;
   3397  1.15.2.2  thorpej 	adder->x_scan_count_5 = 0x093A;
   3398  1.15.2.2  thorpej 	adder->x_scan_count_6 = 0x313C;
   3399  1.15.2.2  thorpej 	adder->sync_phase_adj = 0x0100;
   3400  1.15.2.2  thorpej 	adder->x_scan_conf = 0x00C8;
   3401  1.15.2.2  thorpej 	/*
   3402  1.15.2.2  thorpej 	 * got a bug in secound pass ADDER! lets take care of it
   3403  1.15.2.2  thorpej 	 *
   3404  1.15.2.2  thorpej 	 * normally, just use the code in the following bug fix code, but to
   3405  1.15.2.2  thorpej 	 * make repeated demos look pretty, load the registers as if there was
   3406  1.15.2.2  thorpej 	 * no bug and then test to see if we are getting sync
   3407  1.15.2.2  thorpej 	 */
   3408  1.15.2.2  thorpej 	adder->y_scan_count_0 = 0x135F;
   3409  1.15.2.2  thorpej 	adder->y_scan_count_1 = 0x3363;
   3410  1.15.2.2  thorpej 	adder->y_scan_count_2 = 0x2366;
   3411  1.15.2.2  thorpej 	adder->y_scan_count_3 = 0x0388;
   3412  1.15.2.2  thorpej 	/*
   3413  1.15.2.2  thorpej 	 * if no sync, do the bug fix code
   3414  1.15.2.2  thorpej 	 */
   3415  1.15.2.2  thorpej 	if (wait_status(adder, VSYNC) == BAD) {
   3416  1.15.2.2  thorpej 		/* first load all Y scan registers with very short frame and
   3417  1.15.2.2  thorpej 		 * wait for scroll service.  This guarantees at least one SYNC
   3418  1.15.2.2  thorpej 		 * to fix the pass 2 Adder initialization bug (synchronizes
   3419  1.15.2.2  thorpej 		 * XCINCH with DMSEEDH)
   3420  1.15.2.2  thorpej 		 */
   3421  1.15.2.2  thorpej 		adder->y_scan_count_0 = 0x01;
   3422  1.15.2.2  thorpej 		adder->y_scan_count_1 = 0x01;
   3423  1.15.2.2  thorpej 		adder->y_scan_count_2 = 0x01;
   3424  1.15.2.2  thorpej 		adder->y_scan_count_3 = 0x01;
   3425  1.15.2.2  thorpej 		/*
   3426  1.15.2.2  thorpej 		 * delay at least 1 full frame time
   3427  1.15.2.2  thorpej 		 */
   3428  1.15.2.2  thorpej 		(void)wait_status(adder, VSYNC);
   3429  1.15.2.2  thorpej 		(void)wait_status(adder, VSYNC);
   3430  1.15.2.2  thorpej 		/*
   3431  1.15.2.2  thorpej 		 * now load the REAL sync values (in reverse order just to
   3432  1.15.2.2  thorpej 		 * be safe.
   3433  1.15.2.2  thorpej 		 */
   3434  1.15.2.2  thorpej 		adder->y_scan_count_3 = 0x0388;
   3435  1.15.2.2  thorpej 		adder->y_scan_count_2 = 0x2366;
   3436  1.15.2.2  thorpej 		adder->y_scan_count_1 = 0x3363;
   3437  1.15.2.2  thorpej 		adder->y_scan_count_0 = 0x135F;
   3438  1.15.2.2  thorpej 	}
   3439  1.15.2.2  thorpej 	*memcsr = SYNC_ON | UNBLANK;	/* turn off leds and turn on video */
   3440  1.15.2.2  thorpej 	/*
   3441  1.15.2.2  thorpej 	 * zero the index registers
   3442  1.15.2.2  thorpej 	 */
   3443  1.15.2.2  thorpej 	adder->x_index_pending = 0;
   3444  1.15.2.2  thorpej 	adder->y_index_pending = 0;
   3445  1.15.2.2  thorpej 	adder->x_index_new = 0;
   3446  1.15.2.2  thorpej 	adder->y_index_new = 0;
   3447  1.15.2.2  thorpej 	adder->x_index_old = 0;
   3448  1.15.2.2  thorpej 	adder->y_index_old = 0;
   3449  1.15.2.2  thorpej 	adder->pause = 0;
   3450  1.15.2.2  thorpej 	/*
   3451  1.15.2.2  thorpej 	 * set rasterop mode to normal pen down
   3452  1.15.2.2  thorpej 	 */
   3453  1.15.2.2  thorpej 	adder->rasterop_mode = DST_WRITE_ENABLE | DST_INDEX_ENABLE | NORMAL;
   3454  1.15.2.2  thorpej 	/*
   3455  1.15.2.2  thorpej 	 * set the rasterop registers to a default values
   3456  1.15.2.2  thorpej 	 */
   3457  1.15.2.2  thorpej 	adder->source_1_dx = 1;
   3458  1.15.2.2  thorpej 	adder->source_1_dy = 1;
   3459  1.15.2.2  thorpej 	adder->source_1_x = 0;
   3460  1.15.2.2  thorpej 	adder->source_1_y = 0;
   3461  1.15.2.2  thorpej 	adder->destination_x = 0;
   3462  1.15.2.2  thorpej 	adder->destination_y = 0;
   3463  1.15.2.2  thorpej 	adder->fast_dest_dx = 1;
   3464  1.15.2.2  thorpej 	adder->fast_dest_dy = 0;
   3465  1.15.2.2  thorpej 	adder->slow_dest_dx = 0;
   3466  1.15.2.2  thorpej 	adder->slow_dest_dy = 1;
   3467  1.15.2.2  thorpej 	adder->error_1 = 0;
   3468  1.15.2.2  thorpej 	adder->error_2 = 0;
   3469  1.15.2.2  thorpej 	/*
   3470  1.15.2.2  thorpej 	 * scale factor = UNITY
   3471  1.15.2.2  thorpej 	 */
   3472  1.15.2.2  thorpej 	adder->fast_scale = UNITY;
   3473  1.15.2.2  thorpej 	adder->slow_scale = UNITY;
   3474  1.15.2.2  thorpej 	/*
   3475  1.15.2.2  thorpej 	 * set the source 2 parameters
   3476  1.15.2.2  thorpej 	 */
   3477  1.15.2.2  thorpej 	adder->source_2_x = 0;
   3478  1.15.2.2  thorpej 	adder->source_2_y = 0;
   3479  1.15.2.2  thorpej 	adder->source_2_size = 0x0022;
   3480  1.15.2.2  thorpej 	/*
   3481  1.15.2.2  thorpej 	* initialize plane addresses for eight vipers
   3482  1.15.2.2  thorpej 	*/
   3483  1.15.2.2  thorpej 	write_ID(adder, CS_UPDATE_MASK, 0x0001);
   3484  1.15.2.2  thorpej 	write_ID(adder, PLANE_ADDRESS, 0x0000);
   3485  1.15.2.2  thorpej 	write_ID(adder, CS_UPDATE_MASK, 0x0002);
   3486  1.15.2.2  thorpej 	write_ID(adder, PLANE_ADDRESS, 0x0001);
   3487  1.15.2.2  thorpej 	write_ID(adder, CS_UPDATE_MASK, 0x0004);
   3488  1.15.2.2  thorpej 	write_ID(adder, PLANE_ADDRESS, 0x0002);
   3489  1.15.2.2  thorpej 	write_ID(adder, CS_UPDATE_MASK, 0x0008);
   3490  1.15.2.2  thorpej 	write_ID(adder, PLANE_ADDRESS, 0x0003);
   3491  1.15.2.2  thorpej 	write_ID(adder, CS_UPDATE_MASK, 0x0010);
   3492  1.15.2.2  thorpej 	write_ID(adder, PLANE_ADDRESS, 0x0004);
   3493  1.15.2.2  thorpej 	write_ID(adder, CS_UPDATE_MASK, 0x0020);
   3494  1.15.2.2  thorpej 	write_ID(adder, PLANE_ADDRESS, 0x0005);
   3495  1.15.2.2  thorpej 	write_ID(adder, CS_UPDATE_MASK, 0x0040);
   3496  1.15.2.2  thorpej 	write_ID(adder, PLANE_ADDRESS, 0x0006);
   3497  1.15.2.2  thorpej 	write_ID(adder, CS_UPDATE_MASK, 0x0080);
   3498  1.15.2.2  thorpej 	write_ID(adder, PLANE_ADDRESS, 0x0007);
   3499  1.15.2.2  thorpej 	/*
   3500  1.15.2.2  thorpej 	 * initialize the external registers.
   3501  1.15.2.2  thorpej 	 */
   3502  1.15.2.2  thorpej 	write_ID(adder, CS_UPDATE_MASK, 0x00FF);
   3503  1.15.2.2  thorpej 	write_ID(adder, CS_SCROLL_MASK, 0x00FF);
   3504  1.15.2.2  thorpej 	/*
   3505  1.15.2.2  thorpej 	 * initialize resolution mode
   3506  1.15.2.2  thorpej 	 */
   3507  1.15.2.2  thorpej 	write_ID(adder, MEMORY_BUS_WIDTH, 0x000C);     /* bus width = 16 */
   3508  1.15.2.2  thorpej 	write_ID(adder, RESOLUTION_MODE, 0x0000);      /* one bit/pixel */
   3509  1.15.2.2  thorpej 	/*
   3510  1.15.2.2  thorpej 	 * initialize viper registers
   3511  1.15.2.2  thorpej 	 */
   3512  1.15.2.2  thorpej 	write_ID(adder, SCROLL_CONSTANT, SCROLL_ENABLE|VIPER_LEFT|VIPER_UP);
   3513  1.15.2.2  thorpej 	write_ID(adder, SCROLL_FILL, 0x0000);
   3514  1.15.2.2  thorpej 	/*
   3515  1.15.2.2  thorpej 	 * set clipping and scrolling limits to full screen
   3516  1.15.2.2  thorpej 	 */
   3517  1.15.2.2  thorpej 	for (i = 1000, adder->status = 0;
   3518  1.15.2.2  thorpej 	     i > 0 && !(adder->status&ADDRESS_COMPLETE); --i)
   3519  1.15.2.2  thorpej 		;
   3520  1.15.2.2  thorpej 	if (i == 0)
   3521  1.15.2.2  thorpej 	    printf("qd%d: setup_dragon: timeout on ADDRESS_COMPLETE\n",unit);
   3522  1.15.2.2  thorpej 	top = 0;
   3523  1.15.2.2  thorpej 	bottom = 2048;
   3524  1.15.2.2  thorpej 	left = 0;
   3525  1.15.2.2  thorpej 	right = 1024;
   3526  1.15.2.2  thorpej 	adder->x_clip_min = left;
   3527  1.15.2.2  thorpej 	adder->x_clip_max = right;
   3528  1.15.2.2  thorpej 	adder->y_clip_min = top;
   3529  1.15.2.2  thorpej 	adder->y_clip_max = bottom;
   3530  1.15.2.2  thorpej 	adder->scroll_x_min = left;
   3531  1.15.2.2  thorpej 	adder->scroll_x_max = right;
   3532  1.15.2.2  thorpej 	adder->scroll_y_min = top;
   3533  1.15.2.2  thorpej 	adder->scroll_y_max = bottom;
   3534  1.15.2.2  thorpej 	(void)wait_status(adder, VSYNC);	/* wait at LEAST 1 full frame */
   3535  1.15.2.2  thorpej 	(void)wait_status(adder, VSYNC);
   3536  1.15.2.2  thorpej 	adder->x_index_pending = left;
   3537  1.15.2.2  thorpej 	adder->y_index_pending = top;
   3538  1.15.2.2  thorpej 	adder->x_index_new = left;
   3539  1.15.2.2  thorpej 	adder->y_index_new = top;
   3540  1.15.2.2  thorpej 	adder->x_index_old = left;
   3541  1.15.2.2  thorpej 	adder->y_index_old = top;
   3542  1.15.2.2  thorpej 
   3543  1.15.2.2  thorpej 	for (i = 1000, adder->status = 0; i > 0 &&
   3544  1.15.2.2  thorpej 	     !(adder->status&ADDRESS_COMPLETE) ; --i)
   3545  1.15.2.2  thorpej 		;
   3546  1.15.2.2  thorpej 	if (i == 0)
   3547  1.15.2.2  thorpej 	       printf("qd%d: setup_dragon: timeout on ADDRESS_COMPLETE\n",unit);
   3548  1.15.2.2  thorpej 
   3549  1.15.2.2  thorpej 	write_ID(adder, LEFT_SCROLL_MASK, 0x0000);
   3550  1.15.2.2  thorpej 	write_ID(adder, RIGHT_SCROLL_MASK, 0x0000);
   3551  1.15.2.2  thorpej 	/*
   3552  1.15.2.2  thorpej 	* set source and the mask register to all ones (ie: white) o
   3553  1.15.2.2  thorpej 	*/
   3554  1.15.2.2  thorpej 	write_ID(adder, SOURCE, 0xFFFF);
   3555  1.15.2.2  thorpej 	write_ID(adder, MASK_1, 0xFFFF);
   3556  1.15.2.2  thorpej 	write_ID(adder, VIPER_Z_LOAD | FOREGROUND_COLOR_Z, 255);
   3557  1.15.2.2  thorpej 	write_ID(adder, VIPER_Z_LOAD | BACKGROUND_COLOR_Z, 0);
   3558  1.15.2.2  thorpej 	/*
   3559  1.15.2.2  thorpej 	* initialize Operand Control Register banks for fill command
   3560  1.15.2.2  thorpej 	*/
   3561  1.15.2.2  thorpej 	write_ID(adder, SRC1_OCR_A, EXT_NONE | INT_M1_M2  | NO_ID | WAIT);
   3562  1.15.2.2  thorpej 	write_ID(adder, SRC2_OCR_A, EXT_NONE | INT_SOURCE | NO_ID | NO_WAIT);
   3563  1.15.2.2  thorpej 	write_ID(adder, DST_OCR_A, EXT_NONE | INT_NONE	 | NO_ID | NO_WAIT);
   3564  1.15.2.2  thorpej 	write_ID(adder, SRC1_OCR_B, EXT_NONE | INT_SOURCE | NO_ID | WAIT);
   3565  1.15.2.2  thorpej 	write_ID(adder, SRC2_OCR_B, EXT_NONE | INT_M1_M2  | NO_ID | NO_WAIT);
   3566  1.15.2.2  thorpej 	write_ID(adder, DST_OCR_B, EXT_NONE | INT_NONE | NO_ID | NO_WAIT);
   3567  1.15.2.2  thorpej 	/*
   3568  1.15.2.2  thorpej 	* init Logic Unit Function registers, (these are just common values,
   3569  1.15.2.2  thorpej 	* and may be changed as required).
   3570  1.15.2.2  thorpej 	*/
   3571  1.15.2.2  thorpej 	write_ID(adder, LU_FUNCTION_R1, FULL_SRC_RESOLUTION | LF_SOURCE);
   3572  1.15.2.2  thorpej 	write_ID(adder, LU_FUNCTION_R2, FULL_SRC_RESOLUTION | LF_SOURCE |
   3573  1.15.2.2  thorpej 		 INV_M1_M2);
   3574  1.15.2.2  thorpej 	write_ID(adder, LU_FUNCTION_R3, FULL_SRC_RESOLUTION | LF_D_OR_S);
   3575  1.15.2.2  thorpej 	write_ID(adder, LU_FUNCTION_R4, FULL_SRC_RESOLUTION | LF_D_XOR_S);
   3576  1.15.2.2  thorpej 	/*
   3577  1.15.2.2  thorpej 	* load the color map for black & white
   3578  1.15.2.2  thorpej 	*/
   3579  1.15.2.2  thorpej 	for (i = 0, adder->status = 0; i < 10000 && !(adder->status&VSYNC); ++i)
   3580  1.15.2.2  thorpej 		;
   3581  1.15.2.2  thorpej 
   3582  1.15.2.2  thorpej 	if (i == 0)
   3583  1.15.2.2  thorpej 		printf("qd%d: setup_dragon: timeout on VSYNC\n", unit);
   3584  1.15.2.2  thorpej 
   3585  1.15.2.2  thorpej 	red = (short *) qdmap[unit].red;
   3586  1.15.2.2  thorpej 	green = (short *) qdmap[unit].green;
   3587  1.15.2.2  thorpej 	blue = (short *) qdmap[unit].blue;
   3588  1.15.2.2  thorpej 
   3589  1.15.2.2  thorpej 	*red++ = 0x00;			/* black */
   3590  1.15.2.2  thorpej 	*green++ = 0x00;
   3591  1.15.2.2  thorpej 	*blue++ = 0x00;
   3592  1.15.2.2  thorpej 
   3593  1.15.2.2  thorpej 	*red-- = 0xFF;			/* white */
   3594  1.15.2.2  thorpej 	*green-- = 0xFF;
   3595  1.15.2.2  thorpej 	*blue-- = 0xFF;
   3596  1.15.2.2  thorpej 
   3597  1.15.2.2  thorpej 	/*
   3598  1.15.2.2  thorpej 	* set color map for mouse cursor
   3599  1.15.2.2  thorpej 	*/
   3600  1.15.2.2  thorpej 
   3601  1.15.2.2  thorpej 	red += 254;
   3602  1.15.2.2  thorpej 	green += 254;
   3603  1.15.2.2  thorpej 	blue += 254;
   3604  1.15.2.2  thorpej 
   3605  1.15.2.2  thorpej 	*red++ = 0x00;			/* black */
   3606  1.15.2.2  thorpej 	*green++ = 0x00;
   3607  1.15.2.2  thorpej 	*blue++ = 0x00;
   3608  1.15.2.2  thorpej 
   3609  1.15.2.2  thorpej 	*red = 0xFF;			/* white */
   3610  1.15.2.2  thorpej 	*green = 0xFF;
   3611  1.15.2.2  thorpej 	*blue = 0xFF;
   3612  1.15.2.2  thorpej 
   3613  1.15.2.2  thorpej } /* setup_dragon */
   3614  1.15.2.2  thorpej 
   3615  1.15.2.2  thorpej /*
   3616  1.15.2.2  thorpej  * Init the DUART and set defaults in input
   3617  1.15.2.2  thorpej  */
   3618  1.15.2.2  thorpej void
   3619  1.15.2.2  thorpej setup_input(unit)
   3620  1.15.2.2  thorpej 	int unit;
   3621  1.15.2.2  thorpej {
   3622  1.15.2.2  thorpej 	volatile register struct duart *duart;	/* DUART register structure pointer */
   3623  1.15.2.2  thorpej 	register int i, bits;
   3624  1.15.2.2  thorpej 	char id_byte;
   3625  1.15.2.2  thorpej 
   3626  1.15.2.2  thorpej 	duart = (struct duart *) qdmap[unit].duart;
   3627  1.15.2.2  thorpej 	duart->imask = 0;
   3628  1.15.2.2  thorpej 
   3629  1.15.2.2  thorpej 	/*
   3630  1.15.2.2  thorpej 	* setup the DUART for kbd & pointing device
   3631  1.15.2.2  thorpej 	*/
   3632  1.15.2.2  thorpej 	duart->cmdA = RESET_M;	/* reset mode reg ptr for kbd */
   3633  1.15.2.2  thorpej 	duart->modeA = 0x13;	/* 8 bits, no parity, rcv IE, */
   3634  1.15.2.2  thorpej 				/* no RTS control,char error mode */
   3635  1.15.2.2  thorpej 	duart->modeA = 0x07;	/* 1 stop bit,CTS does not IE XMT */
   3636  1.15.2.2  thorpej 				/* no RTS control,no echo or loop */
   3637  1.15.2.2  thorpej 	duart->cmdB = RESET_M;	/* reset mode reg pntr for host */
   3638  1.15.2.2  thorpej 	duart->modeB = 0x07;	/* 8 bits, odd parity, rcv IE.. */
   3639  1.15.2.2  thorpej 				/* ..no RTS cntrl, char error mode */
   3640  1.15.2.2  thorpej 	duart->modeB = 0x07;	/* 1 stop bit,CTS does not IE XMT */
   3641  1.15.2.2  thorpej 				/* no RTS control,no echo or loop */
   3642  1.15.2.2  thorpej 	duart->auxctl = 0x00;	/* baud rate set 1 */
   3643  1.15.2.2  thorpej 	duart->clkselA = 0x99;	/* 4800 baud for kbd */
   3644  1.15.2.2  thorpej 	duart->clkselB = 0x99;	/* 4800 baud for mouse */
   3645  1.15.2.2  thorpej 
   3646  1.15.2.2  thorpej 	/* reset everything for keyboard */
   3647  1.15.2.2  thorpej 
   3648  1.15.2.2  thorpej 	for (bits = RESET_M; bits < START_BREAK; bits += 0x10)
   3649  1.15.2.2  thorpej 		duart->cmdA = bits;
   3650  1.15.2.2  thorpej 
   3651  1.15.2.2  thorpej 	/* reset everything for host */
   3652  1.15.2.2  thorpej 
   3653  1.15.2.2  thorpej 	for (bits = RESET_M; bits < START_BREAK; bits += 0x10)
   3654  1.15.2.2  thorpej 		duart->cmdB = bits;
   3655  1.15.2.2  thorpej 
   3656  1.15.2.2  thorpej 	duart->cmdA = EN_RCV | EN_XMT; /* enbl xmt & rcv for kbd */
   3657  1.15.2.2  thorpej 	duart->cmdB = EN_RCV | EN_XMT; /* enbl xmt & rcv for pointer device */
   3658  1.15.2.2  thorpej 
   3659  1.15.2.2  thorpej 	/*
   3660  1.15.2.2  thorpej 	* init keyboard defaults (DUART channel A)
   3661  1.15.2.2  thorpej 	*/
   3662  1.15.2.2  thorpej 	for (i = 500; i > 0; --i) {
   3663  1.15.2.2  thorpej 		if (duart->statusA&XMT_RDY) {
   3664  1.15.2.2  thorpej 			duart->dataA = LK_DEFAULTS;
   3665  1.15.2.2  thorpej 			break;
   3666  1.15.2.2  thorpej 		}
   3667  1.15.2.2  thorpej 	}
   3668  1.15.2.2  thorpej 
   3669  1.15.2.2  thorpej 	for (i = 100000; i > 0; --i) {
   3670  1.15.2.2  thorpej 		if (duart->statusA&RCV_RDY) {
   3671  1.15.2.2  thorpej 			break;
   3672  1.15.2.2  thorpej 		}
   3673  1.15.2.2  thorpej 	}
   3674  1.15.2.2  thorpej 
   3675  1.15.2.2  thorpej 	if (duart->dataA)	/* flush the ACK */
   3676  1.15.2.2  thorpej 		;
   3677  1.15.2.2  thorpej 
   3678  1.15.2.2  thorpej 	/*
   3679  1.15.2.2  thorpej 	* identify the pointing device
   3680  1.15.2.2  thorpej 	*/
   3681  1.15.2.2  thorpej 	for (i = 500; i > 0; --i) {
   3682  1.15.2.2  thorpej 		if (duart->statusB&XMT_RDY) {
   3683  1.15.2.2  thorpej 			duart->dataB = SELF_TEST;
   3684  1.15.2.2  thorpej 			break;
   3685  1.15.2.2  thorpej 		}
   3686  1.15.2.2  thorpej 	}
   3687  1.15.2.2  thorpej 
   3688  1.15.2.2  thorpej 	/*
   3689  1.15.2.2  thorpej 	* wait for 1st byte of self test report */
   3690  1.15.2.2  thorpej 
   3691  1.15.2.2  thorpej 	for (i = 100000; i > 0; --i) {
   3692  1.15.2.2  thorpej 		if (duart->statusB&RCV_RDY) {
   3693  1.15.2.2  thorpej 			break;
   3694  1.15.2.2  thorpej 		}
   3695  1.15.2.2  thorpej 	}
   3696  1.15.2.2  thorpej 
   3697  1.15.2.2  thorpej 	if (i == 0) {
   3698  1.15.2.2  thorpej 		printf("qd[%d]: setup_input: timeout on 1st byte of self test\n"
   3699  1.15.2.2  thorpej 		       ,unit);
   3700  1.15.2.2  thorpej 		goto OUT;
   3701  1.15.2.2  thorpej 	}
   3702  1.15.2.2  thorpej 
   3703  1.15.2.2  thorpej 	if (duart->dataB)
   3704  1.15.2.2  thorpej 		;
   3705  1.15.2.2  thorpej 
   3706  1.15.2.2  thorpej 	/*
   3707  1.15.2.2  thorpej 	* wait for ID byte of self test report
   3708  1.15.2.2  thorpej 	*/
   3709  1.15.2.2  thorpej 	for (i = 100000; i > 0; --i) {
   3710  1.15.2.2  thorpej 		if (duart->statusB&RCV_RDY) {
   3711  1.15.2.2  thorpej 			break;
   3712  1.15.2.2  thorpej 		}
   3713  1.15.2.2  thorpej 	}
   3714  1.15.2.2  thorpej 
   3715  1.15.2.2  thorpej 	if (i == 0) {
   3716  1.15.2.2  thorpej 		printf("qd[%d]: setup_input: timeout on 2nd byte of self test\n", unit);
   3717  1.15.2.2  thorpej 		goto OUT;
   3718  1.15.2.2  thorpej 	}
   3719  1.15.2.2  thorpej 
   3720  1.15.2.2  thorpej 	id_byte = duart->dataB;
   3721  1.15.2.2  thorpej 
   3722  1.15.2.2  thorpej 	/*
   3723  1.15.2.2  thorpej 	* wait for other bytes to come in
   3724  1.15.2.2  thorpej 	*/
   3725  1.15.2.2  thorpej 	for (i = 100000; i > 0; --i) {
   3726  1.15.2.2  thorpej 		if (duart->statusB & RCV_RDY) {
   3727  1.15.2.2  thorpej 			if (duart->dataB)
   3728  1.15.2.2  thorpej 				;
   3729  1.15.2.2  thorpej 			break;
   3730  1.15.2.2  thorpej 		}
   3731  1.15.2.2  thorpej 	}
   3732  1.15.2.2  thorpej 	if (i == 0) {
   3733  1.15.2.2  thorpej 		printf("qd[%d]: setup_input: timeout on 3rd byte of self test\n", unit);
   3734  1.15.2.2  thorpej 		goto OUT;
   3735  1.15.2.2  thorpej 	}
   3736  1.15.2.2  thorpej 	for (i = 100000; i > 0; --i) {
   3737  1.15.2.2  thorpej 		if (duart->statusB&RCV_RDY) {
   3738  1.15.2.2  thorpej 			if (duart->dataB)
   3739  1.15.2.2  thorpej 				;
   3740  1.15.2.2  thorpej 			break;
   3741  1.15.2.2  thorpej 		}
   3742  1.15.2.2  thorpej 	}
   3743  1.15.2.2  thorpej 	if (i == 0) {
   3744  1.15.2.2  thorpej 		printf("qd[%d]: setup_input: timeout on 4th byte of self test\n", unit);
   3745  1.15.2.2  thorpej 		goto OUT;
   3746  1.15.2.2  thorpej 	}
   3747  1.15.2.2  thorpej 	/*
   3748  1.15.2.2  thorpej 	* flag pointing device type and set defaults
   3749  1.15.2.2  thorpej 	*/
   3750  1.15.2.2  thorpej 	for (i=100000; i>0; --i)
   3751  1.15.2.2  thorpej 		;		/*XXX*/
   3752  1.15.2.2  thorpej 
   3753  1.15.2.2  thorpej 	if ((id_byte & 0x0F) != TABLET_ID) {
   3754  1.15.2.2  thorpej 		qdflags[unit].pntr_id = MOUSE_ID;
   3755  1.15.2.2  thorpej 
   3756  1.15.2.2  thorpej 		for (i = 500; i > 0; --i) {
   3757  1.15.2.2  thorpej 			if (duart->statusB&XMT_RDY) {
   3758  1.15.2.2  thorpej 				duart->dataB = INC_STREAM_MODE;
   3759  1.15.2.2  thorpej 				break;
   3760  1.15.2.2  thorpej 			}
   3761  1.15.2.2  thorpej 		}
   3762  1.15.2.2  thorpej 	}
   3763  1.15.2.2  thorpej 	else {
   3764  1.15.2.2  thorpej 		qdflags[unit].pntr_id = TABLET_ID;
   3765  1.15.2.2  thorpej 
   3766  1.15.2.2  thorpej 		for (i = 500; i > 0; --i) {
   3767  1.15.2.2  thorpej 			if (duart->statusB&XMT_RDY) {
   3768  1.15.2.2  thorpej 				duart->dataB = T_STREAM;
   3769  1.15.2.2  thorpej 				break;
   3770  1.15.2.2  thorpej 			}
   3771  1.15.2.2  thorpej 		}
   3772  1.15.2.2  thorpej 	}
   3773  1.15.2.2  thorpej OUT:
   3774  1.15.2.2  thorpej 	duart->imask = qdflags[unit].duart_imask;
   3775  1.15.2.2  thorpej 
   3776  1.15.2.2  thorpej } /* setup_input */
   3777  1.15.2.2  thorpej 
   3778  1.15.2.2  thorpej /*
   3779  1.15.2.2  thorpej  * delay for at least one display frame time
   3780  1.15.2.2  thorpej  *
   3781  1.15.2.2  thorpej  *	return: BAD means that we timed out without ever seeing the
   3782  1.15.2.2  thorpej  *		      vertical sync status bit
   3783  1.15.2.2  thorpej  *		GOOD otherwise
   3784  1.15.2.2  thorpej  */
   3785  1.15.2.2  thorpej int
   3786  1.15.2.2  thorpej wait_status(adder, mask)
   3787  1.15.2.2  thorpej 	volatile struct adder *adder;
   3788  1.15.2.2  thorpej 	int mask;
   3789  1.15.2.2  thorpej {
   3790  1.15.2.2  thorpej 	register int i;
   3791  1.15.2.2  thorpej 
   3792  1.15.2.2  thorpej 	for (i = 10000, adder->status = 0 ; i > 0  &&
   3793  1.15.2.2  thorpej 	     !(adder->status&mask) ; --i)
   3794  1.15.2.2  thorpej 		;
   3795  1.15.2.2  thorpej 
   3796  1.15.2.2  thorpej 	if (i == 0) {
   3797  1.15.2.2  thorpej 		printf("wait_status: timeout polling for 0x%x in adder->status\n", mask);
   3798  1.15.2.2  thorpej 		return(BAD);
   3799  1.15.2.2  thorpej 	}
   3800  1.15.2.2  thorpej 
   3801  1.15.2.2  thorpej 	return(GOOD);
   3802  1.15.2.2  thorpej 
   3803  1.15.2.2  thorpej } /* wait_status */
   3804  1.15.2.2  thorpej 
   3805  1.15.2.2  thorpej /*
   3806  1.15.2.2  thorpej  * write out onto the ID bus
   3807  1.15.2.2  thorpej  */
   3808  1.15.2.2  thorpej void
   3809  1.15.2.2  thorpej write_ID(adder, adrs, data)
   3810  1.15.2.2  thorpej 	volatile struct adder *adder;
   3811  1.15.2.2  thorpej 	short adrs;
   3812  1.15.2.2  thorpej 	short data;
   3813  1.15.2.2  thorpej {
   3814  1.15.2.2  thorpej 	register int i;
   3815  1.15.2.2  thorpej 
   3816  1.15.2.2  thorpej 	for (i = 100000, adder->status = 0 ;
   3817  1.15.2.2  thorpej 	      i > 0  &&  !(adder->status&ADDRESS_COMPLETE) ; --i)
   3818  1.15.2.2  thorpej 		;
   3819  1.15.2.2  thorpej 
   3820  1.15.2.2  thorpej 	if (i == 0)
   3821  1.15.2.2  thorpej 		goto ERR;
   3822  1.15.2.2  thorpej 
   3823  1.15.2.2  thorpej 	for (i = 100000, adder->status = 0 ;
   3824  1.15.2.2  thorpej 	      i > 0  &&  !(adder->status&TX_READY) ; --i)
   3825  1.15.2.2  thorpej 		;
   3826  1.15.2.2  thorpej 
   3827  1.15.2.2  thorpej 	if (i > 0) {
   3828  1.15.2.2  thorpej 		adder->id_data = data;
   3829  1.15.2.2  thorpej 		adder->command = ID_LOAD | adrs;
   3830  1.15.2.2  thorpej 		return ;
   3831  1.15.2.2  thorpej 	}
   3832  1.15.2.2  thorpej 
   3833  1.15.2.2  thorpej ERR:
   3834  1.15.2.2  thorpej 	printf("write_ID: timeout trying to write to VIPER\n");
   3835  1.15.2.2  thorpej 	return ;
   3836  1.15.2.2  thorpej 
   3837  1.15.2.2  thorpej } /* write_ID */
   3838