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