home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_07_08 / v7n8130a.txt < prev   
Text File  |  1989-10-02  |  1KB  |  53 lines

  1.     
  2.  
  3. --------------------------------------------------------
  4. Listing 3
  5. --------------------------------------------------------
  6. #include <dos.h>
  7. #include <time.h>
  8. int milli_secs = 0;
  9. long int micro_secs;
  10. volatile char kicker = 0;
  11. time_t burn_up , now = 0;
  12. union REGS uregs;
  13. struct SREGS sregs;
  14. main()
  15. {
  16.     wait_new_sec();  /* nag timer till second changes */
  17.     while(same_sec()) { /* for one whole second fritter away & count 976 usec */
  18.         hang_on_mike();   /*   intervals */
  19.     }
  20.     printf("\n~Milliseconds/sec = %d",milli_secs);
  21. }
  22.  
  23. wait_new_sec()
  24. {
  25.     time(&burn_up); /* get long int current second since 1970 */
  26.     burn_up++;      /* predict next second */
  27.     while(now != burn_up)    {  /* are we there yet ? */
  28.         time(&now);
  29.     }
  30. }
  31. same_sec()
  32. {
  33.     if(time(&now) == burn_up)
  34.         return 1;
  35.     else
  36.         return 0;
  37. }
  38. hang_on_mike()
  39. {
  40.     kicker = 0;           /* unpost expiration byte */
  41.     uregs.h.ah = 0x83;    /* event wait */
  42.     uregs.h.al = 0;       /* set interval */
  43.     uregs.x.bx = FP_OFF(&kicker); /* post target */
  44.     segread(&sregs);      /* load up segment struct for int */
  45.     sregs.es   = sregs.ds;/* assure es:bx points to kicker  */
  46.     uregs.x.cx = 0;
  47.     uregs.x.dx = 975;     /* cx dx dword is interval in usecs (res 976) */
  48.     int86x(0x15,&uregs,&uregs,&sregs);
  49.     while(!kicker);             /* fritter a 1024th of a sec */
  50.     milli_secs++;         
  51. }
  52.  
  53.