Skip to main content

Sound routines

Routines · Data · Address index

Sound effects and music: the sound file, the AdLib, speaker and Tandy output, and the channels and effects of the drivers. The routines page explains how the entries are written.

0x154e5, 0x1554a, 0x1555a, 0x154f6, 0x149b5, 0x157fe — AdLib output​

  • Role: 0x154e5 writes value AL to register AH of the chip through ports 0x388 and 0x389, waiting 4 reads of the port after the register (0x1555a) and 23 after the value (0x1554a). 0x154f6 limits a level to 0–63. 0x149b5 resets the music driver: it stops the sound, sets the random state DS:0x43c1 to 0x1234 and clears registers 1, 8 and 0xbd. 0x157fe is the random draw of the music.
  • Used by: How an AdLib note sounds › How a note sounds

0x147f1, 0x14844, 0x146e0, 0x153f9, 0x1475f, 0x2cfe2, 0x2d044, 0x2cc79 — Sound driver timers​

  • Status: the rates are computed from the divisors with the standard 1 193 182 Hz input clock. Reading driver 1 as an AdLib driver is inferred from its ports 0x388 and 0x389.
  • Role: The sound start-up at 0x2cbfb selects a driver from DS:0x638a. Driver 1: 0x147f1 (called at 0x2cc15) installs the INT 08h handler 0x146e0 and sets the system timer divisor to 1365 (874.1 Hz); 0x146e0 runs the music every 12 interrupts and passes one interrupt in 48 to the BIOS handler (0x14742–0x14751), a tick rate of 18.2109 Hz; 0x14844 (called at 0x2cc55) restores the vector and divisor 65 536. Drivers 2 and 3: 0x2cfe2 installs 0x2cc79 with divisor 4096 (291.3 Hz); 0x2cc79 passes one interrupt in 16 (0x2cc9f–0x2ccae), 18.2065 Hz; 0x2d044 restores the vector and divisor. On every interrupt 0x2cc79 also counts interrupts in DS:0x6c46 (0 to 291) and, at each wrap, a byte DS:0x6c48 from 0 to 59 (0x2cc80–0x2cc99; no reader of either was found), then runs the sound (0x2cc9c). 0x2cfe2 also sets the speaker timer to mode 3 (0x2d024), saves port 0x61 in DS:0x6c18 and sets up one voice, or three when the Tandy flag is set; 0x2d044 silences the voices. Driver 1 also has an entry 0x153f9, listed in its entry table at 0x141be, that plays a sampled sound through 0x1475f with divisor 75 (15.9 kHz); 0x1475f never passes an interrupt to the BIOS, which would stop every tick counter while it plays, and restores divisor 1365 at the end (0x147ba). It reads two 4-bit deltas per byte (bit 3 the sign, bits 0–2 the size), adds each to a running value that starts at 8, and writes the result to the level register of channel 0's first operator (0x14771–0x147a1), after setting that voice up (0x153ff–0x15442). No instruction of the game or of the driver calls 0x153f9: no far call to it, and its entry table is never read. These are the only places that program the system timer. While command 0xbf has made cs:0x43bc non-zero, 0x146e0 also counts down cs:0x43be on every interrupt and, at 0, flips the key-on bit of channel 0 (0x146e9–0x14726) and reloads the count from cs:0x43bd.
  • Used by: The game clock › Ticks and the two counters, The ending, The introduction, How an AdLib note sounds › Effects, Playing speaker and Tandy programs › How a program plays, AdLib music and sounds (ADL) › In the original files

0x2ca9a — Play a sound effect​

0x2c9f9 — Load the sound file​

