xref: /csrg-svn/sys/pmax/dev/pm.c (revision 63206)
156819Sralph /*-
2*63206Sbostic  * Copyright (c) 1992, 1993
3*63206Sbostic  *	The Regents of the University of California.  All rights reserved.
452130Smckusick  *
552130Smckusick  * This code is derived from software contributed to Berkeley by
656819Sralph  * Ralph Campbell and Rick Macklem.
752130Smckusick  *
852130Smckusick  * %sccs.include.redist.c%
952130Smckusick  *
10*63206Sbostic  *	@(#)pm.c	8.1 (Berkeley) 06/10/93
1156819Sralph  */
1256819Sralph 
1356819Sralph /*
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 
3056819Sralph #include <pm.h>
3156819Sralph #include <dc.h>
3252130Smckusick #if NPM > 0
3356819Sralph #if NDC == 0
3456819Sralph pm needs dc device
3556819Sralph #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 
5256819Sralph #include <pmax/pmax/kn01.h>
5356819Sralph #include <pmax/pmax/pmaxtype.h>
5456819Sralph #include <pmax/pmax/cons.h>
5556819Sralph 
5656525Sbostic #include <pmax/dev/device.h>
5756525Sbostic #include <pmax/dev/pmreg.h>
5856819Sralph #include <pmax/dev/fbreg.h>
5956522Sbostic 
6052130Smckusick /*
6152130Smckusick  * These need to be mapped into user space.
6252130Smckusick  */
6356819Sralph struct fbuaccess pmu;
6456819Sralph struct pmax_fb pmfb;
6556819Sralph static u_short curReg;		/* copy of PCCRegs.cmdr since it's read only */
6652130Smckusick 
6752130Smckusick /*
6852130Smckusick  * Forward references.
6952130Smckusick  */
7056819Sralph static void pmScreenInit();
7156819Sralph static void pmLoadCursor();
7256819Sralph static void pmRestoreCursorColor();
7356819Sralph static void pmCursorColor();
7456819Sralph void pmPosCursor();
7556819Sralph static void pmInitColorMap();
7656819Sralph static void pmVDACInit();
7756819Sralph static void pmLoadColorMap();
7852130Smckusick 
7956819Sralph void pmKbdEvent(), pmMouseEvent(), pmMouseButtons();
8058974Sralph extern void dcPutc();
8152862Sralph extern void (*dcDivertXInput)();
8252862Sralph extern void (*dcMouseEvent)();
8352862Sralph extern void (*dcMouseButtons)();
8456819Sralph extern int pmax_boardtype;
8556819Sralph extern u_short defCursor[32];
8656819Sralph extern struct consdev cn_tab;
8752130Smckusick 
8852130Smckusick int	pmprobe();
8952130Smckusick struct	driver pmdriver = {
9052130Smckusick 	"pm", pmprobe, 0, 0,
9152130Smckusick };
9252130Smckusick 
9352130Smckusick /*
9452130Smckusick  * Test to see if device is present.
9552130Smckusick  * Return true if found and initialized ok.
9652130Smckusick  */
9752130Smckusick /*ARGSUSED*/
9852130Smckusick pmprobe(cp)
9952130Smckusick 	register struct pmax_ctlr *cp;
10052130Smckusick {
10156819Sralph 	register struct pmax_fb *fp = &pmfb;
10252130Smckusick 
10356819Sralph 	if (pmax_boardtype != DS_PMAX)
10452130Smckusick 		return (0);
10556819Sralph 	if (!fp->initialized && !pminit())
10656819Sralph 		return (0);
10756819Sralph 	if (fp->isMono)
10852130Smckusick 		printf("pm0 (monochrome display)\n");
10952130Smckusick 	else
11052130Smckusick 		printf("pm0 (color display)\n");
11152130Smckusick 	return (1);
11252130Smckusick }
11352130Smckusick 
11452130Smckusick /*ARGSUSED*/
11552130Smckusick pmopen(dev, flag)
11652130Smckusick 	dev_t dev;
11752130Smckusick 	int flag;
11852130Smckusick {
11956819Sralph 	register struct pmax_fb *fp = &pmfb;
12053823Smckusick 	int s;
12152130Smckusick 
12256819Sralph 	if (!fp->initialized)
12352130Smckusick 		return (ENXIO);
12456819Sralph 	if (fp->GraphicsOpen)
12552130Smckusick 		return (EBUSY);
12652130Smckusick 
12756819Sralph 	fp->GraphicsOpen = 1;
12856819Sralph 	if (!fp->isMono)
12956819Sralph 		pmInitColorMap();
13052130Smckusick 	/*
13152130Smckusick 	 * Set up event queue for later
13252130Smckusick 	 */
13356819Sralph 	fp->fbu->scrInfo.qe.eSize = PM_MAXEVQ;
13456819Sralph 	fp->fbu->scrInfo.qe.eHead = fp->fbu->scrInfo.qe.eTail = 0;
13556819Sralph 	fp->fbu->scrInfo.qe.tcSize = MOTION_BUFFER_SIZE;
13656819Sralph 	fp->fbu->scrInfo.qe.tcNext = 0;
13756819Sralph 	fp->fbu->scrInfo.qe.timestamp_ms = TO_MS(time);
13853823Smckusick 	s = spltty();
13953823Smckusick 	dcDivertXInput = pmKbdEvent;
14053823Smckusick 	dcMouseEvent = pmMouseEvent;
14153823Smckusick 	dcMouseButtons = pmMouseButtons;
14253823Smckusick 	splx(s);
14352130Smckusick 	return (0);
14452130Smckusick }
14552130Smckusick 
14652130Smckusick /*ARGSUSED*/
14752130Smckusick pmclose(dev, flag)
14852130Smckusick 	dev_t dev;
14952130Smckusick 	int flag;
15052130Smckusick {
15156819Sralph 	register struct pmax_fb *fp = &pmfb;
15252960Sralph 	int s;
15352130Smckusick 
15456819Sralph 	if (!fp->GraphicsOpen)
15552130Smckusick 		return (EBADF);
15652130Smckusick 
15756819Sralph 	fp->GraphicsOpen = 0;
15856819Sralph 	if (!fp->isMono)
15956819Sralph 		pmInitColorMap();
16052960Sralph 	s = spltty();
16152960Sralph 	dcDivertXInput = (void (*)())0;
16252960Sralph 	dcMouseEvent = (void (*)())0;
16352960Sralph 	dcMouseButtons = (void (*)())0;
16452960Sralph 	splx(s);
16556819Sralph 	pmScreenInit();
16656819Sralph 	bzero((caddr_t)fp->fr_addr,
16756819Sralph 		(fp->isMono ? 1024 / 8 : 1024) * 864);
16856819Sralph 	pmPosCursor(fp->col * 8, fp->row * 15);
16952130Smckusick 	return (0);
17052130Smckusick }
17152130Smckusick 
17252130Smckusick /*ARGSUSED*/
17358974Sralph pmioctl(dev, cmd, data, flag, p)
17452130Smckusick 	dev_t dev;
17552130Smckusick 	caddr_t data;
17658974Sralph 	struct proc *p;
17752130Smckusick {
17856819Sralph 	register PCCRegs *pcc = (PCCRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_PCC);
17956819Sralph 	register struct pmax_fb *fp = &pmfb;
18052960Sralph 	int s;
18152130Smckusick 
18252130Smckusick 	switch (cmd) {
18352130Smckusick 	case QIOCGINFO:
18458974Sralph 		return (fbmmap(fp, dev, data, p));
18552130Smckusick 
18652130Smckusick 	case QIOCPMSTATE:
18752130Smckusick 		/*
18852130Smckusick 		 * Set mouse state.
18952130Smckusick 		 */
19056819Sralph 		fp->fbu->scrInfo.mouse = *(pmCursor *)data;
19156819Sralph 		pmPosCursor(fp->fbu->scrInfo.mouse.x, fp->fbu->scrInfo.mouse.y);
19252130Smckusick 		break;
19352130Smckusick 
19452130Smckusick 	case QIOCINIT:
19552130Smckusick 		/*
19652130Smckusick 		 * Initialize the screen.
19752130Smckusick 		 */
19856819Sralph 		pmScreenInit();
19952130Smckusick 		break;
20052130Smckusick 
20152130Smckusick 	case QIOCKPCMD:
20252130Smckusick 	    {
20352130Smckusick 		pmKpCmd *kpCmdPtr;
20452130Smckusick 		unsigned char *cp;
20552130Smckusick 
20652130Smckusick 		kpCmdPtr = (pmKpCmd *)data;
20752130Smckusick 		if (kpCmdPtr->nbytes == 0)
20852130Smckusick 			kpCmdPtr->cmd |= 0x80;
20956819Sralph 		if (!fp->GraphicsOpen)
21052130Smckusick 			kpCmdPtr->cmd |= 1;
21156819Sralph 		(*fp->KBDPutc)(fp->kbddev, (int)kpCmdPtr->cmd);
21252130Smckusick 		cp = &kpCmdPtr->par[0];
21352130Smckusick 		for (; kpCmdPtr->nbytes > 0; cp++, kpCmdPtr->nbytes--) {
21452130Smckusick 			if (kpCmdPtr->nbytes == 1)
21552130Smckusick 				*cp |= 0x80;
21656819Sralph 			(*fp->KBDPutc)(fp->kbddev, (int)*cp);
21752130Smckusick 		}
21852130Smckusick 		break;
21952130Smckusick 	    }
22052130Smckusick 
22152130Smckusick 	case QIOCADDR:
22256819Sralph 		*(PM_Info **)data = &fp->fbu->scrInfo;
22352130Smckusick 		break;
22452130Smckusick 
22552130Smckusick 	case QIOWCURSOR:
22656819Sralph 		pmLoadCursor((unsigned short *)data);
22752130Smckusick 		break;
22852130Smckusick 
22952130Smckusick 	case QIOWCURSORCOLOR:
23056819Sralph 		pmCursorColor((unsigned int *)data);
23152130Smckusick 		break;
23252130Smckusick 
23352130Smckusick 	case QIOSETCMAP:
23456819Sralph 		pmLoadColorMap((ColorMap *)data);
23552130Smckusick 		break;
23652130Smckusick 
23752130Smckusick 	case QIOKERNLOOP:
23852960Sralph 		s = spltty();
23952862Sralph 		dcDivertXInput = pmKbdEvent;
24052862Sralph 		dcMouseEvent = pmMouseEvent;
24152862Sralph 		dcMouseButtons = pmMouseButtons;
24252960Sralph 		splx(s);
24352130Smckusick 		break;
24452130Smckusick 
24552130Smckusick 	case QIOKERNUNLOOP:
24652960Sralph 		s = spltty();
24752862Sralph 		dcDivertXInput = (void (*)())0;
24852862Sralph 		dcMouseEvent = (void (*)())0;
24952862Sralph 		dcMouseButtons = (void (*)())0;
25052960Sralph 		splx(s);
25152130Smckusick 		break;
25252130Smckusick 
25352130Smckusick 	case QIOVIDEOON:
25456819Sralph 		if (!fp->isMono)
25556819Sralph 			pmRestoreCursorColor();
25652130Smckusick 		curReg |= PCC_ENPA;
25752130Smckusick 		curReg &= ~PCC_FOPB;
25852130Smckusick 		pcc->cmdr = curReg;
25952130Smckusick 		break;
26052130Smckusick 
26152130Smckusick 	case QIOVIDEOOFF:
26256819Sralph 		if (!fp->isMono)
26356819Sralph 			pmVDACInit();
26452130Smckusick 		curReg |= PCC_FOPB;
26552130Smckusick 		curReg &= ~PCC_ENPA;
26652130Smckusick 		pcc->cmdr = curReg;
26752130Smckusick 		break;
26852130Smckusick 
26952130Smckusick 	default:
27052862Sralph 		printf("pm0: Unknown ioctl command %x\n", cmd);
27152130Smckusick 		return (EINVAL);
27252130Smckusick 	}
27352130Smckusick 	return (0);
27452130Smckusick }
27552130Smckusick 
27658974Sralph /*
27758974Sralph  * Return the physical page number that corresponds to byte offset 'off'.
27858974Sralph  */
27958974Sralph /*ARGSUSED*/
28058974Sralph pmmap(dev, off, prot)
28158974Sralph 	dev_t dev;
28258974Sralph {
28358974Sralph 	int len;
28458974Sralph 
28558974Sralph 	len = pmax_round_page(((vm_offset_t)&pmu & PGOFSET) + sizeof(pmu));
28658974Sralph 	if (off < len)
28758974Sralph 		return pmax_btop(MACH_CACHED_TO_PHYS(&pmu) + off);
28858974Sralph 	off -= len;
28958974Sralph 	if (off >= pmfb.fr_size)
29058974Sralph 		return (-1);
29158974Sralph 	return pmax_btop(MACH_UNCACHED_TO_PHYS(pmfb.fr_addr) + off);
29258974Sralph }
29358974Sralph 
29452675Smckusick pmselect(dev, flag, p)
29552130Smckusick 	dev_t dev;
29652130Smckusick 	int flag;
29752675Smckusick 	struct proc *p;
29852130Smckusick {
29956819Sralph 	struct pmax_fb *fp = &pmfb;
30052130Smckusick 
30152130Smckusick 	switch (flag) {
30252130Smckusick 	case FREAD:
30356819Sralph 		if (fp->fbu->scrInfo.qe.eHead != fp->fbu->scrInfo.qe.eTail)
30452130Smckusick 			return (1);
30556819Sralph 		selrecord(p, &fp->selp);
30652130Smckusick 		break;
30752130Smckusick 	}
30852130Smckusick 
30952130Smckusick 	return (0);
31052130Smckusick }
31152862Sralph 
31252862Sralph static u_char	bg_RGB[3];	/* background color for the cursor */
31352862Sralph static u_char	fg_RGB[3];	/* foreground color for the cursor */
31452862Sralph 
31552862Sralph /*
31652862Sralph  * Test to see if device is present.
31752862Sralph  * Return true if found and initialized ok.
31852862Sralph  */
31952862Sralph pminit()
32052862Sralph {
32156819Sralph 	register PCCRegs *pcc = (PCCRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_PCC);
32256819Sralph 	register struct pmax_fb *fp = &pmfb;
32352862Sralph 
32456819Sralph 	fp->isMono = *(volatile u_short *)MACH_PHYS_TO_UNCACHED(KN01_SYS_CSR) &
32556819Sralph 		KN01_CSR_MONO;
32656819Sralph 	fp->fr_addr = (char *)MACH_PHYS_TO_UNCACHED(KN01_PHYS_FBUF_START);
32758974Sralph 	fp->fr_size = fp->isMono ? 0x40000 : 0x100000;
32858974Sralph 	/*
32958974Sralph 	 * Must be in Uncached space since the fbuaccess structure is
33058974Sralph 	 * mapped into the user's address space uncached.
33158974Sralph 	 */
33258974Sralph 	fp->fbu = (struct fbuaccess *)
33358974Sralph 		MACH_PHYS_TO_UNCACHED(MACH_CACHED_TO_PHYS(&pmu));
33456819Sralph 	fp->posCursor = pmPosCursor;
33556819Sralph 	fp->KBDPutc = dcPutc;
33656819Sralph 	fp->kbddev = makedev(DCDEV, DCKBD_PORT);
33756819Sralph 	if (fp->isMono) {
33852862Sralph 		/* check for no frame buffer */
33956819Sralph 		if (badaddr((char *)fp->fr_addr, 4))
34052862Sralph 			return (0);
34152862Sralph 	}
34252862Sralph 
34352862Sralph 	/*
34452862Sralph 	 * Initialize the screen.
34552862Sralph 	 */
34652862Sralph 	pcc->cmdr = PCC_FOPB | PCC_VBHI;
34752862Sralph 
34852862Sralph 	/*
34952862Sralph 	 * Initialize the cursor register.
35052862Sralph 	 */
35152862Sralph 	pcc->cmdr = curReg = PCC_ENPA | PCC_ENPB;
35252862Sralph 
35352862Sralph 	/*
35452862Sralph 	 * Initialize screen info.
35552862Sralph 	 */
35656819Sralph 	fp->fbu->scrInfo.max_row = 56;
35756819Sralph 	fp->fbu->scrInfo.max_col = 80;
35856819Sralph 	fp->fbu->scrInfo.max_x = 1024;
35956819Sralph 	fp->fbu->scrInfo.max_y = 864;
36056819Sralph 	fp->fbu->scrInfo.max_cur_x = 1023;
36156819Sralph 	fp->fbu->scrInfo.max_cur_y = 863;
36256819Sralph 	fp->fbu->scrInfo.version = 11;
36356819Sralph 	fp->fbu->scrInfo.mthreshold = 4;
36456819Sralph 	fp->fbu->scrInfo.mscale = 2;
36556819Sralph 	fp->fbu->scrInfo.min_cur_x = -15;
36656819Sralph 	fp->fbu->scrInfo.min_cur_y = -15;
36756819Sralph 	fp->fbu->scrInfo.qe.timestamp_ms = TO_MS(time);
36856819Sralph 	fp->fbu->scrInfo.qe.eSize = PM_MAXEVQ;
36956819Sralph 	fp->fbu->scrInfo.qe.eHead = fp->fbu->scrInfo.qe.eTail = 0;
37056819Sralph 	fp->fbu->scrInfo.qe.tcSize = MOTION_BUFFER_SIZE;
37156819Sralph 	fp->fbu->scrInfo.qe.tcNext = 0;
37252862Sralph 
37352862Sralph 	/*
37452862Sralph 	 * Initialize the color map, the screen, and the mouse.
37552862Sralph 	 */
37656819Sralph 	pmInitColorMap();
37756819Sralph 	pmScreenInit();
37856819Sralph 	fbScroll(fp);
37952862Sralph 
38056819Sralph 	fp->initialized = 1;
38156819Sralph 	if (cn_tab.cn_fb == (struct pmax_fb *)0)
38256819Sralph 		cn_tab.cn_fb = fp;
38352862Sralph 	return (1);
38452862Sralph }
38552862Sralph 
38652862Sralph /*
38752862Sralph  * ----------------------------------------------------------------------------
38852862Sralph  *
38956819Sralph  * pmScreenInit --
39052862Sralph  *
39152862Sralph  *	Initialize the screen.
39252862Sralph  *
39352862Sralph  * Results:
39452862Sralph  *	None.
39552862Sralph  *
39652862Sralph  * Side effects:
39752862Sralph  *	The screen is initialized.
39852862Sralph  *
39952862Sralph  * ----------------------------------------------------------------------------
40052862Sralph  */
40152862Sralph static void
40256819Sralph pmScreenInit()
40352862Sralph {
40456819Sralph 	register struct pmax_fb *fp = &pmfb;
40552862Sralph 
40652862Sralph 	/*
40752862Sralph 	 * Home the cursor.
40852862Sralph 	 * We want an LSI terminal emulation.  We want the graphics
40952862Sralph 	 * terminal to scroll from the bottom. So start at the bottom.
41052862Sralph 	 */
41156819Sralph 	fp->row = 55;
41256819Sralph 	fp->col = 0;
41352862Sralph 
41452862Sralph 	/*
41552862Sralph 	 * Load the cursor with the default values
41652862Sralph 	 *
41752862Sralph 	 */
41856819Sralph 	pmLoadCursor(defCursor);
41952862Sralph }
42052862Sralph 
42152862Sralph /*
42252862Sralph  * ----------------------------------------------------------------------------
42352862Sralph  *
42456819Sralph  * pmLoadCursor --
42552862Sralph  *
42652862Sralph  *	Routine to load the cursor Sprite pattern.
42752862Sralph  *
42852862Sralph  * Results:
42952862Sralph  *	None.
43052862Sralph  *
43152862Sralph  * Side effects:
43252862Sralph  *	The cursor is loaded into the hardware cursor.
43352862Sralph  *
43452862Sralph  * ----------------------------------------------------------------------------
43552862Sralph  */
43652862Sralph static void
43756819Sralph pmLoadCursor(cur)
43852862Sralph 	unsigned short *cur;
43952862Sralph {
44056819Sralph 	register PCCRegs *pcc = (PCCRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_PCC);
44152862Sralph 	register int i;
44252862Sralph 
44352862Sralph 	curReg |= PCC_LODSA;
44452862Sralph 	pcc->cmdr = curReg;
44552862Sralph 	for (i = 0; i < 32; i++) {
44652862Sralph 		pcc->memory = cur[i];
44752862Sralph 		MachEmptyWriteBuffer();
44852862Sralph 	}
44952862Sralph 	curReg &= ~PCC_LODSA;
45052862Sralph 	pcc->cmdr = curReg;
45152862Sralph }
45252862Sralph 
45352862Sralph /*
45452862Sralph  * ----------------------------------------------------------------------------
45552862Sralph  *
45656819Sralph  * pmRestoreCursorColor --
45752862Sralph  *
45852862Sralph  *	Routine to restore the color of the cursor.
45952862Sralph  *
46052862Sralph  * Results:
46152862Sralph  *	None.
46252862Sralph  *
46352862Sralph  * Side effects:
46452862Sralph  *	None.
46552862Sralph  *
46652862Sralph  * ----------------------------------------------------------------------------
46752862Sralph  */
46852862Sralph static void
46956819Sralph pmRestoreCursorColor()
47052862Sralph {
47156819Sralph 	register VDACRegs *vdac = (VDACRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_VDAC);
47252862Sralph 	register int i;
47352862Sralph 
47452862Sralph 	vdac->overWA = 0x04;
47552862Sralph 	MachEmptyWriteBuffer();
47652862Sralph 	for (i = 0; i < 3; i++) {
47752862Sralph 		vdac->over = bg_RGB[i];
47852862Sralph 		MachEmptyWriteBuffer();
47952862Sralph 	}
48052862Sralph 
48152862Sralph 	vdac->overWA = 0x08;
48252862Sralph 	MachEmptyWriteBuffer();
48352862Sralph 	vdac->over = 0x00;
48452862Sralph 	MachEmptyWriteBuffer();
48552862Sralph 	vdac->over = 0x00;
48652862Sralph 	MachEmptyWriteBuffer();
48752862Sralph 	vdac->over = 0x7f;
48852862Sralph 	MachEmptyWriteBuffer();
48952862Sralph 
49052862Sralph 	vdac->overWA = 0x0c;
49152862Sralph 	MachEmptyWriteBuffer();
49252862Sralph 	for (i = 0; i < 3; i++) {
49352862Sralph 		vdac->over = fg_RGB[i];
49452862Sralph 		MachEmptyWriteBuffer();
49552862Sralph 	}
49652862Sralph }
49752862Sralph 
49852862Sralph /*
49952862Sralph  * ----------------------------------------------------------------------------
50052862Sralph  *
50156819Sralph  * pmCursorColor --
50252862Sralph  *
50352862Sralph  *	Set the color of the cursor.
50452862Sralph  *
50552862Sralph  * Results:
50652862Sralph  *	None.
50752862Sralph  *
50852862Sralph  * Side effects:
50952862Sralph  *	None.
51052862Sralph  *
51152862Sralph  * ----------------------------------------------------------------------------
51252862Sralph  */
51352862Sralph static void
51456819Sralph pmCursorColor(color)
51552862Sralph 	unsigned int color[];
51652862Sralph {
51752862Sralph 	register int i, j;
51852862Sralph 
51952862Sralph 	for (i = 0; i < 3; i++)
52052862Sralph 		bg_RGB[i] = (u_char)(color[i] >> 8);
52152862Sralph 
52252862Sralph 	for (i = 3, j = 0; i < 6; i++, j++)
52352862Sralph 		fg_RGB[j] = (u_char)(color[i] >> 8);
52452862Sralph 
52556819Sralph 	pmRestoreCursorColor();
52652862Sralph }
52752862Sralph 
52852862Sralph /*
52952862Sralph  * ----------------------------------------------------------------------------
53052862Sralph  *
53156819Sralph  * pmInitColorMap --
53252862Sralph  *
53352862Sralph  *	Initialize the color map.
53452862Sralph  *
53552862Sralph  * Results:
53652862Sralph  *	None.
53752862Sralph  *
53852862Sralph  * Side effects:
53952862Sralph  *	The colormap is initialized appropriately whether it is color or
54052862Sralph  *	monochrome.
54152862Sralph  *
54252862Sralph  * ----------------------------------------------------------------------------
54352862Sralph  */
54452862Sralph static void
54556819Sralph pmInitColorMap()
54652862Sralph {
54756819Sralph 	register VDACRegs *vdac = (VDACRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_VDAC);
54856819Sralph 	struct pmax_fb *fp = &pmfb;
54952862Sralph 	register int i;
55052862Sralph 
55156819Sralph 	*(volatile char *)MACH_PHYS_TO_UNCACHED(KN01_PHYS_COLMASK_START) = 0xff;
55252862Sralph 	MachEmptyWriteBuffer();
55352862Sralph 
55456819Sralph 	if (fp->isMono) {
55552862Sralph 		vdac->mapWA = 0; MachEmptyWriteBuffer();
55652862Sralph 		for (i = 0; i < 256; i++) {
55752862Sralph 			vdac->map = (i < 128) ? 0x00 : 0xff;
55852862Sralph 			MachEmptyWriteBuffer();
55952862Sralph 			vdac->map = (i < 128) ? 0x00 : 0xff;
56052862Sralph 			MachEmptyWriteBuffer();
56152862Sralph 			vdac->map = (i < 128) ? 0x00 : 0xff;
56252862Sralph 			MachEmptyWriteBuffer();
56352862Sralph 		}
56452862Sralph 	} else {
56552862Sralph 		vdac->mapWA = 0; MachEmptyWriteBuffer();
56652862Sralph 		vdac->map = 0; MachEmptyWriteBuffer();
56752862Sralph 		vdac->map = 0; MachEmptyWriteBuffer();
56852862Sralph 		vdac->map = 0; MachEmptyWriteBuffer();
56952862Sralph 
57052862Sralph 		for (i = 1; i < 256; i++) {
57152862Sralph 			vdac->map = 0xff; MachEmptyWriteBuffer();
57252862Sralph 			vdac->map = 0xff; MachEmptyWriteBuffer();
57352862Sralph 			vdac->map = 0xff; MachEmptyWriteBuffer();
57452862Sralph 		}
57552862Sralph 	}
57652862Sralph 
57752862Sralph 	for (i = 0; i < 3; i++) {
57852862Sralph 		bg_RGB[i] = 0x00;
57952862Sralph 		fg_RGB[i] = 0xff;
58052862Sralph 	}
58156819Sralph 	pmRestoreCursorColor();
58252862Sralph }
58352862Sralph 
58452862Sralph /*
58552862Sralph  * ----------------------------------------------------------------------------
58652862Sralph  *
58756819Sralph  * pmVDACInit --
58852862Sralph  *
58952862Sralph  *	Initialize the VDAC.
59052862Sralph  *
59152862Sralph  * Results:
59252862Sralph  *	None.
59352862Sralph  *
59452862Sralph  * Side effects:
59552862Sralph  *	None.
59652862Sralph  *
59752862Sralph  * ----------------------------------------------------------------------------
59852862Sralph  */
59952862Sralph static void
60056819Sralph pmVDACInit()
60152862Sralph {
60256819Sralph 	register VDACRegs *vdac = (VDACRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_VDAC);
60352862Sralph 
60452862Sralph 	/*
60552862Sralph 	 *
60652862Sralph 	 * Initialize the VDAC
60752862Sralph 	 */
60852862Sralph 	vdac->overWA = 0x04; MachEmptyWriteBuffer();
60952862Sralph 	vdac->over = 0x00; MachEmptyWriteBuffer();
61052862Sralph 	vdac->over = 0x00; MachEmptyWriteBuffer();
61152862Sralph 	vdac->over = 0x00; MachEmptyWriteBuffer();
61252862Sralph 	vdac->overWA = 0x08; MachEmptyWriteBuffer();
61352862Sralph 	vdac->over = 0x00; MachEmptyWriteBuffer();
61452862Sralph 	vdac->over = 0x00; MachEmptyWriteBuffer();
61552862Sralph 	vdac->over = 0x7f; MachEmptyWriteBuffer();
61652862Sralph 	vdac->overWA = 0x0c; MachEmptyWriteBuffer();
61752862Sralph 	vdac->over = 0xff; MachEmptyWriteBuffer();
61852862Sralph 	vdac->over = 0xff; MachEmptyWriteBuffer();
61952862Sralph 	vdac->over = 0xff; MachEmptyWriteBuffer();
62052862Sralph }
62152862Sralph 
62252862Sralph /*
62352862Sralph  * ----------------------------------------------------------------------------
62452862Sralph  *
62556819Sralph  * pmLoadColorMap --
62652862Sralph  *
62752862Sralph  *	Load the color map.
62852862Sralph  *
62952862Sralph  * Results:
63052862Sralph  *	None.
63152862Sralph  *
63252862Sralph  * Side effects:
63352862Sralph  *	The color map is loaded.
63452862Sralph  *
63552862Sralph  * ----------------------------------------------------------------------------
63652862Sralph  */
63752862Sralph static void
63856819Sralph pmLoadColorMap(ptr)
63952862Sralph 	ColorMap *ptr;
64052862Sralph {
64156819Sralph 	register VDACRegs *vdac = (VDACRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_VDAC);
64252862Sralph 
64352862Sralph 	if (ptr->index > 256)
64452862Sralph 		return;
64552862Sralph 
64652862Sralph 	vdac->mapWA = ptr->index; MachEmptyWriteBuffer();
64752862Sralph 	vdac->map = ptr->Entry.red; MachEmptyWriteBuffer();
64852862Sralph 	vdac->map = ptr->Entry.green; MachEmptyWriteBuffer();
64952862Sralph 	vdac->map = ptr->Entry.blue; MachEmptyWriteBuffer();
65052862Sralph }
65152862Sralph 
65252862Sralph /*
65352862Sralph  *----------------------------------------------------------------------
65452862Sralph  *
65556819Sralph  * pmPosCursor --
65652862Sralph  *
65752862Sralph  *	Postion the cursor.
65852862Sralph  *
65952862Sralph  * Results:
66052862Sralph  *	None.
66152862Sralph  *
66252862Sralph  * Side effects:
66352862Sralph  *	None.
66452862Sralph  *
66552862Sralph  *----------------------------------------------------------------------
66652862Sralph  */
66756819Sralph void
66856819Sralph pmPosCursor(x, y)
66952862Sralph 	register int x, y;
67052862Sralph {
67156819Sralph 	register PCCRegs *pcc = (PCCRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_PCC);
67256819Sralph 	register struct pmax_fb *fp = &pmfb;
67352862Sralph 
67456819Sralph 	if (y < fp->fbu->scrInfo.min_cur_y || y > fp->fbu->scrInfo.max_cur_y)
67556819Sralph 		y = fp->fbu->scrInfo.max_cur_y;
67656819Sralph 	if (x < fp->fbu->scrInfo.min_cur_x || x > fp->fbu->scrInfo.max_cur_x)
67756819Sralph 		x = fp->fbu->scrInfo.max_cur_x;
67856819Sralph 	fp->fbu->scrInfo.cursor.x = x;		/* keep track of real cursor */
67956819Sralph 	fp->fbu->scrInfo.cursor.y = y;		/* position, indep. of mouse */
68052862Sralph 	pcc->xpos = PCC_X_OFFSET + x;
68152862Sralph 	pcc->ypos = PCC_Y_OFFSET + y;
68252862Sralph }
68356819Sralph 
68456819Sralph /*
68556819Sralph  * pm keyboard and mouse input. Just punt to the generic ones in fb.c
68656819Sralph  */
68756819Sralph void
68856819Sralph pmKbdEvent(ch)
68956819Sralph 	int ch;
69056819Sralph {
69156819Sralph 	fbKbdEvent(ch, &pmfb);
69256819Sralph }
69356819Sralph 
69456819Sralph void
69556819Sralph pmMouseEvent(newRepPtr)
69656819Sralph 	MouseReport *newRepPtr;
69756819Sralph {
69856819Sralph 	fbMouseEvent(newRepPtr, &pmfb);
69956819Sralph }
70056819Sralph 
70156819Sralph void
70256819Sralph pmMouseButtons(newRepPtr)
70356819Sralph 	MouseReport *newRepPtr;
70456819Sralph {
70556819Sralph 	fbMouseButtons(newRepPtr, &pmfb);
70656819Sralph }
70756819Sralph #endif /* NDC */
70856819Sralph #endif /* NPM */
709