home *** CD-ROM | disk | FTP | other *** search
/ Da Capo / da_capo_vol1.bin / programs / amiga / edit / amisox3.3 / dist / sbprog.doc < prev    next >
Internet Message Format  |  1994-01-23  |  22KB

  1. Xref: mork comp.os.msdos.programmer:12918 comp.music:6191 rec.games.programmer:5211
  2. Path: mork!netcomsv!decwrl!mips!zaphod.mps.ohio-state.edu!usc!news.bbn.com!noc.near.net!uhasun!smylex!jlee
  3. From: jlee@smylex.UUCP (Jeff Lee)
  4. Newsgroups: comp.os.msdos.programmer,comp.music,rec.games.programmer
  5. Subject: Programming the AdLib/Sound Blaster
  6. Message-ID: <250-JNEWS-1.2@smylex.UUCP>
  7. Date: 25 Feb 92 15:02:02 GMT
  8. Sender: jlee@smylex.UUCP
  9. Organization: Shipbrook Software  (Newington, CT)
  10. Lines: 484
  11.  
  12. Hello, all.  I've updated my doc file on programming the AdLib/Sound Blaster
  13. cards, and since I'm still getting requests for the original, I decided that
  14. it would save time to post it here.  Apologies to those who aren't interested.
  15.  
  16. -------------------------------------------------------------------------------
  17.  
  18.                       Programming the AdLib/Sound Blaster
  19.                                 FM Music Chips
  20.                            Version 2.0 (24 Feb 1992)
  21.  
  22.                   Copyright (c) 1991, 1992 by Jeffrey S. Lee
  23.  
  24.                                jlee@smylex.uucp
  25.  
  26.  
  27.  
  28.                         Warranty and Copyright Policy
  29.  
  30.      This document is provided on an "as-is" basis, and its author makes
  31.      no warranty or representation, express or implied, with respect to
  32.      its quality performance or fitness for a particular purpose.  In no
  33.      event will the author of this document be liable for direct, indirect,
  34.      special, incidental, or consequential damages arising out of the use
  35.      or inability to use the information contained within.  Use of this
  36.      document is at your own risk.
  37.  
  38.      This file may be used and copied freely so long as the applicable
  39.      copyright notices are retained, and no modifications are made to the
  40.      text of the document.  No money shall be charged for its distribution
  41.      beyond reasonable shipping, handling and duplication costs, nor shall
  42.      proprietary changes be made to this document so that it cannot be
  43.      distributed freely.  This document may not be included in published
  44.      material or commercial packages without the written consent of its
  45.      author.
  46.  
  47.  
  48.  
  49.                                    Overview
  50.  
  51.      Two of the most popular sound cards for the IBM-PC, the AdLib and the
  52.      Sound Blaster, suffer from a real dearth of clear documentation for 
  53.      programmers.  AdLib Inc. and Creative Labs, Inc. both sell developers'
  54.      kits for their sound cards, but these are expensive, and (in the case
  55.      of the Sound Blaster developers' kit) can be extremely cryptic.
  56.  
  57.      This document is intended to provide programmers with a FREE source
  58.      of information about the programming of these sound cards.
  59.  
  60.      The information contained in this document is a combination of 
  61.      information found in the Sound Blaster Software Developer's Kit, and
  62.      that learned by painful experience.  Some of the information may not
  63.      be valid for AdLib cards; if this is so, I apologize in advance.
  64.  
  65.      Please note that numbers will be given in hexadecimal, unless otherwise
  66.      indicated.  If a number is written out longhand (sixteen instead of 16)
  67.      it is in decimal.
  68.  
  69.  |   Changes from Version 1 of the file will be indicated by the use of change
  70.  |   bars in the left-hand margin.
  71.  
  72.  
  73.  
  74.                          Chapter One - Sound Card I/O
  75.  
  76.      The sound card is programmed by sending data to its internal registers
  77.      via its two I/O ports:
  78.  
  79.              0388 (hex) - Address/Status port  (R/W)
  80.              0389 (hex) - Data port            (W/O)
  81.  
  82.  |   The Sound Blaster Pro is capable of stereo FM music, which is accessed
  83.  |   in exactly the same manner.  Ports 0220 and 0221 (hex) are the address/
  84.  |   data ports for the left speaker, and ports 0222 and 0223 (hex) are the
  85.  |   ports for the right speaker.  Ports 0388 and 0389 (hex) will cause both
  86.  |   speakers to output sound.
  87.  
  88.      The sound card possesses an array of two hundred forty-four registers;
  89.      to write to a particular register, send the register number (01-F5) to
  90.      the address port, and the desired value to the data port.
  91.  
  92.      After writing to the register port, you must wait twelve cycles before 
  93.      sending the data; after writing the data, eighty-four cycles must elapse
  94.      before any other sound card operation may be performed.
  95.  
  96.  |   The AdLib manual gives the wait times in microseconds: three point three
  97.  |   (3.3) microseconds for the address, and twenty-three (23) microseconds
  98.  |   for the data.
  99.  |
  100.  |   The most accurate method of producing the delay is to read the register
  101.  |   port six times after writing to the register port, and read the register
  102.  |   port thirty-five times after writing to the data port.
  103.  
  104.      The sound card registers are write-only.
  105.  
  106.      The address port also functions as a sound card status byte.  To 
  107.      retrieve the sound card's status, simply read port 388.  The status 
  108.      byte has the following structure:
  109.  
  110.               7      6      5      4      3      2      1      0
  111.           +------+------+------+------+------+------+------+------+
  112.           | both | tmr  | tmr  |              unused              |
  113.           | tmrs |  1   |  2   |                                  |
  114.           +------+------+------+------+------+------+------+------+
  115.  
  116.           Bit 7 - set if either timer has expired.
  117.               6 - set if timer 1 has expired.
  118.               5 - set if timer 2 has expired.
  119.  
  120.  
  121.  
  122.                        Chapter Two - The Registers
  123.  
  124. The following table shows the function of each register in the sound 
  125. card.  Registers will be explained in detail after the table.  Registers
  126. not listed are unused.
  127.  
  128.    Address      Function
  129.    -------      ----------------------------------------------------
  130.      01         Test LSI / Enable waveform control
  131.      02         Timer 1 data
  132.      03         Timer 2 data
  133.      04         Timer control flags
  134.      08         Speech synthesis mode / Keyboard split note select
  135.    20..35       Amp Mod / Vibrato / EG type / Key Scaling / Multiple
  136.    40..55       Key scaling level / Operator output level
  137.    60..75       Attack Rate / Decay Rate
  138.    80..95       Sustain Level / Release Rate
  139.    A0..A8       Frequency (low 8 bits)
  140.    B0..B8       Key On / Octave / Frequency (high 2 bits)
  141.      BD         AM depth / Vibrato depth / Rhythm control
  142.    C0..C8       Feedback strength / Connection type
  143.    E0..F5       Wave Select
  144.  
  145. The groupings of twenty-two registers (20-35, 40-55, etc.) have an odd
  146. order due to the use of two operators for each FM voice.  The following
  147. table shows the offsets within each group of registers for each operator.
  148.  
  149.  
  150.    Channel        1   2   3   4   5   6   7   8   9
  151.    Operator 1    00  01  02  08  09  0A  10  11  12
  152.    Operator 2    03  04  05  0B  0C  0D  13  14  15
  153.  
  154. Thus, the addresses of the attack/decay bytes for channel 3 are 62 for
  155. the first operator, and 65 for the second.  (The address of the second
  156. operator is always the address of the first operator plus three).
  157.  
  158. To further illustrate the relationship, the addresses needed to control
  159. channel 5 are:
  160.  
  161.     29 - Operator 1  AM/VIB/EG/KSR/Multiplier
  162.     2C - Operator 2  AM/VIB/EG/KSR/Multiplier
  163.     49 - Operator 1  KSL/Output Level
  164.     4C - Operator 2  KSL/Output Level
  165.     69 - Operator 1  Attack/Decay
  166.     6C - Operator 2  Attack/Decay
  167.     89 - Operator 1  Sustain/Release
  168.     8C - Operator 2  Sustain/Release
  169.     A4 -             Frequency (low 8 bits)
  170.     B4 -             Key On/Octave/Frequency (high 2 bits)
  171.     C4 -             Feedback/Connection Type
  172.     E9 - Operator 1  Waveform
  173.     EC - Operator 2  Waveform
  174.  
  175.  
  176.  
  177.                        Explanations of Registers
  178.  
  179. Byte 01 - This byte is normally used to test the LSI device.  All bits
  180.           should normally be zero.  Bit 5, if enabled, allows the FM 
  181.           chips to control the waveform of each operator.
  182.  
  183.              7     6     5     4     3     2     1     0
  184.           +-----+-----+-----+-----+-----+-----+-----+-----+
  185.           |   unused  | WS  |            unused           |
  186.           +-----+-----+-----+-----+-----+-----+-----+-----+
  187.  
  188.  
  189. Byte 02 - Timer 1 Data.  If Timer 1 is enabled, the value in this 
  190.           register will be incremented until