#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 *nvvram; static int imgw; static int imgh; static int imgx; static int imgy; static void putcmap(unsigned char map[256*3]) { int i; bt->addr = 0; for (i=0;i<256*3;i++) bt->cmap = map[i] * 0x01000000; } 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); nvvram = 0x16000 + (unsigned char *)mrv; vram = nvvram; } static void midblockeof(void) __attribute__((__noreturn__)); static void midblockeof(void) { fprintf(stderr,"%s: unexpected EOF\n",__progname); exit(1); } static void clearfb(void) { while (fb->s & 0x10000000) ; fb->pm = 0xff; fb->fg = 0; fb->arecty = 0; fb->arectx = 0; fb->arecty = 900; fb->arectx = 1152; while ((fb->draw & 0xa0000000) == 0xa0000000) ; while (fb->s & 0x10000000) ; } static void block_size(void) { if (scanf("%d%d",&imgw,&imgh) != 2) midblockeof(); getchar(); imgx = (1152 - imgw) / 2; imgy = (900 - imgh) / 2; clearfb(); } static void block_map(void) { char cmap[256*3]; if (fread(&cmap[0],1,256*3,stdin) != 256*3) midblockeof(); putcmap(&cmap[0]); } static void block_image(void) { int y; unsigned char *fbram; fbram = nvvram + (imgy * 1152) + imgx; for (y=0;y