HIDDEN int deb_open(FBIO *ifp, char *file, int width, int height) { FB_CK_FBIO(ifp); if ( file == (char *)NULL ) fb_log( "fb_open( 0x%lx, NULL, %d, %d )\n", (unsigned long)ifp, width, height ); else fb_log( "fb_open( 0x%lx, \"%s\", %d, %d )\n", (unsigned long)ifp, file, width, height ); /* check for default size */ if ( width <= 0 ) width = ifp->if_width; if ( height <= 0 ) height = ifp->if_height; /* set debug bit vector */ if ( file != NULL ) { char *cp; for ( cp = file; *cp != '\0' && !isdigit(*cp); cp++ ) ; sscanf( cp, "%d", &ifp->if_debug ); } else { ifp->if_debug = 0; } /* Give the user whatever width was asked for */ ifp->if_width = width; ifp->if_height = height; return 0; }
HIDDEN int deb_write(FBIO *ifp, int x, int y, const unsigned char *pixelp, int count) { int i; FB_CK_FBIO(ifp); fb_log( "fb_write( 0x%lx,%4d,%4d, 0x%lx, %d )\n", (unsigned long)ifp, x, y, (unsigned long)pixelp, count ); /* write them out, four per line */ if ( ifp->if_debug & FB_DEBUG_RW ) { for ( i = 0; i < count; i++ ) { if ( i % 4 == 0 ) fb_log( "%4d:", i ); fb_log( " [%3d,%3d,%3d]", *(pixelp+(i*3)+RED), *(pixelp+(i*3)+GRN), *(pixelp+(i*3)+BLU) ); if ( i % 4 == 3 ) fb_log( "\n" ); } if ( i % 4 != 0 ) fb_log( "\n" ); } return count; }
HIDDEN int deb_flush(FBIO *ifp) { FB_CK_FBIO(ifp); fb_log( "if_flush( 0x%lx )\n", (unsigned long)ifp ); return 0; }
HIDDEN int deb_free(FBIO *ifp) { FB_CK_FBIO(ifp); fb_log( "fb_free( 0x%lx )\n", (unsigned long)ifp ); return 0; }
HIDDEN int deb_wmap(FBIO *ifp, const ColorMap *cmp) { int i; FB_CK_FBIO(ifp); if ( cmp == NULL ) fb_log( "fb_wmap( 0x%lx, NULL )\n", (unsigned long)ifp ); else fb_log( "fb_wmap( 0x%lx, 0x%lx )\n", (unsigned long)ifp, (unsigned long)cmp ); if ( ifp->if_debug & FB_DEBUG_CMAP && cmp != NULL ) { for ( i = 0; i < 256; i++ ) { fb_log( "%3d: [ 0x%4lx, 0x%4lx, 0x%4lx ]\n", i, (unsigned long)cmp->cm_red[i], (unsigned long)cmp->cm_green[i], (unsigned long)cmp->cm_blue[i] ); } } return 0; }
HIDDEN int deb_rmap(FBIO *ifp, ColorMap *cmp) { FB_CK_FBIO(ifp); fb_log( "fb_rmap( 0x%lx, 0x%lx )\n", (unsigned long)ifp, (unsigned long)cmp ); return 0; }
HIDDEN int deb_setcursor(FBIO *ifp, const unsigned char *bits, int xbits, int ybits, int xorig, int yorig) { FB_CK_FBIO(ifp); fb_log( "fb_setcursor( 0x%lx, 0x%lx, %d, %d, %d, %d )\n", (unsigned long)ifp, bits, xbits, ybits, xorig, yorig ); return 0; }
int fb_reset(FBIO *ifp) { if (ifp) { FB_CK_FBIO(ifp); } return 0; }
HIDDEN int deb_view(FBIO *ifp, int xcenter, int ycenter, int xzoom, int yzoom) { FB_CK_FBIO(ifp); fb_log( "fb_view( 0x%lx,%4d,%4d,%4d,%4d )\n", (unsigned long)ifp, xcenter, ycenter, xzoom, yzoom ); fb_sim_view( ifp, xcenter, ycenter, xzoom, yzoom ); return 0; }
HIDDEN int deb_bwwriterect(FBIO *ifp, int xmin, int ymin, int width, int height, const unsigned char *pp) { FB_CK_FBIO(ifp); fb_log( "fb_bwwriterect( 0x%lx,%4d,%4d,%4d,%4d, 0x%lx )\n", (unsigned long)ifp, xmin, ymin, width, height, (unsigned long)pp ); return( width*height ); }
int fb_viewport(FBIO *ifp, int UNUSED(left), int UNUSED(top), int UNUSED(right), int UNUSED(bottom)) { if (ifp) { FB_CK_FBIO(ifp); } return 0; }
HIDDEN int deb_read(FBIO *ifp, int x, int y, unsigned char *pixelp, int count) { FB_CK_FBIO(ifp); fb_log( "fb_read( 0x%lx,%4d,%4d, 0x%lx, %d )\n", (unsigned long)ifp, x, y, (unsigned long)pixelp, count ); return count; }
HIDDEN int deb_getcursor(FBIO *ifp, int *mode, int *x, int *y) { FB_CK_FBIO(ifp); fb_log( "fb_getcursor( 0x%lx, 0x%x, 0x%x, 0x%x )\n", (unsigned long)ifp, mode, x, y ); fb_sim_getcursor( ifp, mode, x, y ); fb_log( " <= %d %d %d\n", *mode, *x, *y ); return 0; }
/* * F B _ S I M _ C U R S O R * * A routine to simulate the effect of fb_cursor() by simply * storing this information into the FBIO structure. */ int fb_sim_cursor(FBIO *ifp, int mode, int x, int y) { FB_CK_FBIO(ifp); ifp->if_cursmode = mode; ifp->if_xcurs = x; ifp->if_ycurs = y; return 0; }
/* * F B _ S I M _ G E T C U R S O R * * A routine to simulate the effect of fb_getcursor() by simply * reading this information from the FBIO structure. */ int fb_sim_getcursor(FBIO *ifp, int *mode, int *x, int *y) { FB_CK_FBIO(ifp); *mode = ifp->if_cursmode; *x = ifp->if_xcurs; *y = ifp->if_ycurs; return 0; }
HIDDEN int deb_getview(FBIO *ifp, int *xcenter, int *ycenter, int *xzoom, int *yzoom) { FB_CK_FBIO(ifp); fb_log( "fb_getview( 0x%lx, 0x%x, 0x%x, 0x%x, 0x%x )\n", (unsigned long)ifp, xcenter, ycenter, xzoom, yzoom ); fb_sim_getview( ifp, xcenter, ycenter, xzoom, yzoom ); fb_log( " <= %d %d %d %d\n", *xcenter, *ycenter, *xzoom, *yzoom ); return 0; }
int fb_scursor(FBIO *ifp, int UNUSED(mode), int UNUSED(x), int UNUSED(y)) { if (ifp) { FB_CK_FBIO(ifp); } /* We could actually implement this but it * is probably of no value. */ return 0; }
/* * F B _ S I M _ V I E W * * A routine to simulate the effect of fb_view() by simply * storing this information into the FBIO structure. */ int fb_sim_view(FBIO *ifp, int xcenter, int ycenter, int xzoom, int yzoom) { FB_CK_FBIO(ifp); ifp->if_xcenter = xcenter; ifp->if_ycenter = ycenter; ifp->if_xzoom = xzoom; ifp->if_yzoom = yzoom; return 0; }
/* * F B _ S I M _ G E T V I E W * * A routine to simulate the effect of fb_getview() by simply * reading this information from the FBIO structure. */ int fb_sim_getview(FBIO *ifp, int *xcenter, int *ycenter, int *xzoom, int *yzoom) { FB_CK_FBIO(ifp); *xcenter = ifp->if_xcenter; *ycenter = ifp->if_ycenter; *xzoom = ifp->if_xzoom; *yzoom = ifp->if_yzoom; return 0; }
HIDDEN int deb_clear(FBIO *ifp, unsigned char *pp) { FB_CK_FBIO(ifp); if ( pp == 0 ) fb_log( "fb_clear( 0x%lx, NULL )\n", (unsigned long)ifp ); else fb_log( "fb_clear( 0x%lx, &[%d %d %d] )\n", (unsigned long)ifp, (int)(pp[RED]), (int)(pp[GRN]), (int)(pp[BLU]) ); return 0; }
int fb_window(FBIO *ifp, int x, int y) { int xcenter, ycenter; int xzoom, yzoom; if (ifp) { FB_CK_FBIO(ifp); fb_getview(ifp, &xcenter, &ycenter, &xzoom, &yzoom); xcenter = x; ycenter = y; return fb_view(ifp, xcenter, ycenter, xzoom, yzoom); } else { return 0; } }
/*ARGSUSED*/ HIDDEN int deb_help(FBIO *ifp) { FB_CK_FBIO(ifp); fb_log( "Description: %s\n", debug_interface.if_type ); fb_log( "Device: %s\n", ifp->if_name ); fb_log( "Max width/height: %d %d\n", debug_interface.if_max_width, debug_interface.if_max_height ); fb_log( "Default width/height: %d %d\n", debug_interface.if_width, debug_interface.if_height ); fb_log( "\ Usage: /dev/debug[#]\n\ where # is a optional bit vector from:\n\ 1 debug buffered I/O calls\n\ 2 show colormap entries in rmap/wmap calls\n\ 4 show actual pixel values in read/write calls\n" ); /*8 buffered read/write values - ifdef'd out*/ return 0; }
HIDDEN int mem_open(FBIO *ifp, const char *file, int width, int height) { int mode; const char *cp; FBIO *fbp; char modebuf[80]; char *mp; int alpha; struct modeflags *mfp; FB_CK_FBIO(ifp); /* This function doesn't look like it will work if file * is NULL - stop before we start, if that's the case.*/ if (file == NULL) return -1; /* * First, attempt to determine operating mode for this open, * based upon the "unit number" or flags. * file = "/dev/mem###" * The default mode is zero. */ mode = 0; if (bu_strncmp(file, "/dev/mem", 8)) { /* How did this happen?? */ mode = 0; } else { /* Parse the options */ alpha = 0; mp = &modebuf[0]; cp = &file[8]; while (*cp != '\0' && !isspace((int)*cp)) { *mp++ = *cp; /* copy it to buffer */ if (isdigit((int)*cp)) { cp++; continue; } alpha++; for (mfp = modeflags; mfp->c != '\0'; mfp++) { if (mfp->c == *cp) { mode = (mode&~mfp->mask)|mfp->value; break; } } if (mfp->c == '\0' && *cp != '-') { fb_log("if_mem: unknown option '%c' ignored\n", *cp); } cp++; } *mp = '\0'; if (!alpha) mode = atoi(modebuf); } /* build a local static info struct */ if ((MIL(ifp) = (char *)calloc(1, sizeof(struct mem_info))) == NULL) { fb_log("mem_open: mem_info malloc failed\n"); return -1; } cp = &file[strlen("/dev/mem")]; while (*cp != '\0' && *cp != ' ' && *cp != '\t') cp++; /* skip suffix */ while (*cp != '\0' && (*cp == ' ' || *cp == '\t' || *cp == ';')) cp++; /* skip blanks and separators */ if (*cp) { /* frame buffer device specified */ if ((fbp = fb_open(cp, width, height)) == FBIO_NULL) { free(MIL(ifp)); return -1; } MI(ifp)->fbp = fbp; ifp->if_width = fbp->if_width; ifp->if_height = fbp->if_height; ifp->if_selfd = fbp->if_selfd; if ((mode & MODE_1MASK) == MODE_1IMMEDIATE) MI(ifp)->write_thru = 1; } else { /* no frame buffer specified */ if (width > 0) ifp->if_width = width; if (height > 0) ifp->if_height = height; } if ((MI(ifp)->mem = (unsigned char *)calloc(ifp->if_width*ifp->if_height, 3)) == NULL) { fb_log("mem_open: memory buffer malloc failed\n"); (void)free(MIL(ifp)); return -1; } if ((MI(ifp)->fbp != FBIO_NULL) && (mode & MODE_2MASK) == MODE_2PREREAD) { /* Pre read all of the image data and cmap */ int got; got = fb_readrect(MI(ifp)->fbp, 0, 0, ifp->if_width, ifp->if_height, (unsigned char *)MI(ifp)->mem); if (got != ifp->if_width * ifp->if_height) { fb_log("if_mem: WARNING: pre-read of %d only got %d, your image is truncated.\n", ifp->if_width * ifp->if_height, got); } if (fb_rmap(MI(ifp)->fbp, &(MI(ifp)->cmap)) < 0) fb_make_linear_cmap(&(MI(ifp)->cmap)); } else { /* Image data begins black, colormap linear */ fb_make_linear_cmap(&(MI(ifp)->cmap)); } return 0; }