0x2cbfb, 0x2cc3e — Start and stop the sound driver​

  • Role: 0x2cbfb (driver) stores its argument in the sound driver and starts that driver: driver 1 through 0x147f1; drivers 2 and 3 through 0x2cfe2, driver 2 clearing DS:0x638c and driver 3 setting it and the Tandy flag, then calling 0x2d0c2 (0x2cc1c–0x2cc37). The start-up calls it at 0x18a76 with the value read from EOSPREFS.DAT. 0x2cc3e stops the current driver — 0x14844 for driver 1, 0x2d044 for driver 2, 0x2d0d5 then 0x2d044 for driver 3, which also clears the Tandy flag — and sets the sound driver to 0.
  • Used by:

0x2d082, 0x2d0ad — Start or stop a speaker or Tandy sound​

0x2ccbf — Run the speaker or Tandy sound​

  • Range: 0x2ccbf–0x2cf31

  • Role: Called by the timer interrupt 291.3 times per second; works on the sound state. A start request (0x2ccbf–0x2cd1a) copies the program address to DS:0x6a88 and resets three voices: position 0, waiting for an element, not finished, tempo factor 1; it leaves the loop counters as they are. It sets the start delays of voices 1 and 2 to 35 and 70 interrupts (0x2cd15). Then, while a sound plays, each voice up to the voice count (DS:0x6c19) waits out its start delay (0x2cd39–0x2cd5c) and its countdown, or reads elements (0x2cd69–0x2cebc):

    • 0x00–0x5f: a note. Its frequency comes from the speaker or Tandy note table, as the Tandy flag selects; 0 silences the voice. The countdown is (duration + 1) × tempo factor − 1 (0x2cda9–0x2cdb6); the inc al at 0x2cdaf wraps a duration of 255 to 0 (ANOMALY-117).
    • 0x60–0x7f and unknown bytes: end of the voice (0x2cd7e, 0x2cebc).
    • 0xcd, 0xd1: loop counters A and B (DS:0x6c3a, 0x6c3e); 0xce, 0xd2: count down and jump back by a word; a signed overflow of the jump ends the voice (0x2cdc6–0x2ce3b).
    • 0xe6: frequency in hertz, divided into 1 193 180 for the speaker or 111 860 for the Tandy chip (at most 1023), without a check of the divisor (0x2ce4a–0x2ce5b, ANOMALY-119).
    • 0xe2: tempo factor, 0 read as 1; 0xe8: subtract, with a floor of 1 applied only when the result overflows and is zero, which cannot happen (0x2ce8e–0x2ce96, bug, ANOMALY-118); 0xe9: add, 255 on a signed overflow.

    The countdown runs down one step per interrupt; at −2 the voice reads its next element on the following interrupt (0x2cec3–0x2cede). A voice that ends, or every voice on a stop request, is silenced (0x2ceea). When all voices have ended, the sound is over (0x2cf05–0x2cf26).

  • Comparative source: REF-SCUMM-023, PCSpeakerDriver::update.

  • Used by: Playing speaker and Tandy programs › How a program plays, Anomalies, tempo floor, frequency division, Anomalies and bugs, Level 4: reference tables › Sounds

0x2cf32, 0x2cf5c, 0x2cf81 — Speaker and Tandy output​

  • Role: Voice v on, off and frequency. With the Tandy flag clear they drive the PC speaker: frequency as the divisor of system timer channel 2 (port 0x42), on and off through bits 0 and 1 of port 0x61. With the flag set they write to the Tandy sound chip at port 0xc0: a 10-bit divisor for tone channel v, and its attenuation, 15 minus the voice level when on, 15 (silent) when off.
  • Used by: Playing speaker and Tandy programs › How a program plays

0x2cfb5, 0x2cfd2, 0x2d0c2, 0x2d0d5 — Speaker and Tandy voices​

  • Role: 0x2cfb5 sets the voice count to 3, silences four channels and sets bits 5 and 6 of port 0x61; 0x2cfd2 sets the voice count to 1 and restores port 0x61 as saved at start-up, speaker off. 0x2d0c2 calls 0x2cfb5; 0x2d0d5 calls both, in that order.
  • Used by:

0x2a300, 0x2a314 — Environmental sound​

