SIMUL$ Four-Voice Sound (De Re Atari)

Type
Sound
Category
Simultaneous four-channel sound
Author
Bob Fraser (Section 7 of De Re Atari)
Published in
De Re Atari: A Guide to Effective Programming (Atari Program Exchange, APX-90008, 1982), Section 7, "Sound" (BASIC Sound)
Year
1982
Language
Atari BASIC
Requirements
Any Atari 8-bit, 16K RAM, Atari BASIC

About the program

De Re Atari ("All About Atari") was written by Atari's Software Development Support Group as a training manual for professional programmers. Early versions went to registered developers in 1981, and the 1982 edition was sold through the Atari Program Exchange as APX-90008. Its sound chapter, written by Bob Fraser, lists BASIC's two problems with music. If you play a chord with four SOUND statements, the first note starts noticeably before the last one. And every SOUND statement resets POKEY's AUDCTL register, which wipes out special settings such as 16-bit frequencies and filters. The fix is SIMUL$, a tiny machine-language routine that writes all the sound registers in one quick burst. This demonstration plays a short sequence of chords with it.

What you need

Any Atari 8-bit with Atari BASIC, and the TV or monitor sound turned up.

Typing it in

Plain ASCII. Line 9999 is the machine code, so check it carefully: 16 values ending with -1. Lines 100–999 are the music, eight values per chord.

How to use it

RUN it. It plays eight chords, building up from a single note to four voices, and then ends.

How it works

  • Lines 20–25 READ the bytes of line 9999 into SIMUL$ until they reach the -1.
  • The routine is PLA / STA $CB (save the argument count), LDX #0, then a loop: PLA / PLA (take the low byte of the next argument), STA $D200,X, INX, CPX $CB, BNE, and finally RTS. Locations $D200–$D207 (53760–53767) are AUDF1, AUDC1, AUDF2, AUDC2 and so on, so the arguments go straight into the POKEY registers.
  • Line 50 passes eight values: frequency and control for each of the four channels. A control value of 168 means pure tone (distortion 10 × 16 = 160) at volume 8, and 166 is the same tone at volume 6.
  • You can pass fewer arguments to set only the first one, two or three channels.
  • Because no SOUND statement runs, any value you POKE into AUDCTL (53768) stays in force.

Variations to try

  • Add your own chords before line 999. Keep the -1 line last.
  • Try POKE 53768,1 (15 kHz base clock) after line 10 to hear AUDCTL take effect and stay set.
  • Change the delay in line 55 to alter the tempo.

Listing

10 SOUND 0,0,0,0:DIM SIMUL$(16)
20 RESTORE 9999:X=1
25 READ Q:IF Q<>-1 THEN SIMUL$(X)=CHR$(Q):X=X+1:GOTO 25
27 RESTORE 100
30 READ F1,C1,F2,C2,F3,C3,F4,C4
40 IF F1=-1 THEN END
50 X=USR(ADR(SIMUL$),F1,C1,F2,C2,F3,C3,F4,C4)
55 FOR X=0 TO 150:NEXT X
60 GOTO 30
100 DATA 182,168,0,0,0,0,0,0
110 DATA 162,168,182,166,0,0,0,0
120 DATA 144,168,162,166,35,166,0,0
130 DATA 128,168,144,166,40,166,35,166
140 DATA 121,168,128,166,45,166,40,166
150 DATA 108,168,121,166,47,166,45,166
160 DATA 96,168,108,166,53,166,47,166
170 DATA 91,168,96,166,60,166,53,166
999 DATA -1,0,0,0,0,0,0,0
9000 REM
9010 REM
9020 REM this data contains the machine lang. program,
9030 REM and is read into SIMUL$
9999 DATA 104,133,203,162,0,104,104,157,0,210,232,228,203,208,246,96,-1

Credits