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

📄 cg5test.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	/*	red to cyan	*/	k = 0; i = 0; j = 255;	knt = 16;	do {		red1[k] = j; grn1[k] = i; blu1[k] = i;		k++;		i = k * 16 - 1;		j = 255 - i;	} while (k < knt);	/*	green to magenta	*/	i = 0; j = 255;	knt += 16;	do {		red1[k] = i; grn1[k] = j; blu1[k] = i;		k++;		i = k * 16 - 1;		j = 255 - i;	} while (k < knt);	/*	blue to yellow	*/	i = 0; j = 255;	knt += 16;	do {		red1[k] = i; grn1[k] = i; blu1[k] = j;		k++;		i = k * 16 - 1;		j = 255 - i;	} while (k < knt);	/*	cyan to white	*/	i = 0;	knt += 16;	do {		red1[k] = i; grn1[k] = 255; blu1[k] = 255;		k++;		i = k * 16 - 1;	} while (k < knt);	/*	majenta to white	*/	i = 0;	knt += 16;	do {		red1[k] = 255; grn1[k] = i; blu1[k] = 255;		k++;		i = k * 16 - 1;	} while (k < knt);	/*	yellow to white	*/	i = 0;	knt += 16;	do {		red1[k] = 255; grn1[k] = 255; blu1[k] = i;		k++;		i = k * 16 - 1;	} while (k < knt);	/*	white to red	*/	j = 255;	knt += 16;	do {		red1[k] = 255; grn1[k] = j; blu1[k] = j;		k++;		j = 255 - k * 16 - 1;	} while (k < knt);	/*	white to green	*/	j = 255;	knt += 16;	do {		red1[k] = j; grn1[k] = 255; blu1[k] = j;		k++;		j = 255 - k * 16 - 1;	} while (k < knt);	/*	white to blue	*/	j = 255;	knt += 16;	do {		red1[k] = j; grn1[k] = j; blu1[k] = 255;		k++;		j = 255 - k * 16 - 1;	} while (k < knt);	/*	red to black	*/	j = 255;	knt += 16;	do {		red1[k] = j; grn1[k] = 0; blu1[k] = 0;		k++;		j = 255 - k * 16 - 1;	} while (k < knt);	/*	green to black	*/	j = 255;	knt += 16;	do {		red1[k] = 0; grn1[k] = j; blu1[k] = 0;		k++;		j = 255 -  k * 16 - 1;	} while (k < knt);	/*	blue to black	*/	j = 255;	knt += 16;	do {		red1[k] = 0; grn1[k] = 0; blu1[k] = j;		k++;		j = 255 - k * 16 - 1;	} while (k < knt);	/*	black to cyan	*/	i = 0;	knt += 16;	do {		red1[k] = 0; grn1[k] = i; blu1[k] = i;		k++;		i = k * 16 - 1;	} while (k < knt);	/*	black to magenta	*/	i = 0;	knt += 16;	do {		red1[k] = i; grn1[k] = 0; blu1[k] = i;		k++;		i = k * 16 - 1;	} while (k < knt);	/*	black to yellow	*/	i = 0;	knt += 16;	do {		red1[k] = i; grn1[k] = i; blu1[k] = 0;		k++;		i = k * 16 - 1;	} while (k < knt);	/*	white to black	*/	j = 255;	knt += 16;	do {		red1[k] = j; grn1[k] = j; blu1[k] = j;		k++;		j = 255 - k * 16 - 1;	} while (k < knt);	pr_putcolormap(prfd, 0, 256, red1, grn1, blu1);	pr_getcolormap(prfd, 0, 256, red2, grn2, blu2);	checkmap();	return 0;}static char *dblarray[] = {			"read memory set A",			"read memory set B",			"read A, write to A and B",			"",			};char *dblptr;checkmap(){	int i;	dblptr = dblarray[3];	for (i = 0; i <= 255; i++)	{		if (red1[i] != red2[i] || simulate_error == RED_FAILED)		{	  sprintf(msg, "Colormap error - red, loc = %d, exp = %d, actual = %d.",				i, red1[i], red2[i]);			errorprint(-RED_FAILED, msg);		}		if (grn1[i] != grn2[i] || simulate_error == GREEN_FAILED)		{	  sprintf(msg, "Colormap error - green, loc = %d, exp = %d, actual = %d.",				i, grn1[i], grn2[i]);			errorprint(-GREEN_FAILED, msg);		}		if (blu1[i] != blu2[i] || simulate_error == BLUE_FAILED)		{	  sprintf(msg, "Colormap error - blue, loc = %d, exp = %d, actual = %d.",				i, blu1[i], blu2[i]);			errorprint(-BLUE_FAILED, msg);		}	}	flush_io();	return 0;}enable_vid(){	int fd;	int vid;	vid = FBVIDEO_ON;	fd = open(DEVICE, O_RDWR);	if (fd > 0) {		ioctl(fd, FBIOSVIDEO, &vid, 0);		close(fd);	} 	return 0;}dblbuf_test(){	/* lets wait for a vertical retrace */	ioctl(prfd, FBIOVERTICAL, 0);	(void) pr_dbl_set(prfd, PR_DBL_WRITE, PR_DBL_B, 0);	pr_put(prfd, 0, 0, 0x55);	(void) pr_dbl_set(prfd, PR_DBL_WRITE, PR_DBL_A, 0);	pr_put(prfd, 0, 0, 0xAA);	(void) pr_dbl_set(prfd, PR_DBL_READ, PR_DBL_B, 0);	if ( pr_get(prfd, 0, 0) == 0x55 ) {		(void) pr_dbl_set(prfd, PR_DBL_DISPLAY, PR_DBL_A,		   	PR_DBL_READ, PR_DBL_A, PR_DBL_WRITE, PR_DBL_BOTH, 0);		return (1);	} else {		(void) pr_dbl_set(prfd, PR_DBL_DISPLAY, PR_DBL_A,		   	PR_DBL_READ, PR_DBL_A, PR_DBL_WRITE, PR_DBL_BOTH, 0);		return (0);	}/*### PR_DBL_AVAIL does not work in 3.5	if ( pr_dbl_get(prfd, PR_DBL_AVAIL) == PR_DBL_EXISTS ) {		return (1);	}	return 0;###*/}rw_displayA(){	/* lets wait for a vertical retrace	ioctl(prfd, FBIOVERTICAL, 0);	*//*### removed because discrepancy between sun 4 and sun 3.	if ( pr_dbl_set(prfd, PR_DBL_DISPLAY, PR_DBL_A,		   PR_DBL_READ, PR_DBL_A, PR_DBL_WRITE, PR_DBL_A, 0) < 0 ) {		dblflag = 0;	} else		dblflag = 1;###*/	(void) pr_dbl_set(prfd, PR_DBL_DISPLAY, PR_DBL_A,		   PR_DBL_READ, PR_DBL_A, PR_DBL_WRITE, PR_DBL_A, 0);	/* lets wait for a vertical retrace	ioctl(prfd, FBIOVERTICAL, 0);	*/	dblptr = dblarray[0];	return(0);}rw_displayB(){	/* lets wait for a vertical retrace	ioctl(prfd, FBIOVERTICAL, 0);	*//*### removed because discrepancy between sun 4 and sun 3.	if ( pr_dbl_set(prfd, PR_DBL_DISPLAY, PR_DBL_B,		   PR_DBL_READ, PR_DBL_B, PR_DBL_WRITE, PR_DBL_B, 0) < 0 ) {		dblflag = 0;	} else		dblflag = 1;###*/	(void) pr_dbl_set(prfd, PR_DBL_DISPLAY, PR_DBL_B,		   PR_DBL_READ, PR_DBL_B, PR_DBL_WRITE, PR_DBL_B, 0);	/* lets wait for a vertical retrace	ioctl(prfd, FBIOVERTICAL, 0);	*/	dblptr = dblarray[1];	return(0);}rdispA_writeboth(){	/* read, display memory B.	 * write to memory A.	 */	/* lets wait for a vertical retrace	ioctl(prfd, FBIOVERTICAL, 0);	*/	(void) pr_dbl_set(prfd, PR_DBL_DISPLAY, PR_DBL_A,			   PR_DBL_READ, PR_DBL_A,			   PR_DBL_WRITE, PR_DBL_BOTH, 0);	/* lets wait for a vertical retrace	ioctl(prfd, FBIOVERTICAL, 0);	*/	dblptr = dblarray[2];	return(0);}rdispB_writeA(){	/* read, display memory B.	 * write to memory A.	 */	/* lets wait for a vertical retrace	ioctl(prfd, FBIOVERTICAL, 0);	*/	(void) pr_dbl_set(prfd, PR_DBL_DISPLAY, PR_DBL_B,			   PR_DBL_READ, PR_DBL_B,			   PR_DBL_WRITE, PR_DBL_A, 0);	/* lets wait for a vertical retrace	ioctl(prfd, FBIOVERTICAL, 0);	*/	dblptr = dblarray[1];	return(0);}rdispA_writeB(){	/* read, display memory A.	 * write to memory B.	 */	/* lets wait for a vertical retrace	ioctl(prfd, FBIOVERTICAL, 0);	*/	(void) pr_dbl_set(prfd, PR_DBL_DISPLAY, PR_DBL_A,			   PR_DBL_READ, PR_DBL_A,			   PR_DBL_WRITE, PR_DBL_B, 0);	/* lets wait for a vertical retrace	ioctl(prfd, FBIOVERTICAL, 0);	*/	dblptr = dblarray[0];	return(0);}setup_desktop(){	Cursor	cursor;	struct       inputmask im;	char         *temp_argv=NULL;	char *winname; 	unsigned int planes;	/* if (single headed && window system ) we set up	 * a new window.	 * Otherwise we just do test on CG.	 */	if ( ( (return_code == CG_1BUF) || (return_code == CG_2BUF) )				&& (winname = getenv("WINDOW_PARENT")) )	{		iograb = TRUE;	/* we are running under window system */	/*	 * open up the suntools parent	 * environment. 	 */		rootfd = open(winname, O_RDONLY);		if (rootfd <= 0)			syserror(-DEV_NOT_OPEN, "rootfd");	/*	 * get a new window	 */		winfd = win_getnewwindow();		if (winfd < 0)			syserror(-SCREEN_NOT_OPEN, "winfd");		/* make 'suntools' the 'parent'. */		win_setlink(winfd, WL_PARENT,			win_nametonumber(winname)); 		/* set oldest child of new node to be		   the youngest child of parent. */		win_setlink(winfd, WL_OLDERSIB,			win_getlink(rootfd, WL_YOUNGESTCHILD));	/*	 * get screen size of suntools window	 * and set the size of new window same size.	 */		win_screenget(rootfd, &new_screen);		win_setrect(winfd, &new_screen.scr_rect);		input_imnull(&im);		im.im_flags |= IM_ASCII;	/* catch 0-127(CTRL-C == 3) */		win_set_kbd_mask(winfd, &im);		/* put the new node into the tree. */		win_insert(winfd);		/* Prevent any cursor from display.		 * This must be done because the cursor		 * could sneak into the display.		 */		/* remove the new window cursor */		cursor = cursor_create((char *)0);		win_getcursor(rootfd, cursor);		cursor_set(cursor, CURSOR_SHOW_CURSOR, 0, 0);		win_setcursor(rootfd, cursor);		cursor_copy(cursor);		cursor_destroy(cursor);		win_grabio(winfd); 		check_input();		/* remove the mouse.		 * this is necessary because the mouse		 * is still active over the other windows and		 * clicking the mouse button will cause an interrupt.		 * I will fix it when exitting.		 */		win_remove_input_device(rootfd,					new_screen.scr_msname);	}	enable_vid();	width = prfd->pr_width;	height = prfd->pr_height;	depth = prfd->pr_depth;	/* save the current CG state */	pr_getattributes(prfd, &tmpplane);	pr_getcolormap(prfd, 0, 256, tred, tgrn, tblu);	/* enable all planes */	planes = 0xff;	pr_putattributes(prfd, &planes);	return (0);}errorprint(err, msg)int err;char *msg;{	if (!exec_by_sundiag) {		clean_up();		exit(0);	} else	cg_send_message(err, FATAL, msg);	return (0);}syserror(err, c)int err;char *c;{	perror(c);	sprintf(msg, "Couldn't create new screen for '%s'.",		DEVICE);	if (!exec_by_sundiag) {		clean_up();		exit(0);	} else	cg_send_message(err, FATAL, msg);	return (0);}struct       sgttyb  ttybuf;int origsigs;short	orig_sg_flags;		/* orig mode flags for stdin */setup_signals(){	/* set up signals for non-blocking	 * input.  If this is not done,	 * the windows will have a queue of	 * input events to handle.	 */	ioctl(0, TIOCGETP, &ttybuf);	orig_sg_flags = ttybuf.sg_flags;/* save original mode flags */	ttybuf.sg_flags |= CBREAK;      /* non-block mode */	ttybuf.sg_flags &= ~ECHO;       /* no echo */	ioctl(0, TIOCSETP, &ttybuf);	origsigs = sigsetmask(0);	signal(SIGINT, finish);	signal(SIGQUIT, finish);	signal(SIGHUP, finish);	return (0);}#define BUFSIZE 256static char tmpbuf[BUFSIZE];flush_io(){	int tfd, arg, knt;	arg = 0;	if (devtopfd)		tfd = devtopfd;	else		tfd = 0;	ioctl(tfd, FIONREAD, &arg);	knt = BUFSIZE;	while (arg > 0)	{		if (arg < knt)			knt = arg;		knt = read (tfd, tmpbuf, knt);		arg -= knt;	}	return (0);}reset_signals(){	ioctl(0, TIOCGETP, &ttybuf);	ttybuf.sg_flags = orig_sg_flags;	/* restore orig mode flags */	ioctl(0, TIOCSETP, &ttybuf);	/* set up original signals */	sigsetmask(origsigs);	signal ( SIGINT, SIG_IGN );	signal ( SIGQUIT, SIG_IGN );	signal ( SIGHUP, SIG_IGN );	/* flush the buffer */	flush_io();	return (0);}clean_up(){	Cursor	cursor;	int msfd;	int flag;	reset_signals();	if (prfd <= 0)		return(0);	if ( dblflag )		rdispA_writeboth();	pr_putattributes(prfd, &tmpplane);	pr_putcolormap(prfd, 0, 256, tred, tgrn, tblu);	if (iograb == TRUE )	{			cursor = cursor_create((char *)0);			win_getcursor(rootfd, cursor);			cursor_set(cursor, CURSOR_SHOW_CURSOR, 1, 0);			win_setcursor(rootfd, cursor);			cursor_destroy(cursor);			win_releaseio(winfd); 			flag = win_is_input_device(rootfd, "/dev/mouse");			/* re-install the mouse */         		msfd = open(new_screen.scr_msname, O_RDWR );			if (msfd >= 0) {				win_set_input_device(rootfd, msfd,						new_screen.scr_msname);				close (msfd);			wmgr_refreshwindow ( rootfd );			}	}	mem_destroy(mobs);	mem_destroy(mexp);	if ( prfd > 0 )		pr_destroy(prfd);	return (0);}check_input(){	Event	event;	int arg;	arg = 0;	ioctl(winfd, FIONREAD, &arg);	if (arg != 0) {		input_readevent(winfd, &event);		if (event_id(&event) == 0x03)		/* CTRL-C */			finish();	}	return(0);}cg_send_message(where, msg_type, msg)    int             where;    int             msg_type;    char           *msg;{    if ( iograb ) {       win_releaseio ( winfd );       sleep(15);    }    send_message(where, msg_type, msg);    if ( iograb )       win_grabio ( winfd );}

⌨️ 快捷键说明

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