home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name utspkon -- Turn on the speaker
- *
- * Synopsis utspkon(freq);
- *
- * unsigned freq The frequency of the sound wave to
- * produce.
- *
- * Description This function turns the speaker on so that it produces a
- * sound wave with a specified frequency. The resulting
- * sound is produced until UTSPKOFF is called or until
- * another call is made to UTSPKON.
- *
- * Method The 8253 Programmable Interrupt Timer expects a "latch
- * register value" which when multiplied by the wave
- * frequency is the clock frequency, 1.19318 Mhz. The
- * latch value is computed and the 8253 is programmed
- * accordingly.
- *
- * Returns (None. Function return type is void.)
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1984, 1986
- *
- * Version 3.02 March 24, 1987
- * Removed a strong typing warning (no change in object
- * code).
- *
- **/
-
- #include <butility.h>
-
- #if LAT300
- #include <dos.h> /* Declare inp() and outp(). */
- #endif
- #if MSC300
- #include <conio.h> /* Declare inp() and outp(). */
- #endif
-
- /* The following are hardware */
- /* port addresses needed to ac- */
- /* cess 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
-
- void utspkon(freq)
- unsigned freq;
- {
- unsigned latch;
-
- outp(PB8255,inp(PB8255) | 3); /* Enable speaker data and */
- /* timer gate signals on PortB. */
-
- /* Now program channel 2 of the 8253 timer to generate a square */
- /* wave of frequency "freq" Hz. */
-
- outp(CMD8253,0x0b6);
- latch = (unsigned) (CLKFREQ/freq);/* The value to place in the */
- outp(LTC8253,utlobyte(latch)); /* latch register. The least */
- outp(LTC8253,uthibyte(latch)); /* significant byte followed by */
- /* the most significant byte. */
- }