The Console Speaker: Clicks, Bells and a Fifth Voice from CONSOL
Press a key on an Atari and you hear a click. Print CHR$(253) and it beeps. Neither sound comes from POKEY, the chip that makes all the music: both come from a single bit in GTIA's CONSOL register, the same register that reads the START, SELECT and OPTION keys. On the 400 and 800 that bit drives a small speaker inside the computer; on the XL and XE, which have no internal speaker, its output is mixed into the TV sound. This "console speaker" can only be on or off, but with careful timing it plays tones, and it does so independently of POKEY's four voices.
What you'll learn: how the console speaker is wired, what the OS does with it (the key click, the bell, the cassette beeps), how to make a tone in BASIC and in assembly, why the vertical blank spoils the tone and how to stop it, and how to play it alongside POKEY.
What you need: Atari BASIC and MADS. We ran everything in atari800 (NTSC, XL/XE mode with its built-in AltirraOS, and a real Atari BASIC revision C ROM), recorded the emulator's sound output to WAV files and measured the frequencies with a Fourier transform on the PC. The figures below are those measurements.
1. One bit of CONSOL
CONSOL is at 53279 ($D01F). The Altirra Hardware Reference Manual describes its four low bits as bidirectional lines: bits 0–2 are the START, SELECT and OPTION keys, and bit 3 is the loudspeaker. Writing a 1 to a bit pulls its line to ground, and writing a 0 lets it go high. To make a sound you flip bit 3 back and forth; each flip moves the speaker cone one way or the other, so the rate of flipping sets the pitch.
The OS writes 8 to CONSOL in every vertical blank, which parks the speaker in one position (and leaves the console keys readable). The 400/800 OS source shows that this happens in the second, "deferred" stage of the vertical blank routine, after the check of the CRITIC flag. That detail matters later.
2. How the OS makes its sounds
The OS source (revision A of the 400/800 OS) contains three users of the speaker:
- CLICK ($FCD8), the key click. It counts X down from 127 to 0, and for each value stores X into CONSOL and then writes WSYNC to wait for the end of the scan line. Bit 3 of X changes every 8 counts, so the speaker flips every 8 scan lines, a 16-line square wave lasting 128 lines. At about 15,700 scan lines a second (NTSC: 1.79 MHz divided by 114 cycles per line) that is a burst of roughly 980 Hz lasting about 8 milliseconds: a click.
- BELL ($F90A), used for
CHR$(253)and the screen editor's warnings, simply calls CLICK 33 times in a row, giving a beep of about a quarter of a second at the same pitch. In our recording, a BASIC loop printingCHR$(253)produced a tone measured at about 959 Hz, a little below the 980 Hz the arithmetic predicts. - BEEP, in the cassette handler, makes the "press PLAY" prompt beeps with two simple delay loops around writes of $FF and 0 to CONSOL.
On XL/XE machines, Mapping the Atari gives NOCLIK at location 731 ($2DB): POKE it with any non-zero value to switch the key click off, and with 0 to switch it back on.
3. A tone from BASIC
The simplest possible tone:
10 POKE 53279,0:POKE 53279,8:GOTO 10
It works, and our recording measured about 245 Hz, set entirely by how fast Atari BASIC runs the loop. It also showed extra peaks 60 Hz above and below the tone. BASIC is not much use for tunes on this speaker: the pitch depends on the code inside the loop, so it changes with every edit.
4. A steady tone in assembly
For a predictable pitch, count scan lines with WSYNC, as the OS click does. This program flips bit 3 every HALF scan lines. With 30 lines per half wave the period is 60 lines, so the tone should be 15,700 / 60, about 262 Hz, close to middle C. The MODE symbol, given on the MADS command line (mads tone.asm -d:MODE=1), selects three variants:
; Square-wave tones on the GTIA console speaker, timed by WSYNC. MADS.
CRITIC = $42
CONSOL = $D01F
WSYNC = $D40A
AUDF1 = $D200
AUDC1 = $D201
AUDCTL = $D208
SKCTL = $D20F
HALF = 30 ; scan lines per half wave: 15700/60 = 262 Hz (NTSC)
org $2000
start .if MODE=1
lda #1 ; stop the VBI's stage 2, which writes 8 to CONSOL
sta CRITIC
.endif
.if MODE=2
lda #0 ; POKEY plays E above it at the same time
sta AUDCTL
lda #3
sta SKCTL
lda #96 ; 63920 / (2 * 97) = 329.5 Hz
sta AUDF1
lda #$A8 ; pure tone, volume 8
sta AUDC1
lda #1
sta CRITIC
.endif
lda #0
loop eor #8 ; flip the speaker bit
sta CONSOL
ldx #HALF
wait sta WSYNC ; wait HALF scan lines
dex
bne wait
jmp loop
run start
We recorded each variant for about a second:
| Variant | What we measured |
|---|---|
| MODE=0: OS vertical blank untouched | Main peak about 254–255 Hz, with a comb of extra peaks every 60 Hz around it. |
| MODE=1: CRITIC set to 1 | A clean square wave at about 261 Hz, with the odd harmonics (783, 1,305 Hz…) a square wave should have. |
| MODE=2: as MODE=1, plus POKEY voice 1 | Both notes present at full strength: about 261 Hz from the speaker and 330 Hz from POKEY. |
The illustration at the top shows the three spectra.
Why MODE=0 sounds rough. Sixty times a second the vertical blank interrupt takes the CPU away for a while, so one half wave comes out longer than the rest, and the OS also writes 8 to CONSOL, which can flip the speaker out of turn. A disturbance repeated 60 times a second shows up as those sidebands spaced 60 Hz apart, and the note sounds buzzy and slightly flat.
Why CRITIC helps. Setting CRITIC (location 66) to a non-zero value makes the OS skip the second stage of its vertical blank routine, which is where the CONSOL write lives. The first stage still runs (it updates the clock RTCLOK), so the tone still came out a fraction below the theoretical 262 Hz, but the spectrum was clean. The price is that everything else in stage 2 stops while CRITIC is set: the shadow registers aren't copied, so colour changes, joystick shadows, key repeat and the system timers other than timer 1 all freeze. Set it only while the speaker is playing, and clear it afterwards. For perfect timing you would have to disable the vertical blank interrupt entirely.
5. A fifth voice
Because the console speaker is a separate output, it can play while all four POKEY voices are busy. MODE=2 shows it with one POKEY voice. As an extra square-wave channel it costs a lot, though: the CPU has to flip the bit itself at exactly the right moments. In the listing the CPU does nothing else, so in a real program you would drive it from a timer or a display list interrupt, or interleave the flips with other work in a cycle-counted loop. There is also no volume control: the speaker is either on or off.
6. Practical uses
- A short click or tick for menus, independent of the music: copy CLICK's six-instruction loop into your own program. Don't call the ROM routine by address: $FCD8 is where it sits in the 400/800 revision A OS, and other OS versions are laid out differently.
- A warning beep that works with sound off in POKEY: print
CHR$(253). - Silence: POKE 731,1 on an XL/XE to stop key clicks during a program that uses its own sounds.
Troubleshooting
- No sound at all on an XL/XE through a monitor: the console speaker is mixed into the TV/monitor audio, so the audio lead must be connected. On a 400/800 the clicks come from the speaker inside the computer.
- The tone is buzzy or warbles: the vertical blank is interrupting. Set CRITIC during the tone, or turn the VBI off.
- The pitch changes when you edit the program: you are timing with instruction loops. Count scan lines with WSYNC instead.
- The pitch is about 1% lower on a PAL machine: PAL Ataris have a slightly slower CPU clock, so a scan line is longer (about 15,560 a second).
- Colours, joystick reading or key repeat stop working: CRITIC is still set. Clear it after the sound.
Further reading
- Altirra Hardware Reference Manual: CONSOL ($D01F) in the GTIA chapter and the register reference.
- Atari 400/800 OS source listing, revision A: CLICK, BELL, BEEP and the vertical blank routine.
- Ian Chadwick, Mapping the Atari: CONSOL (53279), WSYNC (54282), CRITIC (66) and NOCLIK (731).
- On this site: POKEY Sound Basics, Advanced POKEY, Reading the Keyboard, Console Keys and HELP, Vertical Blank Interrupts, Inside the OS Interrupt Handlers.
Credits
- Picture: Spectra of the example's output recorded from atari800: the console tone disturbed by the vertical blank, the same tone with stage 2 of the VBI switched off, and the tone playing alongside a POKEY voice. — Program authors; screenshot by the site
- Altirra Hardware Reference Manual — 6.11 General purpose I/O and CONSOL ($D01F) register reference (bit 3 loudspeaker; OS writes $08 in VBI; XL routes speaker to TV) — Avery Lee (Altirra)
- Atari 400/800 OS source listing, Rev. A — CLICK ($FCD8), BELL ($F90A), BEEP (cassette), VBI stage 2 CONSOL write after CRITIC test — ksquiggle
- Mapping the Atari — CONSOL 53279, WSYNC (keyboard click note), CRITIC, NOCLIK 731 — AtariArchives.org
