MAG - CGAZV5N1.ZIP - SOUND.C

 
Output of file : SOUND.C contained in archive : CGAZV5N1.ZIP

/********* Listing 3 ************* SOUND.C *************
* Turn speaker on and off, and set frequency
* Copyright per Listing 1
*********************************************************/

#include /* inp() and outp() declarations */
#include "timer.h"

#ifndef MAKEFD
#include "sound.fd"
#endif

#define PORT_B 0x61 /* 8255 PPI Port "B" */

void sound_init()
{
outp(TIMER_CWD, COUNTER_2 | ADDR_BOTH | SQUARE_WAVE | BINARY);
}


void sound_on()
{
outp(PORT_B, inp(PORT_B) | 0x03);
}


void sound_off()
{
outp(PORT_B, inp(PORT_B) & 0xFC);
}


void sound_freq(new_freq)
unsigned new_freq;
{
unsigned period;

new_freq++; /* avoid divison by zero! */
period = (unsigned) (CLK_IN / (long)new_freq);
outp(TIMER_2, period & 0xFF); /* Load LSB */
outp(TIMER_2, period >> 8); /* Load MSB */
}