xref: /csrg-svn/sys/pmax/dev/pm.c (revision 69799)
156819Sralph /*-
263206Sbostic  * Copyright (c) 1992, 1993
363206Sbostic  *	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*69799Sralph  *	@(#)pm.c	8.2 (Berkeley) 06/02/95
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;
175*69799Sralph 	u_long cmd;
17652130Smckusick 	caddr_t data;
17758974Sralph 	struct proc *p;
17852130Smckusick {
17956819Sralph 	register PCCRegs *pcc = (PCCRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_PCC);
18056819Sralph 	register struct pmax_fb *fp = &pmfb;
18152960Sralph 	int s;
18252130Smckusick 
18352130Smckusick 	switch (cmd) {
18452130Smckusick 	case QIOCGINFO:
18558974Sralph 		return (fbmmap(fp, dev, data, p));
18652130Smckusick 
18752130Smckusick 	case QIOCPMSTATE:
18852130Smckusick 		/*
18952130Smckusick 		 * Set mouse state.
19052130Smckusick 		 */
19156819Sralph 		fp->fbu->scrInfo.mouse = *(pmCursor *)data;
19256819Sralph 		pmPosCursor(fp->fbu->scrInfo.mouse.x, fp->fbu->scrInfo.mouse.y);
19352130Smckusick 		break;
19452130Smckusick 
19552130Smckusick 	case QIOCINIT:
19652130Smckusick 		/*
19752130Smckusick 		 * Initialize the screen.
19852130Smckusick 		 */
19956819Sralph 		pmScreenInit();
20052130Smckusick 		break;
20152130Smckusick 
20252130Smckusick 	case QIOCKPCMD:
20352130Smckusick 	    {
20452130Smckusick 		pmKpCmd *kpCmdPtr;
20552130Smckusick 		unsigned char *cp;
20652130Smckusick 
20752130Smckusick 		kpCmdPtr = (pmKpCmd *)data;
20852130Smckusick 		if (kpCmdPtr->nbytes == 0)
20952130Smckusick 			kpCmdPtr->cmd |= 0x80;
21056819Sralph 		if (!fp->GraphicsOpen)
21152130Smckusick 			kpCmdPtr->cmd |= 1;
21256819Sralph 		(*fp->KBDPutc)(fp->kbddev, (int)kpCmdPtr->cmd);
21352130Smckusick 		cp = &kpCmdPtr->par[0];
21452130Smckusick 		for (; kpCmdPtr->nbytes > 0; cp++, kpCmdPtr->nbytes--) {
21552130Smckusick 			if (kpCmdPtr->nbytes == 1)
21652130Smckusick 				*cp |= 0x80;
21756819Sralph 			(*fp->KBDPutc)(fp->kbddev, (int)*cp);
21852130Smckusick 		}
21952130Smckusick 		break;
22052130Smckusick 	    }
22152130Smckusick 
22252130Smckusick 	case QIOCADDR:
22356819Sralph 		*(PM_Info **)data = &fp->fbu->scrInfo;
22452130Smckusick 		break;
22552130Smckusick 
22652130Smckusick 	case QIOWCURSOR:
22756819Sralph 		pmLoadCursor((unsigned short *)data);
22852130Smckusick 		break;
22952130Smckusick 
23052130Smckusick 	case QIOWCURSORCOLOR:
23156819Sralph 		pmCursorColor((unsigned int *)data);
23252130Smckusick 		break;
23352130Smckusick 
23452130Smckusick 	case QIOSETCMAP:
23556819Sralph 		pmLoadColorMap((ColorMap *)data);
23652130Smckusick 		break;
23752130Smckusick 
23852130Smckusick 	case QIOKERNLOOP:
23952960Sralph 		s = spltty();
24052862Sralph 		dcDivertXInput = pmKbdEvent;
24152862Sralph 		dcMouseEvent = pmMouseEvent;
24252862Sralph 		dcMouseButtons = pmMouseButtons;
24352960Sralph 		splx(s);
24452130Smckusick 		break;
24552130Smckusick 
24652130Smckusick 	case QIOKERNUNLOOP:
24752960Sralph 		s = spltty();
24852862Sralph 		dcDivertXInput = (void (*)())0;
24952862Sralph 		dcMouseEvent = (void (*)())0;
25052862Sralph 		dcMouseButtons = (void (*)())0;
25152960Sralph 		splx(s);
25252130Smckusick 		break;
25352130Smckusick 
25452130Smckusick 	case QIOVIDEOON:
25556819Sralph 		if (!fp->isMono)
25656819Sralph 			pmRestoreCursorColor();
25752130Smckusick 		curReg |= PCC_ENPA;
25852130Smckusick 		curReg &= ~PCC_FOPB;
25952130Smckusick 		pcc->cmdr = curReg;
26052130Smckusick 		break;
26152130Smckusick 
26252130Smckusick 	case QIOVIDEOOFF:
26356819Sralph 		if (!fp->isMono)
26456819Sralph 			pmVDACInit();
26552130Smckusick 		curReg |= PCC_FOPB;
26652130Smckusick 		curReg &= ~PCC_ENPA;
26752130Smckusick 		pcc->cmdr = curReg;
26852130Smckusick 		break;
26952130Smckusick 
27052130Smckusick 	default:
27152862Sralph 		printf("pm0: Unknown ioctl command %x\n", cmd);
27252130Smckusick 		return (EINVAL);
27352130Smckusick 	}
27452130Smckusick 	return (0);
27552130Smckusick }
27652130Smckusick 
27758974Sralph /*
27858974Sralph  * Return the physical page number that corresponds to byte offset 'off'.
27958974Sralph  */
28058974Sralph /*ARGSUSED*/
28158974Sralph pmmap(dev, off, prot)
28258974Sralph 	dev_t dev;
28358974Sralph {
28458974Sralph 	int len;
28558974Sralph 
28658974Sralph 	len = pmax_round_page(((vm_offset_t)&pmu & PGOFSET) + sizeof(pmu));
28758974Sralph 	if (off < len)
28858974Sralph 		return pmax_btop(MACH_CACHED_TO_PHYS(&pmu) + off);
28958974Sralph 	off -= len;
29058974Sralph 	if (off >= pmfb.fr_size)
29158974Sralph 		return (-1);
29258974Sralph 	return pmax_btop(MACH_UNCACHED_TO_PHYS(pmfb.fr_addr) + off);
29358974Sralph }
29458974Sralph 
29552675Smckusick pmselect(dev, flag, p)
29652130Smckusick 	dev_t dev;
29752130Smckusick 	int flag;
29852675Smckusick 	struct proc *p;
29952130Smckusick {
30056819Sralph 	struct pmax_fb *fp = &pmfb;
30152130Smckusick 
30252130Smckusick 	switch (flag) {
30352130Smckusick 	case FREAD:
30456819Sralph 		if (fp->fbu->scrInfo.qe.eHead != fp->fbu->scrInfo.qe.eTail)
30552130Smckusick 			return (1);
30656819Sralph 		selrecord(p, &fp->selp);
30752130Smckusick 		break;
30852130Smckusick 	}
30952130Smckusick 
31052130Smckusick 	return (0);
31152130Smckusick }
31252862Sralph 
31352862Sralph static u_char	bg_RGB[3];	/* background color for the cursor */
31452862Sralph static u_char	fg_RGB[3];	/* foreground color for the cursor */
31552862Sralph 
31652862Sralph /*
31752862Sralph  * Test to see if device is present.
31852862Sralph  * Return true if found and initialized ok.
31952862Sralph  */
32052862Sralph pminit()
32152862Sralph {
32256819Sralph 	register PCCRegs *pcc = (PCCRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_PCC);
32356819Sralph 	register struct pmax_fb *fp = &pmfb;
32452862Sralph 
32556819Sralph 	fp->isMono = *(volatile u_short *)MACH_PHYS_TO_UNCACHED(KN01_SYS_CSR) &
32656819Sralph 		KN01_CSR_MONO;
32756819Sralph 	fp->fr_addr = (char *)MACH_PHYS_TO_UNCACHED(KN01_PHYS_FBUF_START);
32858974Sralph 	fp->fr_size = fp->isMono ? 0x40000 : 0x100000;
32958974Sralph 	/*
33058974Sralph 	 * Must be in Uncached space since the fbuaccess structure is
33158974Sralph 	 * mapped into the user's address space uncached.
33258974Sralph 	 */
33358974Sralph 	fp->fbu = (struct fbuaccess *)
33458974Sralph 		MACH_PHYS_TO_UNCACHED(MACH_CACHED_TO_PHYS(&pmu));
33556819Sralph 	fp->posCursor = pmPosCursor;
33656819Sralph 	fp->KBDPutc = dcPutc;
33756819Sralph 	fp->kbddev = makedev(DCDEV, DCKBD_PORT);
33856819Sralph 	if (fp->isMono) {
33952862Sralph 		/* check for no frame buffer */
34056819Sralph 		if (badaddr((char *)fp->fr_addr, 4))
34152862Sralph 			return (0);
34252862Sralph 	}
34352862Sralph 
34452862Sralph 	/*
34552862Sralph 	 * Initialize the screen.
34652862Sralph 	 */
34752862Sralph 	pcc->cmdr = PCC_FOPB | PCC_VBHI;
34852862Sralph 
34952862Sralph 	/*
35052862Sralph 	 * Initialize the cursor register.
35152862Sralph 	 */
35252862Sralph 	pcc->cmdr = curReg = PCC_ENPA | PCC_ENPB;
35352862Sralph 
35452862Sralph 	/*
35552862Sralph 	 * Initialize screen info.
35652862Sralph 	 */
35756819Sralph 	fp->fbu->scrInfo.max_row = 56;
35856819Sralph 	fp->fbu->scrInfo.max_col = 80;
35956819Sralph 	fp->fbu->scrInfo.max_x = 1024;
36056819Sralph 	fp->fbu->scrInfo.max_y = 864;
36156819Sralph 	fp->fbu->scrInfo.max_cur_x = 1023;
36256819Sralph 	fp->fbu->scrInfo.max_cur_y = 863;
36356819Sralph 	fp->fbu->scrInfo.version = 11;
36456819Sralph 	fp->fbu->scrInfo.mthreshold = 4;
36556819Sralph 	fp->fbu->scrInfo.mscale = 2;
36656819Sralph 	fp->fbu->scrInfo.min_cur_x = -15;
36756819Sralph 	fp->fbu->scrInfo.min_cur_y = -15;
36856819Sralph 	fp->fbu->scrInfo.qe.timestamp_ms = TO_MS(time);
36956819Sralph 	fp->fbu->scrInfo.qe.eSize = PM_MAXEVQ;
37056819Sralph 	fp->fbu->scrInfo.qe.eHead = fp->fbu->scrInfo.qe.eTail = 0;
37156819Sralph 	fp->fbu->scrInfo.qe.tcSize = MOTION_BUFFER_SIZE;
37256819Sralph 	fp->fbu->scrInfo.qe.tcNext = 0;
37352862Sralph 
37452862Sralph 	/*
37552862Sralph 	 * Initialize the color map, the screen, and the mouse.
37652862Sralph 	 */
37756819Sralph 	pmInitColorMap();
37856819Sralph 	pmScreenInit();
37956819Sralph 	fbScroll(fp);
38052862Sralph 
38156819Sralph 	fp->initialized = 1;
38256819Sralph 	if (cn_tab.cn_fb == (struct pmax_fb *)0)
38356819Sralph 		cn_tab.cn_fb = fp;
38452862Sralph 	return (1);
38552862Sralph }
38652862Sralph 
38752862Sralph /*
38852862Sralph  * ----------------------------------------------------------------------------
38952862Sralph  *
39056819Sralph  * pmScreenInit --
39152862Sralph  *
39252862Sralph  *	Initialize the screen.
39352862Sralph  *
39452862Sralph  * Results:
39552862Sralph  *	None.
39652862Sralph  *
39752862Sralph  * Side effects:
39852862Sralph  *	The screen is initialized.
39952862Sralph  *
40052862Sralph  * ----------------------------------------------------------------------------
40152862Sralph  */
40252862Sralph static void
40356819Sralph pmScreenInit()
40452862Sralph {
40556819Sralph 	register struct pmax_fb *fp = &pmfb;
40652862Sralph 
40752862Sralph 	/*
40852862Sralph 	 * Home the cursor.
40952862Sralph 	 * We want an LSI terminal emulation.  We want the graphics
41052862Sralph 	 * terminal to scroll from the bottom. So start at the bottom.
41152862Sralph 	 */
41256819Sralph 	fp->row = 55;
41356819Sralph 	fp->col = 0;
41452862Sralph 
41552862Sralph 	/*
41652862Sralph 	 * Load the cursor with the default values
41752862Sralph 	 *
41852862Sralph 	 */
41956819Sralph 	pmLoadCursor(defCursor);
42052862Sralph }
42152862Sralph 
42252862Sralph /*
42352862Sralph  * ----------------------------------------------------------------------------
42452862Sralph  *
42556819Sralph  * pmLoadCursor --
42652862Sralph  *
42752862Sralph  *	Routine to load the cursor Sprite pattern.
42852862Sralph  *
42952862Sralph  * Results:
43052862Sralph  *	None.
43152862Sralph  *
43252862Sralph  * Side effects:
43352862Sralph  *	The cursor is loaded into the hardware cursor.
43452862Sralph  *
43552862Sralph  * ----------------------------------------------------------------------------
43652862Sralph  */
43752862Sralph static void
43856819Sralph pmLoadCursor(cur)
43952862Sralph 	unsigned short *cur;
44052862Sralph {
44156819Sralph 	register PCCRegs *pcc = (PCCRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_PCC);
44252862Sralph 	register int i;
44352862Sralph 
44452862Sralph 	curReg |= PCC_LODSA;
44552862Sralph 	pcc->cmdr = curReg;
44652862Sralph 	for (i = 0; i < 32; i++) {
44752862Sralph 		pcc->memory = cur[i];
44852862Sralph 		MachEmptyWriteBuffer();
44952862Sralph 	}
45052862Sralph 	curReg &= ~PCC_LODSA;
45152862Sralph 	pcc->cmdr = curReg;
45252862Sralph }
45352862Sralph 
45452862Sralph /*
45552862Sralph  * ----------------------------------------------------------------------------
45652862Sralph  *
45756819Sralph  * pmRestoreCursorColor --
45852862Sralph  *
45952862Sralph  *	Routine to restore the color of the cursor.
46052862Sralph  *
46152862Sralph  * Results:
46252862Sralph  *	None.
46352862Sralph  *
46452862Sralph  * Side effects:
46552862Sralph  *	None.
46652862Sralph  *
46752862Sralph  * ----------------------------------------------------------------------------
46852862Sralph  */
46952862Sralph static void
47056819Sralph pmRestoreCursorColor()
47152862Sralph {
47256819Sralph 	register VDACRegs *vdac = (VDACRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_VDAC);
47352862Sralph 	register int i;
47452862Sralph 
47552862Sralph 	vdac->overWA = 0x04;
47652862Sralph 	MachEmptyWriteBuffer();
47752862Sralph 	for (i = 0; i < 3; i++) {
47852862Sralph 		vdac->over = bg_RGB[i];
47952862Sralph 		MachEmptyWriteBuffer();
48052862Sralph 	}
48152862Sralph 
48252862Sralph 	vdac->overWA = 0x08;
48352862Sralph 	MachEmptyWriteBuffer();
48452862Sralph 	vdac->over = 0x00;
48552862Sralph 	MachEmptyWriteBuffer();
48652862Sralph 	vdac->over = 0x00;
48752862Sralph 	MachEmptyWriteBuffer();
48852862Sralph 	vdac->over = 0x7f;
48952862Sralph 	MachEmptyWriteBuffer();
49052862Sralph 
49152862Sralph 	vdac->overWA = 0x0c;
49252862Sralph 	MachEmptyWriteBuffer();
49352862Sralph 	for (i = 0; i < 3; i++) {
49452862Sralph 		vdac->over = fg_RGB[i];
49552862Sralph 		MachEmptyWriteBuffer();
49652862Sralph 	}
49752862Sralph }
49852862Sralph 
49952862Sralph /*
50052862Sralph  * ----------------------------------------------------------------------------
50152862Sralph  *
50256819Sralph  * pmCursorColor --
50352862Sralph  *
50452862Sralph  *	Set the color of the cursor.
50552862Sralph  *
50652862Sralph  * Results:
50752862Sralph  *	None.
50852862Sralph  *
50952862Sralph  * Side effects:
51052862Sralph  *	None.
51152862Sralph  *
51252862Sralph  * ----------------------------------------------------------------------------
51352862Sralph  */
51452862Sralph static void
51556819Sralph pmCursorColor(color)
51652862Sralph 	unsigned int color[];
51752862Sralph {
51852862Sralph 	register int i, j;
51952862Sralph 
52052862Sralph 	for (i = 0; i < 3; i++)
52152862Sralph 		bg_RGB[i] = (u_char)(color[i] >> 8);
52252862Sralph 
52352862Sralph 	for (i = 3, j = 0; i < 6; i++, j++)
52452862Sralph 		fg_RGB[j] = (u_char)(color[i] >> 8);
52552862Sralph 
52656819Sralph 	pmRestoreCursorColor();
52752862Sralph }
52852862Sralph 
52952862Sralph /*
53052862Sralph  * ----------------------------------------------------------------------------
53152862Sralph  *
53256819Sralph  * pmInitColorMap --
53352862Sralph  *
53452862Sralph  *	Initialize the color map.
53552862Sralph  *
53652862Sralph  * Results:
53752862Sralph  *	None.
53852862Sralph  *
53952862Sralph  * Side effects:
54052862Sralph  *	The colormap is initialized appropriately whether it is color or
54152862Sralph  *	monochrome.
54252862Sralph  *
54352862Sralph  * ----------------------------------------------------------------------------
54452862Sralph  */
54552862Sralph static void
54656819Sralph pmInitColorMap()
54752862Sralph {
54856819Sralph 	register VDACRegs *vdac = (VDACRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_VDAC);
54956819Sralph 	struct pmax_fb *fp = &pmfb;
55052862Sralph 	register int i;
55152862Sralph 
55256819Sralph 	*(volatile char *)MACH_PHYS_TO_UNCACHED(KN01_PHYS_COLMASK_START) = 0xff;
55352862Sralph 	MachEmptyWriteBuffer();
55452862Sralph 
55556819Sralph 	if (fp->isMono) {
55652862Sralph 		vdac->mapWA = 0; MachEmptyWriteBuffer();
55752862Sralph 		for (i = 0; i < 256; i++) {
55852862Sralph 			vdac->map = (i < 128) ? 0x00 : 0xff;
55952862Sralph 			MachEmptyWriteBuffer();
56052862Sralph 			vdac->map = (i < 128) ? 0x00 : 0xff;
56152862Sralph 			MachEmptyWriteBuffer();
56252862Sralph 			vdac->map = (i < 128) ? 0x00 : 0xff;
56352862Sralph 			MachEmptyWriteBuffer();
56452862Sralph 		}
56552862Sralph 	} else {
56652862Sralph 		vdac->mapWA = 0; MachEmptyWriteBuffer();
56752862Sralph 		vdac->map = 0; MachEmptyWriteBuffer();
56852862Sralph 		vdac->map = 0; MachEmptyWriteBuffer();
56952862Sralph 		vdac->map = 0; MachEmptyWriteBuffer();
57052862Sralph 
57152862Sralph 		for (i = 1; i < 256; i++) {
57252862Sralph 			vdac->map = 0xff; MachEmptyWriteBuffer();
57352862Sralph 			vdac->map = 0xff; MachEmptyWriteBuffer();
57452862Sralph 			vdac->map = 0xff; MachEmptyWriteBuffer();
57552862Sralph 		}
57652862Sralph 	}
57752862Sralph 
57852862Sralph 	for (i = 0; i < 3; i++) {
57952862Sralph 		bg_RGB[i] = 0x00;
58052862Sralph 		fg_RGB[i] = 0xff;
58152862Sralph 	}
58256819Sralph 	pmRestoreCursorColor();
58352862Sralph }
58452862Sralph 
58552862Sralph /*
58652862Sralph  * ----------------------------------------------------------------------------
58752862Sralph  *
58856819Sralph  * pmVDACInit --
58952862Sralph  *
59052862Sralph  *	Initialize the VDAC.
59152862Sralph  *
59252862Sralph  * Results:
59352862Sralph  *	None.
59452862Sralph  *
59552862Sralph  * Side effects:
59652862Sralph  *	None.
59752862Sralph  *
59852862Sralph  * ----------------------------------------------------------------------------
59952862Sralph  */
60052862Sralph static void
60156819Sralph pmVDACInit()
60252862Sralph {
60356819Sralph 	register VDACRegs *vdac = (VDACRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_VDAC);
60452862Sralph 
60552862Sralph 	/*
60652862Sralph 	 *
60752862Sralph 	 * Initialize the VDAC
60852862Sralph 	 */
60952862Sralph 	vdac->overWA = 0x04; MachEmptyWriteBuffer();
61052862Sralph 	vdac->over = 0x00; MachEmptyWriteBuffer();
61152862Sralph 	vdac->over = 0x00; MachEmptyWriteBuffer();
61252862Sralph 	vdac->over = 0x00; MachEmptyWriteBuffer();
61352862Sralph 	vdac->overWA = 0x08; MachEmptyWriteBuffer();
61452862Sralph 	vdac->over = 0x00; MachEmptyWriteBuffer();
61552862Sralph 	vdac->over = 0x00; MachEmptyWriteBuffer();
61652862Sralph 	vdac->over = 0x7f; MachEmptyWriteBuffer();
61752862Sralph 	vdac->overWA = 0x0c; MachEmptyWriteBuffer();
61852862Sralph 	vdac->over = 0xff; MachEmptyWriteBuffer();
61952862Sralph 	vdac->over = 0xff; MachEmptyWriteBuffer();
62052862Sralph 	vdac->over = 0xff; MachEmptyWriteBuffer();
62152862Sralph }
62252862Sralph 
62352862Sralph /*
62452862Sralph  * ----------------------------------------------------------------------------
62552862Sralph  *
62656819Sralph  * pmLoadColorMap --
62752862Sralph  *
62852862Sralph  *	Load the color map.
62952862Sralph  *
63052862Sralph  * Results:
63152862Sralph  *	None.
63252862Sralph  *
63352862Sralph  * Side effects:
63452862Sralph  *	The color map is loaded.
63552862Sralph  *
63652862Sralph  * ----------------------------------------------------------------------------
63752862Sralph  */
63852862Sralph static void
63956819Sralph pmLoadColorMap(ptr)
64052862Sralph 	ColorMap *ptr;
64152862Sralph {
64256819Sralph 	register VDACRegs *vdac = (VDACRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_VDAC);
64352862Sralph 
64452862Sralph 	if (ptr->index > 256)
64552862Sralph 		return;
64652862Sralph 
64752862Sralph 	vdac->mapWA = ptr->index; MachEmptyWriteBuffer();
64852862Sralph 	vdac->map = ptr->Entry.red; MachEmptyWriteBuffer();
64952862Sralph 	vdac->map = ptr->Entry.green; MachEmptyWriteBuffer();
65052862Sralph 	vdac->map = ptr->Entry.blue; MachEmptyWriteBuffer();
65152862Sralph }
65252862Sralph 
65352862Sralph /*
65452862Sralph  *----------------------------------------------------------------------
65552862Sralph  *
65656819Sralph  * pmPosCursor --
65752862Sralph  *
65852862Sralph  *	Postion the cursor.
65952862Sralph  *
66052862Sralph  * Results:
66152862Sralph  *	None.
66252862Sralph  *
66352862Sralph  * Side effects:
66452862Sralph  *	None.
66552862Sralph  *
66652862Sralph  *----------------------------------------------------------------------
66752862Sralph  */
66856819Sralph void
66956819Sralph pmPosCursor(x, y)
67052862Sralph 	register int x, y;
67152862Sralph {
67256819Sralph 	register PCCRegs *pcc = (PCCRegs *)MACH_PHYS_TO_UNCACHED(KN01_SYS_PCC);
67356819Sralph 	register struct pmax_fb *fp = &pmfb;
67452862Sralph 
67556819Sralph 	if (y < fp->fbu->scrInfo.min_cur_y || y > fp->fbu->scrInfo.max_cur_y)
67656819Sralph 		y = fp->fbu->scrInfo.max_cur_y;
67756819Sralph 	if (x < fp->fbu->scrInfo.min_cur_x || x > fp->fbu->scrInfo.max_cur_x)
67856819Sralph 		x = fp->fbu->scrInfo.max_cur_x;
67956819Sralph 	fp->fbu->scrInfo.cursor.x = x;		/* keep track of real cursor */
68056819Sralph 	fp->fbu->scrInfo.cursor.y = y;		/* position, indep. of mouse */
68152862Sralph 	pcc->xpos = PCC_X_OFFSET + x;
68252862Sralph 	pcc->ypos = PCC_Y_OFFSET + y;
68352862Sralph }
68456819Sralph 
68556819Sralph /*
68656819Sralph  * pm keyboard and mouse input. Just punt to the generic ones in fb.c
68756819Sralph  */
68856819Sralph void
68956819Sralph pmKbdEvent(ch)
69056819Sralph 	int ch;
69156819Sralph {
69256819Sralph 	fbKbdEvent(ch, &pmfb);
69356819Sralph }
69456819Sralph 
69556819Sralph void
69656819Sralph pmMouseEvent(newRepPtr)
69756819Sralph 	MouseReport *newRepPtr;
69856819Sralph {
69956819Sralph 	fbMouseEvent(newRepPtr, &pmfb);
70056819Sralph }
70156819Sralph 
70256819Sralph void
70356819Sralph pmMouseButtons(newRepPtr)
70456819Sralph 	MouseReport *newRepPtr;
70556819Sralph {
70656819Sralph 	fbMouseButtons(newRepPtr, &pmfb);
70756819Sralph }
70856819Sralph #endif /* NDC */
70956819Sralph #endif /* NPM */
710