xref: /original-bsd/sys/pmax/dev/cfb.c (revision e49f9654)
1 /*-
2  * Copyright (c) 1992, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Ralph Campbell and Rick Macklem.
7  *
8  * %sccs.include.redist.c%
9  *
10  *	@(#)cfb.c	8.2 (Berkeley) 06/02/95
11  */
12 
13 /*
14  *  devGraphics.c --
15  *
16  *     	This file contains machine-dependent routines for the graphics device.
17  *
18  *	Copyright (C) 1989 Digital Equipment Corporation.
19  *	Permission to use, copy, modify, and distribute this software and
20  *	its documentation for any purpose and without fee is hereby granted,
21  *	provided that the above copyright notice appears in all copies.
22  *	Digital Equipment Corporation makes no representations about the
23  *	suitability of this software for any purpose.  It is provided "as is"
24  *	without express or implied warranty.
25  *
26  * from: $Header: /sprite/src/kernel/dev/ds3100.md/RCS/devGraphics.c,
27  *	v 9.2 90/02/13 22:16:24 shirriff Exp $ SPRITE (DECWRL)";
28  */
29 /*
30  * Mach Operating System
31  * Copyright (c) 1991,1990,1989 Carnegie Mellon University
32  * All Rights Reserved.
33  *
34  * Permission to use, copy, modify and distribute this software and its
35  * documentation is hereby granted, provided that both the copyright
36  * notice and this permission notice appear in all copies of the
37  * software, derivative works or modified versions, and any portions
38  * thereof, and that both notices appear in supporting documentation.
39  *
40  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
41  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
42  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43  *
44  * Carnegie Mellon requests users of this software to return to
45  *
46  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
47  *  School of Computer Science
48  *  Carnegie Mellon University
49  *  Pittsburgh PA 15213-3890
50  *
51  * any improvements or extensions that they make and grant Carnegie the
52  * rights to redistribute these changes.
53  */
54 
55 #include <cfb.h>
56 #if NCFB > 0
57 #include <sys/param.h>
58 #include <sys/time.h>
59 #include <sys/kernel.h>
60 #include <sys/ioctl.h>
61 #include <sys/file.h>
62 #include <sys/errno.h>
63 #include <sys/proc.h>
64 #include <sys/mman.h>
65 
66 #include <vm/vm.h>
67 
68 #include <machine/machConst.h>
69 #include <machine/pmioctl.h>
70 
71 #include <pmax/pmax/maxine.h>
72 #include <pmax/pmax/cons.h>
73 #include <pmax/pmax/pmaxtype.h>
74 
75 #include <pmax/dev/device.h>
76 #include <pmax/dev/cfbreg.h>
77 #include <pmax/dev/fbreg.h>
78 
79 #include <dc.h>
80 #include <dtop.h>
81 #include <scc.h>
82 
83 #define PMAX	/* enable /dev/pm compatibility */
84 
85 /*
86  * These need to be mapped into user space.
87  */
88 struct fbuaccess cfbu;
89 struct pmax_fb cfbfb;
90 
91 /*
92  * Forward references.
93  */
94 static void cfbScreenInit();
95 static void cfbLoadCursor();
96 static void cfbRestoreCursorColor();
97 static void cfbCursorColor();
98 void cfbPosCursor();
99 static void cfbInitColorMap();
100 static void cfbLoadColorMap();
101 static void bt459_set_cursor_ram(), bt459_video_on(), bt459_video_off();
102 static void bt459_select_reg(), bt459_write_reg();
103 static u_char bt459_read_reg();
104 static void cfbConfigMouse(), cfbDeconfigMouse();
105 
106 void cfbKbdEvent(), cfbMouseEvent(), cfbMouseButtons();
107 #if NDC > 0
108 extern void (*dcDivertXInput)();
109 extern void (*dcMouseEvent)();
110 extern void (*dcMouseButtons)();
111 #endif
112 #if NSCC > 0
113 extern void (*sccDivertXInput)();
114 extern void (*sccMouseEvent)();
115 extern void (*sccMouseButtons)();
116 #endif
117 #if NDTOP > 0
118 extern void (*dtopDivertXInput)();
119 extern void (*dtopMouseEvent)();
120 extern void (*dtopMouseButtons)();
121 #endif
122 extern int pmax_boardtype;
123 extern u_short defCursor[32];
124 extern struct consdev cn_tab;
125 
126 int	cfbprobe();
127 struct	driver cfbdriver = {
128 	"cfb", cfbprobe, 0, 0,
129 };
130 
131 #define	CFB_OFFSET_VRAM		0x0		/* from module's base */
132 #define CFB_OFFSET_BT459	0x200000	/* Bt459 registers */
133 #define CFB_OFFSET_IREQ		0x300000	/* Interrupt req. control */
134 #define CFB_OFFSET_ROM		0x380000	/* Diagnostic ROM */
135 #define CFB_OFFSET_RESET	0x3c0000	/* Bt459 resets on writes */
136 #define CFB_FB_SIZE		0x100000	/* frame buffer size */
137 
138 /*
139  * Test to see if device is present.
140  * Return true if found and initialized ok.
141  */
142 /*ARGSUSED*/
143 cfbprobe(cp)
144 	register struct pmax_ctlr *cp;
145 {
146 	register struct pmax_fb *fp = &cfbfb;
147 
148 	if (!fp->initialized && !cfbinit(cp->pmax_addr))
149 		return (0);
150 	printf("cfb0 (color display)\n");
151 	return (1);
152 }
153 
154 /*ARGSUSED*/
155 cfbopen(dev, flag)
156 	dev_t dev;
157 	int flag;
158 {
159 	register struct pmax_fb *fp = &cfbfb;
160 	int s;
161 
162 	if (!fp->initialized)
163 		return (ENXIO);
164 	if (fp->GraphicsOpen)
165 		return (EBUSY);
166 
167 	fp->GraphicsOpen = 1;
168 	cfbInitColorMap();
169 	/*
170 	 * Set up event queue for later
171 	 */
172 	fp->fbu->scrInfo.qe.eSize = PM_MAXEVQ;
173 	fp->fbu->scrInfo.qe.eHead = fp->fbu->scrInfo.qe.eTail = 0;
174 	fp->fbu->scrInfo.qe.tcSize = MOTION_BUFFER_SIZE;
175 	fp->fbu->scrInfo.qe.tcNext = 0;
176 	fp->fbu->scrInfo.qe.timestamp_ms = TO_MS(time);
177 	cfbConfigMouse();
178 	return (0);
179 }
180 
181 /*ARGSUSED*/
182 cfbclose(dev, flag)
183 	dev_t dev;
184 	int flag;
185 {
186 	register struct pmax_fb *fp = &cfbfb;
187 	int s;
188 
189 	if (!fp->GraphicsOpen)
190 		return (EBADF);
191 
192 	fp->GraphicsOpen = 0;
193 	cfbInitColorMap();
194 	cfbDeconfigMouse();
195 	cfbScreenInit();
196 	bzero((caddr_t)fp->fr_addr, 1024 * 864);
197 	cfbPosCursor(fp->col * 8, fp->row * 15);
198 	return (0);
199 }
200 
201 /*ARGSUSED*/
202 cfbioctl(dev, cmd, data, flag, p)
203 	dev_t dev;
204 	u_long cmd;
205 	caddr_t data;
206 	struct proc *p;
207 {
208 	register struct pmax_fb *fp = &cfbfb;
209 	int s;
210 
211 	switch (cmd) {
212 	case QIOCGINFO:
213 		return (fbmmap(fp, dev, data, p));
214 
215 	case QIOCPMSTATE:
216 		/*
217 		 * Set mouse state.
218 		 */
219 		fp->fbu->scrInfo.mouse = *(pmCursor *)data;
220 		cfbPosCursor(fp->fbu->scrInfo.mouse.x, fp->fbu->scrInfo.mouse.y);
221 		break;
222 
223 	case QIOCINIT:
224 		/*
225 		 * Initialize the screen.
226 		 */
227 		cfbScreenInit();
228 		break;
229 
230 	case QIOCKPCMD:
231 	    {
232 		pmKpCmd *kpCmdPtr;
233 		unsigned char *cp;
234 
235 		kpCmdPtr = (pmKpCmd *)data;
236 		if (kpCmdPtr->nbytes == 0)
237 			kpCmdPtr->cmd |= 0x80;
238 		if (!fp->GraphicsOpen)
239 			kpCmdPtr->cmd |= 1;
240 		(*fp->KBDPutc)(fp->kbddev, (int)kpCmdPtr->cmd);
241 		cp = &kpCmdPtr->par[0];
242 		for (; kpCmdPtr->nbytes > 0; cp++, kpCmdPtr->nbytes--) {
243 			if (kpCmdPtr->nbytes == 1)
244 				*cp |= 0x80;
245 			(*fp->KBDPutc)(fp->kbddev, (int)*cp);
246 		}
247 		break;
248 	    }
249 
250 	case QIOCADDR:
251 		*(PM_Info **)data = &fp->fbu->scrInfo;
252 		break;
253 
254 	case QIOWCURSOR:
255 		cfbLoadCursor((unsigned short *)data);
256 		break;
257 
258 	case QIOWCURSORCOLOR:
259 		cfbCursorColor((unsigned int *)data);
260 		break;
261 
262 	case QIOSETCMAP:
263 		cfbLoadColorMap((ColorMap *)data);
264 		break;
265 
266 	case QIOKERNLOOP:
267 		cfbConfigMouse();
268 		break;
269 
270 	case QIOKERNUNLOOP:
271 		cfbDeconfigMouse();
272 		break;
273 
274 	case QIOVIDEOON:
275 		cfbRestoreCursorColor();
276 		bt459_video_on();
277 		break;
278 
279 	case QIOVIDEOOFF:
280 		bt459_video_off();
281 		break;
282 
283 	default:
284 		printf("cfb0: Unknown ioctl command %x\n", cmd);
285 		return (EINVAL);
286 	}
287 	return (0);
288 }
289 
290 cfbselect(dev, flag, p)
291 	dev_t dev;
292 	int flag;
293 	struct proc *p;
294 {
295 	struct pmax_fb *fp = &cfbfb;
296 
297 	switch (flag) {
298 	case FREAD:
299 		if (fp->fbu->scrInfo.qe.eHead != fp->fbu->scrInfo.qe.eTail)
300 			return (1);
301 		selrecord(p, &fp->selp);
302 		break;
303 	}
304 
305 	return (0);
306 }
307 
308 /*
309  * Return the physical page number that corresponds to byte offset 'off'.
310  */
311 /*ARGSUSED*/
312 cfbmap(dev, off, prot)
313 	dev_t dev;
314 {
315 	int len;
316 
317 	len = pmax_round_page(((vm_offset_t)&cfbu & PGOFSET) + sizeof(cfbu));
318 	if (off < len)
319 		return pmax_btop(MACH_CACHED_TO_PHYS(&cfbu) + off);
320 	off -= len;
321 	if (off >= cfbfb.fr_size)
322 		return (-1);
323 	return pmax_btop(MACH_UNCACHED_TO_PHYS(cfbfb.fr_addr) + off);
324 }
325 
326 static u_char	cursor_RGB[6];	/* cursor color 2 & 3 */
327 
328 /*
329  * XXX This assumes 2bits/cursor pixel so that the 1Kbyte cursor RAM
330  * defines a 64x64 cursor. If the bt459 does not map the cursor RAM
331  * this way, this code is Screwed!
332  */
333 static void
334 cfbLoadCursor(cursor)
335 	u_short *cursor;
336 {
337 #ifdef PMAX
338 	register int i, j, k, pos;
339 	register u_short ap, bp, out;
340 
341 	/*
342 	 * Fill in the cursor sprite using the A and B planes, as provided
343 	 * for the pmax.
344 	 * XXX This will have to change when the X server knows that this
345 	 * is not a pmax display.
346 	 */
347 	pos = 0;
348 	for (k = 0; k < 16; k++) {
349 		ap = *cursor;
350 		bp = *(cursor + 16);
351 		j = 0;
352 		while (j < 4) {
353 			out = 0;
354 			for (i = 0; i < 4; i++) {
355 #ifndef CURSOR_EB
356 				out = (out << 2) | ((ap & 0x1) << 1) |
357 					(bp & 0x1);
358 #else
359 				out = ((out >> 2) & 0x3f) |
360 					((ap & 0x1) << 7) |
361 					((bp & 0x1) << 6);
362 #endif
363 				ap >>= 1;
364 				bp >>= 1;
365 			}
366 			bt459_set_cursor_ram(pos, out);
367 			pos++;
368 			j++;
369 		}
370 		while (j < 16) {
371 			bt459_set_cursor_ram(pos, 0);
372 			pos++;
373 			j++;
374 		}
375 		cursor++;
376 	}
377 	while (pos < 1024) {
378 		bt459_set_cursor_ram(pos, 0);
379 		pos++;
380 	}
381 #endif /* PMAX */
382 }
383 
384 /*
385  * Set a cursor ram value.
386  */
387 static void
388 bt459_set_cursor_ram(pos, val)
389 	int pos;
390 	register u_char val;
391 {
392 	register bt459_regmap_t *regs = (bt459_regmap_t *)
393 		(cfbfb.fr_addr + CFB_OFFSET_BT459);
394 	register int cnt;
395 	u_char nval;
396 
397 	cnt = 0;
398 	do {
399 		bt459_write_reg(regs, BT459_REG_CRAM_BASE + pos, val);
400 		nval = bt459_read_reg(regs, BT459_REG_CRAM_BASE + pos);
401 	} while (val != nval && ++cnt < 10);
402 }
403 
404 /*
405  * Generic register access
406  */
407 static void
408 bt459_select_reg(regs, regno)
409 	bt459_regmap_t *regs;
410 {
411 	regs->addr_lo = regno;
412 	regs->addr_hi = regno >> 8;
413 	MachEmptyWriteBuffer();
414 }
415 
416 static void
417 bt459_write_reg(regs, regno, val)
418 	bt459_regmap_t *regs;
419 {
420 	regs->addr_lo = regno;
421 	regs->addr_hi = regno >> 8;
422 	MachEmptyWriteBuffer();
423 	regs->addr_reg = val;
424 	MachEmptyWriteBuffer();
425 }
426 
427 static u_char
428 bt459_read_reg(regs, regno)
429 	bt459_regmap_t *regs;
430 {
431 	regs->addr_lo = regno;
432 	regs->addr_hi = regno >> 8;
433 	MachEmptyWriteBuffer();
434 	return (regs->addr_reg);
435 }
436 
437 /*
438  * Initialization
439  */
440 int
441 cfbinit(cp)
442 	char *cp;
443 {
444 	register bt459_regmap_t *regs;
445 	register struct pmax_fb *fp = &cfbfb;
446 
447 	/* check for no frame buffer */
448 	if (badaddr(cp, 4))
449 		return (0);
450 
451 	fp->isMono = 0;
452 	fp->fr_addr = (char *)(cp + CFB_OFFSET_VRAM);
453 	fp->fr_size = CFB_FB_SIZE;
454 	/*
455 	 * Must be in Uncached space since the fbuaccess structure is
456 	 * mapped into the user's address space uncached.
457 	 */
458 	fp->fbu = (struct fbuaccess *)
459 		MACH_PHYS_TO_UNCACHED(MACH_CACHED_TO_PHYS(&cfbu));
460 	fp->posCursor = cfbPosCursor;
461 	if (tb_kbdmouseconfig(fp))
462 		return (0);
463 
464 	/*
465 	 * Initialize the screen.
466 	 */
467 	regs = (bt459_regmap_t *)(fp->fr_addr + CFB_OFFSET_BT459);
468 
469 	if (bt459_read_reg(regs, BT459_REG_ID) != 0x4a)
470 		return (0);
471 
472 	/* Reset the chip */
473 	*(volatile int *)(fp->fr_addr + CFB_OFFSET_RESET) = 0;
474 	DELAY(2000);	/* ???? check right time on specs! ???? */
475 
476 	/* use 4:1 input mux */
477 	bt459_write_reg(regs, BT459_REG_CMD0, 0x40);
478 
479 	/* no zooming, no panning */
480 	bt459_write_reg(regs, BT459_REG_CMD1, 0x00);
481 
482 	/*
483 	 * signature test, X-windows cursor, no overlays, SYNC* PLL,
484 	 * normal RAM select, 7.5 IRE pedestal, do sync
485 	 */
486 #ifndef PMAX
487 	bt459_write_reg(regs, BT459_REG_CMD2, 0xc2);
488 #else /* PMAX */
489 	bt459_write_reg(regs, BT459_REG_CMD2, 0xc0);
490 #endif /* PMAX */
491 
492 	/* get all pixel bits */
493 	bt459_write_reg(regs, BT459_REG_PRM, 0xff);
494 
495 	/* no blinking */
496 	bt459_write_reg(regs, BT459_REG_PBM, 0x00);
497 
498 	/* no overlay */
499 	bt459_write_reg(regs, BT459_REG_ORM, 0x00);
500 
501 	/* no overlay blink */
502 	bt459_write_reg(regs, BT459_REG_OBM, 0x00);
503 
504 	/* no interleave, no underlay */
505 	bt459_write_reg(regs, BT459_REG_ILV, 0x00);
506 
507 	/* normal operation, no signature analysis */
508 	bt459_write_reg(regs, BT459_REG_TEST, 0x00);
509 
510 	/*
511 	 * no blinking, 1bit cross hair, XOR reg&crosshair,
512 	 * no crosshair on either plane 0 or 1,
513 	 * regular cursor on both planes.
514 	 */
515 	bt459_write_reg(regs, BT459_REG_CCR, 0xc0);
516 
517 	/* home cursor */
518 	bt459_write_reg(regs, BT459_REG_CXLO, 0x00);
519 	bt459_write_reg(regs, BT459_REG_CXHI, 0x00);
520 	bt459_write_reg(regs, BT459_REG_CYLO, 0x00);
521 	bt459_write_reg(regs, BT459_REG_CYHI, 0x00);
522 
523 	/* no crosshair window */
524 	bt459_write_reg(regs, BT459_REG_WXLO, 0x00);
525 	bt459_write_reg(regs, BT459_REG_WXHI, 0x00);
526 	bt459_write_reg(regs, BT459_REG_WYLO, 0x00);
527 	bt459_write_reg(regs, BT459_REG_WYHI, 0x00);
528 	bt459_write_reg(regs, BT459_REG_WWLO, 0x00);
529 	bt459_write_reg(regs, BT459_REG_WWHI, 0x00);
530 	bt459_write_reg(regs, BT459_REG_WHLO, 0x00);
531 	bt459_write_reg(regs, BT459_REG_WHHI, 0x00);
532 
533 	/*
534 	 * Initialize screen info.
535 	 */
536 	fp->fbu->scrInfo.max_row = 56;
537 	fp->fbu->scrInfo.max_col = 80;
538 	fp->fbu->scrInfo.max_x = 1024;
539 	fp->fbu->scrInfo.max_y = 864;
540 	fp->fbu->scrInfo.max_cur_x = 1023;
541 	fp->fbu->scrInfo.max_cur_y = 863;
542 	fp->fbu->scrInfo.version = 11;
543 	fp->fbu->scrInfo.mthreshold = 4;
544 	fp->fbu->scrInfo.mscale = 2;
545 	fp->fbu->scrInfo.min_cur_x = 0;
546 	fp->fbu->scrInfo.min_cur_y = 0;
547 	fp->fbu->scrInfo.qe.timestamp_ms = TO_MS(time);
548 	fp->fbu->scrInfo.qe.eSize = PM_MAXEVQ;
549 	fp->fbu->scrInfo.qe.eHead = fp->fbu->scrInfo.qe.eTail = 0;
550 	fp->fbu->scrInfo.qe.tcSize = MOTION_BUFFER_SIZE;
551 	fp->fbu->scrInfo.qe.tcNext = 0;
552 
553 	/*
554 	 * Initialize the color map, the screen, and the mouse.
555 	 */
556 	cfbInitColorMap();
557 	cfbScreenInit();
558 	fbScroll(fp);
559 
560 	fp->initialized = 1;
561 	if (cn_tab.cn_fb == (struct pmax_fb *)0)
562 		cn_tab.cn_fb = fp;
563 	return (1);
564 }
565 
566 /*
567  * ----------------------------------------------------------------------------
568  *
569  * cfbScreenInit --
570  *
571  *	Initialize the screen.
572  *
573  * Results:
574  *	None.
575  *
576  * Side effects:
577  *	The screen is initialized.
578  *
579  * ----------------------------------------------------------------------------
580  */
581 static void
582 cfbScreenInit()
583 {
584 	register struct pmax_fb *fp = &cfbfb;
585 
586 	/*
587 	 * Home the cursor.
588 	 * We want an LSI terminal emulation.  We want the graphics
589 	 * terminal to scroll from the bottom. So start at the bottom.
590 	 */
591 	fp->row = 55;
592 	fp->col = 0;
593 
594 	/*
595 	 * Load the cursor with the default values
596 	 *
597 	 */
598 	cfbLoadCursor(defCursor);
599 }
600 
601 /*
602  * ----------------------------------------------------------------------------
603  *
604  * RestoreCursorColor --
605  *
606  *	Routine to restore the color of the cursor.
607  *
608  * Results:
609  *	None.
610  *
611  * Side effects:
612  *	None.
613  *
614  * ----------------------------------------------------------------------------
615  */
616 static void
617 cfbRestoreCursorColor()
618 {
619 	bt459_regmap_t *regs = (bt459_regmap_t *)(cfbfb.fr_addr + CFB_OFFSET_BT459);
620 	register int i;
621 
622 #ifndef PMAX
623 	bt459_select_reg(regs, BT459_REG_CCOLOR_2);
624 	for (i = 0; i < 6; i++) {
625 		regs->addr_reg = cursor_RGB[i];
626 		MachEmptyWriteBuffer();
627 	}
628 #else /* PMAX */
629 	bt459_select_reg(regs, BT459_REG_CCOLOR_1);
630 	for (i = 0; i < 3; i++) {
631 		regs->addr_reg = cursor_RGB[i];
632 		MachEmptyWriteBuffer();
633 	}
634 	bt459_select_reg(regs, BT459_REG_CCOLOR_3);
635 	for (i = 3; i < 6; i++) {
636 		regs->addr_reg = cursor_RGB[i];
637 		MachEmptyWriteBuffer();
638 	}
639 #endif /* PMAX */
640 }
641 
642 /*
643  * ----------------------------------------------------------------------------
644  *
645  * CursorColor --
646  *
647  *	Set the color of the cursor.
648  *
649  * Results:
650  *	None.
651  *
652  * Side effects:
653  *	None.
654  *
655  * ----------------------------------------------------------------------------
656  */
657 static void
658 cfbCursorColor(color)
659 	unsigned int color[];
660 {
661 	register int i, j;
662 
663 	for (i = 0; i < 6; i++)
664 		cursor_RGB[i] = (u_char)(color[i] >> 8);
665 
666 	cfbRestoreCursorColor();
667 }
668 
669 /*
670  *----------------------------------------------------------------------
671  *
672  * PosCursor --
673  *
674  *	Postion the cursor.
675  *
676  * Results:
677  *	None.
678  *
679  * Side effects:
680  *	None.
681  *
682  *----------------------------------------------------------------------
683  */
684 void
685 cfbPosCursor(x, y)
686 	register int x, y;
687 {
688 	bt459_regmap_t *regs = (bt459_regmap_t *)(cfbfb.fr_addr + CFB_OFFSET_BT459);
689 	register struct pmax_fb *fp = &cfbfb;
690 
691 	if (y < fp->fbu->scrInfo.min_cur_y || y > fp->fbu->scrInfo.max_cur_y)
692 		y = fp->fbu->scrInfo.max_cur_y;
693 	if (x < fp->fbu->scrInfo.min_cur_x || x > fp->fbu->scrInfo.max_cur_x)
694 		x = fp->fbu->scrInfo.max_cur_x;
695 	fp->fbu->scrInfo.cursor.x = x;		/* keep track of real cursor */
696 	fp->fbu->scrInfo.cursor.y = y;		/* position, indep. of mouse */
697 
698 	x += 219;
699 	y += 34;
700 
701 	bt459_select_reg(regs, BT459_REG_CXLO);
702 	regs->addr_reg = x;
703 	MachEmptyWriteBuffer();
704 	regs->addr_reg = x >> 8;
705 	MachEmptyWriteBuffer();
706 	regs->addr_reg = y;
707 	MachEmptyWriteBuffer();
708 	regs->addr_reg = y >> 8;
709 	MachEmptyWriteBuffer();
710 }
711 
712 /*
713  * ----------------------------------------------------------------------------
714  *
715  * InitColorMap --
716  *
717  *	Initialize the color map.
718  *
719  * Results:
720  *	None.
721  *
722  * Side effects:
723  *	The colormap is initialized appropriately.
724  *
725  * ----------------------------------------------------------------------------
726  */
727 static void
728 cfbInitColorMap()
729 {
730 	bt459_regmap_t *regs = (bt459_regmap_t *)(cfbfb.fr_addr + CFB_OFFSET_BT459);
731 	register int i;
732 
733 	bt459_select_reg(regs, 0);
734 	regs->addr_cmap = 0; MachEmptyWriteBuffer();
735 	regs->addr_cmap = 0; MachEmptyWriteBuffer();
736 	regs->addr_cmap = 0; MachEmptyWriteBuffer();
737 
738 	for (i = 1; i < 256; i++) {
739 		regs->addr_cmap = 0xff; MachEmptyWriteBuffer();
740 		regs->addr_cmap = 0xff; MachEmptyWriteBuffer();
741 		regs->addr_cmap = 0xff; MachEmptyWriteBuffer();
742 	}
743 
744 	for (i = 0; i < 3; i++) {
745 		cursor_RGB[i] = 0x00;
746 		cursor_RGB[i + 3] = 0xff;
747 	}
748 	cfbRestoreCursorColor();
749 }
750 
751 /*
752  * ----------------------------------------------------------------------------
753  *
754  * LoadColorMap --
755  *
756  *	Load the color map.
757  *
758  * Results:
759  *	None.
760  *
761  * Side effects:
762  *	The color map is loaded.
763  *
764  * ----------------------------------------------------------------------------
765  */
766 static void
767 cfbLoadColorMap(ptr)
768 	ColorMap *ptr;
769 {
770 	bt459_regmap_t *regs = (bt459_regmap_t *)(cfbfb.fr_addr + CFB_OFFSET_BT459);
771 
772 	if (ptr->index > 256)
773 		return;
774 
775 	bt459_select_reg(regs, ptr->index);
776 
777 	regs->addr_cmap = ptr->Entry.red; MachEmptyWriteBuffer();
778 	regs->addr_cmap = ptr->Entry.green; MachEmptyWriteBuffer();
779 	regs->addr_cmap = ptr->Entry.blue; MachEmptyWriteBuffer();
780 }
781 
782 /*
783  * Video on/off state.
784  */
785 static struct vstate {
786 	u_char	color0[3];	/* saved color map entry zero */
787 	u_char	off;		/* TRUE if display is off */
788 } vstate;
789 
790 /*
791  * ----------------------------------------------------------------------------
792  *
793  * bt459_video_on
794  *
795  *	Enable the video display.
796  *
797  * Results:
798  *	None.
799  *
800  * Side effects:
801  *	The display is enabled.
802  *
803  * ----------------------------------------------------------------------------
804  */
805 static void
806 bt459_video_on()
807 {
808 	bt459_regmap_t *regs = (bt459_regmap_t *)(cfbfb.fr_addr + CFB_OFFSET_BT459);
809 
810 	if (!vstate.off)
811 		return;
812 
813 	/* restore old color map entry zero */
814 	bt459_select_reg(regs, 0);
815 	regs->addr_cmap = vstate.color0[0];
816 	MachEmptyWriteBuffer();
817 	regs->addr_cmap = vstate.color0[1];
818 	MachEmptyWriteBuffer();
819 	regs->addr_cmap = vstate.color0[2];
820 	MachEmptyWriteBuffer();
821 
822 	/* enable normal display */
823 	bt459_write_reg(regs, BT459_REG_PRM, 0xff);
824 	bt459_write_reg(regs, BT459_REG_CCR, 0xc0);
825 
826 	vstate.off = 0;
827 }
828 
829 /*
830  * ----------------------------------------------------------------------------
831  *
832  * bt459_video_off
833  *
834  *	Disable the video display.
835  *
836  * Results:
837  *	None.
838  *
839  * Side effects:
840  *	The display is disabled.
841  *
842  * ----------------------------------------------------------------------------
843  */
844 static void
845 bt459_video_off()
846 {
847 	bt459_regmap_t *regs = (bt459_regmap_t *)(cfbfb.fr_addr + CFB_OFFSET_BT459);
848 
849 	if (vstate.off)
850 		return;
851 
852 	/* save old color map entry zero */
853 	bt459_select_reg(regs, 0);
854 	vstate.color0[0] = regs->addr_cmap;
855 	vstate.color0[1] = regs->addr_cmap;
856 	vstate.color0[2] = regs->addr_cmap;
857 
858 	/* set color map entry zero to zero */
859 	bt459_select_reg(regs, 0);
860 	regs->addr_cmap = 0;
861 	MachEmptyWriteBuffer();
862 	regs->addr_cmap = 0;
863 	MachEmptyWriteBuffer();
864 	regs->addr_cmap = 0;
865 	MachEmptyWriteBuffer();
866 
867 	/* disable display */
868 	bt459_write_reg(regs, BT459_REG_PRM, 0);
869 	bt459_write_reg(regs, BT459_REG_CCR, 0);
870 
871 	vstate.off = 1;
872 }
873 
874 /*
875  * cfb keyboard and mouse input. Just punt to the generic ones in fb.c
876  */
877 void
878 cfbKbdEvent(ch)
879 	int ch;
880 {
881 	fbKbdEvent(ch, &cfbfb);
882 }
883 
884 void
885 cfbMouseEvent(newRepPtr)
886 	MouseReport *newRepPtr;
887 {
888 	fbMouseEvent(newRepPtr, &cfbfb);
889 }
890 
891 void
892 cfbMouseButtons(newRepPtr)
893 	MouseReport *newRepPtr;
894 {
895 	fbMouseButtons(newRepPtr, &cfbfb);
896 }
897 
898 /*
899  * Configure the mouse and keyboard based on machine type
900  */
901 static void
902 cfbConfigMouse()
903 {
904 	int s;
905 
906 	s = spltty();
907 	switch (pmax_boardtype) {
908 #if NDC > 0
909 	case DS_3MAX:
910 		dcDivertXInput = cfbKbdEvent;
911 		dcMouseEvent = cfbMouseEvent;
912 		dcMouseButtons = cfbMouseButtons;
913 		break;
914 #endif
915 #if NSCC > 1
916 	case DS_3MIN:
917 		sccDivertXInput = cfbKbdEvent;
918 		sccMouseEvent = cfbMouseEvent;
919 		sccMouseButtons = cfbMouseButtons;
920 		break;
921 #endif
922 #if NDTOP > 0
923 	case DS_MAXINE:
924 		dtopDivertXInput = cfbKbdEvent;
925 		dtopMouseEvent = cfbMouseEvent;
926 		dtopMouseButtons = cfbMouseButtons;
927 		break;
928 #endif
929 	default:
930 		printf("Can't configure mouse/keyboard\n");
931 	};
932 	splx(s);
933 }
934 
935 /*
936  * and deconfigure them
937  */
938 static void
939 cfbDeconfigMouse()
940 {
941 	int s;
942 
943 	s = spltty();
944 	switch (pmax_boardtype) {
945 #if NDC > 0
946 	case DS_3MAX:
947 		dcDivertXInput = (void (*)())0;
948 		dcMouseEvent = (void (*)())0;
949 		dcMouseButtons = (void (*)())0;
950 		break;
951 #endif
952 #if NSCC > 1
953 	case DS_3MIN:
954 		sccDivertXInput = (void (*)())0;
955 		sccMouseEvent = (void (*)())0;
956 		sccMouseButtons = (void (*)())0;
957 		break;
958 #endif
959 #if NDTOP > 0
960 	case DS_MAXINE:
961 		dtopDivertXInput = (void (*)())0;
962 		dtopMouseEvent = (void (*)())0;
963 		dtopMouseButtons = (void (*)())0;
964 		break;
965 #endif
966 	default:
967 		printf("Can't deconfigure mouse/keyboard\n");
968 	};
969 }
970 #endif /* NCFB */
971