home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / sgi / hardware / 86 < prev    next >
Encoding:
Text File  |  1993-01-07  |  5.7 KB  |  215 lines

  1. Path: sparky!uunet!dtix!mimsy!nmrdc1!cbda8.apgea.army.mil.!adm!news
  2. From: john@sg25.aud.temple.edu (John W. Schwegler)
  3. Newsgroups: comp.sys.sgi.hardware
  4. Subject: Re: From where do I get a SYNC signal?
  5. Message-ID: <34915@adm.brl.mil>
  6. Date: 7 Jan 93 21:27:05 GMT
  7. Sender: news@adm.brl.mil
  8. Lines: 205
  9.  
  10.  
  11. Try the following code, which synchronizes a RESET signal on the parallel
  12. port out line with the swapping of screens (on our Indigo, it does so,
  13. anyway :)
  14.  
  15. This program generates a visual stimulus. Two types are available:
  16. checkerboard/gray scale, or checkerboard/inverse checkerboard. The parallel
  17. port signal comes out well synchronized with the screen refresh (use an
  18. oscilloscope to compare retrace/RESET signal for exact timing in your case).
  19. Just rip out the current drawing code and use the parallel port stuff.
  20.  
  21. By the way, the parallel port reset signal comes out on pin 16 of the
  22. DB-25 connector, according to the October comp.sys.sgi archives,
  23. courtesy of Dave Olson.
  24.  
  25. Compile and link the two source files below with -lgl_s -lc_s:
  26. ______________________________________________________________________________
  27. testmon.c: 
  28. ______________________________________________________________________________
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <math.h>
  32. #include <gl.h>
  33. #include <getopt.h>
  34. #include <limits.h>
  35. #include <sys/types.h>
  36. #include <sys/prctl.h>
  37. #include <sys/schedctl.h>
  38. #include <sys/lock.h>
  39.  
  40.  
  41.  
  42. extern char *optarg;
  43. extern int optind;
  44. int xm,ym;
  45. void make_gray(float gray);
  46. void make_pat(int firston,int h,int v);
  47.  
  48. main(int argc,char **argv)
  49. {
  50. int which_screen,count;
  51. pid_t sync_pid;
  52. int frame1=0,frame2=0;
  53. int nx=15,ny=12;
  54. int xset=0,yset=0;
  55. int use_gray=0;
  56. int nswap = 30;
  57. float gray_lev = 0.00;
  58. signed char c;
  59.  
  60. if (schedctl(NDPRI,0,NDPHIMIN-2) < 0) {
  61.         fprintf(stderr,"*******************************************\n");
  62.         fprintf(stderr,"WARNING: not running in high-priority mode!\n");
  63.         fprintf(stderr,"*******************************************\n");
  64.         sleep(3);
  65.         }
  66. if (plock(PROCLOCK) < 0) {
  67.         fprintf(stderr,"******************************\n");
  68.         fprintf(stderr,"WARNING: not locked in memory!\n");
  69.         fprintf(stderr,"******************************\n");
  70.         sleep(3);
  71.         }
  72. foreground();
  73. xm = getgdesc(GD_XPMAX);
  74. ym = getgdesc(GD_YPMAX);
  75. while ((c = getopt(argc,argv,"x:y:g:s:f:rh")) != -1) {
  76.         switch (c) {
  77.                 case 'x':
  78.                   nx = atoi(optarg);
  79.                   if (!yset) ny = (ym*nx)/xm;
  80.                   xset = 1;
  81.                   break;
  82.                 case 'y':
  83.                   ny = atoi(optarg);
  84.                   if (!xset) nx = (xm*ny)/ym;
  85.                   yset = 1;
  86.                   break;
  87.                 case 's':
  88.                   nswap = atoi(optarg);
  89.                   if (frame1 == 0) { 
  90.                         frame1 = nswap;
  91.                         frame2 = nswap;
  92.                         }
  93.                   break;
  94.                 case 'f':
  95.                   frame1 = atoi(optarg);
  96.                   frame2 = nswap;
  97.                   break;
  98.                 case 'g':
  99.                   use_gray = 1;
  100.                   gray_lev = atof(optarg);
  101.                   printf("Gray is %g.\n",gray_lev);
  102.                   break;
  103.                 case 'r':
  104.                   use_gray = 0;
  105.                   break;
  106.                 case 'h':
  107.                 case '?':
  108.                 default:
  109.                   fprintf(stderr,"usage: %s [-x nxpat] [-y nypat] [-g
  110. graylev] [-s swapint] [rh?]\n",
  111.                         argv[0]);
  112.                   exit(2);
  113.                 }
  114.         }
  115. noborder();
  116. init_plp();
  117. prefposition(0,xm-1,0,ym-1);
  118. winopen("test");
  119. doublebuffer();
  120. gconfig();
  121. make_pat(1,nx,ny);
  122. swapbuffers();
  123. if (use_gray) {
  124.         make_gray(gray_lev);
  125.         }
  126. else {
  127.         make_pat(0,nx,ny);
  128.         }
  129. which_screen = 1;
  130. while (1) {
  131.         if (which_screen == 1)
  132.                 swapinterval(frame1);
  133.         else
  134.                 swapinterval(frame2);
  135.         swapbuffers();
  136.         if (which_screen == 1)
  137.                 plp_trig();
  138.         which_screen = 3 - which_screen;
  139.         }
  140. }
  141.  
  142. void 
  143. make_pat(int firston,int h,int v)
  144. {
  145. float x,y;
  146. int j,k;
  147. int hcol,vcol;
  148.  
  149. x = ((float) xm)/h;
  150. y = ((float) ym)/v;
  151. vcol = firston;
  152. for (j=0; j < v; j++) {
  153.         hcol = vcol;
  154.         for (k=0; k < h; k++) {
  155.                 if (hcol) color(WHITE);
  156.                 else color(BLACK);
  157.                 rectf(x*k,y*j,(k+1)*x,(j+1)*y);
  158.                 hcol = 1-hcol;
  159.                 }
  160.         vcol = 1-vcol;
  161.         
  162.         }
  163. }
  164.  
  165. void 
  166. make_gray(float ngray)
  167. {
  168. float x,y;
  169. x = ((float) xm)-1;
  170. y = ((float) ym)-1;
  171. mapcolor(512,(short) (ngray*255.),(short) (255.*ngray),(short) (255.*ngray));
  172. gflush();
  173. qtest();
  174. color(512);
  175. rectf(0.,0.,x,y);
  176. }
  177. ______________________________________________________________________________
  178. plp.c:
  179. ______________________________________________________________________________
  180. #include <stdio.h>
  181. #include <sys/types.h>
  182. #include <sys/stat.h>
  183. #include <fcntl.h>
  184. #include <sys/plp.h>
  185.  
  186. #define NPTS 2
  187. static int fd;
  188.  
  189. init_plp()
  190. {
  191. if ((fd = open("/dev/plp",O_RDWR)) < 0) {
  192.         fprintf(stderr,"Couldn't open plp port!\n");
  193.         exit(1);
  194.         }
  195. if (ioctl(fd,PLPIOCIGNACK,1) < 0) {
  196.         fprintf(stderr,"Wouldn't take IGNACK\n");
  197.         exit(1);
  198.         }
  199. if (ioctl(fd,PLPIOCSTROBE,PLP_STROBE(126,63,63))) {
  200.         fprintf(stderr,"Wouldn't take PLP STROBE\n");
  201.         exit(1);
  202.         }
  203. }
  204.  
  205.  
  206. plp_trig()
  207. {
  208. ioctl(fd,PLPIOCRESET);
  209. }
  210. ______________________________________________________________________________
  211. "Genius may have its limitations,       | John Schwegler
  212.    but stupidity is not thus            | Temple U. Auditory Research Dept.
  213.    handicapped."                        | john@sg25.aud.temple.edu
  214.          - Elbert Hubbard               | (215) 221-3687 FAX 221-7523
  215.