#include #include #include #include #include #include #include #include extern const char *__progname; #include "gl-int.h" #include "gl-md-asm.h" static const char *defpath = "/dev/bwtwo0"; static struct gl_fb1 fb; static struct gl_fb1 shadow; #define NOMINAL_AR (NOMINAL_XSIZE/(double)NOMINAL_YSIZE) static int x_probe_big(const char *path) { int fd; caddr_t mm; struct fbtype fbtype; double ar; if (! path) path = defpath; fd = open(path,O_RDWR,0); if (fd < 0) return(0); if ( (ioctl(fd,FBIOGTYPE,&fbtype) < 0) || (fbtype.fb_depth != 1) ) { close(fd); return(0); } mm = mmap(0,fbtype.fb_size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0); if (mm == (caddr_t)-1) { fprintf(stderr,"%s: mmap %s: %s\n",__progname,path,strerror(errno)); exit(1); } fb.vram = (void *) mm; close(fd); ar = fbtype.fb_width / (double)fbtype.fb_height; fb.stride = (fbtype.fb_width + 7) / 8; fb.xsize = fbtype.fb_width; fb.ysize = fbtype.fb_height; if (ar < (NOMINAL_AR*.9)) { fb.ysize = fb.xsize / NOMINAL_AR; fb.vram += fb.stride * ((fbtype.fb_height-fb.ysize)/2); } else if (ar > (NOMINAL_AR/.9)) { fb.xsize = fb.ysize * NOMINAL_AR; fb.vram += (fbtype.fb_width - fb.xsize) / 16; } fb.size = fb.stride * fb.ysize; shadow.stride = (fb.xsize + 7) / 8; shadow.xsize = fb.xsize; shadow.ysize = fb.ysize; shadow.size = shadow.stride * shadow.ysize; #ifdef MAP_ANON mm = mmap(0,shadow.size,PROT_READ|PROT_WRITE,MAP_ANON,-1,0); if (mm == (caddr_t)-1) { fprintf(stderr,"%s: mmap scratch space: %s\n",__progname,strerror(errno)); exit(1); } #else fd = open("/dev/zero",O_RDWR,0); if (fd < 0) { fprintf(stderr,"%s: can't open /dev/zero: %s\n",__progname,strerror(errno)); exit(1); } mm = mmap(0,shadow.size,PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,0); if (mm == (caddr_t)-1) { fprintf(stderr,"%s: mmap scratch space: %s\n",__progname,strerror(errno)); exit(1); } close(fd); #endif shadow.vram = (void *) mm; XMAXSCREEN = shadow.xsize; YMAXSCREEN = shadow.ysize; PIXELSCALE = shadow.xsize / (double)NOMINAL_XSIZE; return(1); } static int x_probe_small(const char *path) { int fd; caddr_t fbmm; caddr_t shmm; struct fbtype fbtype; double ar; unsigned char *grey1; unsigned char *grey2; int w; int i; if (! path) path = defpath; fd = open(path,O_RDWR,0); if (fd < 0) return(0); if ( (ioctl(fd,FBIOGTYPE,&fbtype) < 0) || (fbtype.fb_depth != 1) ) { close(fd); return(0); } fbmm = mmap(0,fbtype.fb_size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0); if (fbmm == (caddr_t)-1) { fprintf(stderr,"%s: mmap %s: %s\n",__progname,path,strerror(errno)); exit(1); } fb.vram = (void *) fbmm; close(fd); ar = fbtype.fb_width / (double)fbtype.fb_height; fb.stride = (fbtype.fb_width + 7) / 8; fb.xsize = fbtype.fb_width; fb.ysize = fbtype.fb_height; if (ar < (NOMINAL_AR*.9)) { fb.ysize = fb.xsize / NOMINAL_AR; fb.vram += fb.stride * ((fbtype.fb_height-fb.ysize)/2); } else if (ar > (NOMINAL_AR/.9)) { fb.xsize = fb.ysize * NOMINAL_AR; fb.vram += (fbtype.fb_width - fb.xsize) / 8; } i = fb.ysize / 2; fb.vram += fb.stride * ((fb.ysize-i) / 2); fb.ysize = i; i = ((fb.xsize / 2) >> 3) << 3; { char *v; v = getenv("BWTWO_OFFSET"); if (v) fb.vram += atoi(v); } { char *v; v = getenv("BWTWO_STRETCH"); if (v) i += 8 * atoi(v); } fb.vram += (fb.xsize - i) / 16; fb.xsize = i; fb.size = fb.stride * fb.ysize; shadow.stride = (fb.xsize + 7) / 8; shadow.xsize = fb.xsize; shadow.ysize = fb.ysize; shadow.size = shadow.stride * shadow.ysize; #ifdef MAP_ANON shmm = mmap(0,shadow.size,PROT_READ|PROT_WRITE,MAP_ANON,-1,0); if (shmm == (caddr_t)-1) { fprintf(stderr,"%s: mmap scratch space: %s\n",__progname,strerror(errno)); exit(1); } #else fd = open("/dev/zero",O_RDWR,0); if (fd < 0) { fprintf(stderr,"%s: can't open /dev/zero: %s\n",__progname,strerror(errno)); exit(1); } shmm = mmap(0,shadow.size,PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,0); if (shmm == (caddr_t)-1) { fprintf(stderr,"%s: mmap scratch space: %s\n",__progname,strerror(errno)); exit(1); } close(fd); #endif w = (fbtype.fb_width + 7) / 8; grey1 = malloc(2*w); grey2 = grey1 + w; memset(grey1,0x55,w); memset(grey2,0xaa,w); for (i=0;i