📄 pr_test.c
字号:
#ifndef lintstatic char sccsid[] = "@(#)pr_test.c 1.1 92/07/30 Copyr 1990 Sun Micro";#endif/* * Copyright (c) 1990 by Sun Microsystems, Inc. *//**********************************************************************//* Include files *//**********************************************************************/#include <fcntl.h>#include <stdio.h>#include <sys/types.h>#include <sys/timeb.h>#include <string.h>#include <pixrect/pixrect_hs.h>#include <pixrect/gtvar.h>#include <sdrtns.h> /* sdrtns.h should always be included */#include <gttest.h>#include <errmsg.h>#define CHUNK_WIDTH 64#define CHUNK_HEIGHT 64#define NBANK 5/**********************************************************************//* External variables *//**********************************************************************/externint ierr;externlong random();externchar *sprintf();externchar *initstate(), *setstate();externtime_t time();externchar *device_name;/**********************************************************************//* Static variables *//**********************************************************************/static char *groupnames[] = { "CURRENT plane", "MONO plane", "8-BIT COLOR plane", "OVERLAY ENABLE plane", "OVERLAY plane", "24-BIT COLOR plane", "VIDEO PLANE", "VIDEO ENABLE plane", "TRANSPARENT OVERLAY plane", "WINDOW ID plane", "Z-BUFFER", "CURSOR ENABLE plane", "CURSOR plane", "LAST-PLUS-ONE plane", };staticchar groups[PIXPG_INVALID+1];staticint ngroups;staticlong rand_state[32] = { 3, 0x9a319039, 0x8999220b, 0x27fb47b9, 0x32d9c024, 0x9b663182, 0x5da1f342, 0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd, 0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86, 0xda672e2a, 0x1588ca88, 0xe369735d, 0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc, 0xde3b81e0, 0xdf0a6fb5, 0xf103bc02, 0x48f340fb, 0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e, };statictime_t ltime;staticPixrect *device_pr = (Pixrect *)NULL;staticint def_wid = 0;/**********************************************************************/Pixrect *open_pr_device()/**********************************************************************/{ int op; int wpart = 0; int fd; func_name = "open_pr_device"; TRACE_IN if (device_pr == (Pixrect *)NULL) { device_pr = pr_open(device_name); if (device_pr == NULL || device_pr < 0) { dump_status(); (void)fb_send_message(HAWK_FATAL_ERROR, FATAL, DLXERR_OPEN, device_name); } } fd = open(device_name, O_RDWR); if (fd < 0) { dump_status(); (void)fb_send_message(HAWK_FATAL_ERROR, FATAL, DLXERR_OPEN); } if (ioctl(fd, FB_GETWPART, &wpart) < 0) { dump_status(); (void)fb_send_message(HAWK_FATAL_ERROR, FATAL, DLXERR_GET_WPART); } if (wpart != 5) { wpart = 5; if (ioctl(fd, FB_SETWPART, &wpart) < 0) { dump_status(); (void)fb_send_message(HAWK_FATAL_ERROR, FATAL, DLXERR_SET_WPART); } } (void)close(fd); TRACE_OUT return (device_pr);}/**********************************************************************/intwid_alloc(pixr, attrb)/**********************************************************************/Pixrect *pixr;int attrb;{ struct fb_wid_alloc winfo; /* from fbio.h */ int fd; func_name = "wid_alloc"; TRACE_IN winfo.wa_index = -1; winfo.wa_count = 1; winfo.wa_type = attrb; if (pr_ioctl(pixr, FBIO_WID_ALLOC, &winfo) < 0) { (void)fb_send_message(SKIP_ERROR, WARNING, DLXERR_UNIQUE_WID); } else { def_wid = winfo.wa_index; } /* fd = open(device_name, O_RDWR); if (fd < 0) { dump_status(); (void)fb_send_message(HAWK_FATAL_ERROR, FATAL, DLXERR_OPEN); } winfo.wa_index = -1; winfo.wa_count = 1; winfo.wa_type = attrb; if (ioctl(fd, FBIO_WID_ALLOC, &winfo) < 0) { dump_status(); (void)fb_send_message(HAWK_FATAL_ERROR, FATAL, DLXERR_UNIQUE_WID); } def_wid = winfo.wa_index; (void)close(fd); */ TRACE_OUT return(def_wid);}/**********************************************************************/intwid_free(pixr, ind, attrib)/**********************************************************************/Pixrect *pixr;int ind;int attrib;{ struct fb_wid_alloc winfo; /* from fbio.h */ func_name = "wid_free"; TRACE_IN winfo.wa_index = ind; winfo.wa_count = 1; winfo.wa_type = attrib; if (pr_ioctl(pixr, FBIO_WID_FREE, &winfo) < 0) { (void)fb_send_message(SKIP_ERROR, WARNING, DLXERR_WID_FREE); } TRACE_OUT return 0;}/**********************************************************************/intclut_alloc(pixr)/**********************************************************************/Pixrect *pixr;{ struct fb_clutalloc clut; func_name = "clut_alloc"; TRACE_IN clut.flags = CLUT_8BIT; clut.clutindex = -1; if (pr_ioctl(pixr, FB_CLUTALLOC, &clut) < 0) { (void)fb_send_message(SKIP_ERROR, WARNING, DLXERR_CLUT_ALLOC); } TRACE_OUT return clut.index;} /**********************************************************************/intclut_free(pixr, ind)/**********************************************************************/Pixrect *pixr;int ind;{ struct fb_clutalloc clut; func_name = "clut_alloc"; TRACE_IN clut.flags = CLUT_8BIT; clut.index = ind; if (pr_ioctl(pixr, FB_CLUTFREE, &clut) < 0) { (void)fb_send_message(SKIP_ERROR, WARNING, DLXERR_CLUT_FREE); } TRACE_OUT return 0;}/**********************************************************************/close_pr_device()/**********************************************************************/{ func_name = "close_pr_device"; TRACE_IN if (device_pr) { (void)pr_close(device_pr); } device_pr = (Pixrect *)NULL; TRACE_OUT}/**********************************************************************/char *pr_test(pr, mask)/**********************************************************************/Pixrect *pr;register int mask;/* Test the pixrect memory by writing a random pattern to it */{ static char errtxt[256]; char errtxt2[256]; Pixrect *mprs = (Pixrect *) NULL, /* source pixrect */ *mprd = (Pixrect *) NULL, /* destination pixrect */ *mprc = (Pixrect *) NULL, /* complement pixrect */ *mpr_save = (Pixrect *) NULL; register *wptr; register *rptr; register *cptr; register int i; register int j; register int k; register int pps; register int rest; int chunk_width = CHUNK_WIDTH; int chunk_width_rest; int chunk_height = CHUNK_HEIGHT; int chunk_height_rest; int nx; int ny; char err=0; int scr_x; int scr_y; int bank; func_name = "pr_test"; TRACE_IN /* initialize state of the random generator */ ltime = time((time_t *)0); (void)initstate((unsigned int)ltime, (char *)rand_state, 128); (void)setstate((char *)rand_state); /* create memory pixrect to save the original screen */ mpr_save = mem_create(chunk_width, chunk_height, pr->pr_depth); if (mpr_save == NULL) { (void)strcpy(errtxt, DLXERR_OPEN_MEM_PIXRECT); goto error_return; } /* create memory pixrect to puit random patterns */ mprs = mem_create(chunk_width, chunk_height, pr->pr_depth); if (mprs == NULL) { (void)strcpy(errtxt, DLXERR_OPEN_MEM_PIXRECT); goto error_return; } pps = (chunk_width * chunk_height * pr->pr_depth)/ (sizeof(int) << 3); wptr = (int *)mpr_d(mprs)->md_image; for (i = 0 ; i < pps - 1 ; i++) { *wptr++ = random(); } if ((rest = pps % sizeof(int))) { char *cp = (char *)wptr; for (i = rest ; i > 0 ; i--) { *cp++ = (char)random(); } } else { *wptr = random() & mask; } mprd = mem_create(chunk_width, chunk_height, pr->pr_depth); if (mprd == NULL) { (void)strcpy(errtxt, DLXERR_OPEN_MEM_PIXRECT); goto error_return; } mprc = mem_create(chunk_width, chunk_height, pr->pr_depth); if (mprc == NULL) { (void)strcpy(errtxt, DLXERR_OPEN_MEM_PIXRECT); goto error_return; } /* calculate number of loops */ nx = pr->pr_width / chunk_width; chunk_width_rest = pr->pr_width % chunk_width; if (chunk_width_rest) nx++; else chunk_width_rest = chunk_width; ny = pr->pr_height / chunk_height; chunk_height_rest = pr->pr_height % chunk_height; if (chunk_height_rest) ny++; else chunk_height_rest = chunk_height; for (i = 0 ; i < ny ; i++) { int pr_y = i*chunk_height; /* y origin of random pixrect */ if (i == ny-1) chunk_height = chunk_height_rest; for (j = 0 ; j < nx ; j++) { int pr_x = j*chunk_width; /* x origin of random pixrect */ if (j == nx-1) chunk_width = chunk_width_rest; (void)check_key(); /* save the current screen */ (void)pr_rop (mpr_save, 0, 0, chunk_width, chunk_height, PIX_SRC | PIX_DONTCLIP, pr, pr_x, pr_y); /* write pattern to pixrect device */ (void)pr_rop (pr, pr_x, pr_y, chunk_width, chunk_height, PIX_SRC | PIX_DONTCLIP, mprs, 0, 0); wptr = (int *)mpr_d(mprs)->md_image; /* copy screen into memory pixrect */ (void)pr_rop (mprd, 0, 0, chunk_width, chunk_height, PIX_SRC | PIX_DONTCLIP, pr, pr_x, pr_y); rptr = (int *)mpr_d(mprd)->md_image; /* write the complement pattern to pixrect device */ (void)pr_rop (pr, pr_x, pr_y, chunk_width, chunk_height, PIX_NOT(PIX_SRC), mprs, 0, 0); /* copy screen into memory pixrect */ (void)pr_rop (mprc, 0, 0, chunk_width, chunk_height, PIX_SRC | PIX_DONTCLIP, pr, pr_x, pr_y); cptr = (int *)mpr_d(mprc)->md_image; /* restore previous screen */ (void)pr_rop (pr, pr_x, pr_y, chunk_width, chunk_height, PIX_SRC | PIX_DONTCLIP, mpr_save, 0, 0); if ((rest= pps % sizeof(int))) pps--; for (k = 0 ; k < pps ; k++) { scr_x = pr_x + (k % chunk_width); scr_y = pr_y + (k / chunk_width); bank = scr_x % NBANK; if ((*wptr ^ *rptr) & mask) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -