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