home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 428_02 / libsrc / tone.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-13  |  551 b   |  32 lines

  1. /*
  2. ** tone.c
  3. **
  4. ** Pictor, Version 1.51, Copyright (c) 1992-94 SoftCircuits
  5. ** Redistributed by permission.
  6. */
  7.  
  8. #include <conio.h>
  9. #include "pictor.h"
  10.  
  11. /*
  12. ** Sounds the computer's internal speaker.
  13. */
  14. void tone(int freq,int duration)
  15. {
  16.     int count,oldport;
  17.  
  18.     /* prevent divide-by-0 */
  19.     if(freq == 0)
  20.         return;
  21.  
  22.     outp(0x43,0xB6);
  23.     count = (int)(1193180L / (long)freq);
  24.     outp(0x42,count & 0xFF);
  25.     outp(0x42,count >> 8);
  26.     oldport = inp(0x61);
  27.     outp(0x61,oldport | 0x03);
  28.     pause(duration);
  29.     outp(0x61,oldport);
  30.  
  31. } /* tone */
  32.