#include #include #include #include #include #include #include #include extern const char *__progname; static const char *fbpath = "/dev/cgsix1"; static int fbfd; static volatile struct cg6thc *thc; static volatile struct cg6tec *tec; static volatile struct cg6fbc *fbc; static volatile unsigned char *vram; static unsigned int fbsnap1[1152*900/4]; static unsigned int fbsnap2[1152*900/4]; static unsigned int fbsnap3[1152*900/4]; #define TECSIZE (0x1000/4) static unsigned int tecsnap[TECSIZE]; static void resethw(void) { thc->cursxy = 0xffe0ffe0; tec->mv = 0; tec->clip = 0; tec->vdc = 0; fbc->s = 0; fbc->bg = 0; fbc->pixelm = ~0; fbc->s = 0; fbc->alu = ALU_NORMAL | ALU_FG; fbc->mode = MODE_NORMAL | MODE_COLOR8; fbc->clip = 0; fbc->offx = 0; fbc->offy = 0; fbc->clipminx = 0; fbc->clipminy = 0; fbc->clipmaxx = 1151; fbc->clipmaxy = 899; fbc->fg = 0; fbc->pm = ~0; } static void initfb(void) { void *mrv; struct fbgattr a; fbfd = open(fbpath,O_RDWR,0); if (fbfd < 0) { fprintf(stderr,"%s: can't open %s: %s\n",__progname,fbpath,strerror(errno)); exit(1); } if ( (ioctl(fbfd,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) ) { fprintf(stderr,"%s: %s isn't an 1152x900 cgsix\n",__progname,fbpath); exit(1); } mrv = mmap(0,0x16000+a.fbtype.fb_size,PROT_READ|PROT_WRITE,MAP_SHARED,fbfd,0x70000000); if (mrv == MAP_FAILED) { fprintf(stderr,"%s: can't mmap %s: %s\n",__progname,fbpath,strerror(errno)); exit(1); } fbc = mrv; thc = (void *)(0x5000+(unsigned char *)mrv); tec = (void *)(0x1000+(unsigned char *)mrv); vram = 0x16000 + (unsigned char *)mrv; resethw(); fbc->fg = 0; fbc->pm = ~0; fbc->arecty = 0; fbc->arectx = 0; fbc->arecty = 900; fbc->arectx = 1152; while (fbc->s & 0x10000000) ; fbc->clipminx = 0; fbc->clipminy = 0; fbc->clipmaxx = 1151; fbc->clipmaxy = 899; fbc->pm = 0x0f; } static void fbdrain(void) { while (fbc->s & 0x10000000) ; } static void usage(void) { fprintf(stderr,"Usage: %s [-fb fbdev] [-kb|-kbd kbdev] modelfile\n",__progname); } static void handleargs(int ac, char **av) { int skip; int errs; skip = 0; errs = 0; for (ac--,av++;ac;ac--,av++) { if (skip > 0) { skip --; continue; } if (**av != '-') { fprintf(stderr,"%s: extra argument `%s'\n",__progname,*av); errs ++; continue; } if (0) { needarg:; fprintf(stderr,"%s: %s needs a following argument\n",__progname,*av); errs ++; continue; } #define WANTARG() do { if (++skip >= ac) goto needarg; } while (0) if (!strcmp(*av,"-fb")) { WANTARG(); fbpath = av[skip]; continue; } #undef WANTARG fprintf(stderr,"%s: unrecognized option `%s'\n",__progname,*av); errs ++; } if (errs) { usage(); exit(1); } } static void clearit(void) { fbc->fg = 0; fbc->pm = ~0; fbc->arecty = 0; fbc->arectx = 0; fbc->arecty = 900; fbc->arectx = 1152; while ((fbc->draw & 0xa0000000) == 0xa0000000) ; } static void drawit(void) { fbc->fg = 0xff; fbc->aquadz = 0; fbc->aquady = 100; fbc->aquadx = 100; fbc->aquadz = 0; fbc->aquady = 100; fbc->aquadx = 300; fbc->aquadz = 0; fbc->aquady = 200; fbc->aquadx = 200; fbc->aquadz = 0; fbc->aquady = 150; fbc->aquadx = 50; while ((fbc->draw & 0xa0000000) == 0xa0000000) ; } int main(int, char **); int main(int ac, char **av) { int i; int j; int k; setlinebuf(stdout); handleargs(ac,av); initfb(); clearit(); fbdrain(); for (i=((1152*900)/4)-1;i>=0;i--) fbsnap1[i] = ((volatile unsigned int *)vram)[i]; drawit(); fbdrain(); for (i=((1152*900)/4)-1;i>=0;i--) fbsnap2[i] = ((volatile unsigned int *)vram)[i]; for (i=0;i=0;k--) fbsnap3[k] = ((volatile unsigned int *)vram)[k]; if (! bcmp(&fbsnap1[0],&fbsnap3[0],1152*900)) { printf("%4d %2d b\n",i,j); } else if (! bcmp(&fbsnap2[0],&fbsnap3[0],1152*900)) { printf("%4d %2d o\n",i,j); } else { printf("%4d %2d !\n",i,j); } ((volatile unsigned int *)tec)[i] = tecsnap[i]; } } exit(0); }