## 7.5  SPEAKER INTERFACE

The speaker interface on the PC and XT is implemented via the 8255 PPI
chip,
which occupies I/O addresses 60h to 62h inclusive, and also provides the
interface to the keyboard.  Port B (read/write, at I/O address 61h) and
Port
C (read-only, at I/O address 62h) are used by the speaker interface.

On the AT and later machines, which do not have a PPI chip, these
functions are
implemented in an ASIC in the chipset, or with discrete logic, as a partly
read-only, partly read/write register at I/O address 61h, known as Port B.

In most respects, the PC/XT and AT interfaces are similar.  CTC channel
two
gate input can be controlled by software via a read/write bit in an I/O
register; this signal is known as Timer 2 Gate.  The CTC channel two
output
pin can be read back directly, via a read-only bit in an I/O register, and
is
AND-gated with a signal called Speaker Data (software controlled, via a
read/write I/O register bit), the speaker being driven from the output of
the
AND gate, sometimes via a simple resistor-capacitor lowpass filter to
remove
high frequency components.  On the PC and XT only, the speaker control
signal

(after the AND gate, and inverted) can also be read back by software,
though
this seems to be an undocumented feature and may not work on all machines.

Figure 1 (FIGURES archive) shows the speaker interface signals and
circuitry.

PC and XT : I/O address 61h, "PPI Port B", read/write
        7 6 5 4 3 2 1 0
        * * * * * * . .  Not relevant to speaker - do not modify!
        . . . . . . * .  Speaker Data
        . . . . . . . *  Timer 2 Gate

PC and XT : I/O address 62h, "PPI Port C", read only
        7 6 5 4 3 2 1 0
        * * . . * * * *  Not relevant to speaker, read-only
        . . * . . . . .  Timer 2 output read-back
        . . . * . . . .  Speaker signal (after AND gate, inverted),
undocumented

AT and later : I/O address 61h, "Port B", partly read/write, partly
read-only
        7 6 5 4 3 2 1 0
        * * . . . . . .  Not relevant to speaker, read-only
        . . * . . . . .  Timer 2 output read-back, read-only
        . . . * . . . .  Refresh Detect (read-only), see section  7.37
        . . . . * * . .  Not relevant to speaker - do not modify!
(read/write)
        . . . . . . * .  Speaker Data (read/write)
        . . . . . . . *  Timer 2 Gate (read/write)

I have a nasty suspicion that the PS/2 may not implement Port B properly.
Can
anyone confirm or deny this?  (*)

Audio generation can be done via CTC channel two, by setting Timer 2 Gate
high
and Speaker Data also high.  This enables channel two, and enables its
output tocontrol the speaker directly.  Alternatively, if Timer 2 Gate is
set low, CTC

channel two output goes high (assuming an appropriate mode is programmed
for
channel two), and Speaker Data can be manipulated to drive the speaker
directly.
The former technique is used in the sample program in section  7.30.


