home *** CD-ROM | disk | FTP | other *** search
/ PC Plus 58 / ISSUE_58_JUL_1991 / MAGAZINE / SOUND.C < prev   
Encoding:
C/C++ Source or Header  |  1991-01-01  |  772 b   |  41 lines

  1. #include <stdio.h>
  2.  
  3. long freq=1193180;     /*frequency of timer*/
  4. int port61, port43, port42;
  5.  
  6.  
  7. main()
  8. {
  9. int c,sound=261;
  10.  
  11. port61=inp(0x61);     /*get value in port x061*/
  12. port61|=03;        /*set bits 0 and 1 */
  13. outp(0x61,port61);    /*write it back to turn on speaker*/
  14.  
  15. while((c=getch())!='q')        /*change value to PIT*/
  16.     {
  17.     new_sound(sound);
  18.     if(c=='z') sound+=1;
  19.     if(c=='x') sound-=1;
  20.     }
  21.  
  22. port61=inp(0x61);        /*turn speaker off*/
  23. port61&=0xfc;
  24. outp(0x61,port61);
  25. }
  26.  
  27.  
  28. new_sound(sound)         /*set up PIT for new sound*/
  29. int sound;
  30. {
  31. port43=0xb6; 
  32. outp(0x43,port43);         /*tell PIT to expect new value*/
  33.  
  34. port42=(int) (freq/sound);      /*determine note*/
  35. outp(0x42,(port42&0xff));    /*send low byte*/
  36. outp(0x42,(port42&0xff00)/256);    /*send high byte*/
  37. }
  38.  
  39.  
  40.  
  41.