Playing AdLib programs
AdLib music and sounds (ADL) · How an AdLib note sounds · Sound and music · Sound effects
In brief
What the AdLib sound driver does with the programs of an ADL file once the game has loaded it: how a program takes a channel and steps through its commands, how a sound played from a block is made quieter with distance, and the markers that the introduction and the ending wait for. How each note and its instrument become the registers of the card, and the effects, are on how an AdLib note sounds. The anomalies of the program queue and of the command table close the page.
How a program plays
A program starts on the channel named by its first byte, and only if its priority, the second byte, is at least that of the program already playing there. Channels 0 to 8 are the nine voices of the AdLib card; channel 9 has no voice and only controls the others.1
About 72.8 times a second, the driver advances every channel. A channel adds its tempo to an 8-bit counter; each time the counter passes 255 the channel takes a step. It then runs commands until one sets a duration (a note, a rest or a wait) and waits that many steps before going on.2 A tempo of 255 thus gives about one step per tick; the tunes set a common tempo, and their voices follow it.
The commands, from 0x80 to 0xc9, are listed with their operands in the
field reference; a byte below 0x80 is a note,
followed by its duration. How the original files use them, for silence, tunes,
sound effects and fades, is described under
the programs in these files.
A sound played from a block comes with a volume of (15 − distance) × 16. Unless the entry of the table selects program 0, the game changes two bytes of the program in the driver's memory before starting it, whatever its first command is: the priority and the operand of that command. It restores them before the next sound.3
t = ((operand × 4) ^ 0xff) × volume # kept to 16 bits
operand = (t >> 10) ^ 0x3f
priority = t >> 11
An operand of 0 thus becomes 4, with priority 29, on the party's block; 32 with priority 15 seven blocks away; 60 with priority 1 at 14 blocks; and 63, silent, with priority 0 at 15 blocks. The operands and first commands of the original files are given under the programs in these files.
Music markers
Command 0xc7 sets a marker value that the game can read, and the
introduction and the
ending wait for these markers.
Which files set them.4
Anomalies
The first two can happen with the original files; the third is never reached with them.
Bug: each sound request writes past its queue slot. Requests wait in a
16-slot queue of one byte per slot, but each one is stored as a two-byte
word, so its high byte, always 0, lands in the next slot. A request stored
in the last slot writes that 0 into the first byte of channel 0's state,
its level offset. Every ADL file changes that offset, in the fades among
others. Every sixteenth request therefore resets channel 0 to its full
level. Run on the driver's code, a request stored in slot 15 halfway
through the fade of a level file sets channel 0's offset from 30 back to 0:
its next level write is 15 instead of 43, 28 steps louder, while the other
voices go on fading.5 A faithful reimplementation clears channel 0's level
offset whenever a request is stored in slot 15.
(ANOMALY-97)
A full sound queue empties itself. Nothing checks that the queue has
room. The sixteenth request pending at once makes the write position equal
to the read position, which the driver takes for an empty queue: none of
the sixteen requests is started, and the next request overwrites the first
of them and is the only one played. The queue is emptied on every tick,
so this needs sixteen requests within about 1/73 of a second.
(ANOMALY-98)
Bug: command bytes 0xca to 0xf0 jump outside the command table. The
driver accepts command bytes up to 0xf0, but its table has 74 entries,
up to 0xc9. Bytes 0xca to 0xf0 take their handler address from the
data that follows the table, and the driver jumps there (inferred: data
run as code). Bytes 0xf1 to 0xff stop the channel. No original file
contains these bytes; a reimplementation may treat them as a stop.
(ANOMALY-99)
Sources
Locations refer to the game executable
reference; the comparative sources are listed in the
technical references
(REF-MW-015,
REF-SCUMM-012). The statements about the
original files come from decoding every program of the ten files of the
file inventory with the schema.