#include #include #include #include #include #include #include #include #include #include #include #include #include extern const char *__progname; #include "cg6.h" static const char *fbpath = "/dev/cgsix0"; static unsigned char cmap[16][3] = { { 0, 0, 0 }, { 0, 0, 255 }, { 0, 255, 0 }, { 0, 255, 255 }, { 255, 0, 0 }, { 255, 0, 255 }, { 255, 255, 0 }, { 255, 255, 255 }, { 160, 160, 160 }, { 0, 0, 255 }, { 0, 255, 0 }, { 0, 255, 255 }, { 255, 0, 0 }, { 255, 0, 255 }, { 255, 255, 0 }, { 255, 255, 255 } }; static int fbfd; static volatile struct cg6fbc *fb; static volatile struct brooktree *bt; static volatile unsigned char *vram; static unsigned char vgmem[0x4000]; static unsigned char colour_lookup[32]; static int drawbit; /* The assembly part of the vector generator */ extern int s_vg(const unsigned char *, volatile struct cg6fbc *, unsigned int, const unsigned char *, unsigned int); static void drain(void) { while (fb->s & 0x10000000) ; } static void setupfb(void) { void *mrv; struct fbgattr a; fbfd = open(fbpath,O_RDWR,0); if (fbfd < 0) { fprintf(stderr,"%s: %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) ) { close(fbfd); fprintf(stderr,"%s: %s: not a cg6\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); } fb = mrv; bt = (void *)(0x2000+(unsigned char *)mrv); vram = 0x16000 + (unsigned char *)mrv; drawbit = 0; fb->bg = 0; fb->pixelm = ~0; fb->s = 0; fb->mode = MODE_NORMAL | MODE_COLOR8; fb->alu = ALU_NORMAL | ALU_FG; fb->clip = 0; fb->offx = 0; fb->offy = 0; fb->clipminx = 0; fb->clipminy = 0; fb->clipmaxx = 1151; fb->clipmaxy = 899; fb->pm = ~0; drain(); fb->clipminx = 0; fb->clipminy = 0; fb->clipmaxx = 1151; fb->clipmaxy = 899; fb->pm = ~0; } static void setcmap(int bit) { int i; int v; bt->addr = 0; for (i=0;i<=255;i++) { v = (bit ? (i >> 4) : i) & 15; bt->cmap = cmap[v][0] * 0x01000000; bt->cmap = cmap[v][1] * 0x01000000; bt->cmap = cmap[v][2] * 0x01000000; } } static void draw(void) { while ((fb->draw & 0xa0000000) == 0xa0000000) ; } static void fbrect(int fg, int x1, int y1, int x2, int y2) { fb->fg = 0x11 * fg; fb->arecty = y1; fb->arectx = x1; fb->arecty = y2; fb->arectx = x2; draw(); } int main(void); int main(void) { setupfb(); drain(); setcmap(0); fb->alu = ALU_NORMAL | ALU_FG; fbrect(0,0,0,1151,899); if ( (fread(&vgmem[0],1,0x4000,stdin) == 0x4000) && (fread(&colour_lookup[0],1,32,stdin) == 32) ) { static void result(const char *tag, int rv) { switch (rv) { case 0: break; case 1: printf("%s: invalid pc\n",tag); break; case 2: printf("%s: cycle limit\n",tag); break; case 3: printf("%s: stack overflow\n",tag); break; case 4: printf("%s: stack underflow\n",tag); break; default: printf("?%d\n",rv); break; } } fb->alu = ALU_NORMAL | ALU_FG | ALU_DST; result("main",s_vg(&vgmem[0],fb,1,&colour_lookup[0],0x01000000)); result("aux",s_vg(&vgmem[0x2000],fb,1,&colour_lookup[16],0x01000000)); } return(0); }