0x10251, 0x1025a, 0x10260, 0x1027a, 0x10293, 0x102aa — Sound data access​

0x14886 — Queue a program​

0x1486e, 0x148a6 — Music tick and start the queued programs​

  • Range: 0x1486e–0x14885, 0x148a6–0x14917
  • Role: The music tick 0x1486e, run by the timer handler 0x146e0 every 12th interrupt (about 72.8 times a second), calls 0x148a6, then 0x14a09, then the beat counter 0x15507. 0x148a6 takes each pending request from the queue, finds the program through the pointer table (cs:0x43de), and reads its channel and priority bytes. If the priority is at least the channel's current one, it clears the channel's state (0x1560f), sets the priority and the command pointer, sets the step counter and the tempo so that the program runs on the next tick, and, except for channel 9, prepares the voice (0x156ae). Channel 0 also clears cs:0x43bc.
  • Comparative source: REF-SCUMM-012, sound/drivers/adlib.cpp, AdLibDriver::setupPrograms.
  • Used by: Playing AdLib programs › How a program plays

0x14a09 — Run the channels​

0x152b4, 0x15369, 0x15399, 0x153c1 — Note frequency, key on and off, duration​

  • Range: 0x152b4–0x15368, 0x15369–0x15398, 0x15399–0x153c0, 0x153c1–0x153f8
  • Role: 0x152b4 turns a note byte into AdLib registers 0xa0 and 0xb0 of the channel: the low four bits plus the base note (channel byte 0x12) give a semitone, wrapped into 0–11 with a change of octave (0x152c9–0x152da); the high four bits plus the base octave (0x07) give the block; the semitone selects a frequency number from the frequency table, to which the base frequency (0x24) is added. A non-zero pitch bend (0x42) then adds, for an upward bend, the byte at the bend's index in bend table (raw low four bits + 2), or subtracts, for a downward one, the byte at the bend's size in table (raw low four bits) (0x152f9–0x15340); neither index is bounded (ANOMALY-124). The key-on bit is kept. 0x15369 sets the key-on bit, computes the vibrato step as the frequency number shifted right by 9 − depth and restarts the vibrato delay. 0x15399 clears the key-on bit, except on channel 9 and, while the rhythm mode is on, on channels 6–8. 0x153c1 sets the duration: plus a random amount masked by channel byte 0x36 when that byte is non-zero, and returns; otherwise, when the fraction set by 0xa4 is non-zero, it also sets the note-off point (0x21) to the duration / 8 times that fraction. The random draw 0x157fe adds 0x9248 to the word cs:0x43c1 (seed 0x1234) and rotates it right by 3.
  • Comparative source: REF-SCUMM-012, AdLibDriver::setupNote, noteOn, noteOff, setupDuration.
  • Used by: How an AdLib note sounds › How a note sounds, Anomalies and bugs

0x15599, 0x155d1, 0x1556a — Operator levels​

  • Range: 0x15599–0x155d0, 0x155d1–0x1560e, 0x1556a–0x15598
  • Role: 0x15599 computes the level of the channel's second operator: the instrument level (channel byte 0x2f, low six bits) plus the level offsets at bytes 0x20, 0x00 and 0x30, minus the high byte of the velocity (0x34) shifted left by (0x33 + 1) when 0x33 is non-zero; the instrument's two high bits are kept. 0x155d1 does the same for the first operator from byte 0x2e, adding the offsets only when the instrument adds both operators (byte 0x31), and using 0x32 for the velocity. Both add in one byte and then keep a value up to 63, set a value from 64 to 127 to 63 and a value from 128 to 255 to 0 (0x155ba–0x155c6, 0x155f8–0x15604) (ANOMALY-123). 0x1556a writes them to registers 0x43 and, for an additive instrument, 0x40 of the channel's operators.
  • Comparative source: REF-SCUMM-012, AdLibDriver::calculateOpLevel1, calculateOpLevel2, adjustVolume.
  • Used by: How an AdLib note sounds › How a note sounds, AdLib music and sounds (ADL), Anomalies and bugs

