home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / ST_NEWS / STN_01_C.MSA / PROGRAMS_IRQ.C < prev    next >
C/C++ Source or Header  |  1994-03-14  |  1KB  |  56 lines

  1. #include <osbind.h>
  2. long int var;
  3. short int index;
  4.  
  5. synchronize(routine)
  6. int (*routine)(); /* pointer to (=address of) function */
  7. { register long *vblqueue;
  8.   register short *nvbls;
  9.   register long i,j;
  10.   register short bool=0;
  11.   register long save;
  12.   /* next install a routine in the VBL-queue */
  13.   save=Super(0); /* switch to supervisor status */
  14.   nvbls=0x454; /* address of number of VBL routines */
  15.   i=(*nvbls); /* get the number */
  16.   vblqueue=0x456; /* address of pointer to VBL queue */
  17.   vblqueue=(*vblqueue); /* address of VBL queue */
  18.   for(j=0;j<i;j++)
  19.     { if (*(vblqueue+j)==0) /* check if place is used */
  20.         { *(vblqueue+j)=routine; /* install */
  21.           bool=1; /* synchronizing succeeded */
  22.           break;
  23.         }
  24.     }
  25.   index=j; /* remember index of VBL queue where routine was */
  26.   if(!bool)
  27.     { Cconws("Unable to synchronise routine with VBL-irq");
  28.       Super(save);
  29.       Cconin();
  30.       Pterm0(); /* synchronisation failed, quit */
  31.     }
  32.   Super(save); /* restore previous state */
  33. }
  34.  
  35. rmsync()
  36. { register long *vblqueue;
  37.   register long save;
  38.   save=Super(0);
  39.   vblqueue=0x456;
  40.   vblqueue=(*vblqueue);
  41.   *(vblqueue+index)=0;
  42.   Super(save);
  43. }
  44. countirqs()
  45. { var++;
  46. }
  47.  
  48. main()
  49. { synchronize(countirqs);
  50.   Crawcin();
  51.   rmsync();
  52.   printf("%ld VBL-interrupts have been executed",var);
  53.   Crawcin();
  54. }
  55.  
  56.