Home | History | Annotate | Line # | Download | only in vsa
smg.c revision 1.27.8.5
      1  1.27.8.4   nathanw /*	$NetBSD: smg.c,v 1.27.8.5 2002/09/17 21:18:39 nathanw Exp $ */
      2       1.1     ragge /*
      3       1.1     ragge  * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
      4       1.1     ragge  * All rights reserved.
      5       1.1     ragge  *
      6       1.1     ragge  * Redistribution and use in source and binary forms, with or without
      7       1.1     ragge  * modification, are permitted provided that the following conditions
      8       1.1     ragge  * are met:
      9       1.1     ragge  * 1. Redistributions of source code must retain the above copyright
     10       1.1     ragge  *    notice, this list of conditions and the following disclaimer.
     11       1.1     ragge  * 2. Redistributions in binary form must reproduce the above copyright
     12       1.1     ragge  *    notice, this list of conditions and the following disclaimer in the
     13       1.1     ragge  *    documentation and/or other materials provided with the distribution.
     14       1.1     ragge  * 3. All advertising materials mentioning features or use of this software
     15       1.1     ragge  *    must display the following acknowledgement:
     16       1.6     ragge  *	This product includes software developed at Ludd, University of
     17       1.6     ragge  *	Lule}, Sweden and its contributors.
     18       1.1     ragge  * 4. The name of the author may not be used to endorse or promote products
     19       1.1     ragge  *    derived from this software without specific prior written permission
     20       1.1     ragge  *
     21       1.1     ragge  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22       1.1     ragge  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23       1.1     ragge  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24       1.1     ragge  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25       1.1     ragge  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26       1.1     ragge  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27       1.1     ragge  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28       1.1     ragge  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29       1.1     ragge  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30       1.1     ragge  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31       1.1     ragge  */
     32       1.1     ragge 
     33       1.1     ragge #include <sys/param.h>
     34       1.1     ragge #include <sys/device.h>
     35       1.1     ragge #include <sys/systm.h>
     36      1.21   thorpej #include <sys/callout.h>
     37       1.1     ragge #include <sys/time.h>
     38       1.1     ragge #include <sys/malloc.h>
     39       1.1     ragge #include <sys/conf.h>
     40       1.6     ragge #include <sys/kernel.h>
     41       1.1     ragge 
     42      1.26     ragge #include <machine/vsbus.h>
     43      1.26     ragge #include <machine/sid.h>
     44      1.26     ragge #include <machine/cpu.h>
     45      1.26     ragge #include <machine/ka420.h>
     46      1.26     ragge 
     47       1.1     ragge #include <dev/cons.h>
     48       1.1     ragge 
     49  1.27.8.1   nathanw #include <dev/dec/dzreg.h>
     50  1.27.8.1   nathanw #include <dev/dec/dzvar.h>
     51      1.26     ragge #include <dev/dec/dzkbdvar.h>
     52      1.26     ragge 
     53       1.1     ragge #include <dev/wscons/wsdisplayvar.h>
     54       1.1     ragge #include <dev/wscons/wsconsio.h>
     55       1.1     ragge #include <dev/wscons/wscons_callbacks.h>
     56       1.1     ragge 
     57      1.26     ragge #include "dzkbd.h"
     58      1.26     ragge #include "opt_wsfont.h"
     59       1.1     ragge 
     60      1.26     ragge /* Safety guard */
     61      1.26     ragge #ifndef FONT_QVSS8x15
     62      1.26     ragge #include <dev/wsfont/qvss8x15.h>
     63      1.26     ragge #endif
     64       1.1     ragge 
     65      1.26     ragge /* Screen hardware defs */
     66       1.6     ragge #define SM_COLS		128	/* char width of screen */
     67       1.6     ragge #define SM_ROWS		57	/* rows of char on screen */
     68       1.6     ragge #define SM_CHEIGHT	15	/* lines a char consists of */
     69       1.6     ragge #define SM_NEXTROW	(SM_COLS * SM_CHEIGHT)
     70      1.26     ragge #define	SM_YWIDTH	864
     71      1.26     ragge #define SM_XWIDTH	1024
     72      1.26     ragge 
     73      1.26     ragge /* Cursor register definitions */
     74      1.26     ragge #define	CUR_CMD		0
     75      1.26     ragge #define	CUR_XPOS	4
     76      1.26     ragge #define CUR_YPOS	8
     77      1.26     ragge #define CUR_XMIN_1	12
     78      1.26     ragge #define CUR_XMAX_1	16
     79      1.26     ragge #define CUR_YMIN_1	20
     80      1.26     ragge #define CUR_YMAX_1	24
     81      1.26     ragge #define CUR_XMIN_2	28
     82      1.26     ragge #define CUR_XMAX_2	32
     83      1.26     ragge #define CUR_YMIN_2	36
     84      1.26     ragge #define CUR_YMAX_2	40
     85      1.26     ragge #define CUR_LOAD	44
     86      1.26     ragge 
     87      1.26     ragge #define CUR_CMD_TEST	0x8000
     88      1.26     ragge #define CUR_CMD_HSHI	0x4000
     89      1.26     ragge #define CUR_CMD_VBHI	0x2000
     90      1.26     ragge #define CUR_CMD_LODSA	0x1000
     91      1.26     ragge #define CUR_CMD_FORG2	0x0800
     92      1.26     ragge #define CUR_CMD_ENRG2	0x0400
     93      1.26     ragge #define CUR_CMD_FORG1	0x0200
     94      1.26     ragge #define CUR_CMD_ENRG1	0x0100
     95      1.26     ragge #define CUR_CMD_XHWID	0x0080
     96      1.26     ragge #define CUR_CMD_XHCL1	0x0040
     97      1.26     ragge #define CUR_CMD_XHCLP	0x0020
     98      1.26     ragge #define CUR_CMD_XHAIR	0x0010
     99      1.26     ragge #define CUR_CMD_FOPB	0x0008
    100      1.26     ragge #define CUR_CMD_ENPB	0x0004
    101      1.26     ragge #define CUR_CMD_FOPA	0x0002
    102      1.26     ragge #define CUR_CMD_ENPA	0x0001
    103      1.26     ragge 
    104      1.26     ragge #define CUR_XBIAS	216	/* Add to cursor position */
    105      1.26     ragge #define	CUR_YBIAS	33
    106      1.26     ragge 
    107      1.26     ragge #define	WRITECUR(addr, val)	*(volatile short *)(curaddr + (addr)) = (val)
    108      1.26     ragge static	caddr_t	curaddr;
    109      1.26     ragge static	short curcmd, curx, cury, hotX, hotY;
    110      1.26     ragge static	int bgmask, fgmask;
    111       1.1     ragge 
    112      1.24      matt static	int smg_match(struct device *, struct cfdata *, void *);
    113      1.24      matt static	void smg_attach(struct device *, struct device *, void *);
    114       1.1     ragge 
    115       1.1     ragge struct	smg_softc {
    116       1.1     ragge 	struct	device ss_dev;
    117       1.1     ragge };
    118       1.1     ragge 
    119       1.1     ragge struct cfattach smg_ca = {
    120       1.1     ragge 	sizeof(struct smg_softc), smg_match, smg_attach,
    121       1.1     ragge };
    122       1.1     ragge 
    123      1.24      matt static void	smg_cursor(void *, int, int, int);
    124      1.24      matt static int	smg_mapchar(void *, int, unsigned int *);
    125      1.24      matt static void	smg_putchar(void *, int, int, u_int, long);
    126      1.24      matt static void	smg_copycols(void *, int, int, int,int);
    127      1.24      matt static void	smg_erasecols(void *, int, int, int, long);
    128      1.24      matt static void	smg_copyrows(void *, int, int, int);
    129      1.24      matt static void	smg_eraserows(void *, int, int, long);
    130  1.27.8.4   nathanw static int	smg_allocattr(void *, int, int, int, long *);
    131       1.1     ragge 
    132       1.1     ragge const struct wsdisplay_emulops smg_emulops = {
    133       1.1     ragge 	smg_cursor,
    134       1.5  drochner 	smg_mapchar,
    135       1.4  drochner 	smg_putchar,
    136       1.1     ragge 	smg_copycols,
    137       1.1     ragge 	smg_erasecols,
    138       1.1     ragge 	smg_copyrows,
    139       1.1     ragge 	smg_eraserows,
    140  1.27.8.4   nathanw 	smg_allocattr
    141       1.1     ragge };
    142       1.1     ragge 
    143       1.1     ragge const struct wsscreen_descr smg_stdscreen = {
    144       1.6     ragge 	"128x57", SM_COLS, SM_ROWS,
    145       1.6     ragge 	&smg_emulops,
    146       1.6     ragge 	8, SM_CHEIGHT,
    147       1.6     ragge 	WSSCREEN_UNDERLINE|WSSCREEN_REVERSE,
    148       1.1     ragge };
    149       1.1     ragge 
    150       1.1     ragge const struct wsscreen_descr *_smg_scrlist[] = {
    151       1.1     ragge 	&smg_stdscreen,
    152       1.1     ragge };
    153       1.1     ragge 
    154       1.1     ragge const struct wsscreen_list smg_screenlist = {
    155       1.1     ragge 	sizeof(_smg_scrlist) / sizeof(struct wsscreen_descr *),
    156       1.1     ragge 	_smg_scrlist,
    157       1.1     ragge };
    158       1.1     ragge 
    159      1.12     ragge static	caddr_t	sm_addr;
    160      1.12     ragge 
    161      1.26     ragge extern struct wsdisplay_font qvss8x15;
    162      1.26     ragge static  u_char *qf;
    163      1.26     ragge 
    164       1.6     ragge #define QCHAR(c) (c < 32 ? 32 : (c > 127 ? c - 66 : c - 32))
    165      1.26     ragge #define QFONT(c,line)	qf[QCHAR(c) * 15 + line]
    166       1.6     ragge #define	SM_ADDR(row, col, line) \
    167       1.6     ragge 	sm_addr[col + (row * SM_CHEIGHT * SM_COLS) + line * SM_COLS]
    168       1.6     ragge 
    169       1.6     ragge 
    170      1.24      matt static int	smg_ioctl(void *, u_long, caddr_t, int, struct proc *);
    171      1.24      matt static paddr_t	smg_mmap(void *, off_t, int);
    172      1.24      matt static int	smg_alloc_screen(void *, const struct wsscreen_descr *,
    173      1.24      matt 				      void **, int *, int *, long *);
    174      1.24      matt static void	smg_free_screen(void *, void *);
    175      1.24      matt static int	smg_show_screen(void *, void *, int,
    176      1.24      matt 				     void (*) (void *, int, int), void *);
    177      1.24      matt static void	smg_crsr_blink(void *);
    178       1.1     ragge 
    179       1.1     ragge const struct wsdisplay_accessops smg_accessops = {
    180       1.1     ragge 	smg_ioctl,
    181       1.1     ragge 	smg_mmap,
    182       1.1     ragge 	smg_alloc_screen,
    183       1.1     ragge 	smg_free_screen,
    184       1.1     ragge 	smg_show_screen,
    185      1.11  drochner 	0 /* load_font */
    186       1.1     ragge };
    187       1.1     ragge 
    188       1.1     ragge struct	smg_screen {
    189       1.1     ragge 	int	ss_curx;
    190       1.1     ragge 	int	ss_cury;
    191       1.2     ragge 	u_char	ss_image[SM_ROWS][SM_COLS];	/* Image of current screen */
    192       1.6     ragge 	u_char	ss_attr[SM_ROWS][SM_COLS];	/* Reversed etc... */
    193       1.1     ragge };
    194       1.1     ragge 
    195       1.2     ragge static	struct smg_screen smg_conscreen;
    196       1.2     ragge static	struct smg_screen *curscr;
    197       1.1     ragge 
    198      1.21   thorpej static	struct callout smg_cursor_ch = CALLOUT_INITIALIZER;
    199      1.21   thorpej 
    200       1.1     ragge int
    201      1.26     ragge smg_match(struct device *parent, struct cfdata *match, void *aux)
    202       1.1     ragge {
    203      1.15     ragge 	struct vsbus_attach_args *va = aux;
    204      1.17     ragge 	volatile short *curcmd;
    205      1.17     ragge 	volatile short *cfgtst;
    206      1.15     ragge 	short tmp, tmp2;
    207      1.15     ragge 
    208      1.27     ragge 	if (vax_boardtype == VAX_BTYP_49 || vax_boardtype == VAX_BTYP_53)
    209      1.17     ragge 		return 0;
    210      1.17     ragge 
    211      1.17     ragge 	curcmd = (short *)va->va_addr;
    212      1.17     ragge 	cfgtst = (short *)vax_map_physmem(VS_CFGTST, 1);
    213      1.15     ragge 	/*
    214      1.15     ragge 	 * Try to find the cursor chip by testing the flip-flop.
    215      1.15     ragge 	 * If nonexistent, no glass tty.
    216      1.15     ragge 	 */
    217      1.26     ragge 	curcmd[0] = CUR_CMD_HSHI|CUR_CMD_FOPB;
    218      1.15     ragge 	DELAY(300000);
    219      1.15     ragge 	tmp = cfgtst[0];
    220      1.26     ragge 	curcmd[0] = CUR_CMD_TEST|CUR_CMD_HSHI;
    221      1.15     ragge 	DELAY(300000);
    222      1.15     ragge 	tmp2 = cfgtst[0];
    223      1.15     ragge 	vax_unmap_physmem((vaddr_t)cfgtst, 1);
    224      1.15     ragge 
    225      1.15     ragge 	if (tmp2 != tmp)
    226      1.15     ragge 		return 20; /* Using periodic interrupt */
    227      1.15     ragge 	else
    228      1.12     ragge 		return 0;
    229       1.1     ragge }
    230       1.1     ragge 
    231       1.1     ragge void
    232      1.26     ragge smg_attach(struct device *parent, struct device *self, void *aux)
    233       1.1     ragge {
    234       1.1     ragge 	struct wsemuldisplaydev_attach_args aa;
    235       1.1     ragge 
    236       1.1     ragge 	printf("\n");
    237      1.15     ragge 	sm_addr = (caddr_t)vax_map_physmem(SMADDR, (SMSIZE/VAX_NBPG));
    238      1.26     ragge 	curaddr = (caddr_t)vax_map_physmem(KA420_CUR_BASE, 1);
    239      1.15     ragge 	if (sm_addr == 0) {
    240      1.15     ragge 		printf("%s: Couldn't alloc graphics memory.\n", self->dv_xname);
    241      1.15     ragge 		return;
    242      1.15     ragge 	}
    243       1.2     ragge 	curscr = &smg_conscreen;
    244  1.27.8.3   nathanw 	aa.console = (vax_confdata & (KA420_CFG_L3CON|KA420_CFG_MULTU)) == 0;
    245  1.27.8.3   nathanw 
    246       1.1     ragge 	aa.scrdata = &smg_screenlist;
    247       1.1     ragge 	aa.accessops = &smg_accessops;
    248      1.22     ragge 	callout_reset(&smg_cursor_ch, hz / 2, smg_crsr_blink, NULL);
    249      1.26     ragge 	curcmd = CUR_CMD_HSHI;
    250      1.26     ragge 	WRITECUR(CUR_CMD, curcmd);
    251      1.26     ragge 	qf = qvss8x15.data;
    252       1.1     ragge 
    253       1.1     ragge 	config_found(self, &aa, wsemuldisplaydevprint);
    254       1.1     ragge }
    255       1.1     ragge 
    256       1.6     ragge static	u_char *cursor;
    257       1.6     ragge static	int cur_on;
    258       1.6     ragge 
    259       1.6     ragge static void
    260      1.26     ragge smg_crsr_blink(void *arg)
    261       1.6     ragge {
    262       1.6     ragge 	if (cur_on)
    263       1.6     ragge 		*cursor ^= 255;
    264      1.21   thorpej 	callout_reset(&smg_cursor_ch, hz / 2, smg_crsr_blink, NULL);
    265       1.6     ragge }
    266       1.6     ragge 
    267       1.1     ragge void
    268      1.26     ragge smg_cursor(void *id, int on, int row, int col)
    269       1.1     ragge {
    270       1.2     ragge 	struct smg_screen *ss = id;
    271       1.2     ragge 
    272       1.6     ragge 	if (ss == curscr) {
    273       1.6     ragge 		SM_ADDR(ss->ss_cury, ss->ss_curx, 14) =
    274       1.6     ragge 		    QFONT(ss->ss_image[ss->ss_cury][ss->ss_curx], 14);
    275       1.6     ragge 		cursor = &SM_ADDR(row, col, 14);
    276       1.6     ragge 		if ((cur_on = on))
    277       1.6     ragge 			*cursor ^= 255;
    278       1.6     ragge 	}
    279       1.2     ragge 	ss->ss_curx = col;
    280       1.2     ragge 	ss->ss_cury = row;
    281       1.5  drochner }
    282       1.5  drochner 
    283      1.14     ragge int
    284      1.26     ragge smg_mapchar(void *id, int uni, unsigned int *index)
    285       1.5  drochner {
    286      1.13  drochner 	if (uni < 256) {
    287      1.13  drochner 		*index = uni;
    288      1.13  drochner 		return (5);
    289      1.13  drochner 	}
    290      1.13  drochner 	*index = ' ';
    291       1.5  drochner 	return (0);
    292       1.1     ragge }
    293       1.1     ragge 
    294       1.1     ragge static void
    295      1.26     ragge smg_putchar(void *id, int row, int col, u_int c, long attr)
    296       1.1     ragge {
    297       1.2     ragge 	struct smg_screen *ss = id;
    298       1.4  drochner 	int i;
    299       1.1     ragge 
    300       1.4  drochner 	c &= 0xff;
    301       1.4  drochner 
    302       1.4  drochner 	ss->ss_image[row][col] = c;
    303       1.6     ragge 	ss->ss_attr[row][col] = attr;
    304       1.2     ragge 	if (ss != curscr)
    305       1.2     ragge 		return;
    306       1.6     ragge 	for (i = 0; i < 15; i++) {
    307       1.6     ragge 		unsigned char ch = QFONT(c, i);
    308       1.6     ragge 
    309       1.6     ragge 		SM_ADDR(row, col, i) = (attr & WSATTR_REVERSE ? ~ch : ch);
    310       1.6     ragge 
    311       1.6     ragge 	}
    312       1.6     ragge 	if (attr & WSATTR_UNDERLINE)
    313       1.6     ragge 		SM_ADDR(row, col, 14) ^= SM_ADDR(row, col, 14);
    314       1.1     ragge }
    315       1.1     ragge 
    316       1.1     ragge /*
    317       1.1     ragge  * copies columns inside a row.
    318       1.1     ragge  */
    319       1.1     ragge static void
    320      1.26     ragge smg_copycols(void *id, int row, int srccol, int dstcol, int ncols)
    321       1.1     ragge {
    322       1.2     ragge 	struct smg_screen *ss = id;
    323       1.1     ragge 	int i;
    324       1.1     ragge 
    325       1.2     ragge 	bcopy(&ss->ss_image[row][srccol], &ss->ss_image[row][dstcol], ncols);
    326       1.6     ragge 	bcopy(&ss->ss_attr[row][srccol], &ss->ss_attr[row][dstcol], ncols);
    327       1.2     ragge 	if (ss != curscr)
    328       1.2     ragge 		return;
    329       1.1     ragge 	for (i = 0; i < SM_CHEIGHT; i++)
    330       1.6     ragge 		bcopy(&SM_ADDR(row,srccol, i), &SM_ADDR(row, dstcol, i),ncols);
    331       1.1     ragge }
    332       1.1     ragge 
    333       1.1     ragge /*
    334       1.1     ragge  * Erases a bunch of chars inside one row.
    335       1.1     ragge  */
    336       1.1     ragge static void
    337      1.26     ragge smg_erasecols(void *id, int row, int startcol, int ncols, long fillattr)
    338       1.1     ragge {
    339       1.2     ragge 	struct smg_screen *ss = id;
    340       1.1     ragge 	int i;
    341       1.1     ragge 
    342       1.2     ragge 	bzero(&ss->ss_image[row][startcol], ncols);
    343       1.6     ragge 	bzero(&ss->ss_attr[row][startcol], ncols);
    344       1.2     ragge 	if (ss != curscr)
    345       1.2     ragge 		return;
    346       1.1     ragge 	for (i = 0; i < SM_CHEIGHT; i++)
    347       1.6     ragge 		bzero(&SM_ADDR(row, startcol, i), ncols);
    348       1.1     ragge }
    349       1.1     ragge 
    350       1.1     ragge static void
    351      1.26     ragge smg_copyrows(void *id, int srcrow, int dstrow, int nrows)
    352       1.1     ragge {
    353       1.2     ragge 	struct smg_screen *ss = id;
    354       1.1     ragge 	int frows;
    355       1.1     ragge 
    356       1.6     ragge 	bcopy(&ss->ss_image[srcrow][0], &ss->ss_image[dstrow][0],
    357       1.6     ragge 	    nrows * SM_COLS);
    358       1.6     ragge 	bcopy(&ss->ss_attr[srcrow][0], &ss->ss_attr[dstrow][0],
    359       1.6     ragge 	    nrows * SM_COLS);
    360       1.2     ragge 	if (ss != curscr)
    361       1.2     ragge 		return;
    362       1.1     ragge 	if (nrows > 25) {
    363       1.1     ragge 		frows = nrows >> 1;
    364       1.1     ragge 		if (srcrow > dstrow) {
    365       1.1     ragge 			bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
    366       1.1     ragge 			    &sm_addr[(dstrow * SM_NEXTROW)],
    367       1.1     ragge 			    frows * SM_NEXTROW);
    368       1.1     ragge 			bcopy(&sm_addr[((srcrow + frows) * SM_NEXTROW)],
    369       1.1     ragge 			    &sm_addr[((dstrow + frows) * SM_NEXTROW)],
    370       1.1     ragge 			    (nrows - frows) * SM_NEXTROW);
    371       1.1     ragge 		} else {
    372       1.1     ragge 			bcopy(&sm_addr[((srcrow + frows) * SM_NEXTROW)],
    373       1.1     ragge 			    &sm_addr[((dstrow + frows) * SM_NEXTROW)],
    374       1.1     ragge 			    (nrows - frows) * SM_NEXTROW);
    375       1.1     ragge 			bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
    376       1.1     ragge 			    &sm_addr[(dstrow * SM_NEXTROW)],
    377       1.1     ragge 			    frows * SM_NEXTROW);
    378       1.1     ragge 		}
    379       1.1     ragge 	} else
    380       1.1     ragge 		bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
    381       1.1     ragge 		    &sm_addr[(dstrow * SM_NEXTROW)], nrows * SM_NEXTROW);
    382       1.1     ragge }
    383       1.1     ragge 
    384       1.1     ragge static void
    385      1.26     ragge smg_eraserows(void *id, int startrow, int nrows, long fillattr)
    386       1.1     ragge {
    387       1.2     ragge 	struct smg_screen *ss = id;
    388       1.1     ragge 	int frows;
    389       1.1     ragge 
    390       1.6     ragge 	bzero(&ss->ss_image[startrow][0], nrows * SM_COLS);
    391       1.6     ragge 	bzero(&ss->ss_attr[startrow][0], nrows * SM_COLS);
    392       1.2     ragge 	if (ss != curscr)
    393       1.2     ragge 		return;
    394       1.1     ragge 	if (nrows > 25) {
    395       1.1     ragge 		frows = nrows >> 1;
    396       1.1     ragge 		bzero(&sm_addr[(startrow * SM_NEXTROW)], frows * SM_NEXTROW);
    397       1.1     ragge 		bzero(&sm_addr[((startrow + frows) * SM_NEXTROW)],
    398       1.1     ragge 		    (nrows - frows) * SM_NEXTROW);
    399       1.1     ragge 	} else
    400       1.1     ragge 		bzero(&sm_addr[(startrow * SM_NEXTROW)], nrows * SM_NEXTROW);
    401       1.1     ragge }
    402       1.1     ragge 
    403       1.1     ragge static int
    404  1.27.8.4   nathanw smg_allocattr(void *id, int fg, int bg, int flags, long *attrp)
    405       1.1     ragge {
    406       1.6     ragge 	*attrp = flags;
    407       1.1     ragge 	return 0;
    408       1.1     ragge }
    409       1.1     ragge 
    410      1.26     ragge static void
    411      1.26     ragge setcursor(struct wsdisplay_cursor *v)
    412      1.26     ragge {
    413      1.26     ragge 	u_short red, green, blue, curfg[16], curmask[16];
    414      1.26     ragge 	int i;
    415      1.26     ragge 
    416      1.26     ragge 	/* Enable cursor */
    417      1.26     ragge 	if (v->which & WSDISPLAY_CURSOR_DOCUR) {
    418      1.26     ragge 		if (v->enable)
    419      1.26     ragge 			curcmd |= CUR_CMD_ENPB|CUR_CMD_ENPA;
    420      1.26     ragge 		else
    421      1.26     ragge 			curcmd &= ~(CUR_CMD_ENPB|CUR_CMD_ENPA);
    422      1.26     ragge 		WRITECUR(CUR_CMD, curcmd);
    423      1.26     ragge 	}
    424      1.26     ragge 	if (v->which & WSDISPLAY_CURSOR_DOHOT) {
    425      1.26     ragge 		hotX = v->hot.x;
    426      1.26     ragge 		hotY = v->hot.y;
    427      1.26     ragge 	}
    428      1.26     ragge 	if (v->which & WSDISPLAY_CURSOR_DOCMAP) {
    429      1.26     ragge 		/* First background */
    430      1.26     ragge 		red = fusword(v->cmap.red);
    431      1.26     ragge 		green = fusword(v->cmap.green);
    432      1.26     ragge 		blue = fusword(v->cmap.blue);
    433      1.26     ragge 		bgmask = (((30L * red + 59L * green + 11L * blue) >> 8) >=
    434      1.26     ragge 		    (((1<<8)-1)*50)) ? ~0 : 0;
    435      1.26     ragge 		red = fusword(v->cmap.red+2);
    436      1.26     ragge 		green = fusword(v->cmap.green+2);
    437      1.26     ragge 		blue = fusword(v->cmap.blue+2);
    438      1.26     ragge 		fgmask = (((30L * red + 59L * green + 11L * blue) >> 8) >=
    439      1.26     ragge 		    (((1<<8)-1)*50)) ? ~0 : 0;
    440      1.26     ragge 	}
    441      1.26     ragge 	if (v->which & WSDISPLAY_CURSOR_DOSHAPE) {
    442      1.26     ragge 		WRITECUR(CUR_CMD, curcmd | CUR_CMD_LODSA);
    443      1.26     ragge 		copyin(v->image, curfg, sizeof(curfg));
    444      1.26     ragge 		copyin(v->mask, curmask, sizeof(curmask));
    445      1.26     ragge 		for (i = 0; i < sizeof(curfg)/2; i++) {
    446      1.26     ragge 			WRITECUR(CUR_LOAD, (curfg[i] & fgmask) |
    447      1.26     ragge 			    ((curmask[i] & ~curfg[i]) & bgmask));
    448      1.26     ragge 		}
    449      1.26     ragge 		for (i = 0; i < sizeof(curmask)/2; i++) {
    450      1.26     ragge 			WRITECUR(CUR_LOAD, curmask[i]);
    451      1.26     ragge 		}
    452      1.26     ragge 		WRITECUR(CUR_CMD, curcmd);
    453      1.26     ragge 	}
    454      1.26     ragge }
    455      1.26     ragge 
    456       1.1     ragge int
    457      1.26     ragge smg_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
    458       1.1     ragge {
    459      1.26     ragge 	struct wsdisplay_fbinfo *fb = (void *)data;
    460      1.26     ragge 	static short curc;
    461       1.8     ragge 
    462       1.8     ragge 	switch (cmd) {
    463       1.8     ragge 	case WSDISPLAYIO_GTYPE:
    464      1.26     ragge 		*(u_int *)data = WSDISPLAY_TYPE_VAX_MONO;
    465       1.8     ragge 		break;
    466       1.8     ragge 
    467       1.8     ragge 	case WSDISPLAYIO_GINFO:
    468      1.26     ragge 		fb->height = SM_YWIDTH;
    469      1.26     ragge 		fb->width = SM_XWIDTH;
    470      1.26     ragge 		fb->depth = 1;
    471      1.26     ragge 		fb->cmsize = 2;
    472      1.26     ragge 		break;
    473      1.26     ragge 
    474      1.26     ragge 	case WSDISPLAYIO_SVIDEO:
    475      1.26     ragge 		if (*(u_int *)data == WSDISPLAYIO_VIDEO_ON) {
    476      1.26     ragge 			curcmd = curc;
    477      1.26     ragge 		} else {
    478      1.26     ragge 			curc = curcmd;
    479      1.26     ragge 			curcmd &= ~(CUR_CMD_FOPA|CUR_CMD_ENPA);
    480      1.26     ragge 			curcmd |= CUR_CMD_FOPB;
    481      1.26     ragge 		}
    482      1.26     ragge 		WRITECUR(CUR_CMD, curcmd);
    483      1.26     ragge 		break;
    484      1.26     ragge 
    485      1.26     ragge 	case WSDISPLAYIO_GVIDEO:
    486      1.26     ragge 		*(u_int *)data = (curcmd & CUR_CMD_FOPB ?
    487      1.26     ragge 		    WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON);
    488      1.26     ragge 		break;
    489      1.26     ragge 
    490      1.26     ragge 	case WSDISPLAYIO_SCURSOR:
    491      1.26     ragge 		setcursor((struct wsdisplay_cursor *)data);
    492      1.26     ragge 		break;
    493      1.26     ragge 
    494      1.26     ragge 	case WSDISPLAYIO_SCURPOS:
    495      1.26     ragge 		curx = ((struct wsdisplay_curpos *)data)->x;
    496      1.26     ragge 		cury = ((struct wsdisplay_curpos *)data)->y;
    497      1.26     ragge 		WRITECUR(CUR_XPOS, curx + CUR_XBIAS);
    498      1.26     ragge 		WRITECUR(CUR_YPOS, cury + CUR_YBIAS);
    499      1.26     ragge 		break;
    500      1.26     ragge 
    501      1.26     ragge 	case WSDISPLAYIO_GCURPOS:
    502      1.26     ragge 		((struct wsdisplay_curpos *)data)->x = curx;
    503      1.26     ragge 		((struct wsdisplay_curpos *)data)->y = cury;
    504      1.26     ragge 		break;
    505       1.8     ragge 
    506       1.8     ragge 	default:
    507  1.27.8.2   nathanw 		return EPASSTHROUGH;
    508       1.8     ragge 	}
    509       1.8     ragge 	return 0;
    510       1.1     ragge }
    511       1.1     ragge 
    512      1.23    simonb static paddr_t
    513      1.26     ragge smg_mmap(void *v, off_t offset, int prot)
    514       1.1     ragge {
    515       1.9       mrg 	if (offset >= SMSIZE || offset < 0)
    516       1.8     ragge 		return -1;
    517      1.20     ragge 	return (SMADDR + offset) >> PGSHIFT;
    518       1.1     ragge }
    519       1.1     ragge 
    520       1.1     ragge int
    521      1.26     ragge smg_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
    522      1.26     ragge     int *curxp, int *curyp, long *defattrp)
    523       1.1     ragge {
    524       1.2     ragge 	*cookiep = malloc(sizeof(struct smg_screen), M_DEVBUF, M_WAITOK);
    525       1.3     ragge 	bzero(*cookiep, sizeof(struct smg_screen));
    526       1.3     ragge 	*curxp = *curyp = *defattrp = 0;
    527       1.1     ragge 	return 0;
    528       1.1     ragge }
    529       1.1     ragge 
    530       1.1     ragge void
    531      1.26     ragge smg_free_screen(void *v, void *cookie)
    532       1.1     ragge {
    533       1.1     ragge }
    534       1.1     ragge 
    535      1.19  drochner int
    536      1.26     ragge smg_show_screen(void *v, void *cookie, int waitok,
    537      1.26     ragge     void (*cb)(void *, int, int), void *cbarg)
    538       1.1     ragge {
    539       1.2     ragge 	struct smg_screen *ss = cookie;
    540       1.2     ragge 	int row, col, line;
    541       1.2     ragge 
    542       1.2     ragge 	if (ss == curscr)
    543      1.19  drochner 		return (0);
    544       1.2     ragge 
    545       1.6     ragge 	for (row = 0; row < SM_ROWS; row++)
    546       1.8     ragge 		for (line = 0; line < SM_CHEIGHT; line++) {
    547       1.6     ragge 			for (col = 0; col < SM_COLS; col++) {
    548       1.6     ragge 				u_char s, c = ss->ss_image[row][col];
    549       1.6     ragge 
    550       1.6     ragge 				if (c < 32)
    551       1.6     ragge 					c = 32;
    552       1.6     ragge 				s = QFONT(c, line);
    553       1.6     ragge 				if (ss->ss_attr[row][col] & WSATTR_REVERSE)
    554       1.6     ragge 					s ^= 255;
    555       1.6     ragge 				SM_ADDR(row, col, line) = s;
    556       1.2     ragge 			}
    557       1.8     ragge 			if (ss->ss_attr[row][col] & WSATTR_UNDERLINE)
    558       1.8     ragge 				SM_ADDR(row, col, line) = 255;
    559       1.8     ragge 		}
    560       1.6     ragge 	cursor = &sm_addr[(ss->ss_cury * SM_CHEIGHT * SM_COLS) + ss->ss_curx +
    561       1.6     ragge 	    ((SM_CHEIGHT - 1) * SM_COLS)];
    562       1.2     ragge 	curscr = ss;
    563      1.19  drochner 	return (0);
    564       1.1     ragge }
    565       1.1     ragge 
    566       1.1     ragge cons_decl(smg);
    567       1.1     ragge 
    568       1.1     ragge void
    569       1.1     ragge smgcninit(cndev)
    570       1.6     ragge 	struct	consdev *cndev;
    571       1.1     ragge {
    572      1.24      matt 	extern void lkccninit(struct consdev *);
    573      1.24      matt 	extern int lkccngetc(dev_t);
    574      1.26     ragge 	extern int dz_vsbus_lk201_cnattach __P((int));
    575       1.1     ragge 	/* Clear screen */
    576      1.10     ragge 	memset(sm_addr, 0, 128*864);
    577       1.1     ragge 
    578       1.2     ragge 	curscr = &smg_conscreen;
    579       1.2     ragge 	wsdisplay_cnattach(&smg_stdscreen, &smg_conscreen, 0, 0, 0);
    580      1.18     ragge 	cn_tab->cn_pri = CN_INTERNAL;
    581      1.26     ragge 	qf = qvss8x15.data;
    582      1.26     ragge 
    583      1.26     ragge #if NDZKBD > 0
    584      1.26     ragge 	dzkbd_cnattach(0); /* Connect keyboard and screen together */
    585       1.1     ragge #endif
    586       1.1     ragge }
    587       1.1     ragge 
    588      1.18     ragge /*
    589      1.18     ragge  * Called very early to setup the glass tty as console.
    590      1.18     ragge  * Because it's called before the VM system is inited, virtual memory
    591      1.18     ragge  * for the framebuffer can be stolen directly without disturbing anything.
    592      1.18     ragge  */
    593      1.18     ragge void
    594      1.18     ragge smgcnprobe(cndev)
    595      1.18     ragge 	struct  consdev *cndev;
    596       1.1     ragge {
    597      1.18     ragge 	extern vaddr_t virtual_avail;
    598  1.27.8.5   nathanw 	extern const struct cdevsw wsdisplay_cdevsw;
    599      1.18     ragge 
    600       1.1     ragge 	switch (vax_boardtype) {
    601       1.1     ragge 	case VAX_BTYP_410:
    602       1.1     ragge 	case VAX_BTYP_420:
    603       1.1     ragge 	case VAX_BTYP_43:
    604      1.16     ragge 		if ((vax_confdata & KA420_CFG_L3CON) ||
    605      1.16     ragge 		    (vax_confdata & KA420_CFG_MULTU))
    606      1.16     ragge 			break; /* doesn't use graphics console */
    607      1.18     ragge 		sm_addr = (caddr_t)virtual_avail;
    608      1.18     ragge 		virtual_avail += SMSIZE;
    609      1.18     ragge 		ioaccess((vaddr_t)sm_addr, SMADDR, (SMSIZE/VAX_NBPG));
    610      1.18     ragge 		cndev->cn_pri = CN_INTERNAL;
    611  1.27.8.5   nathanw 		cndev->cn_dev = makedev(cdevsw_lookup_major(&wsdisplay_cdevsw),
    612  1.27.8.5   nathanw 					0);
    613      1.18     ragge 		break;
    614       1.1     ragge 
    615       1.1     ragge 	default:
    616       1.1     ragge 		break;
    617       1.1     ragge 	}
    618       1.1     ragge }
    619