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

📄 fb_start.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * Copyright (c) 1992, 1993 *	The Regents of the University of California.  All rights reserved. * * This code is derived from software contributed to Berkeley by * Sony Corp. and Kazumasa Utashiro of Software Research Associates, Inc. * * 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. * * from: $Hdr: fb_start.c,v 4.300 91/06/27 20:42:40 root Rel41 $ SONY * *	@(#)fb_start.c	8.1 (Berkeley) 6/11/93 */#include <sys/param.h>#include <sys/systm.h>#ifdef IPC_MRX#include "../../iop/framebuf.h"#include "../../iop/fbreg.h"#include "page.h"#else#include <news3400/iop/framebuf.h>#include <news3400/iop/fbreg.h>#endif#include <news3400/fb/fbdefs.h>#ifdef CPU_SINGLE#include <machine/cpu.h>extern struct tty cons;extern int cnstart();#define PRE_EMPT	need_resched()#endifstatic struct fbdev	*cfb = 0;static lPoint		mp;#ifdef CPU_SINGLEstatic int		curs_pending = 0;#endifextern struct fbdevsw	fbdevsw[];extern int		nfbdev;#ifdef CPU_SINGLEextern char	*ext_fnt_addr[];extern char	*ext_fnt24_addr[];#elseextern char	**ext_fnt_addr;extern char	**ext_fnt24_addr;#endifstatic char copyfuncv[MAXPLANE] = {	BF_S, BF_S, BF_S, BF_S, BF_S, BF_S, BF_S, BF_S,		/* SRC */	BF_S, BF_S, BF_S, BF_S, BF_S, BF_S, BF_S, BF_S,		/* SRC */	BF_S, BF_S, BF_S, BF_S, BF_S, BF_S, BF_S, BF_S		/* SRC */};unsigned short fb_color_pallet_def[48] = {	/* define initial color *//*	R,	G,	B	*/	0,	0,	0,	0,	0,	0x44,	0,	0x44,	0,	0,	0x44,	0x44,	0x44,	0,	0,	0x44,	0,	0x44,	0x44,	0x44,	0,	0x44,	0x44,	0x44,	0x88,	0x88,	0x88,	0,	0,	0xff,	0,	0xff,	0,	0,	0xff,	0xff,	0xff,	0,	0,	0xff,	0,	0xff,	0xff,	0xff,	0,	0xff,	0xff,	0xff};unsigned short fb_gray_pallet_def[48] = {	/* define initial color *//*	R,	G,	B	*/	0xff,	0xff,	0xff,	0xff,	0xff,	0,	0xff,	0,	0xff,	0xff,	0,	0,	0,	0xff,	0xff,	0,	0xff,	0,	0,	0,	0xff,	0x88,	0x88,	0x88,	0x44,	0x44,	0x44,	0x44,	0x44,	0,	0x44,	0,	0x44,	0x44,	0,	0,	0,	0x44,	0x44,	0,	0x44,	0,	0,	0,	0x44,	0,	0,	0};static int bitmap_use;		/* shared variable for bitmap exclusion ctrl */#ifdef IPC_MRXstruct fb_map rommap;#endif#ifdef CPU_SINGLEvoidlock_bitmap(){	int s;	/* wait(bitmap_use) */	s = splbitmap();	while (bitmap_use & FB_BUSY) {		bitmap_use |= FB_WANTED;		sleep((caddr_t)&bitmap_use, FBPRI);	}	bitmap_use |= FB_BUSY;	splx(s);}voidunlock_bitmap(){	int s;	/* signal(bitmap_use) */	s = splbitmap();	if (bitmap_use & FB_WANTED)		wakeup((caddr_t)&bitmap_use);	bitmap_use &= ~(FB_BUSY|FB_WANTED);	splx(s);}lock_bitmap_poll(){	int s;	/* wait(bitmap_use) */	s = splbitmap();	if (bitmap_use & (FB_BUSY|FB_WANTED)) {		splx(s);		return (1);	}	bitmap_use |= FB_BUSY;	splx(s);	return (0);}voidunlock_bitmap_poll(){	int s;	/* signal(bitmap_use) */	s = splbitmap();	if (bitmap_use & FB_WANTED)		wakeup((caddr_t)&bitmap_use);	bitmap_use &= ~(FB_BUSY|FB_WANTED);	splx(s);}bmlockedp(){	return (bitmap_use & (FB_WANTED|FB_BUSY));}#ifdef NOTDEF /* KU:XXX not necessary for news3200 */voidrop_wait(fb)	struct fbdev *fb;{	register int s;	int i;	s = splbitmap();/* KU:XXX trick! */#define in_interrupt()	((caddr_t)&fb < (caddr_t)MACH_CODE_START)	if (in_interrupt() || (fb->run_flag & FB_WAITING)) {		splx(s);		fbbm_rop_wait(fb);	} else {		if (fbbm_ioctl(fb, FB_STATUSCHECK, 0) &		    (FB_STATUS_ROPWAIT|FB_STATUS_ROPEXEC)) {			i = FB_INT_ROPDONE;			fbbm_ioctl(fb, FB_INTENABLE, &i);			if (!(fbbm_ioctl(fb, FB_STATUSCHECK, 0) &			    (FB_STATUS_ROPWAIT|FB_STATUS_ROPEXEC))) {				i = FB_INT_ROPDONE;				fbbm_ioctl(fb, FB_INTCLEAR, &i);			} else {				fb->run_flag |= FB_WAITING;				sleep((caddr_t)&fb->run_flag, FBPRI);			}		}		splx(s);	}}#endif /* NOTDEF */#else /* CPU_SINGLE */#ifdef IPC_MRXstruct page {	char bytes[NBPG];};extern struct page *page_base;extern struct page *page_max;extern struct map pagemap[];extern struct pte_iop page_pt[];extern int mapped_page;caddr_tfb_map_page(map, n, prot)	register int *map;	register int n;	register int prot;{	register int x;	register struct pte_iop *p;	register struct page *addr;	register int s = spl7();	static int last_x, last_n;	if (last_n >= n) {		x = last_x;	} else {		rmfree(pagemap, last_n, last_x);		mapped_page -= last_n;		last_x = 0;		last_n = 0;		if ((x = rmalloc(pagemap, n)) <= 0) {			splx(s);			return (NULL);		}		mapped_page += n;		last_x = x;		last_n = n;	}	addr = page_base + x;	prot |= PG_PAGE;	for (p = page_pt + x; n > 0; p++, n--) {		*(int *)p = prot | *map++;		tbis((caddr_t)addr);		addr++;	}	splx(s);	return ((caddr_t)(page_base + x));}caddr_tfb_map_page2(map, n, prot)	register int *map;	register int n;	register int prot;{	register int x;	register struct pte_iop *p;	register struct page *addr;	register int s;	if (n == 0)		return (NULL);	s = spl7();	if ((x = rmalloc(pagemap, n)) <= 0) {		splx(s);		return (NULL);	}	mapped_page += n;	addr = page_base + x;	prot |= PG_PAGE;	for (p = page_pt + x; n > 0; p++, n--) {		*(int *)p = prot | (*map++);		tbis((caddr_t)addr);		addr++;	}	splx(s);	return ((caddr_t)(page_base + x));}#endif /* IPC_MRX */#endif /* CPU_SINGLE */iopmemfbmap(addr, len, map)	register caddr_t addr;	register int len;	register struct fb_map *map;{	register caddr_t *p;	register int i;	map->fm_vaddr = addr;	map->fm_offset = (unsigned)addr & CLOFSET;	map->fm_count = len;	len += map->fm_offset;	p = map->fm_addr;	addr -= map->fm_offset;	for (i = 0; i < NFBMAP && len > 0; i++) {		*p++ = addr;		addr += CLBYTES;		len -= CLBYTES;	}}intnofunc(){	return 0;}interror(){	return FB_RERROR;}voidcheckArea(fb, x, y)	register struct fbdev *fb;	register int *x, *y;{	if (*x < fb->moveArea.origin.x)		*x = fb->moveArea.origin.x;	if (*y < fb->moveArea.origin.y)		*y = fb->moveArea.origin.y;	if (*x >= (fb->moveArea.origin.x + fb->moveArea.extent.x))		*x = (fb->moveArea.origin.x + fb->moveArea.extent.x) - 1;	if (*y >= (fb->moveArea.origin.y + fb->moveArea.extent.y))		*y = (fb->moveArea.origin.y + fb->moveArea.extent.y) - 1;}cursorIn(fb, clip)	register struct fbdev *fb;	register lRectangle *clip;{	if (clip == 0)		return (1);	if (cfb != fb)		return (0);	return (clip->origin.x < fb->cursorP.x + fb->size.x &&		clip->origin.x + clip->extent.x > fb->cursorP.x &&		clip->origin.y < fb->cursorP.y + fb->size.y &&		clip->origin.y + clip->extent.y > fb->cursorP.y);}voidfbcopy1(src, dst, fv)	lPoint src;	lPoint dst;	char *fv;{	lRectangle sr, dr;	sr.origin = src;	sr.extent = cfb->size;	dr.origin = dst;	if (cliprect2(&sr, &cfb->FrameRect, &dr, &cfb->VisRect)) {		fbbm_rop_init(cfb, fv);		fbbm_rop_copy(cfb, &sr, &dr.origin, 1, FB_PLANEALL);	}}voidfbcopy2(src, dst)	lPoint src;	lPoint dst;{	lRectangle sr, dr;	sr.origin = src;	sr.extent = cfb->size;	dr.origin = dst;	if (cliprect2(&sr, &cfb->FrameRect, &dr, &cfb->FrameRect)) {		fbbm_rop_init(cfb, copyfuncv);		fbbm_rop_copy(cfb, &sr, &dr.origin, 0, FB_PLANEALL);	}}voidfbcopy3(src, dst)	lPoint src;	lPoint dst;{	lRectangle sr, dr;	sr.origin = src;	sr.extent = cfb->size;	dr.origin = dst;	if (cliprect2(&sr, &cfb->FrameRect, &dr, &cfb->VisRect)) {		fbbm_rop_init(cfb, copyfuncv);		fbbm_rop_copy(cfb, &sr, &dr.origin, 0, FB_PLANEALL);	}}voidcursorOn(fb)	register struct fbdev *fb;{#ifdef CPU_SINGLE	int s = splbitmap();#endif	if (cfb == fb && fb->cursorShow && !fb->cursorVis) {		if (fb->hard_cursor) {			fbbm_cursor_on(fb);		} else {			fbcopy2(fb->cursorP, fb->SaveRect.origin);			fbcopy1(fb->MaskRect.origin, fb->cursorP,				fb->maskfuncv);			fbcopy1(fb->CursorRect.origin, fb->cursorP,				fb->curfuncv);		}		fb->cursorVis = 1;	}#ifdef CPU_SINGLE	splx(s);#endif}voidcursorOff(fb)	register struct fbdev *fb;{#ifdef CPU_SINGLE	int s = splbitmap();#endif	if (cfb == fb && fb->cursorShow && fb->cursorVis) {		if (fb->hard_cursor)			fbbm_cursor_off(fb);		else			fbcopy3(fb->SaveRect.origin, fb->cursorP);		fb->cursorVis = 0;	}#ifdef CPU_SINGLE	splx(s);#endif}voidsoftCursorCheck(fb, stype, srect, dtype, drect)	struct fbdev *fb;	char stype, dtype;	lRectangle *srect, *drect;{	if (cfb == fb  && cfb->cursorVis &&	    ((stype == BM_FB && cursorIn(fb, srect)) ||	    (dtype == BM_FB && cursorIn(fb, drect))))		cursorOff(cfb);}voidcursorCheck(fb, stype, srect, dtype, drect)	struct fbdev *fb;	char stype, dtype;	lRectangle *srect, *drect;{	if (!fb->hard_cursor)		softCursorCheck(fb, stype, srect, dtype, drect);}intredrawCursor(fb)	register struct fbdev *fb;{	int s;	lPoint	tmp;	if (cfb == fb && fb->cursorSet) {		s = spl7();		tmp = mp;		splx(s);#ifdef CPU_SINGLE		s = splbitmap();#endif		if (fb->cursorP.x != tmp.x || fb->cursorP.y != tmp.y) {			if (fb->cursorVis) {				if (! fb->hard_cursor) {					fbcopy3(fb->SaveRect.origin,						fb->cursorP);				}			}			fb->cursorP = tmp;			if (fb->hard_cursor) {				fbbm_cursor_off(fb);				fbbm_cursor_move(fb);			}			if (fb->cursorVis) {				if (fb->hard_cursor) {					fbbm_cursor_on(fb);				} else {					fbcopy2(fb->cursorP,						fb->SaveRect.origin);					fbcopy1(fb->MaskRect.origin,						fb->cursorP, fb->maskfuncv);					fbcopy1(fb->CursorRect.origin,						fb->cursorP, fb->curfuncv);				}			}		}#ifdef CPU_SINGLE		splx(s);#endif	}	return (0);}voidupdateCursor(x, y, flag)	int *x, *y;	int flag;{	int s;	if (cfb && cfb->cursorSet) {		checkArea(cfb, x, y);		s = spl7();		mp.x = *x - cfb->hot.x;		mp.y = *y - cfb->hot.y;		splx(s);#ifdef CPU_SINGLE		if (flag || cfb->hard_cursor) {			curs_pending = 0;			redrawCursor(cfb);		} else if (cfb->type == FB_LCDM) {			if (!lock_bitmap_poll()) {				curs_pending = 0;				redrawCursor(cfb);				unlock_bitmap_poll();			} else {				curs_pending = 1;			}		}#else		redrawCursor(cfb);#endif	}}setCursor(fb, cursor)	register struct fbdev *fb;	register lCursor2  *cursor;{	register char *fv;	register int f0, f1, i, color;#ifdef CPU_SINGLE	register int s = splbitmap();#endif	int	data;	if (cfb == fb) {		cursorOff(cfb);		fb->cursorShow = 0;		fb->cursorP.x += cfb->hot.x;		fb->cursorP.y += cfb->hot.y;#ifdef CPU_SINGLE		data = FB_INT_VSYNC;		fbbm_ioctl(fb, FB_INTCLEAR, &data);#endif		cfb = NULL;	}	if (cursor) {		fb->CursorRect = cursor->cursorRect;		fb->MaskRect = cursor->maskRect;		fb->SaveRect = cursor->saveRect;		fb->moveArea = cursor->moveArea;		fb->hot = cursor->hot;		fb->size = cursor->size;		f0 = 0x4 | ((cursor->func >> 2) & 0x3);		f1 = 0x4 | (cursor->func & 0x3);		i = fb->fbNplane;		fv = fb->curfuncv;		color = cursor->cursor_color;		while (i-- > 0) {			*fv++ = (color & 1) ? f1 : f0;			color >>= 1;		}		i = fb->fbNplane;		fv = fb->maskfuncv;		color = cursor->mask_color;		while (i-- > 0) {			*fv++ = (color & 1) ? f1 : f0;			color >>= 1;		}		checkArea(fb, &fb->cursorP.x, &fb->cursorP.y);		fb->cursorP.x -= fb->hot.x;		fb->cursorP.y -= fb->hot.y;		fb->cursorSet = 1;		fb->cursorShow = 0;		fb->cursorVis = 0;		if (fb->hard_cursor) {			fbbm_cursor_off(fb);			fbbm_cursor_set(fb, cursor->cursor_color, cursor->mask_color);			fbbm_cursor_move(fb);		}	} else {		fb->cursorP.x = fb->VisRect.extent.x / 2;		fb->cursorP.y = fb->VisRect.extent.y / 2;		fb->cursorSet = 0;		fb->cursorShow = 0;		fb->cursorVis = 0;		if (fb->hard_cursor)			fbbm_cursor_off(fb);	}#ifdef CPU_SINGLE	splx(s);#endif	return (FB_ROK);}showCursor(fb)	register struct fbdev *fb;

⌨️ 快捷键说明

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