home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_01 / 2n01067b < prev    next >
Text File  |  1990-12-02  |  921b  |  42 lines

  1. #include "uclock.h"
  2. #include "sound.h"
  3.  
  4. static int usec_timeout(uclock_t start, uclock_t finish, uclock_t usecs)
  5. {
  6.         if (usecs >= (finish - start))
  7.                 return 0;
  8.         else    return 1;
  9. }
  10.  
  11. void dosound(int freq)
  12. {
  13.         unsigned i;
  14.  
  15.         outp(C8253, SETIMER);
  16.         i = (unsigned)freq%256;
  17.         outp(F8253, i);
  18.         i = (unsigned)freq/256;
  19.         outp(F8253, i);
  20. }
  21.  
  22. void mktone(int freq, int update, unsigned delay)
  23. {
  24.         uclock_t start;
  25.  
  26.         if (0 == freq)
  27.         {
  28.                 soundoff();
  29.                 return;
  30.         }
  31.         dosound(freq);
  32.         if (update != UPDATE)
  33.                 soundon();
  34.         if (delay == 0)
  35.                 return;
  36.         start = usec_clock();
  37.         while (!usec_timeout(start, usec_clock(), 1000L * (long)delay))
  38.                 ;
  39.         if (update == TOGGLE)
  40.                 soundoff();
  41. }
  42.