ken@turtleva.UUCP (Ken Turkowski) (12/22/83)
echo x - drivers/ae_util.c cat >drivers/ae_util.c <<'!Funky!Stuff!' /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Utility routines for the Big Frame Buffer Entries: - bbopen() - opens frame buffer returns 1 if successful, -1 if failed - bbclose()- closes frame buffer so it may be used by another process - bbinit() - opens frame buffer calls reset_bb() returns 1 if successful, -1 if failed - bbquiet_init() - same as bbinit() but does not write error message - reset_bb() - sets BB to raster mode, unzoomed with X and Y regs at lower left, clears miscellaneous control parameters - bbpalw() - loads pallette from supplied arrays - bbpalr() - reads back pallette into supplied arrays - bbwrite() - writes pixels on one scanline of BB, 32-bit write - bbwbyte() - writes pixels on one scanline of BB, selecting one of 4 bytes - bbwword() - writes pixels on one scanline of BB, select from 2 16-bit words - bbread() - reads pixels from one scanline of BB, 32-bit read - bbrbyte() - reads pixels from one scanline of BB, selecting one of 4 bytes - bbrword() - reads pixels from one scanline of BB, select from 2 16-bit words - bbzoom() - zooms picture by supplied factor and centers on supplied coordinates - bbset_cnt() - sets refresh count - bbget_cnt() - returns current refresh count ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ # include <sgtty.h> # include <stdio.h> #define BBMODE 2 static short fd; /* file descriptor */ static char *BBDEV = "/dev/ttyh7"; static char *AEDDEV = "/dev/ttyh7"; /* ++++++++++++++++++++++ AED_INIT +++++++++++++++++++++++++++++++++++++++ */ short aed_init() /* open and initialize AED */ { int arg; fd = open(AEDDEV,BBMODE); if ( fd < 0) { printf(" AED not available, sorry \n"); fflush(1); /* flush standard output */ return -1; } else { arg = NTTYDISC; ioctl(fd, TIOCSETD, &arg); arg = LLITOUT; ioctl(fd, TIOCLBIS, &arg); write(fd, "\033", 1); /* initialize to raster mode */ return 1; } } /* ++++++++++++++++++++++ AED_MOV +++++++++++++++++++++++++++++++++++++++ */ aed_mov(X, Y) short X, Y; { write(fd, "\033Q", 2); /* set CAP */ aed_coord(X, Y); } /* ++++++++++++++++++++++ AED_WPX +++++++++++++++++++++++++++++++++++++++ */ aed_wpx(pix) short pix; { char *buf; buf = "\033Tx"; buf[2] = pix; write(fd, buf, 3); } /* ++++++++++++++++++++++ AED_WRITE ++++++++++++++++++++++++++++++++++++++ */ aed_write(X, Y, pixels, numpix) /* write in pixels, raster order */ short X, Y; short *pixels; int numpix; { register int i; #ifdef DOESNTWORK char array[1024]; if (fd < 0) error(" AED access denied "); if (numpix > 1024) error(" Too many pixels in scanline "); for (i = 0; i < numpix; i++) { array[i] = pixels[i]; } write(fd, "\033Q", 2); /* set CAP */ aed_coord(X, Y); write(fd, "\033r", 2); /* define area of interest */ aed_coord(X + numpix - 1, Y); write(fd, "\033X", 2); /* write horizontal scan */ write(fd, array, numpix); /* Also DOESNTWORK */ register short *pixptr; static char buf[8] = { '\033', 'Q', 'z', 'x', 'y', '\033', 'T', 'p' }; if (fd < 0) error(" AED access denied "); pixptr = pixels; write(fd, "\033", 1); /* set graphics mode */ for (i = numpix; i > 0; i--) { buf[2] = ((X >> 4) & 0x10) | ((Y >> 8) & 0x1); buf[3] = X++; buf[4] = Y; buf[6] = *pixptr++; write(fd, buf, 8); } #else DOESNTWORK for (i = numpix; i > 0; i--) { aed_mov(X++, Y); aed_wpx(*pixels++); } #endif DOESNTWORK } /* ++++++++++++++++++++++ FB_PUTMAP +++++++++++++++++++++++++++++++++++++++ */ fb_putmap(red, grn, blu) short red[256], grn[256], blu[256]; { register int i; char palette[768]; register char *palptr; for (palptr = palette, i = 0; i < 256; i++) { *palptr++ = red[i]; *palptr++ = grn[i]; *palptr++ = blu[i]; } if (fd < 0) error(" AED access denied "); write(fd, "\033K\000\000", 4); write(fd, palette, 768); } /* ++++++++++++++++++++++++++++++ AED_COORD +++++++++++++++++++++++++++++++ */ aed_coord(x, y) short x, y; { char array[3]; array[0] = ((x >> 4) & 0x10) | ((y >> 8) & 0x1); array[1] = x; array[2] = y; write(fd, array, 3); } /* ++++++++++++++++++++++ AED_DONE +++++++++++++++++++++++++++++++++++++++ */ aed_done() { } /* ++++++++++++++++++++++ BBOPEN +++++++++++++++++++++++++++++++++++++++ */ short bbopen() /* grab frame buffer */ { fd = open(BBDEV,BBMODE); if ( fd < 0) { printf(" Big Buffer not available, sorry \n"); fflush(1); /* flush standard output */ return -1; } else { return 1; } } /* +++++++++++++++++++++++ BBCLOSE ++++++++++++++++++++++++++++++++++++ */ bbclose() /* close Big Buffer for another process to use */ { close(fd); fd = -1; } /* ++++++++++++++++++++++ BBINIT +++++++++++++++++++++++++++++++++++++++ */ short bbinit() /* grab BigBuffer */ { long bb_addr,dummy; short bbquiet_init(); fd = open(BBDEV,BBMODE); if ( bbquiet_init() < 0) { printf(" Big Buffer not available, sorry \n"); fflush(1); /* flush standard output */ return -1; } else { return 1; } } /* +++++++++++++++++++++ BBQUIET_INIT +++++++++++++++++++++++++++++++++++++++ */ short bbquiet_init() /* grab BigBuffer (quietly - no error message) */ { struct sgttyb ttybuf; fd = open(BBDEV,BBMODE); if ( fd < 0) { return -1; /* failure return */ } else { gtty(fd, &ttybuf); ttybuf.sg_flags |= RAW; stty(fd, &ttybuf); write(fd, "\033", 1); /* initialize to raster mode */ return 1; } } /* ++++++++++++++++++++++ RESET_BB ++++++++++++++++++++++++++++++++++++++ */ reset_bb() /* reset BB to raster mode unzoomed */ { long dummy; if (fd < 0) error(" Big buffer access denied "); write(fd, "\0330", 2); } /* ++++++++++++++++++++++++++++++ BBPALW ++++++++++++++++++++++++++++++++++ */ bbpalw(red,grn,blu,start,length) short red[],grn[],blu[],start,length; { register int i, count; char array[768]; register char *arrptr; if (fd < 0) error(" Big buffer access denied "); arrptr = array; i = start; for (count = length; count-- > 0; i++) { *arrptr++ = red[i]; *arrptr++ = grn[i]; *arrptr++ = blu[i]; } if (fd < 0) error(" Big buffer access denied "); write(fd, "\033K", 2); write(fd, array, 3 * length); } /* ++++++++++++++++++++++++++++++ BBWRITE +++++++++++++++++++++++++++++++++ */ bbwrite(X,Y,pixels,numpix) /* write 32-bit pixels in raster order */ short X,Y,numpix; long pixels[]; { char array[1024]; register int i; if (numpix > 1024) error(" Too many pixels in scanline "); for (i = 0; i < numpix; i++) { array[i] = pixels[i]; } if (fd < 0) error(" Big buffer access denied "); write(fd, "\033Q", 2); /* set CAP */ aed_coord(X, Y); write(fd, "r", 1); /* define area of interest */ aed_coord(X + numpix - 1, Y); write(fd, "X", 1); /* write horizontal scan */ write(fd, array, numpix); } /* ++++++++++++++++++++++++++++++ BBWBYTE +++++++++++++++++++++++++++++++++ */ bbwbyte(byte,X,Y,pixels,numpix) /* write selected byte in pixels, raster order*/ short byte,X,Y,numpix; short pixels[]; { char array[1024]; register int i; if (numpix > 1024) error(" Too many pixels in scanline "); for (i = 0; i < numpix; i++) { array[i] = pixels[i]; } if (fd < 0) error(" Big buffer access denied "); write(fd, "\033Q", 2); /* set CAP */ aed_coord(X, Y); write(fd, "r", 1); /* define area of interest */ aed_coord(X + numpix - 1, Y); write(fd, "X", 1); /* write horizontal scan */ write(fd, array, numpix); } /* ++++++++++++++++++++++++++++++ BBREAD +++++++++++++++++++++++++++++++++ */ bbread(X,Y,pixels,numpix) /* read 32-bit pixels in raster order */ short X,Y,numpix; long pixels[]; { char array[1024]; register int i; if (numpix > 1024) error(" Too many pixels in scanline "); if (fd < 0) error(" Big buffer access denied "); write(fd, "\033Q", 2); /* set CAP */ aed_coord(X, Y); write(fd, "r", 1); /* define area of interest */ aed_coord(X + numpix - 1, Y); write(fd, "t", 1); /* read horizontal scan */ read(fd, array, numpix); for (i = 0; i < numpix; i++) { pixels[i] = array[i]; } } /* ++++++++++++++++++++++++++++++ BBRBYTE +++++++++++++++++++++++++++++++++ */ bbrbyte(byte,X,Y,pixels,numpix) /* read selected byte in pixels, raster order */ short byte,X,Y,numpix; short pixels[]; { char array[1024]; register int i; if (numpix > 1024) error(" Too many pixels in scanline "); if (fd < 0) error(" Big buffer access denied "); write(fd, "\033Q", 2); /* set CAP */ aed_coord(X, Y); write(fd, "r", 1); /* define area of interest */ aed_coord(X + numpix - 1, Y); write(fd, "t", 1); /* read horizontal scan */ read(fd, array, numpix); for (i = 0; i < numpix; i++) { pixels[i] = array[i]; } } error(fmt, arg1, arg2, arg3) char *fmt; int arg1, arg2, arg3; { fprintf(stderr, fmt, arg1, arg2, arg3); } fbquad(quad) /* initialization with quadrant as argument */ short quad; { short bbinit(); return(bbinit()); } fbwrite(X,Y,buffer,numpix) /* write from 'buffer' to FB */ short X,Y,numpix,buffer[]; { bbwbyte(0,X,Y,buffer,numpix); } bbzoom() { } nocore() { } get_bb() { } fbpalw() { } !Funky!Stuff!