/* Written by Steve Kenessey 09/28/98 */
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/fbio.h>
#include <sys/visual_io.h>



/* frame buffer type codes */
static	char *typenames[] = {
	  "SUN1BW", "SUN1COLOR", "SUN2BW", "SUN2COLOR", "SUN2GP",
	  "SUN5COLOR", "SUN3COLOR", "MEMCOLOR", "SUN4COLOR",
	  "reserved for customer", "reserved for customer",
	  "reserved for customer", "SUNFAST_COLOR", "SUNROP_COLOR",
	  "SUNFB_VIDEO", "SUNGIFB", "SUNGPLAS", "SUNGP3", "SUNGT",
	  "SUNLEO", "MDICOLOR",
	} ;

#define	NTYPES	(sizeof(typenames)/sizeof(typenames[0]))

void main(int argc,char **argv)
{
  struct fbtype type;
  struct fbgattr attrs;
  struct fbinfo info;
  struct cg6_info cg6info;
  struct mon_info moninfo;
  struct vis_identifier id;
  int fd,ret,opd;
  char *fname;

  if (argc > 1)
     fname=argv[1];
  else
     fname="/dev/fb";
  
  if ((fd=open(fname,O_RDONLY)) < 0){
	perror(fname);
        exit(1);
  }

  if (ioctl(fd,VIS_GETIDENTIFIER,&id) >= 0){
	printf("fb identifier = %s\n", id.name) ;
  } else {
        perror("VIS_GETIDENTIFIER ioctl failed");
        exit(2);
  }

  if ((ret=ioctl(fd,FBIOGATTR,&attrs)) >= 0){
      printf("real_type = %d (%s)\nowner=%d\n",
	attrs.real_type,
	(attrs.real_type < NTYPES) ? typenames[attrs.real_type] : "new",
	attrs.owner) ;
      printf("fb_type=%d (%s)\nfb_height=%d\nfb_width=%d\nfb_depth=%d\nfb_cmsize=%d\nfb_size=%d\n", \
	  attrs.fbtype.fb_type,
	  (attrs.fbtype.fb_type < NTYPES) ?
		typenames[attrs.fbtype.fb_type] : "new",
          attrs.fbtype.fb_height, attrs.fbtype.fb_width,
	  attrs.fbtype.fb_depth, attrs.fbtype.fb_cmsize, attrs.fbtype.fb_size);
      printf("flags=%x\nemulation=%d\ndev_specific=%x %x %x %x %x %x %x %x\n",
	  attrs.sattr.flags, attrs.sattr.emu_type,
	  attrs.sattr.dev_specific[0], attrs.sattr.dev_specific[1],
	  attrs.sattr.dev_specific[2], attrs.sattr.dev_specific[3],
	  attrs.sattr.dev_specific[4], attrs.sattr.dev_specific[5],
	  attrs.sattr.dev_specific[6], attrs.sattr.dev_specific[7]) ;
      printf("emulation types=%d %d %d %d\n",
	  attrs.emu_types[0], attrs.emu_types[1],
	  attrs.emu_types[2], attrs.emu_types[3]) ;
  } else {
      perror("FBIOGATTR ioctl failed");
  }

  if ((ret=ioctl(fd,FBIOGTYPE,&type)) >= 0){
      printf("fb_type=%d (%s)\nfb_height=%d\nfb_width=%d\nfb_depth=%d\nfb_cmsize=%d\nfb_size=%d\n", \
	  type.fb_type,
	  (type.fb_type < NTYPES) ? typenames[type.fb_type] : "new",
          type.fb_height,type.fb_width,
	  type.fb_depth,type.fb_cmsize,type.fb_size);
  } else {
      perror("FBIOGTYPE ioctl failed");
      printf("ioctl ret=%d\n",ret);
  }

  if ((ret=ioctl(fd,FBIOGXINFO,&cg6info)) >= 0){
      printf("accessible_width=%hu\naccessible_height=%hu\nline_bytes=%hu\nhdb_capable=%hu\nvmsize=%hu\n", \
	cg6info.accessible_width,cg6info.accessible_height,
	cg6info.line_bytes,cg6info.hdb_capable,\
	cg6info.vmsize); 
    printf("boardrev=%hx\nsbus slot=%hx\n", cg6info.boardrev,cg6info.slot);
  } else {
      perror("FBIOGXINFO ioctl failed");
      printf("ioctl ret=%d\n",ret);
  }
  if ((ret=ioctl(fd,FBIOMONINFO,&moninfo)) >= 0){
      printf("mon_type=%lu\npixfreq=%lu\nhfreq=%lu\nvfreq=%lu\nvsync=%lu\nhsync=%lu\n", \
	moninfo.mon_type,moninfo.pixfreq,moninfo.hfreq,moninfo.vfreq,\
	moninfo.vsync,moninfo.hsync); 
  } else {
      perror("FBIOMONINFO ioctl failed");
      printf("ioctl ret=%d\n",ret);
  }
  close(fd);
}

