ken@turtleva.UUCP (Ken Turkowski) (12/22/83)
echo x - drivers/bb.h cat >drivers/bb.h <<'!Funky!Stuff!' /* bb.h - header file for Marc2 frame buffer access */ #define BBMODE 2 static char *BBDEV = "/dev/bb0"; #define u_short unsigned short typedef struct { u_short UBA_csr,dummy1; /* the 1st 16 regs. do a 32-bit write */ u_short dataLSB,dataMSB; /* on MSB, 32-bit read on LSB */ u_short r_m_wLSB,r_m_wMSB; u_short r_lm_wLSB,r_lm_wMSB; u_short cntrlLSB,cntrlMSB; short Xpos,Ypos; u_short alu1LSB,alu1MSB; u_short alu2LSB,alu2MSB; u_short dummy2,dummy3; /* the upper 16 regs. read and write */ u_short data2LSB,data2MSB; /* on either word */ u_short r_m_w2LSB,r_m_w2MSB; u_short r_lm_w2LSB,r_lm_w2MSB; } bbdevice; static bbdevice *bb; typedef union { struct { unsigned short LSB,MSB; } w; struct { char red,grn,blu,cvr; } b; } four_byte_pixel; #define TRUE 1 #define FALSE 0 #define LONG_W 100 #define LONG_R 101 #define LONG_RMW 102 #define SHORT_W 200 #define SHORT_R 201 #define SET_RFSH_CNT 300 #define GET_RFSH_CNT 301 #define CTL_WRD_W 400 #define CTL_WRD_R 401 #define CTL_WRD_AND 402 #define CTL_WRD_OR 403 #define GET_ADDR 500 #define START_PLAYBACK 600 #define STOP_PLAYBACK 601 #define SHARE 700 #define UNIBUS_CTL 0 #define DATA_WD 2 #define RMW_WD 4 #define L_RMW_WD 6 #define BB_CTL_WD 8 #define XY_ADDR_WD 10 #define ALU_PRIM 12 #define ALU_SECND 14 #define DATA_SHRT 18 #define RMW_SHRT 20 #define L_RMW_SHRT 22 !Funky!Stuff! echo x - drivers/bb_util.c cat >drivers/bb_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 - get_bb() - opens frame buffer calls reset_bb() and returns pointer to Unibus registers - reset_bb() - sets BB to raster mode, unzoomed with X and Y regs at lower left, clears miscellaneous control parameters - bbcntrlw() - writes into output control section - bbcntrlr() - reads from output control section - 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 <bb.h> #define BBMODE 2 static short fd; /* file descriptor */ static char *BBDEV = "/dev/bb0"; /* ++++++++++++++++++++++ BBOPEN +++++++++++++++++++++++++++++++++++++++ */ short bbopen() /* grab BigBuffer */ { long bb_addr,dummy; 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; fd = open(BBDEV,BBMODE); if ( fd < 0) { printf(" Big Buffer not available, sorry \n"); fflush(1); /* flush standard output */ return -1; } else { ioctl(fd,300,&dummy); /* initialize to raster mode */ return 1; } } /* +++++++++++++++++++++ BBQUIET_INIT +++++++++++++++++++++++++++++++++++++++ */ short bbquiet_init() /* grab BigBuffer (quietly - no error message) */ { long bb_addr,dummy; fd = open(BBDEV,BBMODE); if ( fd < 0) return -1; /* failure return */ else { ioctl(fd,300,&dummy); /* initialize to raster mode */ return 1; } } /* ++++++++++++++++++++++ GET_BB +++++++++++++++++++++++++++++++++++++++ */ bb_regs *get_bb() /* grab BigBuffer and return base address */ { long bb_addr,dummy; fd = open(BBDEV,BBMODE); if ( fd < 0) { printf(" Big Buffer not available, sorry \n"); fflush(1); /* flush standard output */ return (bb_regs *)-1; } else { ioctl(fd,100,&bb_addr); /* get unibus address */ ioctl(fd,300,&dummy); /* initialize to raster mode */ return (bb_regs *)bb_addr; } } /* ++++++++++++++++++++++ RESET_BB ++++++++++++++++++++++++++++++++++++++ */ reset_bb() /* reset BB to raster mode unzoomed */ { long dummy; if (fd < 0) error(" Big buffer access denied "); ioctl(fd,300,&dummy); } /* +++++++++++++++++++++++++++++ BBCNTRLW ++++++++++++++++++++++++++++++++++ */ bbcntrlw(X,Y,pixels,numpix) /* write to output control section */ short X,Y,numpix; long pixels[]; { long array[4],dum; if (fd < 0) error(" Big buffer access denied "); dum = pixels[0]; /* check address before going to kernel mode */ array[0] = X; array[1] = Y; array[2] = (long)pixels; array[3] = numpix; ioctl(fd,150,array); } /* +++++++++++++++++++++++++++++ BBCNTRLR ++++++++++++++++++++++++++++++++++ */ bbcntrlr(X,Y,pixels,numpix) /* read from output control section */ short X,Y,numpix; long pixels[]; { long array[4],dum; if (fd < 0) error(" Big buffer access denied "); dum = pixels[0]; /* check address before going to kernel mode */ array[0] = X; array[1] = Y; array[2] = (long)pixels; array[3] = numpix; ioctl(fd,160,array); } /* ++++++++++++++++++++++++++++++ BBPALW ++++++++++++++++++++++++++++++++++ */ bbpalw(red,grn,blu,start,length) short red[],grn[],blu[],start,length; { short i,X,Y,dum; long array[5]; if (fd < 0) error(" Big buffer access denied "); dum = red[0]; dum = grn[0]; dum = blu[0]; /* check addresses */ array[0] = start; array[1] = length; array[2] = (long)red; array[3] = (long)grn; array[4] = (long)blu; ioctl(fd,310,array); } /* ++++++++++++++++++++++++++++++ BBPALR ++++++++++++++++++++++++++++++++++ */ bbpalr(red,grn,blu,start,length) short red[],grn[],blu[],start,length; { short dum,i,X,Y; long array[5]; if (fd < 0) error(" Big buffer access denied "); dum = red[0]; dum = grn[0]; dum = blu[0]; /* check addresses */ array[0] = start; array[1] = length; array[2] = (long)red; array[3] = (long)grn; array[4] = (long)blu; ioctl(fd,320,array); } /* ++++++++++++++++++++++++++++++ BBWRITE +++++++++++++++++++++++++++++++++ */ bbwrite(X,Y,pixels,numpix) /* write 32-bit pixels in raster order */ short X,Y,numpix; long pixels[]; { short i; long array[4],dum; if (fd < 0) error(" Big buffer access denied "); dum = pixels[0]; /* check address before going to kernel mode */ array[0] = X; array[1] = Y; array[2] = (long)pixels; array[3] = numpix; ioctl(fd,330,array); } /* ++++++++++++++++++++++++++++++ BBWBYTE +++++++++++++++++++++++++++++++++ */ bbwbyte(byte,X,Y,pixels,numpix) /* write selected byte in pixels, raster order*/ short byte,X,Y,numpix; short pixels[]; { short i,dum; long array[5]; if (fd < 0) error(" Big buffer access denied "); dum = pixels[0]; /* check address before going to kernel mode */ array[0] = byte; array[1] = X; array[2] = Y; array[3] = (long)pixels; array[4] = numpix; ioctl(fd,340,array); } /* ++++++++++++++++++++++++++ BBWWORD ++++++++++++++++++++++++++++++++++++++ */ bbwword(word,X,Y,pixels,numpix) /* write into 16-bit short words */ short word,X,Y,numpix,pixels[]; { long array[5]; short dum; if (fd < 0) error(" Big buffer access denied "); dum = pixels[0]; /* check address before going to kernel mode */ array[0] = word; array[1] = X; array[2] = Y; array[3] = (long)pixels; array[4] = numpix; ioctl(fd,350,array); } /* ++++++++++++++++++++++++++++++ BBREAD +++++++++++++++++++++++++++++++++ */ bbread(X,Y,pixels,numpix) /* read 32-bit pixels in raster order */ short X,Y,numpix; long pixels[]; { long array[4],dum; if (fd < 0) error(" Big buffer access denied "); dum = pixels[0]; /* check address before going to kernel mode */ array[0] = X; array[1] = Y; array[2] = (long)pixels; array[3] = numpix; ioctl(fd,360,array); } /* ++++++++++++++++++++++++++++++ BBRBYTE +++++++++++++++++++++++++++++++++ */ bbrbyte(byte,X,Y,pixels,numpix) /* read selected byte in pixels, raster order */ short byte,X,Y,numpix; short pixels[]; { long array[5]; short dum; if (fd < 0) error(" Big buffer access denied "); dum = pixels[0]; array[0] = byte; array[1] = X; array[2] = Y; array[3] = (long)pixels; array[4] = numpix; ioctl(fd,370,array); } /* ++++++++++++++++++++++++++ BBRWORD ++++++++++++++++++++++++++++++++++++++ */ bbrword(word,X,Y,pixels,numpix) /* read from 16-bit short words */ short word,X,Y,numpix,pixels[]; { long array[5]; short dum; if (fd < 0) error(" Big buffer access denied "); dum = pixels[0]; array[0] = word; array[1] = X; array[2] = Y; array[3] = (long)pixels; array[4] = numpix; ioctl(fd,380,array); } /* +++++++++++++++++++++++++++++ BBZOOM ++++++++++++++++++++++++++++++++++++ */ bbzoom(mult,X,Y) /* zoom by factor of 'mult', center on (X,Y) */ short mult,X,Y; { short Xofset,Yofset; long array[3]; Xofset = 320/mult; Yofset = 242/mult; array[0] = mult; /* load zoom factor */ array[1] = (X + 10 - Xofset) / 20; /* x-coord for left side */ array[2] = 2 * (Y + Yofset) / 2; /* y-coord for upper side */ while (array[2] < 0) array[2] += 484; /* restrict to visible & invert */ array[2] %= 484; array[2] = 483 - array[2]; bbcntrlw(1,501,array,3); } /* +++++++++++++++++++++++++++ BBSET_CNT ++++++++++++++++++++++++++++++++ */ bbset_cnt(count) /* set frame count and enable end-of-frame interrupts */ short count; { long frame_count; if (fd < 0) error(" Big buffer access denied "); frame_count = count; ioctl(fd,201,&frame_count); } /* +++++++++++++++++++++++++++ BBGET_CNT ++++++++++++++++++++++++++++++++++++ */ long bbget_cnt() /* retrieve frame count */ { long frame_count; if (fd < 0) error(" Big buffer access denied "); ioctl(fd,200,&frame_count); return frame_count; } !Funky!Stuff!