This program generates a musical sequence using the AY-3-8910 sound chip’s envelope and tone registers to simulate an envelope-shaped musical phrase. It reads triplets of data (two tone period values and a duration/step control) and writes them to the AY registers via the SOUND keyword, then performs a software volume fade-out loop using registers 8 and 9. The fade-out step size is controlled by the third data value (c), which also governs the initial PAUSE duration, allowing notes of different lengths to have proportionally scaled decays. Eighteen notes are played in total, driven entirely by the DATA statement at line 40.
Program Structure
The program is compact at four lines. Line 0 is a REM used as a title/copyright banner. The main logic is a single FOR z=1 TO 18 loop spanning lines 10–30, which reads three values per iteration from the DATA block at line 40. Each iteration sounds a note, holds it, then performs a linear volume fade.
- Line 10: Outer loop counter
z(1–18); readsa(tone period channel A),b(tone period channel B),c(duration/decay rate selector). - Line 20: Sets AY registers — mixer (R7=60), volumes (R8=15, R9=15), tone periods for channels A and B. Channel A period is
a, channel B isa+2(a slight detune for chorus/thickness). - Line 30: Holds the note for
5*cframes, then ramps volume from 14 down to 0 in steps of(5-c), updating R8 and R9 simultaneously each step with a 1-frame pause.
AY Register Usage
| Register | Function | Value / Source |
|---|---|---|
| R0/R1 | Channel A tone period (fine/coarse) | a (fine), b (coarse) |
| R2/R3 | Channel B tone period (fine/coarse) | a+2 (fine), b (coarse) |
| R7 | Mixer control | 60 (decimal) = channels A+B tone enabled, noise off |
| R8 | Channel A amplitude | 15 initially, faded to 0 |
| R9 | Channel B amplitude | 15 initially, faded to 0 |
Notable Techniques
Software envelope simulation: The TS2068’s AY chip has a hardware envelope generator, but this program instead manually decrements volume registers in a FOR loop. This gives the author precise control over decay shape and timing, at the cost of BASIC execution overhead.
Detune for richness: Channel B’s fine-tune period is set to a+2 rather than a, creating a small frequency difference between channels A and B. This produces a slight chorusing or beating effect that thickens the sound.
Data-driven tempo and decay: The third data value c serves double duty — it scales both the sustain pause (5*c frames) and the fade step size (5-c). When c is large, the note sustains longer but fades more slowly; when small, the note is brief with a faster fade. Values observed in the DATA are 1, 2, and 4.
Mixer value 60: Binary 00111100 — this sets channels A and B as tone-enabled and disables noise on all channels, while channel C is entirely silent/disabled.
Data Structure
The DATA statement at line 40 contains 54 values (18 triplets of a,b,c). The a values observed are 47, 92, 158, 209, and 226, representing fine-tune tone period bytes for different pitches. The b values (3, 4, 5) are coarse period bytes selecting the octave range.
Content
Source Code
0 REM SIMULATED ENVELOPE ©1986 BYTE POWER WRITTEN BY K. BOISVERT
10 FOR z=1 TO 18: READ a,b,c
20 SOUND 7,60;8,15;9,15;0,a;1,b;2,a+2;3,b
30 PAUSE 5*c: FOR f=14 TO 0 STEP -(5-c): SOUND 8,f;9,f: PAUSE 1: NEXT f: NEXT z
40 DATA 92,4,2,209,5,2,92,4,2,209,5,2,92,4,1,158,4,1,47,5,1,158,4,1,92,4,4,226,3,2,209,5,2,226,3,2,209,5,2,226,3,1,209,5,1,47,5,1,209,5,1,92,4,4
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
