📄 c24.c
字号:
/******************************************************/do_star(radius, cx, cy, op) double radius; int cx, cy, op;{ int ix, iy; double x, y, angle; for (angle = 0; angle < 6.283185307; angle += 0.31415926) { x = cos(angle) * radius; y = sin(angle) * radius; ix = (int) x; iy = (int) y; do_vector(cx, cy, cx + ix, cy + iy, op, 0); }}/****************************************************//* Verify_clr_map *//* *//* Verify color map tests. Write all three DACs *//* with values ranging from 0 to 255. Display 3 *//* rows of color, beginning with red, green, then *//* blue. Verification of memory to ramdac mapping *//* *//****************************************************/#define SQR(s) ((double)((s)*1.0 * (s)*1.0))#define XBGR(r,g,b) (((b)<<16) + ((g)<<8) + (r))verify_clr_map(){ int state, level, cr, temp, color, x, y; do_rop(0, 0, width, height, (PIX_SRC | PIX_COLOR(0)), 0, 0, 0); for (state = 0; state < 3; state++) { for (level = 0; level < 8; level++) { for (cr = 0; cr < 32; cr++) { temp = cr + level * 32; switch (state) { case 0: color = XBGR(temp, 0, 0); break; case 1: color = XBGR(0, temp, 0); break; case 2: color = XBGR(0, 0, temp); break; } x = cr * 36; y = state * 256 + level * 32; do_rop(x, y, 36, 32, (PIX_SRC | PIX_COLOR(color)), 0, 0, 0); } } }}/*********************************************************//* Verify_rw_memory *//* *//* Verify color, overlay, and enable memory by writing *//* a modulating pattern and then comparing the results. *//* *//*********************************************************/verify_rw_memory(){ do_set_plane_group(PIXPG_COLOR); memtest(); do_set_plane_group(PIXPG_OVERLAY); memtest(); do_set_plane_group(PIXPG_OVERLAY_ENABLE); memtest();}/*******************************************************//* Memtest *//* *//* This routine actually does the grunt work in the *//* memory tests. It is assumed that the frame buffer *//* has the correct memory assigned by set_plane_group *//* before calling this routine. *//* *//*******************************************************/memtest(){ u_long *ptr, *eptr, *sptr; u_long pattern, mask; u_long size, data; struct mpr_data *temp; temp = (struct mpr_data *) prfd->pr_data; ptr = (u_long *) temp->md_image; sptr = ptr; size = width * height * depth / 8; eptr = (u_long *) ((int) sptr + size); pattern = 0x55555555; mask = (depth == 32) ? 0xFFFFFF : 0xFFFFFFFF; while (sptr < eptr) { *sptr++ = pattern; pattern = ~pattern; } /* Check Frame buffer memory */ pattern = 0x55555555; sptr = ptr; while (sptr < eptr) { data = *sptr++; if ((data & mask) != (pattern & mask)) Error(-FRAME_BUFFER_ERROR, "Memory verification failed \n", FALSE); pattern = ~pattern; }}/***************************************************//* verify double buffering functionality *//* *//* perform memory write-reads into each buffer *//***************************************************/verify_db_memory(){ resetfb(); do_set_plane_group(PIXPG_COLOR); if (pr_dbl_get(prfd, PR_DBL_AVAIL) != PR_DBL_EXISTS) Error(-FRAME_BUFFER_ERROR, "Double buffer availability verification failed \n", FALSE); else { pr_dbl_set(prfd, PR_DBL_WRITE, PR_DBL_A, 0); pr_rop(prfd, 0, 0, width, height, (PIX_SRC|PIX_COLOR(0)), 0, 0, 0); pr_dbl_set(prfd, PR_DBL_WRITE, PR_DBL_B, 0); pr_rop(prfd, 0, 0, width, height, (PIX_SRC|PIX_COLOR(0xFFFFFF)), 0, 0, 0); pr_dbl_set(prfd, PR_DBL_DISPLAY, PR_DBL_A, PR_DBL_READ, PR_DBL_A, 0); read_db(0); pr_dbl_set(prfd, PR_DBL_READ, PR_DBL_B, 0); /* pr_dbl_set(prfd, PR_DBL_DISPLAY, PR_DBL_B, 0); */ read_db(0xF0F0F0); }}/***************************************************//* read back and compare double buffer data *//***************************************************/read_db(data_cmp)u_long data_cmp;{ register u_long *ptr, *ptr_limit; u_long data_in, offset; struct mpr_data *temp; temp = (struct mpr_data *) prfd->pr_data; ptr = (u_long *) temp->md_image; ptr_limit = ptr + (1152 * 900); while (ptr < ptr_limit) if ((*ptr++ & 0xF0F0F0) != data_cmp) Error(-FRAME_BUFFER_ERROR, "Double buffer verification failed \n", FALSE);} /****************************************************//* Resetfb *//* *//* Reset the frame buffer back to 24 bit mode *//* and clear the enable plane. *//* *//****************************************************/resetfb(){ do_set_plane_group(PIXPG_OVERLAY_ENABLE); do_rop(0, 0, 1152, 900, PIX_SRC, 0, 0, 0); do_set_plane_group(PIXPG_OVERLAY); do_rop(0, 0, 1152, 900, PIX_SRC, 0, 0, 0); do_set_plane_group(PIXPG_COLOR);}/****************************************************//* Do_stencil *//* *//* Write stencil to screen pixrect and memory *//* pixrect. *//* *//****************************************************/do_stencil(x, y, w, h, op, stpr, stx, sty, spr, sx, sy) int x, y, w, h, op, stx, sty, sx, sy; Pixrect *stpr, *spr;{ pr_stencil(prfd, x, y, w, h, op, stpr, stx, sty, spr, sx, sy); pr_stencil(sepr, x, y, w, h, op, stpr, stx, sty, spr, sx, sy);}/****************************************************//* Do_rop *//* *//* Rop into screen pixrect and expected memory *//* pixrect. *//* *//****************************************************/do_rop(x, y, w, h, op, spr, x1, y1) int x, y, w, h, op, x1, y1; Pixrect *spr;{ check_input(); pr_rop(prfd, x, y, w, h, op, spr, x1, y1); pr_rop(sepr, x, y, w, h, op, spr, x1, y1);}/****************************************************//* Do_vector *//* *//* Draw vector into screen pixrect and into *//* expected memory pixrect. *//* *//****************************************************/do_vector(x0, y0, x1, y1, op, value) int x0, y0, x1, y1, op, value;{ pr_vector(prfd, x0, y0, x1, y1, op, value); pr_vector(sepr, x0, y0, x1, y1, op, value);}/***************************************************//* Do_put *//* *//* Set a pixel in both the screen pixrect and the *//* expected memory pixrect. *//* *//***************************************************/do_put(x, y, color) int x, y, color;{ pr_put(prfd, x, y, color); pr_put(sepr, x, y, color);}/***************************************************//* Check_screen *//* *//* Check the screen against the expected memory *//* pixrect. Return FALSE if bad, return TRUE if *//* good. *//* *//***************************************************/int check_screen(){ int j, i; u_long *sptr, *dptr; check_input(); if (SpecialFlag) pr_rop(sdpr, 0, 0, width, height, PIX_SRC, prfd, 0, 0); j = width * height * depth / 32; for (sptr = (u_long *)sdi, dptr = (u_long *)sde, i = 0; i < j; i++, sptr++, dptr++) { if (*sptr != *dptr) return(FALSE); } return(TRUE);}/*******************************************************//* Clean_up *//* *//* Cleanup, remove all pixrects, return control back *//* over to suntools, and replace the colors back into *//* the color lookup tables. *//* *//*******************************************************/clean_up(){ Cursor cursor; int msfd; int flag, count; char *winname; if ( cg9 ) pr_dbl_set ( prfd, PR_DBL_WRITE, PR_DBL_BOTH, PR_DBL_READ, PR_DBL_B, 0); reset_signals(); if (prfd <= 0) exit(0); pr_putattributes(prfd, &tmpplane); for ( count = 0; count < 256; count++ ) { tred[count] = tblue[count] = tgrn[count] = count; } pr_putlut(prfd, 0, 256, tred, tgrn, tblue); if (iograb) { if (( fb_type.fb_type == cg_type ) && ( winname = getenv ("WINDOW_PARENT" ))) { cursor = cursor_create((char *)0); win_getcursor(rootfd, cursor); cursor_set(cursor, CURSOR_SHOW_CURSOR, 1, 0); win_setcursor(rootfd, cursor); cursor_destroy(cursor); flag = win_is_input_device(rootfd, "/dev/mouse"); /* re-install the mouse */ msfd = open(new_screen.scr_msname, O_RDONLY); if (msfd >= 0) { win_set_input_device(rootfd, msfd, new_screen.scr_msname); close(msfd); } win_releaseio(winfd); } } if (SpecialFlag) mem_destroy(sdpr); mem_destroy(sepr); mem_destroy(oneexp); mem_destroy(onedump); pr_destroy(prfd);}/****************************************************//* Error *//* *//* Throwup the code and the string, if the diag *//* argument was passed then XOR the screen with the *//* expected memory pixrect and display ( used for *//* code debug) . *//* *//****************************************************/Error(code, string, xor) int code, xor; char *string;{ if (SpecialFlag && xor) { code = 0; pr_rop(sdpr, 0, 0, width, height, PIX_SRC ^ PIX_DST, sepr, 0, 0); pr_rop(prfd, 0, 0, width, height, PIX_SRC, sdpr, 0, 0); getchar(); } cg_send_message ( code, FATAL, string );}check_input(){ Event event; int arg = 0; ioctl(winfd, FIONREAD, &arg); if (arg != 0) { input_readevent(winfd, &event); if (event_id(&event) == 0x03) /* CTRL-C */ finish(); } return(0);}cg_lock_scr( func )int (*func)();{ if ( iograb ) { win_grabio( winfd ); sleep(1); (*func)(); win_releaseio( winfd ); } else (*func)();}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 + -