0x156f7, 0x156f8, 0x15751, 0x1577a — Effect routines​

  • Range: 0x156f7 (one ret), 0x156f8–0x15750, 0x15751–0x15779, 0x1577a–0x157fd
  • Role: The two effect slots of a channel (bytes 0x29 and 0x2b) hold the address of one of these routines; run the channels calls both on every tick (0x14ad9–0x14ae0), and a channel reset puts 0x156f7, which does nothing, in both. Commands 0x95 and 0x91 fill the first slot, 0x8d the second.
    • 0x156f8, vibrato: while the delay (0x1f) is non-zero, decrements it. Otherwise adds the rate (0x1d) to a counter (0x1e); on a carry, decrements the half-period count (0x1a), negating the step (0x17) and reloading the count from 0x1b when it reaches 0, and adds the step to the frequency number, written to registers 0xa0 and 0xb0.
    • 0x15751, register cycle: adds the rate (0x39) to a counter (0x3a); on a carry, decrements the index (0x3c), reloading it from 0x3b when it goes below 0, and writes the table byte at that index (table address 0x3e) to register 0x3d + the first operator's offset.
    • 0x1577a, slide: adds the rate (0x13) to a counter (0x14); on a carry, adds the signed step (0x15) to the 10-bit frequency number. A rising sum of 0x2de or more is halved and the block raised; a falling sum of 0x184 or less is doubled and the block lowered (the block wraps within 0–7). Then, to avoid a zero number, 0x157a9–0x157b4 and 0x157c5–0x157d0 push the number, test its low ten bits, and on 0 pop it, add or subtract 1 and pop a second word: the adjustment is discarded and the stack loses a word (ANOMALY-122). The number and block are written to registers 0xa0 and 0xb0.
  • Comparative source: REF-SCUMM-012, AdLibDriver::primaryEffectSlide, primaryEffectVibrato, secondaryEffect1.
  • Used by: How an AdLib note sounds › Effects, AdLib music and sounds (ADL), Anomalies and bugs

0x15507 — Beat counter​

  • Range: 0x15507–0x15525
  • Role: Called at the end of every music tick. Adds the global tempo to the counter cs:0x43d7; on a carry decrements cs:0x43d6 and, at 0, reloads it from cs:0x43d5 and increments the beat counter cs:0x43d8. Command 0x9c sets these counters; 0x9d waits on cs:0x43d8 (0x14ca8–0x14cd2, with the phase flag cs:0x43d9).
  • Used by: How an AdLib note sounds › Effects

0x14918, 0x14948, 0x1495f, 0x1497c, 0x15526, 0x1552b, 0x156ae, 0x1560f — Other driver 1 entries and channel set-up​

  • Role: Of the far entries listed in the driver's table at cs:0x41be, the game calls only start-up (0x147f1), shut-down (0x14844) and the queue, each by a direct far call; no instruction reads the table. The others are never called: 0x14918(position) sets the pulse rate and channel 0's frequency low byte from the tables chosen by 0xbf; 0x14948(flag) sets the sample player's running flag cs:0x43f8; 0x1495f(n) selects program-table base n from cs:0x24c; 0x1497c(selector) returns the driver segment, the program table, the instrument area 0x4ba or the table 0x58a2; 0x15526 returns the sample position; 0x1552b(channel) returns a channel's remaining step count. Two near routines prepare a channel when a program starts: 0x1560f clears bytes 3 to 0x42 of its state (the level offset at byte 0 survives), then sets the tempo to 255, the priority to 0, the note spacing to 1 and both effect slots to the empty routine; 0x156ae sets the attack, decay, sustain and release of both operators to 0xff and writes 0, then 0x20 (key on, frequency 0) to register 0xb0 of the channel, unless the rhythm mode holds channels 6–8.
  • Used by: How an AdLib note sounds › Effects