MAGAZINE\SOUND.C  ·  C  ·  772 B  ·  1991-07-01  ·  from PCPlus_Issue-58_Jul-1991
#include <stdio.h>

long freq=1193180; 	/*frequency of timer*/
int port61, port43, port42;


main()
{
int c,sound=261;

port61=inp(0x61); 	/*get value in port x061*/
port61|=03;		/*set bits 0 and 1 */
outp(0x61,port61);	/*write it back to turn on speaker*/

while((c=getch())!='q')		/*change value to PIT*/
	{
	new_sound(sound);
	if(c=='z') sound+=1;
	if(c=='x') sound-=1;
	}

port61=inp(0x61);		/*turn speaker off*/
port61&=0xfc;
outp(0x61,port61);
}


new_sound(sound) 		/*set up PIT for new sound*/
int sound;
{
port43=0xb6; 
outp(0x43,port43); 		/*tell PIT to expect new value*/

port42=(int) (freq/sound);  	/*determine note*/
outp(0x42,(port42&0xff));	/*send low byte*/
outp(0x42,(port42&0xff00)/256);	/*send high byte*/
}