cgfour fb doesn't wait for vertical retrace

Bob Houvener rocket!bull!houvener at uunet.uu.net
Wed Jul 12 12:29:33 AEST 1989


The docs claim that the cgfour will wait till vertical retrace to change
the color buffer.  The following program shows that it doesn't.  Sun
support said "gee your right".  Can someone help me find a way to sync to
the monitor?

Please reply via mail too uunet!rocket!houvener

compile with 
cc -g -o test1.exe test1.c millisec.c -lm -lsuntool -lsunwindow -lpixrect

----test1.c
/************************************************************************
test.c 
   program to test FBIOVERTICAL signal
************************************************************************/
#include <stdio.h>
#include <sys/ioctl.h>
#include <sun/fbio.h>
#include <fcntl.h>
#include <time.h>

unsigned char red[256];
unsigned char blue[256];
unsigned char green[256];

struct fbcmap cmap =
{
  0,
  256,
  red,
  green,
  blue
};

int cg2;
int errno;
int i;
int return_val = 9999;
long clock(), cputime;


main()
{
  cg2 = open("/dev/cgfour0", O_RDWR);
  if(cg2 == (-1))
    {
      perror("open()");
      exit(errno);
    }
  return_val = ioctl(cg2, FBIOGETCMAP, &cmap);
  if(return_val == (-1))
    {
      perror("ioctl(fb, FBIOGETCMAP, &cmap)");
      exit(errno);
    }
  for(i=cmap.index; i<cmap.index + cmap.count; i++)
    {
      if(red[i] != 0 || green[i] != 0 || blue[i] != 0)
	(void)printf("%d: %d %d %d\n", i, red[i], green[i], blue[i]);
    }

  cputime = millisec();

  for (i=0; i<240; i++)
    {

    /*
      Wait for the vertical retrace of unit 0.  See the sample
      cgtwo driver in the guide to writing drivers manual.
      */

      red[0] = i;
      blue[254] = 255-i;

      {
	int j = 100000;
	while(j--);
      }
      return_val = ioctl(cg2, FBIOPUTCMAP, &cmap); 
      if(return_val == (-1))
	{
	  perror("ioctl(cg2, FBIOPUTCMAP, &cmap)");
	  exit(errno);
	}
    }
  (void)printf ("time to run %.5f secs.\n", (millisec() - cputime)/ 1.0e+3);
}

--- millisec.c
/**************************************************************************
 *
 * File Name: millisec.c	Get time in milliseconds.
 *
 * Description:
 *
 *	This routine will return the time in milliseconds.  The clock
 *	cycle is greater than 1 week.  That is, if an error occurs,
 *	it will be wrong once a week.  The probability is low that this
 *	will occur when used over short periods of time.
 *
 * Calling Sequence:
 *
 *	long millisec();
 *	long initial_time;
 *	initial_time = millisec();
 *
 **************************************************************************/

#include <sys/types.h>
#include <sys/timeb.h>

long millisec()
{
  struct timeb now;

  ftime (&now);

  return ((now.time & 0xfffff) * 1000 + now.millitm);
}



More information about the Comp.sys.sun mailing list