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