Exemplo n.º 1
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;
}
Exemplo n.º 2
0
int
fb_seek(register FBIO *ifp, int x, int y)
{
    long	pixelnum;
    long	pagepixel;

    if ( ifp->if_debug & FB_DEBUG_BIO ) {
	fb_log( "fb_seek( 0x%lx, %d, %d )\n",
		(unsigned long)ifp, x, y );
    }

    if ( x < 0 || y < 0 || x >= ifp->if_width || y >= ifp->if_height ) {
	fb_log(	"fb_seek: illegal address <%d,%d>.\n", x, y );
	return	-1;
    }
    pixelnum = ((long) y * (long) ifp->if_width) + x;
    pagepixel = (long) ifp->if_pno * ifp->if_ppixels;
    if ( pixelnum < pagepixel || pixelnum >= (pagepixel + ifp->if_ppixels) ) {
	if ( ifp->if_pdirty )
	    if ( _fb_pgout( ifp ) == - 1 )
		return	-1;
	if ( _fb_pgin( ifp, (int) (pixelnum / (long) ifp->if_ppixels)) <= -1 )
	    return	-1;
    }
    ifp->if_pixcur = pixelnum;
    /* Compute new pixel pointer into page. */
    ifp->if_pcurp = ifp->if_pbase +
	(ifp->if_pixcur % ifp->if_ppixels)*sizeof(RGBpixel);
    return	0;
}
Exemplo n.º 3
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 ssize_t
dsk_write(fb *ifp, int x, int y, const unsigned char *pixelp, size_t count)
{
    register ssize_t bytes = count * sizeof(RGBpixel);
    ssize_t todo;
    off_t dest;

    dest = (y * ifp->if_width + x) * sizeof(RGBpixel);
    if (dest != (off_t)ifp->if_seekpos) {
	if (lseek(ifp->if_fd, dest, 0) == -1) {
	    fb_log("disk_buffer_write : seek to %ld failed.\n", dest);
	    return -1;
	}
	ifp->if_seekpos = dest;
    }
    while (bytes > 0) {
	ssize_t ret;
	todo = bytes;
	ret = write(ifp->if_fd, (char *) pixelp, todo);
	if (ret != todo) {
	    fb_log("disk_buffer_write: write failed\n");
	    return -1;
	}
	bytes -= todo;
	pixelp += todo / sizeof(RGBpixel);
	ifp->if_seekpos += todo;
    }
    return count;
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
/*
	If args[0] is NULL, spawn a shell, otherwise execute the specified
	command line.
	Return the exit status of the program, or -1 if wait() or fork()
	return an error.
*/
int
exec_Shell(char **args)
{
    int child_pid;

    if (args[0] == NULL) {
	char *arg_sh = getenv("SHELL");
	/* $SHELL, if set, DFL_SHELL otherwise. */
	if (arg_sh == NULL)
	    arg_sh = DFL_SHELL;
	args[0] = arg_sh;
	args[1] = NULL;
    }
    switch (child_pid = fork()) {
	case -1 :
	    fb_log("\"%s\" (%d) could not fork.\n",
		    __FILE__, __LINE__
		);
	    return -1;
	case  0 : /* Child process - execute. */
	    sleep(2);
	    (void)execvp(args[0], args);
	    fb_log("%s : could not execute.\n", args[0]);
	    bu_exit(1, NULL);
	default :
	{
	    int pid;
	    int stat_loc;
	    void (*istat)(), (*qstat)(), (*cstat)();
	    istat = signal(SIGINT, SIG_IGN);
	    qstat = signal(SIGQUIT, SIG_IGN);
	    cstat = signal(SIGCLD, SIG_DFL);
	    while (	(pid = wait(&stat_loc)) != -1
			&& pid != child_pid
		)
		;
	    (void)signal(SIGINT, istat);
	    (void)signal(SIGQUIT, qstat);
	    (void)signal(SIGCLD, cstat);
	    if (pid == -1) {
		fb_log("\"%s\" (%d) wait failed : no children.\n",
			__FILE__, __LINE__
		   );
		return -1;
	    }
	    switch (stat_loc & 0377) {
		case 0177 : /* Child stopped. */
		    fb_log("Child stopped.\n");
		    return (stat_loc >> 8) & 0377;
		case 0 :    /* Child exited. */
		    return (stat_loc >> 8) & 0377;
		default :   /* Child terminated. */
		    fb_log("Child terminated.\n");
		    return 1;
	    }
	}
    }
}
Exemplo n.º 7
0
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;
}
Exemplo n.º 8
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;
}
HIDDEN int
dsk_open(fb *ifp, const char *file, int width, int height)
{
    static char zero = 0;

    FB_CK_FB(ifp);

    /* check for default size */
    if (width == 0)
	width = ifp->if_width;
    if (height == 0)
	height = ifp->if_height;

    if (BU_STR_EQUAL(file, "-")) {
	/*
	 * It is the applications job to write ascending scanlines.
	 * If it does not, then this can be stacked with /dev/mem,
	 * i.e.	/dev/mem -
	 */
	ifp->if_fd = 1;		/* fileno(stdout) */
	ifp->if_width = width;
	ifp->if_height = height;
	ifp->if_seekpos = 0;
	return 0;
    }

    if ((ifp->if_fd = open(file, O_RDWR | O_BINARY, 0)) == -1
	&& (ifp->if_fd = open(file, O_RDONLY | O_BINARY, 0)) == -1) {
	if ((ifp->if_fd = open(file, O_RDWR | O_CREAT | O_BINARY, 0664)) > 0) {
	    /* New file, write byte at end */
	    if (lseek(ifp->if_fd, (height*width*sizeof(RGBpixel)-1), 0) == -1) {
		fb_log("disk_device_open : can not seek to end of new file.\n");
		return -1;
	    }
	    if (write(ifp->if_fd, &zero, 1) < 0) {
		fb_log("disk_device_open : initial write failed.\n");
		return -1;
	    }
	} else
	    return -1;
    }

    setmode(ifp->if_fd, O_BINARY);

    ifp->if_width = width;
    ifp->if_height = height;
    if (lseek(ifp->if_fd, 0, 0) == -1) {
	fb_log("disk_device_open : can not seek to beginning.\n");
	return -1;
    }
    ifp->if_seekpos = 0;
    return 0;
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
0
HIDDEN int
deb_free(FBIO *ifp)
{
    FB_CK_FBIO(ifp);
    fb_log( "fb_free( 0x%lx )\n", (unsigned long)ifp );
    return	0;
}
Exemplo n.º 12
0
/*	Squash takes three super-sampled "bit arrays", and returns an array
	of intensities at half the resolution.  N is the size of the bit
	arrays.  The "bit arrays" are actually int arrays whose values are
	assumed to be only 0 or 1.
*/
void
squash(register int *buf0, register int *buf1, register int *buf2, register float *ret_buf, register int n)
{
    register int     j;
#if DEBUG_SQUASH
    fb_log( "squash: buf0=0x%x buf1=0x%x buf2=0x%x ret_buf=0x%x n=%d\n",
	    buf0, buf1, buf2, ret_buf, n );
#endif
    for ( j = 1; j < n - 1; j++ )
    {
	ret_buf[j] =
	    (
		buf2[j - 1] * CRNR_WT +
		buf2[j] * MID_WT +
		buf2[j + 1] * CRNR_WT +
		buf1[j - 1] * MID_WT +
		buf1[j] * CNTR_WT +
		buf1[j + 1] * MID_WT +
		buf0[j - 1] * CRNR_WT +
		buf0[j] * MID_WT +
		buf0[j + 1] * CRNR_WT
		);
    }
    return;
}
Exemplo n.º 13
0
/*
 * Clear the disk file to the given color.
 */
HIDDEN int
disk_color_clear(fb *ifp, register unsigned char *bpp)
{
    static unsigned char pix_buf[DISK_DMA_BYTES] = {0};
    register unsigned char *pix_to;
    size_t i;
    int fd;
    size_t pixelstodo;

    /* Fill buffer with background color. */
    for (i = DISK_DMA_PIXELS, pix_to = pix_buf; i > 0; i--) {
	COPYRGB(pix_to, bpp);
	pix_to += sizeof(RGBpixel);
    }

    /* Set start of framebuffer */
    fd = ifp->if_fd;
    if (ifp->if_seekpos != 0 && lseek(fd, 0, 0) == -1) {
	fb_log("disk_color_clear : seek failed.\n");
	return -1;
    }

    /* Send until frame buffer is full. */
    pixelstodo = ifp->if_height * ifp->if_width;
    while (pixelstodo > 0) {
	i = pixelstodo > DISK_DMA_PIXELS ? DISK_DMA_PIXELS : pixelstodo;
	if (write(fd, pix_buf, i * sizeof(RGBpixel)) == -1)
	    return -1;
	pixelstodo -= i;
	ifp->if_seekpos += i * sizeof(RGBpixel);
    }

    return 0;
}
Exemplo n.º 14
0
int
fb_sim_bwreadrect(FBIO *ifp, int xmin, int ymin, int width, int height, unsigned char *pp)
{
    register int y;
    register int tot;
    int got;
    unsigned char buf[SIMBUF_SIZE*3];

    if (width > SIMBUF_SIZE) {
	fb_log("fb_sim_bwreadrect() width of %d exceeds internal buffer, aborting\n", width);
	return -SIMBUF_SIZE;	/* FAIL */
    }

    tot = 0;
    for (y=ymin; y < ymin+height; y++) {
	register int x;

	got = fb_read(ifp, xmin, y, buf, (size_t)width);

	/* Extract green chan */
	for (x=0; x < width; x++)
	    *pp++ = buf[x*3+GRN];

	tot += got;
	if (got != width) break;
    }
    return tot;
}
Exemplo n.º 15
0
int
fb_rpixel(register FBIO *ifp, unsigned char *pixelp)
{
    if ( ifp->if_pno == -1 )
	if ( _fb_pgin( ifp, ifp->if_pixcur / ifp->if_ppixels ) <= -1 )
	    return	-1;

    COPYRGB( pixelp, (ifp->if_pcurp) );
    ifp->if_pcurp += sizeof(RGBpixel);	/* position in page */
    ifp->if_pixcur++;	/* position in framebuffer */
    if ( ifp->if_pcurp >= ifp->if_pendp ) {
	if ( _fb_pgout( ifp ) <= -1 )
	    return	-1;
	ifp->if_pno = -1;
    }

#ifdef NEVER
    if ( ifp->if_debug & FB_DEBUG_BRW ) {
	fb_log( "fb_rpixel( 0x%lx, 0x%lx ) => [%3d,%3d,%3d]\n",
		(unsigned long)ifp, (unsigned long)pixelp,
		(*pixelp)[RED], (*pixelp)[GRN], (*pixelp)[BLU] );
    }
#endif /* NEVER */

    return	0;
}
Exemplo n.º 16
0
void fb_mode_done(adv_bool restore)
{
	assert(fb_is_active() && fb_mode_is_active());

	log_std(("video:fb: fb_mode_done()\n"));

	if (munmap(fb_state.ptr, fb_state.fixinfo.smem_len) != 0) {
		log_std(("ERROR:video:fb: munmap failed\n"));
		/* ignore error */
	}

	if (restore) {
		log_std(("video:fb: restore old\n"));

		fb_log(0, &fb_state.oldinfo);

		fb_setvar(&fb_state.oldinfo);
		/* ignore error */
	} else {
		/* ensure to have the correct color, the keyboard driver */
		/* when resetting the console changes some colors */
		fb_setup_color();
		/* ignore error */
	}

	fb_state.mode_active = 0;
}
Exemplo n.º 17
0
HIDDEN int
deb_flush(FBIO *ifp)
{
    FB_CK_FBIO(ifp);
    fb_log( "if_flush( 0x%lx )\n", (unsigned long)ifp );
    return	0;
}
Exemplo n.º 18
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;
}
Exemplo n.º 19
0
HIDDEN ssize_t
dsk_read(fb *ifp, int x, int y, unsigned char *pixelp, size_t count)
{
    size_t bytes = count * sizeof(RGBpixel);
    size_t todo;
    ssize_t got;
    size_t dest;
    size_t bytes_read = 0;
    int fd = ifp->if_fd;

    /* Reads on stdout make no sense.  Take reads from stdin. */
    if (fd == 1) fd = 0;

    dest = ((y * ifp->if_width) + x) * sizeof(RGBpixel);
    if (ifp->if_seekpos != dest && lseek(fd, dest, 0) == -1) {
	fb_log("disk_buffer_read : seek to %ld failed.\n", dest);
	return -1;
    }
    ifp->if_seekpos = dest;
    while (bytes > 0) {
	todo = bytes;
	if ((got = read(fd, (char *) pixelp, todo)) != (ssize_t)todo) {
	    if (got <= 0) {
		if (got < 0) {
		    perror("READ ERROR");
		}

		if (bytes_read <= 0)
		    return -1;	/* error */

		/* early EOF -- indicate what we got */
		return bytes_read/sizeof(RGBpixel);
	    }
	    if (fd != 0) {
		/* This happens all the time reading from pipes */
		fb_log("disk_buffer_read(fd=%d): y=%d read of %lu got %ld bytes\n",
		       fd, y, todo, got);
	    }
	}
	bytes -= got;
	pixelp += got;
	ifp->if_seekpos += got;
	bytes_read += got;
    }
    return bytes_read/sizeof(RGBpixel);
}
Exemplo n.º 20
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;
}
Exemplo n.º 21
0
HIDDEN int
deb_cursor(FBIO *ifp, int mode, int x, int y)
{
    fb_log( "fb_cursor( 0x%lx, %d,%4d,%4d )\n",
	    (unsigned long)ifp, mode, x, y );
    fb_sim_cursor( ifp, mode, x, y );
    return	0;
}
Exemplo n.º 22
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;
}
Exemplo n.º 23
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 );
}
Exemplo n.º 24
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;
}
Exemplo n.º 25
0
HIDDEN int
dsk_wmap(fb *ifp, const ColorMap *cmap)
{
    if (cmap == (ColorMap *) NULL)
	/* Do not write default map to file. */
	return 0;
    if (fb_is_linear_cmap(cmap))
	return 0;
    if (lseek(ifp->if_fd, FILE_CMAP_ADDR, 0) == -1) {
	fb_log("disk_colormap_write : seek to %ld failed.\n",
	       FILE_CMAP_ADDR);
	return -1;
    }
    if (write(ifp->if_fd, (char *) cmap, sizeof(ColorMap))
	!= sizeof(ColorMap)) {
	fb_log("disk_colormap_write : write failed.\n");
	return -1;
    }
    return 0;
}
Exemplo n.º 26
0
int
fb_tell(register FBIO *ifp, int *xp, int *yp)
{
    *yp = (int) (ifp->if_pixcur / ifp->if_width);
    *xp = (int) (ifp->if_pixcur % ifp->if_width);

    if ( ifp->if_debug & FB_DEBUG_BIO ) {
	fb_log( "fb_tell( 0x%lx, 0x%x, 0x%x ) => (%4d,%4d)\n",
		(unsigned long)ifp, xp, yp, *xp, *yp );
    }

    return	0;
}
Exemplo n.º 27
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;
}
Exemplo n.º 28
0
/*
 * A routine to simulate the effect of fb_readrect() when a
 * particular display does not handle it.
 */
