Home | History | Annotate | Line # | Download | only in vsa
smg.c revision 1.2
      1 /*	$NetBSD: smg.c,v 1.2 1998/06/05 22:02:56 ragge Exp $ */
      2 /*
      3  * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *      This product includes software developed at Ludd, University of
     17  *      Lule}, Sweden and its contributors.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 
     34 
     35 
     36 #include <sys/types.h>
     37 #include <sys/param.h>
     38 #include <sys/device.h>
     39 #include <sys/systm.h>
     40 #include <sys/time.h>
     41 #include <sys/malloc.h>
     42 #include <sys/conf.h>
     43 
     44 #include <dev/cons.h>
     45 
     46 #include <dev/wscons/wsdisplayvar.h>
     47 #include <dev/wscons/wsconsio.h>
     48 #include <dev/wscons/wscons_callbacks.h>
     49 
     50 #include <machine/vsbus.h>
     51 #include <machine/sid.h>
     52 
     53 #include "lkc.h"
     54 
     55 #define	SM_COLS		128	/* char width of screen */
     56 #define	SM_ROWS		57	/* rows of char on screen */
     57 #define	SM_CHEIGHT	15	/* lines a char consists of */
     58 #define	SM_NEXTROW	(SM_COLS * SM_CHEIGHT)
     59 
     60 static	int smg_match __P((struct device *, struct cfdata *, void *));
     61 static	void smg_attach __P((struct device *, struct device *, void *));
     62 
     63 struct	smg_softc {
     64 	struct	device ss_dev;
     65 };
     66 
     67 struct cfattach smg_ca = {
     68 	sizeof(struct smg_softc), smg_match, smg_attach,
     69 };
     70 
     71 static void	smg_cursor __P((void *, int, int, int));
     72 static void	smg_putstr __P((void *, int, int, char *, int, long));
     73 static void	smg_copycols __P((void *, int, int, int,int));
     74 static void	smg_erasecols __P((void *, int, int, int, long));
     75 static void	smg_copyrows __P((void *, int, int, int));
     76 static void	smg_eraserows __P((void *, int, int, long));
     77 static int	smg_alloc_attr __P((void *, int, int, int, long *));
     78 
     79 const struct wsdisplay_emulops smg_emulops = {
     80 	smg_cursor,
     81 	smg_putstr,
     82 	smg_copycols,
     83 	smg_erasecols,
     84 	smg_copyrows,
     85 	smg_eraserows,
     86 	smg_alloc_attr
     87 };
     88 
     89 const struct wsscreen_descr smg_stdscreen = {
     90         "128x57", 128, 57,
     91         &smg_emulops,
     92         8, 15,
     93         0, /* WSSCREEN_UNDERLINE??? */
     94 };
     95 
     96 const struct wsscreen_descr *_smg_scrlist[] = {
     97 	&smg_stdscreen,
     98 };
     99 
    100 const struct wsscreen_list smg_screenlist = {
    101 	sizeof(_smg_scrlist) / sizeof(struct wsscreen_descr *),
    102 	_smg_scrlist,
    103 };
    104 
    105 static int	smg_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
    106 static int	smg_mmap __P((void *, off_t, int));
    107 static int	smg_alloc_screen __P((void *, const struct wsscreen_descr *,
    108                                       void **, int *, int *, long *));
    109 static void	smg_free_screen __P((void *, void *));
    110 static void	smg_show_screen __P((void *, void *));
    111 static int	smg_load_font __P((void *, void *, int, int, int, void *));
    112 
    113 const struct wsdisplay_accessops smg_accessops = {
    114 	smg_ioctl,
    115 	smg_mmap,
    116 	smg_alloc_screen,
    117 	smg_free_screen,
    118 	smg_show_screen,
    119 	smg_load_font
    120 };
    121 
    122 struct	smg_screen {
    123 	int	ss_curx;
    124 	int	ss_cury;
    125 	u_char	ss_image[SM_ROWS][SM_COLS];	/* Image of current screen */
    126 };
    127 
    128 static	struct smg_screen smg_conscreen;
    129 static	struct smg_screen *curscr;
    130 
    131 int
    132 smg_match(parent, match, aux)
    133 	struct device *parent;
    134 	struct cfdata *match;
    135 	void *aux;
    136 {
    137 	struct  vsbus_attach_args *va = aux;
    138 
    139 	if (va->va_type != INR_VF)
    140 		return 0;
    141 #ifdef DIAGNOSTIC
    142 	if (sm_addr == 0)
    143 		panic("smg: inconsistency in smg address mapping");
    144 #endif
    145 	return 1;
    146 }
    147 
    148 void
    149 smg_attach(parent, self, aux)
    150 	struct device *parent, *self;
    151 	void *aux;
    152 {
    153 	struct wsemuldisplaydev_attach_args aa;
    154 
    155 	printf("\n");
    156 	curscr = &smg_conscreen;
    157 	aa.console = !(vax_confdata & 0x20);
    158 	aa.scrdata = &smg_screenlist;
    159 	aa.accessops = &smg_accessops;
    160 
    161 	config_found(self, &aa, wsemuldisplaydevprint);
    162 }
    163 
    164 void
    165 smg_cursor(id, on, row, col)
    166 	void *id;
    167 	int on, row, col;
    168 {
    169 	struct smg_screen *ss = id;
    170 
    171 	ss->ss_curx = col;
    172 	ss->ss_cury = row;
    173 	if (ss == curscr)
    174 		sm_addr[(row * 15 * 128) + col + (14 * 128)] = on ? 255 : 0;
    175 }
    176 
    177 static void
    178 smg_putstr(id, row, col, cp, len, attr)
    179 	void *id;
    180 	int row, col;
    181 	char *cp;
    182 	int len;
    183 	long attr;
    184 {
    185 	struct smg_screen *ss = id;
    186 	int i, j;
    187 	extern char q_font[];
    188 
    189 	bcopy(cp, &ss->ss_image[row][col], len);
    190 	if (ss != curscr)
    191 		return;
    192 	for (i = 0; i < len; i++)
    193 		for (j = 0; j < 15; j++)
    194 			sm_addr[col + i + (row * 15 * 128) + j * 128] =
    195 			    q_font[(cp[i] - 32) * 15 + j];
    196 }
    197 
    198 /*
    199  * copies columns inside a row.
    200  */
    201 static void
    202 smg_copycols(id, row, srccol, dstcol, ncols)
    203 	void *id;
    204 	int row, srccol, dstcol, ncols;
    205 {
    206 	struct smg_screen *ss = id;
    207 	int i;
    208 
    209 	bcopy(&ss->ss_image[row][srccol], &ss->ss_image[row][dstcol], ncols);
    210 	if (ss != curscr)
    211 		return;
    212 	for (i = 0; i < SM_CHEIGHT; i++)
    213 		bcopy(&sm_addr[(row * SM_NEXTROW) + srccol + (i * 128)],
    214 		    &sm_addr[(row * SM_NEXTROW) + dstcol + i*128], ncols);
    215 
    216 }
    217 
    218 /*
    219  * Erases a bunch of chars inside one row.
    220  */
    221 static void
    222 smg_erasecols(id, row, startcol, ncols, fillattr)
    223 	void *id;
    224 	int row, startcol, ncols;
    225 	long fillattr;
    226 {
    227 	struct smg_screen *ss = id;
    228 	int i;
    229 
    230 	bzero(&ss->ss_image[row][startcol], ncols);
    231 	if (ss != curscr)
    232 		return;
    233 	for (i = 0; i < SM_CHEIGHT; i++)
    234 		bzero(&sm_addr[(row * SM_NEXTROW) + startcol + i * 128], ncols);
    235 }
    236 
    237 static void
    238 smg_copyrows(id, srcrow, dstrow, nrows)
    239 	void *id;
    240 	int srcrow, dstrow, nrows;
    241 {
    242 	struct smg_screen *ss = id;
    243 	int frows;
    244 
    245 	bcopy(&ss->ss_image[srcrow][0], &ss->ss_image[dstrow][0], nrows * 128);
    246 	if (ss != curscr)
    247 		return;
    248 	if (nrows > 25) {
    249 		frows = nrows >> 1;
    250 		if (srcrow > dstrow) {
    251 			bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
    252 			    &sm_addr[(dstrow * SM_NEXTROW)],
    253 			    frows * SM_NEXTROW);
    254 			bcopy(&sm_addr[((srcrow + frows) * SM_NEXTROW)],
    255 			    &sm_addr[((dstrow + frows) * SM_NEXTROW)],
    256 			    (nrows - frows) * SM_NEXTROW);
    257 		} else {
    258 			bcopy(&sm_addr[((srcrow + frows) * SM_NEXTROW)],
    259 			    &sm_addr[((dstrow + frows) * SM_NEXTROW)],
    260 			    (nrows - frows) * SM_NEXTROW);
    261 			bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
    262 			    &sm_addr[(dstrow * SM_NEXTROW)],
    263 			    frows * SM_NEXTROW);
    264 		}
    265 	} else
    266 		bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
    267 		    &sm_addr[(dstrow * SM_NEXTROW)], nrows * SM_NEXTROW);
    268 }
    269 
    270 static void
    271 smg_eraserows(id, startrow, nrows, fillattr)
    272 	void *id;
    273 	int startrow, nrows;
    274 	long fillattr;
    275 {
    276 	struct smg_screen *ss = id;
    277 	int frows;
    278 
    279 	bzero(&ss->ss_image[startrow][0], nrows * 128);
    280 	if (ss != curscr)
    281 		return;
    282 	if (nrows > 25) {
    283 		frows = nrows >> 1;
    284 		bzero(&sm_addr[(startrow * SM_NEXTROW)], frows * SM_NEXTROW);
    285 		bzero(&sm_addr[((startrow + frows) * SM_NEXTROW)],
    286 		    (nrows - frows) * SM_NEXTROW);
    287 	} else
    288 		bzero(&sm_addr[(startrow * SM_NEXTROW)], nrows * SM_NEXTROW);
    289 }
    290 
    291 static int
    292 smg_alloc_attr(id, fg, bg, flags, attrp)
    293 	void *id;
    294 	int fg, bg;
    295 	int flags;
    296 	long *attrp;
    297 {
    298 	return 0;
    299 }
    300 
    301 int
    302 smg_ioctl(v, cmd, data, flag, p)
    303 	void *v;
    304 	u_long cmd;
    305 	caddr_t data;
    306 	int flag;
    307 	struct proc *p;
    308 {
    309 	return -1;
    310 }
    311 
    312 static int
    313 smg_mmap(v, offset, prot)
    314 	void *v;
    315 	off_t offset;
    316 	int prot;
    317 {
    318 	return -1;
    319 }
    320 
    321 int
    322 smg_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
    323 	void *v;
    324 	const struct wsscreen_descr *type;
    325 	void **cookiep;
    326 	int *curxp, *curyp;
    327 	long *defattrp;
    328 {
    329 	*cookiep = malloc(sizeof(struct smg_screen), M_DEVBUF, M_WAITOK);
    330 	return 0;
    331 }
    332 
    333 void
    334 smg_free_screen(v, cookie)
    335 	void *v;
    336 	void *cookie;
    337 {
    338 }
    339 
    340 void
    341 smg_show_screen(v, cookie)
    342 	void *v;
    343 	void *cookie;
    344 {
    345 	struct smg_screen *ss = cookie;
    346 	int row, col, line;
    347 	extern char q_font[];
    348 
    349 	if (ss == curscr)
    350 		return;
    351 
    352 	for (row = 0; row < 57; row++)
    353 		for (line = 0; line < 15; line++)
    354 			for (col = 0; col < 128; col++) {
    355 				u_char c = ss->ss_image[row][col];
    356 
    357 				if (c > 0x9f)
    358 					c -= 64;
    359 				else if (c > 0x1f)
    360 					c -= 32;
    361 				sm_addr[row * 128 * 15 + line * 128 + col] =
    362 					q_font[c * 15 + line];
    363 			}
    364 	curscr = ss;
    365 }
    366 
    367 static int
    368 smg_load_font(v, cookie, first, num, stride, data)
    369 	void *v;
    370 	void *cookie;
    371 	int first, num, stride;
    372 	void *data;
    373 {
    374 	return 0;
    375 }
    376 
    377 cons_decl(smg);
    378 
    379 #define	WSCONSOLEMAJOR 68
    380 
    381 void
    382 smgcninit(cndev)
    383 	struct  consdev *cndev;
    384 {
    385 	extern void lkccninit __P((struct consdev *));
    386 	extern int lkccngetc __P((dev_t));
    387 	/* Clear screen */
    388 	blkclr(sm_addr, 128*864);
    389 
    390 	curscr = &smg_conscreen;
    391 	wsdisplay_cnattach(&smg_stdscreen, &smg_conscreen, 0, 0, 0);
    392 	cn_tab->cn_dev = makedev(WSCONSOLEMAJOR, 0);
    393 #if NLKC
    394 	lkccninit(cndev);
    395 	wsdisplay_set_cons_kbd(lkccngetc, nullcnpollc);
    396 #endif
    397 }
    398 
    399 int smgprobe(void);
    400 int
    401 smgprobe()
    402 {
    403 	switch (vax_boardtype) {
    404 	case VAX_BTYP_410:
    405 	case VAX_BTYP_420:
    406 	case VAX_BTYP_43:
    407 		if (vax_confdata & 0x20) /* doesn't use graphics console */
    408 			break;
    409 		if (sm_addr == 0) /* Haven't mapped graphic area */
    410 			break;
    411 
    412 		return 1;
    413 
    414 	default:
    415 		break;
    416 	}
    417 	return 0;
    418 }
    419