xref: /csrg-svn/sys/pmax/dev/pm.c (revision 56819)
1*56819Sralph /*-
2*56819Sralph  * Copyright (c) 1992 The Regents of the University of California.
352130Smckusick  * All rights reserved.
452130Smckusick  *
552130Smckusick  * This code is derived from software contributed to Berkeley by
6*56819Sralph  * Ralph Campbell and Rick Macklem.
752130Smckusick  *
852130Smckusick  * %sccs.include.redist.c%
952130Smckusick  *
10*56819Sralph  *	@(#)pm.c	7.8 (Berkeley) 11/15/92
11*56819Sralph  */
12*56819Sralph 
13*56819Sralph /*
1452130Smckusick  *  devGraphics.c --
1552130Smckusick  *
1652130Smckusick  *     	This file contains machine-dependent routines for the graphics device.
1752130Smckusick  *
1852130Smckusick  *	Copyright (C) 1989 Digital Equipment Corporation.
1952130Smckusick  *	Permission to use, copy, modify, and distribute this software and
2052130Smckusick  *	its documentation for any purpose and without fee is hereby granted,
2152130Smckusick  *	provided that the above copyright notice appears in all copies.
2252130Smckusick  *	Digital Equipment Corporation makes no representations about the
2352130Smckusick  *	suitability of this software for any purpose.  It is provided "as is"
2452130Smckusick  *	without express or implied warranty.
2552130Smckusick  *
2652130Smckusick  * from: $Header: /sprite/src/kernel/dev/ds3100.md/RCS/devGraphics.c,
2752130Smckusick  *	v 9.2 90/02/13 22:16:24 shirriff Exp $ SPRITE (DECWRL)";
2852130Smckusick  */
2952130Smckusick 
30*56819Sralph #include <pm.h>
31*56819Sralph #include <dc.h>
3252130Smckusick #if NPM > 0
33*56819Sralph #if NDC == 0
34*56819Sralph pm needs dc device
35*56819Sralph #else
3652130Smckusick 
3756522Sbostic #include <sys/param.h>
3856522Sbostic #include <sys/time.h>
3956522Sbostic #include <sys/kernel.h>
4056522Sbostic #include <sys/ioctl.h>
4156522Sbostic #include <sys/file.h>
4256522Sbostic #include <sys/errno.h>
4356522Sbostic #include <sys/proc.h>
4456522Sbostic #include <sys/mman.h>
4552130Smckusick 
4656522Sbostic #include <vm/vm.h>
4752130Smckusick 
4856522Sbostic #include <machine/machConst.h>
4956522Sbostic #include <machine/dc7085cons.h>
5056522Sbostic #include <machine/pmioctl.h>
5152130Smckusick 
52*56819Sralph #include <pmax/pmax/kn01.h>
53*56819Sralph #include <pmax/pmax/pmaxtype.h>
54*56819Sralph #include <pmax/pmax/cons.h>
55*56819Sralph 
5656525Sbostic #include <pmax/dev/device.h>
5756525Sbostic #include <pmax/dev/pmreg.h>
58*56819Sralph #include <pmax/dev/fbreg.h>
5956522Sbostic 
6052130Smckusick /*
6152130Smckusick  * These need to be mapped into user space.
6252130Smckusick  */
63*56819Sralph struct fbuaccess pmu;
64*56819Sralph struct pmax_fb pmfb;
65*56819Sralph static u_short curReg;		/* copy of PCCRegs.cmdr since it's read only */
6652130Smckusick 
6752130Smckusick /*
6852130Smckusick  * Forward references.
6952130Smckusick  */
70*56819Sralph extern void fbScroll();
7152862Sralph 
72*56819Sralph static void pmScreenInit();
73*56819Sralph static void pmLoadCursor();
74*56819Sralph static void pmRestoreCursorColor();
75*56819Sralph static void pmCursorColor();
76*56819Sralph void pmPosCursor();
77*56819Sralph static void pmInitColorMap();
78*56819Sralph static void pmVDACInit();
79*56819Sralph static void pmLoadColorMap();
8052130Smckusick 
81*56819Sralph extern void dcPutc(), fbKbdEvent(), fbMouseEvent(), fbMouseButtons();
82*56819Sralph void pmKbdEvent(), pmMouseEvent(), pmMouseButtons();
8352862Sralph extern void (*dcDivertXInput)();
8452862Sralph extern void (*dcMouseEvent)();
8552862Sralph extern void (*dcMouseButtons)();
86*56819Sralph extern int pmax_boardtype;
87*56819Sralph extern u_short defCursor[32];
88*56819Sralph extern struct consdev cn_tab;
8952130Smckusick 
9052130Smckusick int	pmprobe();
9152130Smckusick struct	driver pmdriver = {
9252130Smckusick 	"pm", pmprobe, 0, 0,
9352130Smckusick };
9452130Smckusick 
9552130Smckusick /*
9652130Smckusick  * Test to see if device is present.
9752130Smckusick  * Return true if found and initialized ok.
9852130Smckusick  */
9952130Smckusick /*ARGSUSED*/
10052130Smckusick pmprobe(cp)
10152130Smckusick 	register struct pmax_ctlr *cp;
10252130Smckusick {
103*56819Sralph 	register struct pmax_fb *fp = &pmfb;
10452130Smckusick 
105*56819Sralph 	if (pmax_boardtype != DS_PMAX)
10652130Smckusick 		return (0);
107*56819Sralph 	if (!fp->initialized && !pminit())
108*56819Sralph 		return (0);
109*56819Sralph 	if (fp->isMono)
11052130Smckusick 		printf("pm0 (monochrome display)\n");
11152130Smckusick 	else
11252130Smckusick 		printf("pm0 (color display)\n");
11352130Smckusick 	return (1);
11452130Smckusick }
11552130Smckusick 
11652130Smckusick /*ARGSUSED*/
11752130Smckusick pmopen(dev, flag)
11852130Smckusick 	dev_t dev;
11952130Smckusick 	int flag;
12052130Smckusick {
121*56819Sralph 	register struct pmax_fb *fp = &pmfb;
12253823Smckusick 	int s;
12352130Smckusick 
124*56819Sralph 	if (!fp->initialized)
12552130Smckusick 		return (ENXIO);
126*56819Sralph 	if (fp->GraphicsOpen)
12752130Smckusick 		return (EBUSY);
12852130Smckusick 
129*56819Sralph 	fp->GraphicsOpen = 1;
130*56819Sralph 	if (!fp->isMono)
131*56819Sralph 		pmInitColorMap();
13252130Smckusick 	/*
13352130Smckusick 	 * Set up event queue for later
13452130Smckusick 	 */
135*56819Sralph 	fp->fbu->scrInfo.qe.eSize = PM_MAXEVQ;
136*56819Sralph 	fp->fbu->scrInfo.qe.eHead = fp->fbu->scrInfo.qe.eTail = 0;
137*56819Sralph 	fp->fbu->scrInfo.qe.tcSize = MOTION_BUFFER_SIZE;
138*56819Sralph 	fp->fbu->scrInfo.qe.tcNext = 0;
139*56819Sralph 	fp->fbu->scrInfo.qe.timestamp_ms = TO_MS(time);
14053823Smckusick 	s = spltty();
14153823Smckusick 	dcDivertXInput = pmKbdEvent;
14253823Smckusick 	dcMouseEvent = pmMouseEvent;
14353823Smckusick 	dcMouseButtons = pmMouseButtons;
14453823Smckusick 	splx(s);
14552130Smckusick 	return (0);
14652130Smckusick }
14752130Smckusick 
14852130Smckusick /*ARGSUSED*/
14952130Smckusick pmclose(dev, flag)
15052130Smckusick 	dev_t dev;
15152130Smckusick 	int flag;
15252130Smckusick {
153*56819Sralph 	register struct pmax_fb *fp = &pmfb;
15452960Sralph 	int s;
15552130Smckusick 
156*56819Sralph 	if (!fp->GraphicsOpen)
15752130Smckusick 		return (EBADF);
15852130Smckusick 
159*56819Sralph 	fp->GraphicsOpen = 0;
160*56819Sralph 	if (!fp->isMono)
161*56819Sralph 		pmInitColorMap();
16252960Sralph 	s = spltty();
16352960Sralph 	dcDivertXInput = (void (*)())0;
16452960Sralph 	dcMouseEvent = (void (*)())0;
16552960Sralph 	dcMouseButtons = (void (*)())0;
16652960Sralph 	splx(s);
167*56819Sralph 	pmScreenInit();
16852130Smckusick 	vmUserUnmap();
169*56819Sralph 	bzero((caddr_t)fp->fr_addr,
170*56819Sralph 		(fp->isMono ? 1024 / 8 : 1024) * 864);
171*56819Sralph 	pmPosCursor(fp->col * 8, fp->row * 15);
17252130Smckusick 	return (0);
17352130Smckusick }
17452130Smckusick 
17552130Smckusick /*ARGSUSED*/
17652130Smckusick pmioctl(dev, cmd, data, flag)
17752130Smckusick 	dev_t dev;
17852130Smckusick 	caddr_t data;
17952130Smckusick {
180*56819Sralph 	register PCCRegs *pcc = (PCCRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_PCC);
181*56819Sralph 	register struct pmax_fb *fp = &pmfb;
18252960Sralph 	int s;
18352130Smckusick 
18452130Smckusick 	switch (cmd) {
18552130Smckusick 	case QIOCGINFO:
18652130Smckusick 	    {
18752130Smckusick 		caddr_t addr;
18852130Smckusick 		extern caddr_t vmUserMap();
18952130Smckusick 
19052130Smckusick 		/*
19152130Smckusick 		 * Map the all the data the user needs access to into
19252130Smckusick 		 * user space.
19352130Smckusick 		 */
194*56819Sralph 		addr = vmUserMap(sizeof(struct fbuaccess), (unsigned)fp->fbu);
19552130Smckusick 		if (addr == (caddr_t)0)
19652130Smckusick 			goto mapError;
197*56819Sralph 		*(PM_Info **)data = &((struct fbuaccess *)addr)->scrInfo;
198*56819Sralph 		fp->fbu->scrInfo.qe.events = ((struct fbuaccess *)addr)->events;
199*56819Sralph 		fp->fbu->scrInfo.qe.tcs = ((struct fbuaccess *)addr)->tcs;
20052130Smckusick 		/*
20152130Smckusick 		 * Map the plane mask into the user's address space.
20252130Smckusick 		 */
203*56819Sralph 		addr = vmUserMap(4, (unsigned)
204*56819Sralph 			MACH_PHYS_TO_UNCACHED(KN01_PHYS_COLMASK_START));
20552130Smckusick 		if (addr == (caddr_t)0)
20652130Smckusick 			goto mapError;
207*56819Sralph 		fp->fbu->scrInfo.planemask = (char *)addr;
20852130Smckusick 		/*
20952862Sralph 		 * Map the frame buffer into the user's address space.
21052130Smckusick 		 */
211*56819Sralph 		addr = vmUserMap(fp->isMono ? 256*1024 : 1024*1024,
212*56819Sralph 			(unsigned)fp->fr_addr);
21352130Smckusick 		if (addr == (caddr_t)0)
21452130Smckusick 			goto mapError;
215*56819Sralph 		fp->fbu->scrInfo.bitmap = (char *)addr;
21652130Smckusick 		break;
21752130Smckusick 
21852130Smckusick 	mapError:
21952130Smckusick 		vmUserUnmap();
22052130Smckusick 		printf("Cannot map shared data structures\n");
22152130Smckusick 		return (EIO);
22252130Smckusick 	    }
22352130Smckusick 
22452130Smckusick 	case QIOCPMSTATE:
22552130Smckusick 		/*
22652130Smckusick 		 * Set mouse state.
22752130Smckusick 		 */
228*56819Sralph 		fp->fbu->scrInfo.mouse = *(pmCursor *)data;
229*56819Sralph 		pmPosCursor(fp->fbu->scrInfo.mouse.x, fp->fbu->scrInfo.mouse.y);
23052130Smckusick 		break;
23152130Smckusick 
23252130Smckusick 	case QIOCINIT:
23352130Smckusick 		/*
23452130Smckusick 		 * Initialize the screen.
23552130Smckusick 		 */
236*56819Sralph 		pmScreenInit();
23752130Smckusick 		break;
23852130Smckusick 
23952130Smckusick 	case QIOCKPCMD:
24052130Smckusick 	    {
24152130Smckusick 		pmKpCmd *kpCmdPtr;
24252130Smckusick 		unsigned char *cp;
24352130Smckusick 
24452130Smckusick 		kpCmdPtr = (pmKpCmd *)data;
24552130Smckusick 		if (kpCmdPtr->nbytes == 0)
24652130Smckusick 			kpCmdPtr->cmd |= 0x80;
247*56819Sralph 		if (!fp->GraphicsOpen)
24852130Smckusick 			kpCmdPtr->cmd |= 1;
249*56819Sralph 		(*fp->KBDPutc)(fp->kbddev, (int)kpCmdPtr->cmd);
25052130Smckusick 		cp = &kpCmdPtr->par[0];
25152130Smckusick 		for (; kpCmdPtr->nbytes > 0; cp++, kpCmdPtr->nbytes--) {
25252130Smckusick 			if (kpCmdPtr->nbytes == 1)
25352130Smckusick 				*cp |= 0x80;
254*56819Sralph 			(*fp->KBDPutc)(fp->kbddev, (int)*cp);
25552130Smckusick 		}
25652130Smckusick 		break;
25752130Smckusick 	    }
25852130Smckusick 
25952130Smckusick 	case QIOCADDR:
260*56819Sralph 		*(PM_Info **)data = &fp->fbu->scrInfo;
26152130Smckusick 		break;
26252130Smckusick 
26352130Smckusick 	case QIOWCURSOR:
264*56819Sralph 		pmLoadCursor((unsigned short *)data);
26552130Smckusick 		break;
26652130Smckusick 
26752130Smckusick 	case QIOWCURSORCOLOR:
268*56819Sralph 		pmCursorColor((unsigned int *)data);
26952130Smckusick 		break;
27052130Smckusick 
27152130Smckusick 	case QIOSETCMAP:
272*56819Sralph 		pmLoadColorMap((ColorMap *)data);
27352130Smckusick 		break;
27452130Smckusick 
27552130Smckusick 	case QIOKERNLOOP:
27652960Sralph 		s = spltty();
27752862Sralph 		dcDivertXInput = pmKbdEvent;
27852862Sralph 		dcMouseEvent = pmMouseEvent;
27952862Sralph 		dcMouseButtons = pmMouseButtons;
28052960Sralph 		splx(s);
28152130Smckusick 		break;
28252130Smckusick 
28352130Smckusick 	case QIOKERNUNLOOP:
28452960Sralph 		s = spltty();
28552862Sralph 		dcDivertXInput = (void (*)())0;
28652862Sralph 		dcMouseEvent = (void (*)())0;
28752862Sralph 		dcMouseButtons = (void (*)())0;
28852960Sralph 		splx(s);
28952130Smckusick 		break;
29052130Smckusick 
29152130Smckusick 	case QIOVIDEOON:
292*56819Sralph 		if (!fp->isMono)
293*56819Sralph 			pmRestoreCursorColor();
29452130Smckusick 		curReg |= PCC_ENPA;
29552130Smckusick 		curReg &= ~PCC_FOPB;
29652130Smckusick 		pcc->cmdr = curReg;
29752130Smckusick 		break;
29852130Smckusick 
29952130Smckusick 	case QIOVIDEOOFF:
300*56819Sralph 		if (!fp->isMono)
301*56819Sralph 			pmVDACInit();
30252130Smckusick 		curReg |= PCC_FOPB;
30352130Smckusick 		curReg &= ~PCC_ENPA;
30452130Smckusick 		pcc->cmdr = curReg;
30552130Smckusick 		break;
30652130Smckusick 
30752130Smckusick 	default:
30852862Sralph 		printf("pm0: Unknown ioctl command %x\n", cmd);
30952130Smckusick 		return (EINVAL);
31052130Smckusick 	}
31152130Smckusick 	return (0);
31252130Smckusick }
31352130Smckusick 
31452675Smckusick pmselect(dev, flag, p)
31552130Smckusick 	dev_t dev;
31652130Smckusick 	int flag;
31752675Smckusick 	struct proc *p;
31852130Smckusick {
319*56819Sralph 	struct pmax_fb *fp = &pmfb;
32052130Smckusick 
32152130Smckusick 	switch (flag) {
32252130Smckusick 	case FREAD:
323*56819Sralph 		if (fp->fbu->scrInfo.qe.eHead != fp->fbu->scrInfo.qe.eTail)
32452130Smckusick 			return (1);
325*56819Sralph 		selrecord(p, &fp->selp);
32652130Smckusick 		break;
32752130Smckusick 	}
32852130Smckusick 
32952130Smckusick 	return (0);
33052130Smckusick }
33152862Sralph 
33252862Sralph static u_char	bg_RGB[3];	/* background color for the cursor */
33352862Sralph static u_char	fg_RGB[3];	/* foreground color for the cursor */
33452862Sralph 
33552862Sralph /*
33652862Sralph  * Test to see if device is present.
33752862Sralph  * Return true if found and initialized ok.
33852862Sralph  */
33952862Sralph pminit()
34052862Sralph {
341*56819Sralph 	register PCCRegs *pcc = (PCCRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_PCC);
342*56819Sralph 	register struct pmax_fb *fp = &pmfb;
34352862Sralph 
344*56819Sralph 	fp->isMono = *(volatile u_short *)MACH_PHYS_TO_UNCACHED(KN01_SYS_CSR) &
345*56819Sralph 		KN01_CSR_MONO;
346*56819Sralph 	fp->fr_addr = (char *)MACH_PHYS_TO_UNCACHED(KN01_PHYS_FBUF_START);
347*56819Sralph 	fp->fbu = &pmu;
348*56819Sralph 	fp->posCursor = pmPosCursor;
349*56819Sralph 	fp->KBDPutc = dcPutc;
350*56819Sralph 	fp->kbddev = makedev(DCDEV, DCKBD_PORT);
351*56819Sralph 	if (fp->isMono) {
35252862Sralph 		/* check for no frame buffer */
353*56819Sralph 		if (badaddr((char *)fp->fr_addr, 4))
35452862Sralph 			return (0);
35552862Sralph 	}
35652862Sralph 
35752862Sralph 	/*
35852862Sralph 	 * Initialize the screen.
35952862Sralph 	 */
36052862Sralph 	pcc->cmdr = PCC_FOPB | PCC_VBHI;
36152862Sralph 
36252862Sralph 	/*
36352862Sralph 	 * Initialize the cursor register.
36452862Sralph 	 */
36552862Sralph 	pcc->cmdr = curReg = PCC_ENPA | PCC_ENPB;
36652862Sralph 
36752862Sralph 	/*
36852862Sralph 	 * Initialize screen info.
36952862Sralph 	 */
370*56819Sralph 	fp->fbu->scrInfo.max_row = 56;
371*56819Sralph 	fp->fbu->scrInfo.max_col = 80;
372*56819Sralph 	fp->fbu->scrInfo.max_x = 1024;
373*56819Sralph 	fp->fbu->scrInfo.max_y = 864;
374*56819Sralph 	fp->fbu->scrInfo.max_cur_x = 1023;
375*56819Sralph 	fp->fbu->scrInfo.max_cur_y = 863;
376*56819Sralph 	fp->fbu->scrInfo.version = 11;
377*56819Sralph 	fp->fbu->scrInfo.mthreshold = 4;
378*56819Sralph 	fp->fbu->scrInfo.mscale = 2;
379*56819Sralph 	fp->fbu->scrInfo.min_cur_x = -15;
380*56819Sralph 	fp->fbu->scrInfo.min_cur_y = -15;
381*56819Sralph 	fp->fbu->scrInfo.qe.timestamp_ms = TO_MS(time);
382*56819Sralph 	fp->fbu->scrInfo.qe.eSize = PM_MAXEVQ;
383*56819Sralph 	fp->fbu->scrInfo.qe.eHead = fp->fbu->scrInfo.qe.eTail = 0;
384*56819Sralph 	fp->fbu->scrInfo.qe.tcSize = MOTION_BUFFER_SIZE;
385*56819Sralph 	fp->fbu->scrInfo.qe.tcNext = 0;
38652862Sralph 
38752862Sralph 	/*
38852862Sralph 	 * Initialize the color map, the screen, and the mouse.
38952862Sralph 	 */
390*56819Sralph 	pmInitColorMap();
391*56819Sralph 	pmScreenInit();
392*56819Sralph 	fbScroll(fp);
39352862Sralph 
394*56819Sralph 	fp->initialized = 1;
395*56819Sralph 	if (cn_tab.cn_fb == (struct pmax_fb *)0)
396*56819Sralph 		cn_tab.cn_fb = fp;
39752862Sralph 	return (1);
39852862Sralph }
39952862Sralph 
40052862Sralph /*
40152862Sralph  * ----------------------------------------------------------------------------
40252862Sralph  *
403*56819Sralph  * pmScreenInit --
40452862Sralph  *
40552862Sralph  *	Initialize the screen.
40652862Sralph  *
40752862Sralph  * Results:
40852862Sralph  *	None.
40952862Sralph  *
41052862Sralph  * Side effects:
41152862Sralph  *	The screen is initialized.
41252862Sralph  *
41352862Sralph  * ----------------------------------------------------------------------------
41452862Sralph  */
41552862Sralph static void
416*56819Sralph pmScreenInit()
41752862Sralph {
418*56819Sralph 	register struct pmax_fb *fp = &pmfb;
41952862Sralph 
42052862Sralph 	/*
42152862Sralph 	 * Home the cursor.
42252862Sralph 	 * We want an LSI terminal emulation.  We want the graphics
42352862Sralph 	 * terminal to scroll from the bottom. So start at the bottom.
42452862Sralph 	 */
425*56819Sralph 	fp->row = 55;
426*56819Sralph 	fp->col = 0;
42752862Sralph 
42852862Sralph 	/*
42952862Sralph 	 * Load the cursor with the default values
43052862Sralph 	 *
43152862Sralph 	 */
432*56819Sralph 	pmLoadCursor(defCursor);
43352862Sralph }
43452862Sralph 
43552862Sralph /*
43652862Sralph  * ----------------------------------------------------------------------------
43752862Sralph  *
438*56819Sralph  * pmLoadCursor --
43952862Sralph  *
44052862Sralph  *	Routine to load the cursor Sprite pattern.
44152862Sralph  *
44252862Sralph  * Results:
44352862Sralph  *	None.
44452862Sralph  *
44552862Sralph  * Side effects:
44652862Sralph  *	The cursor is loaded into the hardware cursor.
44752862Sralph  *
44852862Sralph  * ----------------------------------------------------------------------------
44952862Sralph  */
45052862Sralph static void
451*56819Sralph pmLoadCursor(cur)
45252862Sralph 	unsigned short *cur;
45352862Sralph {
454*56819Sralph 	register PCCRegs *pcc = (PCCRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_PCC);
45552862Sralph 	register int i;
45652862Sralph 
45752862Sralph 	curReg |= PCC_LODSA;
45852862Sralph 	pcc->cmdr = curReg;
45952862Sralph 	for (i = 0; i < 32; i++) {
46052862Sralph 		pcc->memory = cur[i];
46152862Sralph 		MachEmptyWriteBuffer();
46252862Sralph 	}
46352862Sralph 	curReg &= ~PCC_LODSA;
46452862Sralph 	pcc->cmdr = curReg;
46552862Sralph }
46652862Sralph 
46752862Sralph /*
46852862Sralph  * ----------------------------------------------------------------------------
46952862Sralph  *
470*56819Sralph  * pmRestoreCursorColor --
47152862Sralph  *
47252862Sralph  *	Routine to restore the color of the cursor.
47352862Sralph  *
47452862Sralph  * Results:
47552862Sralph  *	None.
47652862Sralph  *
47752862Sralph  * Side effects:
47852862Sralph  *	None.
47952862Sralph  *
48052862Sralph  * ----------------------------------------------------------------------------
48152862Sralph  */
48252862Sralph static void
483*56819Sralph pmRestoreCursorColor()
48452862Sralph {
485*56819Sralph 	register VDACRegs *vdac = (VDACRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_VDAC);
48652862Sralph 	register int i;
48752862Sralph 
48852862Sralph 	vdac->overWA = 0x04;
48952862Sralph 	MachEmptyWriteBuffer();
49052862Sralph 	for (i = 0; i < 3; i++) {
49152862Sralph 		vdac->over = bg_RGB[i];
49252862Sralph 		MachEmptyWriteBuffer();
49352862Sralph 	}
49452862Sralph 
49552862Sralph 	vdac->overWA = 0x08;
49652862Sralph 	MachEmptyWriteBuffer();
49752862Sralph 	vdac->over = 0x00;
49852862Sralph 	MachEmptyWriteBuffer();
49952862Sralph 	vdac->over = 0x00;
50052862Sralph 	MachEmptyWriteBuffer();
50152862Sralph 	vdac->over = 0x7f;
50252862Sralph 	MachEmptyWriteBuffer();
50352862Sralph 
50452862Sralph 	vdac->overWA = 0x0c;
50552862Sralph 	MachEmptyWriteBuffer();
50652862Sralph 	for (i = 0; i < 3; i++) {
50752862Sralph 		vdac->over = fg_RGB[i];
50852862Sralph 		MachEmptyWriteBuffer();
50952862Sralph 	}
51052862Sralph }
51152862Sralph 
51252862Sralph /*
51352862Sralph  * ----------------------------------------------------------------------------
51452862Sralph  *
515*56819Sralph  * pmCursorColor --
51652862Sralph  *
51752862Sralph  *	Set the color of the cursor.
51852862Sralph  *
51952862Sralph  * Results:
52052862Sralph  *	None.
52152862Sralph  *
52252862Sralph  * Side effects:
52352862Sralph  *	None.
52452862Sralph  *
52552862Sralph  * ----------------------------------------------------------------------------
52652862Sralph  */
52752862Sralph static void
528*56819Sralph pmCursorColor(color)
52952862Sralph 	unsigned int color[];
53052862Sralph {
53152862Sralph 	register int i, j;
53252862Sralph 
53352862Sralph 	for (i = 0; i < 3; i++)
53452862Sralph 		bg_RGB[i] = (u_char)(color[i] >> 8);
53552862Sralph 
53652862Sralph 	for (i = 3, j = 0; i < 6; i++, j++)
53752862Sralph 		fg_RGB[j] = (u_char)(color[i] >> 8);
53852862Sralph 
539*56819Sralph 	pmRestoreCursorColor();
54052862Sralph }
54152862Sralph 
54252862Sralph /*
54352862Sralph  * ----------------------------------------------------------------------------
54452862Sralph  *
545*56819Sralph  * pmInitColorMap --
54652862Sralph  *
54752862Sralph  *	Initialize the color map.
54852862Sralph  *
54952862Sralph  * Results:
55052862Sralph  *	None.
55152862Sralph  *
55252862Sralph  * Side effects:
55352862Sralph  *	The colormap is initialized appropriately whether it is color or
55452862Sralph  *	monochrome.
55552862Sralph  *
55652862Sralph  * ----------------------------------------------------------------------------
55752862Sralph  */
55852862Sralph static void
559*56819Sralph pmInitColorMap()
56052862Sralph {
561*56819Sralph 	register VDACRegs *vdac = (VDACRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_VDAC);
562*56819Sralph 	struct pmax_fb *fp = &pmfb;
56352862Sralph 	register int i;
56452862Sralph 
565*56819Sralph 	*(volatile char *)MACH_PHYS_TO_UNCACHED(KN01_PHYS_COLMASK_START) = 0xff;
56652862Sralph 	MachEmptyWriteBuffer();
56752862Sralph 
568*56819Sralph 	if (fp->isMono) {
56952862Sralph 		vdac->mapWA = 0; MachEmptyWriteBuffer();
57052862Sralph 		for (i = 0; i < 256; i++) {
57152862Sralph 			vdac->map = (i < 128) ? 0x00 : 0xff;
57252862Sralph 			MachEmptyWriteBuffer();
57352862Sralph 			vdac->map = (i < 128) ? 0x00 : 0xff;
57452862Sralph 			MachEmptyWriteBuffer();
57552862Sralph 			vdac->map = (i < 128) ? 0x00 : 0xff;
57652862Sralph 			MachEmptyWriteBuffer();
57752862Sralph 		}
57852862Sralph 	} else {
57952862Sralph 		vdac->mapWA = 0; MachEmptyWriteBuffer();
58052862Sralph 		vdac->map = 0; MachEmptyWriteBuffer();
58152862Sralph 		vdac->map = 0; MachEmptyWriteBuffer();
58252862Sralph 		vdac->map = 0; MachEmptyWriteBuffer();
58352862Sralph 
58452862Sralph 		for (i = 1; i < 256; i++) {
58552862Sralph 			vdac->map = 0xff; MachEmptyWriteBuffer();
58652862Sralph 			vdac->map = 0xff; MachEmptyWriteBuffer();
58752862Sralph 			vdac->map = 0xff; MachEmptyWriteBuffer();
58852862Sralph 		}
58952862Sralph 	}
59052862Sralph 
59152862Sralph 	for (i = 0; i < 3; i++) {
59252862Sralph 		bg_RGB[i] = 0x00;
59352862Sralph 		fg_RGB[i] = 0xff;
59452862Sralph 	}
595*56819Sralph 	pmRestoreCursorColor();
59652862Sralph }
59752862Sralph 
59852862Sralph /*
59952862Sralph  * ----------------------------------------------------------------------------
60052862Sralph  *
601*56819Sralph  * pmVDACInit --
60252862Sralph  *
60352862Sralph  *	Initialize the VDAC.
60452862Sralph  *
60552862Sralph  * Results:
60652862Sralph  *	None.
60752862Sralph  *
60852862Sralph  * Side effects:
60952862Sralph  *	None.
61052862Sralph  *
61152862Sralph  * ----------------------------------------------------------------------------
61252862Sralph  */
61352862Sralph static void
614*56819Sralph pmVDACInit()
61552862Sralph {
616*56819Sralph 	register VDACRegs *vdac = (VDACRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_VDAC);
61752862Sralph 
61852862Sralph 	/*
61952862Sralph 	 *
62052862Sralph 	 * Initialize the VDAC
62152862Sralph 	 */
62252862Sralph 	vdac->overWA = 0x04; MachEmptyWriteBuffer();
62352862Sralph 	vdac->over = 0x00; MachEmptyWriteBuffer();
62452862Sralph 	vdac->over = 0x00; MachEmptyWriteBuffer();
62552862Sralph 	vdac->over = 0x00; MachEmptyWriteBuffer();
62652862Sralph 	vdac->overWA = 0x08; MachEmptyWriteBuffer();
62752862Sralph 	vdac->over = 0x00; MachEmptyWriteBuffer();
62852862Sralph 	vdac->over = 0x00; MachEmptyWriteBuffer();
62952862Sralph 	vdac->over = 0x7f; MachEmptyWriteBuffer();
63052862Sralph 	vdac->overWA = 0x0c; MachEmptyWriteBuffer();
63152862Sralph 	vdac->over = 0xff; MachEmptyWriteBuffer();
63252862Sralph 	vdac->over = 0xff; MachEmptyWriteBuffer();
63352862Sralph 	vdac->over = 0xff; MachEmptyWriteBuffer();
63452862Sralph }
63552862Sralph 
63652862Sralph /*
63752862Sralph  * ----------------------------------------------------------------------------
63852862Sralph  *
639*56819Sralph  * pmLoadColorMap --
64052862Sralph  *
64152862Sralph  *	Load the color map.
64252862Sralph  *
64352862Sralph  * Results:
64452862Sralph  *	None.
64552862Sralph  *
64652862Sralph  * Side effects:
64752862Sralph  *	The color map is loaded.
64852862Sralph  *
64952862Sralph  * ----------------------------------------------------------------------------
65052862Sralph  */
65152862Sralph static void
652*56819Sralph pmLoadColorMap(ptr)
65352862Sralph 	ColorMap *ptr;
65452862Sralph {
655*56819Sralph 	register VDACRegs *vdac = (VDACRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_VDAC);
65652862Sralph 
65752862Sralph 	if (ptr->index > 256)
65852862Sralph 		return;
65952862Sralph 
66052862Sralph 	vdac->mapWA = ptr->index; MachEmptyWriteBuffer();
66152862Sralph 	vdac->map = ptr->Entry.red; MachEmptyWriteBuffer();
66252862Sralph 	vdac->map = ptr->Entry.green; MachEmptyWriteBuffer();
66352862Sralph 	vdac->map = ptr->Entry.blue; MachEmptyWriteBuffer();
66452862Sralph }
66552862Sralph 
66652862Sralph /*
66752862Sralph  *----------------------------------------------------------------------
66852862Sralph  *
669*56819Sralph  * pmPosCursor --
67052862Sralph  *
67152862Sralph  *	Postion the cursor.
67252862Sralph  *
67352862Sralph  * Results:
67452862Sralph  *	None.
67552862Sralph  *
67652862Sralph  * Side effects:
67752862Sralph  *	None.
67852862Sralph  *
67952862Sralph  *----------------------------------------------------------------------
68052862Sralph  */
681*56819Sralph void
682*56819Sralph pmPosCursor(x, y)
68352862Sralph 	register int x, y;
68452862Sralph {
685*56819Sralph 	register PCCRegs *pcc = (PCCRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_PCC);
686*56819Sralph 	register struct pmax_fb *fp = &pmfb;
68752862Sralph 
688*56819Sralph 	if (y < fp->fbu->scrInfo.min_cur_y || y > fp->fbu->scrInfo.max_cur_y)
689*56819Sralph 		y = fp->fbu->scrInfo.max_cur_y;
690*56819Sralph 	if (x < fp->fbu->scrInfo.min_cur_x || x > fp->fbu->scrInfo.max_cur_x)
691*56819Sralph 		x = fp->fbu->scrInfo.max_cur_x;
692*56819Sralph 	fp->fbu->scrInfo.cursor.x = x;		/* keep track of real cursor */
693*56819Sralph 	fp->fbu->scrInfo.cursor.y = y;		/* position, indep. of mouse */
69452862Sralph 	pcc->xpos = PCC_X_OFFSET + x;
69552862Sralph 	pcc->ypos = PCC_Y_OFFSET + y;
69652862Sralph }
697*56819Sralph 
698*56819Sralph /*
699*56819Sralph  * pm keyboard and mouse input. Just punt to the generic ones in fb.c
700*56819Sralph  */
701*56819Sralph void
702*56819Sralph pmKbdEvent(ch)
703*56819Sralph 	int ch;
704*56819Sralph {
705*56819Sralph 	fbKbdEvent(ch, &pmfb);
706*56819Sralph }
707*56819Sralph 
708*56819Sralph void
709*56819Sralph pmMouseEvent(newRepPtr)
710*56819Sralph 	MouseReport *newRepPtr;
711*56819Sralph {
712*56819Sralph 	fbMouseEvent(newRepPtr, &pmfb);
713*56819Sralph }
714*56819Sralph 
715*56819Sralph void
716*56819Sralph pmMouseButtons(newRepPtr)
717*56819Sralph 	MouseReport *newRepPtr;
718*56819Sralph {
719*56819Sralph 	fbMouseButtons(newRepPtr, &pmfb);
720*56819Sralph }
721*56819Sralph #endif /* NDC */
722*56819Sralph #endif /* NPM */
723