int
fb_sim_readrect(FBIO *ifp, int xmin, int ymin, int width, int height, unsigned char *pp)
{
    register int y;
    register int tot;
    int got;

    tot = 0;
    for (y=ymin; y < ymin+height; y++) {
	got = fb_read(ifp, xmin, y, pp, (size_t)width);
	if (got < 0) {
	    fb_log("fb_sim_readrect() y=%d unexpected EOF\n", y);
	    break;
	}
	tot += got;
	if (got != width) {
	    fb_log("fb_sim_readrect() y=%d, read of %d got %d pixels, aborting\n",
		   y, width, got);
	    break;
	}
	pp += width * sizeof(RGBpixel);
    }
    return tot;
}
Exemplo n.º 29
0
int
_fb_pgflush(register FBIO *ifp)
{
    if ( ifp->if_debug & FB_DEBUG_BIO ) {
	fb_log( "_fb_pgflush( 0x%lx )\n", (unsigned long)ifp );
    }

    if ( ifp->if_pdirty ) {
	if ( _fb_pgout( ifp ) <= -1 )
	    return	-1;
	ifp->if_pdirty = 0;
    }

    return	0;
}
Exemplo n.º 30
0
HIDDEN int
dsk_help(fb *ifp)
{
    fb_log("Description: %s\n", disk_interface.if_type);
    fb_log("Device: %s\n", ifp->if_name);
    fb_log("Max width/height: %d %d\n",
	   disk_interface.if_max_width,
	   disk_interface.if_max_height);
    fb_log("Default width/height: %d %d\n",
	   disk_interface.if_width,
	   disk_interface.if_height);
    if (ifp->if_fd == 1) {
	fb_log("File \"-\" reads from stdin, writes to stdout\n");
    } else {
	fb_log("Note: you may have just created a disk file\n");
	fb_log("called \"%s\" by running this.\n", ifp->if_name);
    }

    return 0;
}