⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xcfb.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/*- * Copyright (c) 1992, 1993 *	The Regents of the University of California.  All rights reserved. * * This code is derived from software contributed to Berkeley by * Ralph Campbell and Rick Macklem. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by the University of *	California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors *    may be used to endorse or promote products derived from this software *    without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * *	@(#)xcfb.c	8.1 (Berkeley) 6/10/93 *//*  * Mach Operating System * Copyright (c) 1991,1990,1989 Carnegie Mellon University * All Rights Reserved. *  * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. *  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. *  * Carnegie Mellon requests users of this software to return to *  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU *  School of Computer Science *  Carnegie Mellon University *  Pittsburgh PA 15213-3890 *  * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. *//* *  devGraphics.c -- * *     	This file contains machine-dependent routines for the graphics device. * *	Copyright (C) 1989 Digital Equipment Corporation. *	Permission to use, copy, modify, and distribute this software and *	its documentation for any purpose and without fee is hereby granted, *	provided that the above copyright notice appears in all copies.   *	Digital Equipment Corporation makes no representations about the *	suitability of this software for any purpose.  It is provided "as is" *	without express or implied warranty. * * from: $Header: /sprite/src/kernel/dev/ds3100.md/RCS/devGraphics.c, *	v 9.2 90/02/13 22:16:24 shirriff Exp $ SPRITE (DECWRL)"; */#include <xcfb.h>#include <dtop.h>#if NXCFB > 0#if NDTOP == 0xcfb needs dtop device#else#include <sys/param.h>#include <sys/time.h>#include <sys/kernel.h>#include <sys/ioctl.h>#include <sys/file.h>#include <sys/errno.h>#include <sys/proc.h>#include <sys/mman.h>#include <vm/vm.h>#include <machine/machConst.h>#include <machine/pmioctl.h>#include <pmax/pmax/maxine.h>#include <pmax/pmax/cons.h>#include <pmax/pmax/pmaxtype.h>#include <pmax/dev/device.h>#include <pmax/dev/xcfbreg.h>#include <pmax/dev/dtopreg.h>#include <pmax/dev/fbreg.h>/* * These need to be mapped into user space. */struct fbuaccess xcfbu;struct pmax_fb xcfbfb;/* * Forward references. */static void xcfbScreenInit();static void xcfbLoadCursor();static void xcfbRestoreCursorColor();static void xcfbCursorColor();void xcfbPosCursor();static void xcfbInitColorMap();static void xcfbLoadColorMap();static u_int ims332_read_register();static void ims332_write_register();static void ims332_load_colormap_entry();static void ims332_video_off();static void ims332_video_on();void xcfbKbdEvent(), xcfbMouseEvent(), xcfbMouseButtons();extern void dtopKBDPutc();extern void (*dtopDivertXInput)();extern void (*dtopMouseEvent)();extern void (*dtopMouseButtons)();extern int pmax_boardtype;extern u_short defCursor[32];extern struct consdev cn_tab;int	xcfbprobe();struct	driver xcfbdriver = {	"xcfb", xcfbprobe, 0, 0,};/* * Test to see if device is present. * Return true if found and initialized ok. *//*ARGSUSED*/xcfbprobe(cp)	register struct pmax_ctlr *cp;{	register struct pmax_fb *fp = &xcfbfb;	if (pmax_boardtype != DS_MAXINE)		return (0);	if (!fp->initialized && !xcfbinit())		return (0);	printf("xcfb0 (color display)\n");	return (1);}/*ARGSUSED*/xcfbopen(dev, flag)	dev_t dev;	int flag;{	register struct pmax_fb *fp = &xcfbfb;	int s;	if (!fp->initialized)		return (ENXIO);	if (fp->GraphicsOpen)		return (EBUSY);	fp->GraphicsOpen = 1;	xcfbInitColorMap();	/*	 * Set up event queue for later	 */	fp->fbu->scrInfo.qe.eSize = PM_MAXEVQ;	fp->fbu->scrInfo.qe.eHead = fp->fbu->scrInfo.qe.eTail = 0;	fp->fbu->scrInfo.qe.tcSize = MOTION_BUFFER_SIZE;	fp->fbu->scrInfo.qe.tcNext = 0;	fp->fbu->scrInfo.qe.timestamp_ms = TO_MS(time);	s = spltty();	dtopDivertXInput = xcfbKbdEvent;	dtopMouseEvent = xcfbMouseEvent;	dtopMouseButtons = xcfbMouseButtons;	splx(s);	return (0);}/*ARGSUSED*/xcfbclose(dev, flag)	dev_t dev;	int flag;{	register struct pmax_fb *fp = &xcfbfb;	int s;	if (!fp->GraphicsOpen)		return (EBADF);	fp->GraphicsOpen = 0;	xcfbInitColorMap();	s = spltty();	dtopDivertXInput = (void (*)())0;	dtopMouseEvent = (void (*)())0;	dtopMouseButtons = (void (*)())0;	splx(s);	xcfbScreenInit();	bzero((caddr_t)fp->fr_addr, 1024 * 768);	xcfbPosCursor(fp->col * 8, fp->row * 15);	return (0);}/*ARGSUSED*/xcfbioctl(dev, cmd, data, flag, p)	dev_t dev;	caddr_t data;	struct proc *p;{	register struct pmax_fb *fp = &xcfbfb;	int s;	switch (cmd) {	case QIOCGINFO:		return (fbmmap(fp, dev, data, p));	case QIOCPMSTATE:		/*		 * Set mouse state.		 */		fp->fbu->scrInfo.mouse = *(pmCursor *)data;		xcfbPosCursor(fp->fbu->scrInfo.mouse.x, fp->fbu->scrInfo.mouse.y);		break;	case QIOCINIT:		/*		 * Initialize the screen.		 */		xcfbScreenInit();		break;	case QIOCKPCMD:	    {		pmKpCmd *kpCmdPtr;		unsigned char *cp;		kpCmdPtr = (pmKpCmd *)data;		if (kpCmdPtr->nbytes == 0)			kpCmdPtr->cmd |= 0x80;		if (!fp->GraphicsOpen)			kpCmdPtr->cmd |= 1;		(*fp->KBDPutc)(fp->kbddev, (int)kpCmdPtr->cmd);		cp = &kpCmdPtr->par[0];		for (; kpCmdPtr->nbytes > 0; cp++, kpCmdPtr->nbytes--) {			if (kpCmdPtr->nbytes == 1)				*cp |= 0x80;			(*fp->KBDPutc)(fp->kbddev, (int)*cp);		}		break;	    }	case QIOCADDR:		*(PM_Info **)data = &fp->fbu->scrInfo;		break;	case QIOWCURSOR:		xcfbLoadCursor((unsigned short *)data);		break;	case QIOWCURSORCOLOR:		xcfbCursorColor((unsigned int *)data);		break;	case QIOSETCMAP:		xcfbLoadColorMap((ColorMap *)data);		break;	case QIOKERNLOOP:		s = spltty();		dtopDivertXInput = xcfbKbdEvent;		dtopMouseEvent = xcfbMouseEvent;		dtopMouseButtons = xcfbMouseButtons;		splx(s);		break;	case QIOKERNUNLOOP:		s = spltty();		dtopDivertXInput = (void (*)())0;		dtopMouseEvent = (void (*)())0;		dtopMouseButtons = (void (*)())0;		splx(s);		break;	case QIOVIDEOON:		xcfbRestoreCursorColor();		ims332_video_on();		break;	case QIOVIDEOOFF:		ims332_video_off();		break;	default:		printf("xcfb0: Unknown ioctl command %x\n", cmd);		return (EINVAL);	}	return (0);}/* * Return the physical page number that corresponds to byte offset 'off'. *//*ARGSUSED*/xcfbmap(dev, off, prot)	dev_t dev;{	int len;	len = pmax_round_page(((vm_offset_t)&xcfbu & PGOFSET) + sizeof(xcfbu));	if (off < len)		return pmax_btop(MACH_CACHED_TO_PHYS(&xcfbu) + off);	off -= len;	if (off >= xcfbfb.fr_size)		return (-1);	return pmax_btop(MACH_UNCACHED_TO_PHYS(xcfbfb.fr_addr) + off);}xcfbselect(dev, flag, p)	dev_t dev;	int flag;	struct proc *p;{	struct pmax_fb *fp = &xcfbfb;	switch (flag) {	case FREAD:		if (fp->fbu->scrInfo.qe.eHead != fp->fbu->scrInfo.qe.eTail)			return (1);		selrecord(p, &fp->selp);		break;	}	return (0);}static u_char	cursor_RGB[6];	/* cursor color 2 & 3 *//* *	Routines for the Inmos IMS-G332 Colour video controller * 	Author: Alessandro Forin, Carnegie Mellon University */static u_intims332_read_register(regno){	register u_char *regs = (u_char *)IMS332_ADDRESS;	unsigned char *rptr;	register u_int val, v1;	/* spec sez: */	rptr = regs + 0x80000 + (regno << 4);	val = *((volatile u_short *) rptr );	v1  = *((volatile u_short *) regs );	return (val & 0xffff) | ((v1 & 0xff00) << 8);}static voidims332_write_register(regno, val)	register unsigned int val;{	register u_char *regs = (u_char *)IMS332_ADDRESS;	u_char *wptr;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -