#include #include #include #include #include #include #include #include extern const char *__progname; #include "cg6.h" static const char *devpath = "/dev/cgsix0"; static int fd; static volatile struct cg6fb *fb; static volatile struct brooktree *bt; static volatile unsigned char *vram; static unsigned char cm_r[256]; static unsigned char cm_g[256]; static unsigned char cm_b[256]; static void getcmap(void) { int i; bt->addr = 0; for (i=0;i<256;i++) { cm_r[i] = (bt->cmap >> 24); cm_g[i] = (bt->cmap >> 24); cm_b[i] = (bt->cmap >> 24); } } #if 0 static void savecmap(void) { oldcm.index = 0; oldcm.count = 256; oldcm.red = &oldcm_r[0]; oldcm.green = &oldcm_g[0]; oldcm.blue = &oldcm_b[0]; if (ioctl(fd,FBIOGETCMAP,&oldcm) < 0) { fprintf(stderr,"%s: FBIOGETCMAP: %s\n",__progname,strerror(errno)); exit(1); } } static void restorecmap(void) { oldcm.index = 0; oldcm.count = 256; oldcm.red = &oldcm_r[0]; oldcm.green = &oldcm_g[0]; oldcm.blue = &oldcm_b[0]; ioctl(fd,FBIOPUTCMAP,&oldcm); } #endif static void setup(void) { void *mrv; struct fbgattr a; fd = open(devpath,O_RDWR,0); if (fd < 0) { fprintf(stderr,"%s: %s: %s\n",__progname,devpath,strerror(errno)); exit(1); } if ( (ioctl(fd,FBIOGATTR,&a) < 0) || (a.fbtype.fb_type != FBTYPE_SUNFAST_COLOR) || (a.fbtype.fb_width != 1152) || (a.fbtype.fb_height != 900) || (a.fbtype.fb_depth != 8) ) { close(fd); fprintf(stderr,"%s: %s: not a cg6\n",__progname,devpath); exit(1); } mrv = mmap(0,0x16000+a.fbtype.fb_size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0x70000000); if (mrv == MAP_FAILED) { fprintf(stderr,"%s: can't mmap %s: %s\n",__progname,devpath,strerror(errno)); exit(1); } fb = mrv; bt = (void *)(0x2000+(unsigned char *)mrv); vram = 0x16000 + (unsigned char *)mrv; } static void dumpfb(void) { int y; int x; volatile const unsigned char *vp; unsigned char p; printf("P6\n1152 900\n255\n"); vp = vram; for (y=0;y<900;y++) { for (x=0;x<1152;x++) { p = *vp++; putchar(cm_r[p]); putchar(cm_g[p]); putchar(cm_b[p]); } } } int main(void); int main(void) { setup(); getcmap(); dumpfb(); exit(0); }