home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name UTSPKR -- Turn the speaker on or off.
- *
- * Synopsis utspkr(freq);
- *
- * unsigned freq The frequency of the sound wave to
- * produce, or 0 to turn speaker off.
- *
- * Description If freq is nonzero, this function turns the speaker on
- * so that it produces a (square) sound wave with a specified
- * frequency. The resulting sound is produced until UTSPKR
- * is invoked again.
- *
- * If freq is zero, the speaker is turned off.
- *
- * Freq must be at least 19.
- *
- * Method The 8253 Programmable Interrupt Timer expects a "latch
- * register value" which when multiplied by the wave
- * frequency is the clock frequency, 1,193,180 Hertz. The
- * latch value is computed and the 8253 is programmed
- * accordingly.
- *
- * Returns Nothing.
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1984,1987,1989
- *
- **/
-
- #include <conio.h>
- #include <dos.h>
-
- #include <butil.h>
-
-
- /* The following are hardware port addresses needed to access the */
- /* 8255 (speaker) and 8253 (timer) chips. */
-
- #define PB8255 0x61 /* Port B of the 8255 chip. */
- #define LTC8253 0x42 /* Latch register 8253 (timer)*/
- #define CMD8253 0x43 /* Command register of 8253. */
-
- #define CLKFREQ 1193180L /* System clock frequency. */
-
-
- void utspkr(freq)
- unsigned freq;
- {
- unsigned latch;
-
- if (freq != 0)
- {
- /* Enable speaker data and timer gate signals on PortB. */
- utoutp (PB8255, utinp (PB8255) | 3);
-
- /* Now program channel 2 of the 8253 timer to generate a */
- /* square wave of frequency "freq" Hz. */
-
- /* Divide clock frequency by requested speaker frequency to */
- /* generate value for the timer latch. */
-
- utoutp (CMD8253, 0x0b6);
-
- latch = (unsigned int) (CLKFREQ / freq);
-
- utoutp (LTC8253, utlobyte(latch));
- utoutp (LTC8253, uthibyte(latch));
-
- }
- else /* Clear the lower two bits of Port B. */
- utoutp(PB8255, utinp (PB8255) & ~3);
- }