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