Home | History | Annotate | Line # | Download | only in vsa
smg.c revision 1.4
      1  1.4  drochner /*	$NetBSD: smg.c,v 1.4 1998/06/20 21:59:44 drochner 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.1     ragge  *      This product includes software developed at Ludd, University of
     17  1.1     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 
     34  1.1     ragge 
     35  1.1     ragge 
     36  1.1     ragge #include <sys/types.h>
     37  1.1     ragge #include <sys/param.h>
     38  1.1     ragge #include <sys/device.h>
     39  1.1     ragge #include <sys/systm.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.1     ragge 
     44  1.1     ragge #include <dev/cons.h>
     45  1.1     ragge 
     46  1.1     ragge #include <dev/wscons/wsdisplayvar.h>
     47  1.1     ragge #include <dev/wscons/wsconsio.h>
     48  1.1     ragge #include <dev/wscons/wscons_callbacks.h>
     49  1.1     ragge 
     50  1.1     ragge #include <machine/vsbus.h>
     51  1.1     ragge #include <machine/sid.h>
     52  1.1     ragge 
     53  1.1     ragge #include "lkc.h"
     54  1.1     ragge 
     55  1.1     ragge #define	SM_COLS		128	/* char width of screen */
     56  1.1     ragge #define	SM_ROWS		57	/* rows of char on screen */
     57  1.1     ragge #define	SM_CHEIGHT	15	/* lines a char consists of */
     58  1.1     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.4  drochner static void	smg_putchar __P((void *, int, int, u_int, long));
     73  1.1     ragge static void	smg_copycols __P((void *, int, int, int,int));
     74  1.1     ragge static void	smg_erasecols __P((void *, int, int, int, long));
     75  1.1     ragge static void	smg_copyrows __P((void *, int, int, int));
     76  1.1     ragge static void	smg_eraserows __P((void *, int, int, long));
     77  1.1     ragge static int	smg_alloc_attr __P((void *, int, int, int, long *));
     78  1.1     ragge 
     79  1.1     ragge const struct wsdisplay_emulops smg_emulops = {
     80  1.1     ragge 	smg_cursor,
     81  1.4  drochner 	smg_putchar,
     82  1.1     ragge 	smg_copycols,
     83  1.1     ragge 	smg_erasecols,
     84  1.1     ragge 	smg_copyrows,
     85  1.1     ragge 	smg_eraserows,
     86  1.1     ragge 	smg_alloc_attr
     87  1.1     ragge };
     88  1.1     ragge 
     89  1.1     ragge const struct wsscreen_descr smg_stdscreen = {
     90  1.1     ragge         "128x57", 128, 57,
     91  1.1     ragge         &smg_emulops,
     92  1.1     ragge         8, 15,
     93  1.1     ragge         0, /* WSSCREEN_UNDERLINE??? */
     94  1.1     ragge };
     95  1.1     ragge 
     96  1.1     ragge const struct wsscreen_descr *_smg_scrlist[] = {
     97  1.1     ragge 	&smg_stdscreen,
     98  1.1     ragge };
     99  1.1     ragge 
    100  1.1     ragge const struct wsscreen_list smg_screenlist = {
    101  1.1     ragge 	sizeof(_smg_scrlist) / sizeof(struct wsscreen_descr *),
    102  1.1     ragge 	_smg_scrlist,
    103  1.1     ragge };
    104  1.1     ragge 
    105  1.1     ragge static int	smg_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
    106  1.1     ragge static int	smg_mmap __P((void *, off_t, int));
    107  1.1     ragge static int	smg_alloc_screen __P((void *, const struct wsscreen_descr *,
    108  1.1     ragge                                       void **, int *, int *, long *));
    109  1.1     ragge static void	smg_free_screen __P((void *, void *));
    110  1.1     ragge static void	smg_show_screen __P((void *, void *));
    111  1.1     ragge static int	smg_load_font __P((void *, void *, int, int, int, void *));
    112  1.1     ragge 
    113  1.1     ragge const struct wsdisplay_accessops smg_accessops = {
    114  1.1     ragge 	smg_ioctl,
    115  1.1     ragge 	smg_mmap,
    116  1.1     ragge 	smg_alloc_screen,
    117  1.1     ragge 	smg_free_screen,
    118  1.1     ragge 	smg_show_screen,
    119  1.1     ragge 	smg_load_font
    120  1.1     ragge };
    121  1.1     ragge 
    122  1.1     ragge struct	smg_screen {
    123  1.1     ragge 	int	ss_curx;
    124  1.1     ragge 	int	ss_cury;
    125  1.2     ragge 	u_char	ss_image[SM_ROWS][SM_COLS];	/* Image of current screen */
    126  1.1     ragge };
    127  1.1     ragge 
    128  1.2     ragge static	struct smg_screen smg_conscreen;
    129  1.2     ragge static	struct smg_screen *curscr;
    130  1.1     ragge 
    131  1.1     ragge int
    132  1.1     ragge smg_match(parent, match, aux)
    133  1.1     ragge 	struct device *parent;
    134  1.1     ragge 	struct cfdata *match;
    135  1.1     ragge 	void *aux;
    136  1.1     ragge {
    137  1.1     ragge 	struct  vsbus_attach_args *va = aux;
    138  1.1     ragge 
    139  1.1     ragge 	if (va->va_type != INR_VF)
    140  1.1     ragge 		return 0;
    141  1.1     ragge #ifdef DIAGNOSTIC
    142  1.1     ragge 	if (sm_addr == 0)
    143  1.1     ragge 		panic("smg: inconsistency in smg address mapping");
    144  1.1     ragge #endif
    145  1.1     ragge 	return 1;
    146  1.1     ragge }
    147  1.1     ragge 
    148  1.1     ragge void
    149  1.1     ragge smg_attach(parent, self, aux)
    150  1.1     ragge 	struct device *parent, *self;
    151  1.1     ragge 	void *aux;
    152  1.1     ragge {
    153  1.1     ragge 	struct wsemuldisplaydev_attach_args aa;
    154  1.1     ragge 
    155  1.1     ragge 	printf("\n");
    156  1.2     ragge 	curscr = &smg_conscreen;
    157  1.1     ragge 	aa.console = !(vax_confdata & 0x20);
    158  1.1     ragge 	aa.scrdata = &smg_screenlist;
    159  1.1     ragge 	aa.accessops = &smg_accessops;
    160  1.1     ragge 
    161  1.1     ragge 	config_found(self, &aa, wsemuldisplaydevprint);
    162  1.1     ragge }
    163  1.1     ragge 
    164  1.1     ragge void
    165  1.1     ragge smg_cursor(id, on, row, col)
    166  1.1     ragge 	void *id;
    167  1.1     ragge 	int on, row, col;
    168  1.1     ragge {
    169  1.2     ragge 	struct smg_screen *ss = id;
    170  1.2     ragge 
    171  1.2     ragge 	ss->ss_curx = col;
    172  1.2     ragge 	ss->ss_cury = row;
    173  1.2     ragge 	if (ss == curscr)
    174  1.2     ragge 		sm_addr[(row * 15 * 128) + col + (14 * 128)] = on ? 255 : 0;
    175  1.1     ragge }
    176  1.1     ragge 
    177  1.1     ragge static void
    178  1.4  drochner smg_putchar(id, row, col, c, attr)
    179  1.1     ragge 	void *id;
    180  1.1     ragge 	int row, col;
    181  1.4  drochner 	u_int c;
    182  1.1     ragge 	long attr;
    183  1.1     ragge {
    184  1.2     ragge 	struct smg_screen *ss = id;
    185  1.4  drochner 	int i;
    186  1.1     ragge 	extern char q_font[];
    187  1.1     ragge 
    188  1.4  drochner 	c &= 0xff;
    189  1.4  drochner 
    190  1.4  drochner 	ss->ss_image[row][col] = c;
    191  1.2     ragge 	if (ss != curscr)
    192  1.2     ragge 		return;
    193  1.4  drochner 	for (i = 0; i < 15; i++)
    194  1.4  drochner 		sm_addr[col + (row * 15 * 128) + i * 128] =
    195  1.4  drochner 			q_font[(c - 32) * 15 + i];
    196  1.1     ragge }
    197  1.1     ragge 
    198  1.1     ragge /*
    199  1.1     ragge  * copies columns inside a row.
    200  1.1     ragge  */
    201  1.1     ragge static void
    202  1.1     ragge smg_copycols(id, row, srccol, dstcol, ncols)
    203  1.1     ragge 	void *id;
    204  1.1     ragge 	int row, srccol, dstcol, ncols;
    205  1.1     ragge {
    206  1.2     ragge 	struct smg_screen *ss = id;
    207  1.1     ragge 	int i;
    208  1.1     ragge 
    209  1.2     ragge 	bcopy(&ss->ss_image[row][srccol], &ss->ss_image[row][dstcol], ncols);
    210  1.2     ragge 	if (ss != curscr)
    211  1.2     ragge 		return;
    212  1.1     ragge 	for (i = 0; i < SM_CHEIGHT; i++)
    213  1.1     ragge 		bcopy(&sm_addr[(row * SM_NEXTROW) + srccol + (i * 128)],
    214  1.1     ragge 		    &sm_addr[(row * SM_NEXTROW) + dstcol + i*128], ncols);
    215  1.1     ragge 
    216  1.1     ragge }
    217  1.1     ragge 
    218  1.1     ragge /*
    219  1.1     ragge  * Erases a bunch of chars inside one row.
    220  1.1     ragge  */
    221  1.1     ragge static void
    222  1.1     ragge smg_erasecols(id, row, startcol, ncols, fillattr)
    223  1.1     ragge 	void *id;
    224  1.1     ragge 	int row, startcol, ncols;
    225  1.1     ragge 	long fillattr;
    226  1.1     ragge {
    227  1.2     ragge 	struct smg_screen *ss = id;
    228  1.1     ragge 	int i;
    229  1.1     ragge 
    230  1.2     ragge 	bzero(&ss->ss_image[row][startcol], ncols);
    231  1.2     ragge 	if (ss != curscr)
    232  1.2     ragge 		return;
    233  1.1     ragge 	for (i = 0; i < SM_CHEIGHT; i++)
    234  1.1     ragge 		bzero(&sm_addr[(row * SM_NEXTROW) + startcol + i * 128], ncols);
    235  1.1     ragge }
    236  1.1     ragge 
    237  1.1     ragge static void
    238  1.1     ragge smg_copyrows(id, srcrow, dstrow, nrows)
    239  1.1     ragge 	void *id;
    240  1.1     ragge 	int srcrow, dstrow, nrows;
    241  1.1     ragge {
    242  1.2     ragge 	struct smg_screen *ss = id;
    243  1.1     ragge 	int frows;
    244  1.1     ragge 
    245  1.2     ragge 	bcopy(&ss->ss_image[srcrow][0], &ss->ss_image[dstrow][0], nrows * 128);
    246  1.2     ragge 	if (ss != curscr)
    247  1.2     ragge 		return;
    248  1.1     ragge 	if (nrows > 25) {
    249  1.1     ragge 		frows = nrows >> 1;
    250  1.1     ragge 		if (srcrow > dstrow) {
    251  1.1     ragge 			bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
    252  1.1     ragge 			    &sm_addr[(dstrow * SM_NEXTROW)],
    253  1.1     ragge 			    frows * SM_NEXTROW);
    254  1.1     ragge 			bcopy(&sm_addr[((srcrow + frows) * SM_NEXTROW)],
    255  1.1     ragge 			    &sm_addr[((dstrow + frows) * SM_NEXTROW)],
    256  1.1     ragge 			    (nrows - frows) * SM_NEXTROW);
    257  1.1     ragge 		} else {
    258  1.1     ragge 			bcopy(&sm_addr[((srcrow + frows) * SM_NEXTROW)],
    259  1.1     ragge 			    &sm_addr[((dstrow + frows) * SM_NEXTROW)],
    260  1.1     ragge 			    (nrows - frows) * SM_NEXTROW);
    261  1.1     ragge 			bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
    262  1.1     ragge 			    &sm_addr[(dstrow * SM_NEXTROW)],
    263  1.1     ragge 			    frows * SM_NEXTROW);
    264  1.1     ragge 		}
    265  1.1     ragge 	} else
    266  1.1     ragge 		bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
    267  1.1     ragge 		    &sm_addr[(dstrow * SM_NEXTROW)], nrows * SM_NEXTROW);
    268  1.1     ragge }
    269  1.1     ragge 
    270  1.1     ragge static void
    271  1.1     ragge smg_eraserows(id, startrow, nrows, fillattr)
    272  1.1     ragge 	void *id;
    273  1.1     ragge 	int startrow, nrows;
    274  1.1     ragge 	long fillattr;
    275  1.1     ragge {
    276  1.2     ragge 	struct smg_screen *ss = id;
    277  1.1     ragge 	int frows;
    278  1.1     ragge 
    279  1.2     ragge 	bzero(&ss->ss_image[startrow][0], nrows * 128);
    280  1.2     ragge 	if (ss != curscr)
    281  1.2     ragge 		return;
    282  1.1     ragge 	if (nrows > 25) {
    283  1.1     ragge 		frows = nrows >> 1;
    284  1.1     ragge 		bzero(&sm_addr[(startrow * SM_NEXTROW)], frows * SM_NEXTROW);
    285  1.1     ragge 		bzero(&sm_addr[((startrow + frows) * SM_NEXTROW)],
    286  1.1     ragge 		    (nrows - frows) * SM_NEXTROW);
    287  1.1     ragge 	} else
    288  1.1     ragge 		bzero(&sm_addr[(startrow * SM_NEXTROW)], nrows * SM_NEXTROW);
    289  1.1     ragge }
    290  1.1     ragge 
    291  1.1     ragge static int
    292  1.1     ragge smg_alloc_attr(id, fg, bg, flags, attrp)
    293  1.1     ragge 	void *id;
    294  1.1     ragge 	int fg, bg;
    295  1.1     ragge 	int flags;
    296  1.1     ragge 	long *attrp;
    297  1.1     ragge {
    298  1.1     ragge 	return 0;
    299  1.1     ragge }
    300  1.1     ragge 
    301  1.1     ragge int
    302  1.1     ragge smg_ioctl(v, cmd, data, flag, p)
    303  1.1     ragge 	void *v;
    304  1.1     ragge 	u_long cmd;
    305  1.1     ragge 	caddr_t data;
    306  1.1     ragge 	int flag;
    307  1.1     ragge 	struct proc *p;
    308  1.1     ragge {
    309  1.1     ragge 	return -1;
    310  1.1     ragge }
    311  1.1     ragge 
    312  1.1     ragge static int
    313  1.1     ragge smg_mmap(v, offset, prot)
    314  1.1     ragge 	void *v;
    315  1.1     ragge 	off_t offset;
    316  1.1     ragge 	int prot;
    317  1.1     ragge {
    318  1.1     ragge 	return -1;
    319  1.1     ragge }
    320  1.1     ragge 
    321  1.1     ragge int
    322  1.1     ragge smg_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
    323  1.1     ragge 	void *v;
    324  1.1     ragge 	const struct wsscreen_descr *type;
    325  1.1     ragge 	void **cookiep;
    326  1.1     ragge 	int *curxp, *curyp;
    327  1.1     ragge 	long *defattrp;
    328  1.1     ragge {
    329  1.2     ragge 	*cookiep = malloc(sizeof(struct smg_screen), M_DEVBUF, M_WAITOK);
    330  1.3     ragge 	bzero(*cookiep, sizeof(struct smg_screen));
    331  1.3     ragge 	*curxp = *curyp = *defattrp = 0;
    332  1.1     ragge 	return 0;
    333  1.1     ragge }
    334  1.1     ragge 
    335  1.1     ragge void
    336  1.1     ragge smg_free_screen(v, cookie)
    337  1.1     ragge 	void *v;
    338  1.1     ragge 	void *cookie;
    339  1.1     ragge {
    340  1.1     ragge }
    341  1.1     ragge 
    342  1.1     ragge void
    343  1.1     ragge smg_show_screen(v, cookie)
    344  1.1     ragge 	void *v;
    345  1.1     ragge 	void *cookie;
    346  1.1     ragge {
    347  1.2     ragge 	struct smg_screen *ss = cookie;
    348  1.2     ragge 	int row, col, line;
    349  1.2     ragge 	extern char q_font[];
    350  1.2     ragge 
    351  1.2     ragge 	if (ss == curscr)
    352  1.2     ragge 		return;
    353  1.2     ragge 
    354  1.2     ragge 	for (row = 0; row < 57; row++)
    355  1.2     ragge 		for (line = 0; line < 15; line++)
    356  1.2     ragge 			for (col = 0; col < 128; col++) {
    357  1.2     ragge 				u_char c = ss->ss_image[row][col];
    358  1.2     ragge 
    359  1.2     ragge 				if (c > 0x9f)
    360  1.2     ragge 					c -= 64;
    361  1.2     ragge 				else if (c > 0x1f)
    362  1.2     ragge 					c -= 32;
    363  1.2     ragge 				sm_addr[row * 128 * 15 + line * 128 + col] =
    364  1.2     ragge 					q_font[c * 15 + line];
    365  1.2     ragge 			}
    366  1.2     ragge 	curscr = ss;
    367  1.1     ragge }
    368  1.1     ragge 
    369  1.1     ragge static int
    370  1.1     ragge smg_load_font(v, cookie, first, num, stride, data)
    371  1.1     ragge 	void *v;
    372  1.1     ragge 	void *cookie;
    373  1.1     ragge 	int first, num, stride;
    374  1.1     ragge 	void *data;
    375  1.1     ragge {
    376  1.1     ragge 	return 0;
    377  1.1     ragge }
    378  1.1     ragge 
    379  1.1     ragge cons_decl(smg);
    380  1.1     ragge 
    381  1.1     ragge #define	WSCONSOLEMAJOR 68
    382  1.1     ragge 
    383  1.1     ragge void
    384  1.1     ragge smgcninit(cndev)
    385  1.1     ragge 	struct  consdev *cndev;
    386  1.1     ragge {
    387  1.1     ragge 	extern void lkccninit __P((struct consdev *));
    388  1.1     ragge 	extern int lkccngetc __P((dev_t));
    389  1.1     ragge 	/* Clear screen */
    390  1.1     ragge 	blkclr(sm_addr, 128*864);
    391  1.1     ragge 
    392  1.2     ragge 	curscr = &smg_conscreen;
    393  1.2     ragge 	wsdisplay_cnattach(&smg_stdscreen, &smg_conscreen, 0, 0, 0);
    394  1.1     ragge 	cn_tab->cn_dev = makedev(WSCONSOLEMAJOR, 0);
    395  1.1     ragge #if NLKC
    396  1.1     ragge 	lkccninit(cndev);
    397  1.1     ragge 	wsdisplay_set_cons_kbd(lkccngetc, nullcnpollc);
    398  1.1     ragge #endif
    399  1.1     ragge }
    400  1.1     ragge 
    401  1.1     ragge int smgprobe(void);
    402  1.1     ragge int
    403  1.1     ragge smgprobe()
    404  1.1     ragge {
    405  1.1     ragge 	switch (vax_boardtype) {
    406  1.1     ragge 	case VAX_BTYP_410:
    407  1.1     ragge 	case VAX_BTYP_420:
    408  1.1     ragge 	case VAX_BTYP_43:
    409  1.1     ragge 		if (vax_confdata & 0x20) /* doesn't use graphics console */
    410  1.1     ragge 			break;
    411  1.1     ragge 		if (sm_addr == 0) /* Haven't mapped graphic area */
    412  1.1     ragge 			break;
    413  1.1     ragge 
    414  1.1     ragge 		return 1;
    415  1.1     ragge 
    416  1.1     ragge 	default:
    417  1.1     ragge 		break;
    418  1.1     ragge 	}
    419  1.1     ragge 	return 0;
    420  1.1     ragge }
    421