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