home *** CD-ROM | disk | FTP | other *** search
/ For Beginners & Professional Hackers / cd.iso / docum / doc.all / sbprog.rus < prev    next >
Encoding:
Text File  |  1993-10-01  |  22.7 KB  |  518 lines

  1. -------------------------------------------------------------------------------
  2.  
  3.                       Programming the AdLib/Sound Blaster
  4.                                 FM Music Chips
  5.                            Version 2.0 (24 Feb 1992)
  6.  
  7.         Copyright (c) 1991, 1992 by Jeffrey S. Lee, jlee@smylex.uucp
  8.  
  9.    All dirty translatin' work copyrighted (c) 1993 by MaX, 2:5000/7.1@Fidonet
  10.  
  11.  
  12.  
  13.                         Warranty and Copyright Policy
  14.  
  15.      This document is provided on an "as-is" basis, and its author makes
  16.      no warranty or representation, express or implied, with respect to
  17.      its quality performance or fitness for a particular purpose.  In no
  18.      event will the author of this document be liable for direct, indirect,
  19.      special, incidental, or consequential damages arising out of the use
  20.      or inability to use the information contained within.  Use of this
  21.      document is at your own risk.
  22.  
  23.      This file may be used and copied freely so long as the applicable
  24.      copyright notices are retained, and no modifications are made to the
  25.      text of the document.  No money shall be charged for its distribution
  26.      beyond reasonable shipping, handling and duplication costs, nor shall
  27.      proprietary changes be made to this document so that it cannot be
  28.      distributed freely.  This document may not be included in published
  29.      material or commercial packages without the written consent of its
  30.      author.
  31.  
  32.  
  33.  
  34.                                    Äíº«p
  35.  
  36.      äóÑ ¡á¿í«½ÑÑ »«»π½∩p¡δÑ ºóπ¬«óδÑ »½áΓδ ñ½∩ IBM PC, AdLib ¿ SoundBlaster,
  37.      ßΓpáñáεΓ «Γ «ΓßπΓßΓó¿∩ »«½¡«⌐ ¿ ∩ß¡«⌐ ñ«¬π¼Ñ¡Γᵿ¿ ñ½∩ »p«úpá¼¼¿ßΓ«ó.
  38.      AdLib Inc. ¿ Creative Labs Inc. «íÑ »p«ñáεΓ pẽ¿τ¡δÑ »á¬ÑΓδ »«ñ ¿σ
  39.      ¬ápΓδ, ¡« «¡¿ ¬á¬ »pá󿽫 ñ«p«ú¿Ñ ¿, ó ß½πτáÑ SoundBlaster'á, ¼«úπΓ
  40.      «¬áºáΓ∞ß∩ ºáΦ¿Σp«óá¡δ.
  41.  
  42.      ¥Γá ñ«¬π¼Ñ¡Γᵿ∩ ß»Ñµ¿á½∞¡« ¡á»¿ßá¡á ß Ññ¿¡ßΓóÑ¡¡«⌐ µÑ½∞ε - ñáΓ∞ éá¼
  43.      «Γ¬pδΓπε ¿¡Σ«p¼áµ¿ε « »p«úpἿp«óá¡¿¿ φΓ¿σ ºóπ¬«óδσ »½áΓ.
  44.  
  45.      ê¡Σ«p¼áµ¿∩, ß«ñÑpªáΘá∩ß∩ ó φΓ«¼ ñ«¬π¼Ñ¡ΓÑ - ¬«¼í¿¡áµ¿∩ ¿¡Σ«p¼áµ¿¿,
  46.      ¡á⌐ñÑ¡¡«⌐ ó SoundBlaster Software Developer's Kit ¿ ¡á⌐ñÑ¡¡á∩ ó
  47.      pѺπ½∞ΓáΓÑ »Ñτá½∞¡δσ «»δΓ«ó. HѬ«Γ«pá∩ ¿¡Σ«p¼áµ¿∩ ¼«ªÑΓ «¬áºáΓ∞ß∩
  48.      ¡ÑñÑ⌐ßΓó¿Γѽ∞¡«⌐ ñ½∩ ¬ápΓ AdLib; Ñß½¿ φΓ« Γá¬, ∩ ºápá¡ÑÑ ¿ºó¿¡∩εß∞...
  49.  
  50.      Å«ªá½π⌐ßΓá ¿¼Ñ⌐ΓÑ óó¿ñπ, τΓ« ΦÑßΓ¡áñµáΓ¿p¿τ¡δÑ τ¿ß½á ó «Γ½¿τ¿¿ «Γ
  51.      ñÑß∩Γ¿τ¡δσ ºá¬á¡τ¿óáεΓß∩ ß¿¼ó«½«¼ 'h' (hex). àß½¿ τ¿ß½« ¡á»¿ßá¡«
  52.      »p«»¿ß∞ε (¡á»p¿¼Ñp 'ΦÑßΓ¡áñµáΓ∞' ó¼ÑßΓ« '16'), Γ« τ¿ß½« ñÑß∩Γ¿τ¡«Ñ.
  53.  
  54. *    êº¼Ñ¡Ñ¡¿∩, ó¡ÑßÑ¡¡δÑ »«ß½Ñ óδ»π߬ᠻÑpó«⌐ óÑpß¿¿ φΓ«ú« ñ«¬π¼Ñ¡Γá,
  55. *    óδñÑ½Ñ¡δ »«ßpÑñßΓó«¼ óßΓá󬿠߿¼ó«½á '*' ß½Ñóá «Γ ΓѬßΓá.
  56.  
  57. *    Å«ñ ß½«óἿ '»½áΓá' ¿ '¬ápΓá' »«ñpáºπ¼ÑóáεΓß∩ «íÑ ºóπ¬«óδÑ ¬ápΓδ,
  58. *    AdLib ¿ SoundBlaster, Ñß½¿ ¡Ñ π¬áºá¡« «ípáΓ¡«Ñ.
  59.  
  60.                          â½áóá I.  I/O »«pΓδ.
  61.  
  62.      çóπ¬«óδÑ ¬ápΓδ »p«úpἿpπεΓß∩ »«ßpÑñßΓó«¼ »«ß佬¿ ñá¡¡δσ τÑpѺ
  63.      ñóá I/O »«pΓá:
  64.  
  65.              0388h - Address/Status port  (R/W)
  66.              0389h - Data port            (W/O)
  67.  
  68. *    SoundBlaster Pro ¿¼ÑÑΓ ó«º¼«ª¡«ßΓ∞ ó«ß»p«¿ºó«ñ¿Γ∞ ßΓÑpÑ«ºóπ¬¿,
  69. *    ñ«ßΓπ» ¬ ¬«Γ«pδ¼ «púá¡¿ºπÑΓß∩ Γ«τ¡« ΓᬪÑ:
  70. *   
  71. *            0220h - Address/Status port  (R/W), ½Ñóδ⌐ ¬á¡á½
  72. *            0221h - Data port            (W/O), ½Ñóδ⌐ ¬á¡á½
  73. *
  74. *            0222h - Address/Status port  (R/W), »páóδ⌐ ¬á¡á½
  75. *            0223h - Data port            (W/O), »páóδ⌐ ¬á¡á½
  76. *
  77. *    éδó«ñ τÑpѺ »«pΓδ 0388h ¿ 0389h íπñÑΓ ¿ñΓ¿ ¡á ñóá ¬á¡á½á (¼«¡«).
  78.  
  79.      çóπ¬«óδÑ ¬ápΓδ ¿¼ÑεΓ ¼áß߿󠿺 244 pÑú¿ßΓp«ó. ä½∩ ºá»¿ß¿ ó ¡πª¡δ⌐
  80.      pÑú¿ßΓp ¡áñ« »«ß½áΓ∞ Ñú« ¡«¼Ñp (01h..F5h) ó áñpÑß¡δ⌐ »«pΓ ¿ ¡πª¡«Ñ
  81.      º¡áτÑ¡¿Ñ ó »«pΓ ñá¡¡δσ.
  82.  
  83.      Å«ß½Ñ ºá»¿ß¿ ó áñpÑß¡δ⌐ »«pΓ éá¼ ¡áñ« »«ñ«ªñáΓ∞ 12 µ¿¬½«ó »ÑpÑñ ºá»¿ß∞ε
  84.      ñá¡¡δσ. ÅÑpÑñ _½εí«⌐_ ß½ÑñπεΘÑ⌐ «»ÑpᵿÑ⌐ ß ¬ápΓ«⌐ ñ«½ª¡« »p«⌐Γ¿ 84 µ¿¬½á.
  85.  
  86. *    Éπ¬«ó«ñßΓó« »« AdLib ñáÑΓ ópѼ∩ «ª¿ñá¡¿∩ ó ¼¿¬p«ßѬπ¡ñáσ: 3.3 ¼¬ß ñ½∩
  87. *    áñpÑß¡«ú« »«pΓá ¿ 23 ¼¬ß ñ½∩ ñá¡¡δσ.
  88. *
  89. *    ä½∩ í«½ÑѠᬬπpáΓ¡«⌐ pÑ὿ºáµ¿¿ ºáñÑpª¬¿ ¡áñ« »p«τ¿ΓáΓ∞ áñpÑß¡δ⌐ »«pΓ
  90. *    6 pẠ»«ß½Ñ ºá»¿ß¿ ó ¡Ñú« ¿ 35 pẠ»«ß½Ñ ºá»¿ß¿ ñá¡¡δσ.
  91.  
  92.      ÉÑú¿ßΓpδ ºóπ¬«óδσ »½áΓ »pÑñ¡áº¡áτÑ¡δ Γ«½∞¬« ñ½∩ ºá»¿ß¿.
  93.  
  94.      ÇñpÑß¡δ⌐ »«pΓ ΓᬪѠ¿úpáÑΓ p«½∞ ¿ ¬á¬ íá⌐Γ ßΓáΓπßá, ¬«Γ«pδ⌐ ¿¼ÑÑΓ
  95.      ß½ÑñπεΘπε ßΓpπ¬Γπpπ:
  96.  
  97.                7         6        5     4   3   2   1   0
  98.           ├─────────┼────────┼────────┼───┼───┼───┼───┼───┤
  99.           │   Äíá   │ Æá⌐¼Ñp │ Æá⌐¼Ñp │  HÑ ¿ß»«½∞ºπεΓß∩  │
  100.           │ Γá⌐¼Ñpá │    1   │    2   │   │   │   │   │   │
  101.           └─────────┴────────┴────────┴───┴───┴───┴───┴───┘
  102.  
  103.           ü¿Γ 7 - πßΓá¡«ó½Ñ¡, Ñß½¿ ½εí«⌐ Γá⌐¼Ñp »ÑpÑ»«½¡Ñ¡
  104.               6 - πßΓá¡«ó½Ñ¡, Ñß½¿ Γá⌐¼Ñp 1 »ÑpÑ»«½¡Ñ¡
  105.               5 - πßΓá¡«ó½Ñ¡, Ñß½¿ Γá⌐¼Ñp 2 »ÑpÑ»«½¡Ñ¡
  106.  
  107.      ä½∩ »«½πτÑ¡¿∩ ßΓáΓπßá »p«ßΓ« »p«τ¿Γá⌐ΓÑ »«pΓ 388h.
  108.  
  109.  
  110.  
  111.                            â½áóá II.  ÉÑú¿ßΓpδ.
  112.  
  113.      æ½ÑñπεΘá∩ Γáí½¿µá »«¬áºδóáÑΓ Σπ¡¬µ¿¿ ¬áªñ«ú« pÑú¿ßΓpá ó ¬ápΓÑ.
  114.      äÑΓá½∞¡«Ñ «»¿ßá¡¿Ñ pÑú¿ßΓp«ó ß½ÑñπεΓ ºá Γáí½¿µÑ⌐. HÑ »ÑpÑτ¿ß½Ñ¡¡δÑ
  115.      ¡¿ªÑ pÑú¿ßΓpδ ¡Ñ ¿ß»«½∞ºπεΓß∩.
  116.      |
  117.      The following table shows the function of each register in the sound 
  118.      card.  Registers will be explained in detail after the table.  Registers
  119.      not listed are unused.
  120.  
  121.    Address      Function
  122.    -------      ----------------------------------------------------
  123.      01         Test LSI / Enable waveform control
  124.      02         Timer 1 data
  125.      03         Timer 2 data
  126.      04         Timer control flags
  127.      08         Speech synthesis mode / Keyboard split note select
  128.    20..35       Amp Mod / Vibrato / EG type / Key Scaling / Multiple
  129.    40..55       Key scaling level / Operator output level
  130.    60..75       Attack Rate / Decay Rate
  131.    80..95       Sustain Level / Release Rate
  132.    A0..A8       Frequency (low 8 bits)
  133.    B0..B8       Key On / Octave / Frequency (high 2 bits)
  134.      BD         AM depth / Vibrato depth / Rhythm control
  135.    C0..C8       Feedback strength / Connection type
  136.    E0..F5       Wave Select
  137.  
  138.      ? âpπ»»¿p«ó¬¿ {ñóáñµáΓ¿ ñóπσ} pÑú¿ßΓp«ó (20..35, 40..55 ¿ Γ.ñ.) ¿¼ÑεΓ
  139.      τÑΓ¡δ⌐ »«p∩ñ«¬ ¿º-ºá ¿ß»«½∞º«óá¡¿∩ ñóπσ «»ÑpáΓ«p«ó ñ½∩ ¬áªñ«ú« ú«½«ßá.
  140.      æ½ÑñπεΘá∩ Γáí½¿µá »«¬áºδóáÑΓ ß¼ÑΘÑ¡¿∩ ó ¬áªñ«⌐ úpπ»»Ñ pÑú¿ßΓp«ó ñ½∩
  141.      ¬áªñ«ú« «»ÑpáΓ«pá.
  142.      |
  143.      The groupings of twenty-two registers (20-35, 40-55, etc.) have an odd
  144.      order due to the use of two operators for each FM voice.  The following
  145.      table shows the offsets within each group of registers for each operator.
  146.  
  147.  
  148.    Channel        1   2   3   4   5   6   7   8   9
  149.    Operator 1    00  01  02  08  09  0A  10  11  12
  150.    Operator 2    03  04  05  0B  0C  0D  13  14  15
  151.  
  152. Thus, the addresses of the attack/decay bytes for channel 3 are 62 for
  153. the first operator, and 65 for the second.  (The address of the second
  154. operator is always the address of the first operator plus three).
  155.  
  156. To further illustrate the relationship, the addresses needed to control
  157. channel 5 are:
  158.  
  159.     29 - Operator 1  AM/VIB/EG/KSR/Multiplier
  160.     2C - Operator 2  AM/VIB/EG/KSR/Multiplier
  161.     49 - Operator 1  KSL/Output Level
  162.     4C - Operator 2  KSL/Output Level
  163.     69 - Operator 1  Attack/Decay
  164.     6C - Operator 2  Attack/Decay
  165.     89 - Operator 1  Sustain/Release
  166.     8C - Operator 2  Sustain/Release
  167.     A4 -             Frequency (low 8 bits)
  168.     B4 -             Key On/Octave/Frequency (high 2 bits)
  169.     C4 -             Feedback/Connection Type
  170.     E9 - Operator 1  Waveform
  171.     EC - Operator 2  Waveform
  172.  
  173.  
  174.  
  175.                        äÑΓá½∞¡«Ñ «»¿ßá¡¿Ñ pÑú¿ßΓp«ó.
  176.                        |
  177.                        Explanations of Registers
  178.  
  179. üá⌐Γ 01 - Test LSI / Enable waveform control.
  180.           ¥Γ«Γ íá⌐Γ «íδτ¡« ¿ß»«½∞ºπÑΓß∩ ñ½∩ ΓÑßΓ¿p«óá¡¿∩ LSI. éßÑ í¿Γδ
  181.           ¬á¬ »pá󿽫 ßíp«ΦÑ¡δ ó 0. ôßΓá¡«ó½Ñ¡¡δ⌐ í¿Γ 5 »«ºó«½∩ÑΓ FM τ¿»π
  182.           ¬«¡Γp«½¿p«óáΓ∞ Σ«p¼π ó«½¡δ ¬áªñ«ú« «»ÑpáΓ«pá.
  183.           |
  184. Byte 01 - This byte is normally used to test the LSI device.  All bits
  185.           should normally be zero.  Bit 5, if enabled, allows the FM 
  186.           chips to control the waveform of each operator.
  187.  
  188.              7     6     5     4     3     2     1     0
  189.           +-----+-----+-----+-----+-----+-----+-----+-----+
  190.           |   unused  | WS  |            unused           |
  191.           +-----+-----+-----+-----+-----+-----+-----+-----+
  192.  
  193.  
  194. üá⌐Γ 02 - Timer 1 Data.
  195.           àß½¿ Γá⌐¼Ñp 1 ó¬½ετÑ¡, º¡áτÑ¡¿Ñ φΓ«ú« pÑú¿ßΓpá íπñÑΓ
  196.           ¿¡¬pÑ¼Ñ¡Γ¿p«óáΓß∩ ¬áªñδÑ 80 ¼¿¬p«ßѬπ¡ñ, »«¬á ¡Ñ »ÑpÑ»«½¡¿Γß∩.
  197.           Åp¿ »ÑpÑ»«½¡Ñ¡¿¿ ¬ápΓá óδ»«½¡¿Γ »pÑpδóá¡¿Ñ »« Γá⌐¼Ñpπ (INT 08h)
  198.           ¿ πßΓá¡«ó¿Γ í¿Γδ 7 ¿ 6 ó íá⌐ΓÑ ßΓáΓπßá.
  199.           |
  200. Byte 02 - Timer 1 Data.  If Timer 1 is enabled, the value in this 
  201.           register will be incremented until it overflows.  Upon
  202.           overflow, the sound card will signal a TIMER interrupt
  203.           (INT 08) and set bits 7 and 6 in its status byte.  The
  204.           value for this timer is incremented every eighty (80)
  205.           microseconds.
  206.  
  207.  
  208. üá⌐Γ 03 - Timer 2 Data.
  209.           àß½¿ Γá⌐¼Ñp 2 ó¬½ετÑ¡, º¡áτÑ¡¿Ñ φΓ«ú« pÑú¿ßΓpá íπñÑΓ
  210.           ¿¡¬pÑ¼Ñ¡Γ¿p«óáΓß∩ ¬áªñδÑ 320 ¼¿¬p«ßѬπ¡ñ, »«¬á ¡Ñ »ÑpÑ»«½¡¿Γß∩.
  211.           Åp¿ »ÑpÑ»«½¡Ñ¡¿¿ ¬ápΓá óδ»«½¡¿Γ »pÑpδóá¡¿Ñ »« Γá⌐¼Ñpπ (INT 08h)
  212.           ¿ πßΓá¡«ó¿Γ í¿Γδ 7 ¿ 5 ó íá⌐ΓÑ ßΓáΓπßá.
  213.           |
  214. Byte 03 - Timer 2 Data.  If Timer 2 is enabled, the value in this 
  215.           register will be incremented until it overflows.  Upon
  216.           overflow, the sound card will signal a TIMER interrupt
  217.           (INT 08) and set bits 7 and 5 in its status byte.  The
  218.           value for this timer is incremented every three hundred
  219.           twenty (320) microseconds.
  220.  
  221.  
  222. üá⌐Γ 04 - Timer Control Byte.
  223. Byte 04 - Timer Control Byte
  224.  
  225.         7     6     5     4     3     2     1     0
  226.      +-----+-----+-----+-----+-----+-----+-----+-----+
  227.      | IRQ | T1  | T2  |     unused      | T2  | T1  |
  228.      | RST | MSK | MSK |                 | CTL | CTL |
  229.      +-----+-----+-----+-----+-----+-----+-----+-----+
  230.  
  231.           bit 7 - Resets the flags for timers 1 & 2.  If set,
  232.                   all other bits are ignored.
  233.           bit 6 - Masks Timer 1.  If set, bit 0 is ignored.
  234.           bit 5 - Masks Timer 2.  If set, bit 1 is ignored.
  235.           bit 1 - When clear, Timer 2 does not operate.
  236.                   When set, the value from byte 03 is loaded into
  237.                   Timer 2, and incrementation begins.
  238.           bit 0 - When clear, Timer 1 does not operate.
  239.                   When set, the value from byte 02 is loaded into
  240.                   Timer 1, and incrementation begins.
  241.  
  242.  
  243. Byte 08 - CSM Mode / Keyboard Split.
  244.  
  245.         7     6     5     4     3     2     1     0
  246.      +-----+-----+-----+-----+-----+-----+-----+-----+
  247.      | CSM | Key |              unused               |
  248.      | sel | Spl |                                   |
  249.      +-----+-----+-----+-----+-----+-----+-----+-----+
  250.      
  251.           bit 7 - When set, selects composite sine-wave speech synthesis
  252.                   mode (all KEY-ON bits must be clear).  When clear,
  253.                   selects FM music mode.
  254.  
  255.           bit 6 - Selects the keyboard split point (in conjunction with
  256.                   the F-Number data).  The documentation in the Sound 
  257.                   Blaster manual is utterly incomprehensible on this;
  258.                   I can't reproduce it without violating their copyright.
  259.  
  260.  
  261. Bytes 20-35 - Amplitude Modulation / Vibrato / Envelope Generator Type /
  262.               Keyboard Scaling Rate / Modulator Frequency Multiple
  263.  
  264.         7     6     5     4     3     2     1     0
  265.      +-----+-----+-----+-----+-----+-----+-----+-----+
  266.      | Amp | Vib | EG  | KSR |  Modulator Frequency  |
  267.      | Mod |     | Typ |     |       Multiple        |
  268.      +-----+-----+-----+-----+-----+-----+-----+-----+
  269.  
  270.           bit 7 - Apply amplitude modulation when set; AM depth is
  271.                   controlled by the AM-Depth flag in address BD.
  272.           bit 6 - Apply vibrato when set;  vibrato depth is controlled
  273.                   by the Vib-Depth flag in address BD.
  274.           bit 5 - When set, the sustain level of the voice is maintained
  275.                   until released; when clear, the sound begins to decay
  276.                   immediately after hitting the SUSTAIN phase.
  277.           bit 4 - Keyboard scaling rate.  This is another incomprehensible
  278.                   bit in the Sound Blaster manual.  From experience, if 
  279.                   this bit is set, the sound's envelope is foreshortened as
  280.                   it rises in pitch.
  281.           bits 3-0 - These bits indicate which harmonic the operator will 
  282.                   produce sound (or modulation) in relation to the voice's 
  283.                   specified frequency:
  284.  
  285.                       0 - one octave below
  286.                       1 - at the voice's specified frequency
  287.                       2 - one octave above
  288.                       3 - an octave and a fifth above
  289.                       4 - two octaves above
  290.                       5 - two octaves and a major third above
  291.                       6 - two octaves and a fifth above
  292.                       7 - two octaves and a minor seventh above
  293.                       8 - three octaves above
  294.                       9 - three octaves and a major second above
  295.                       A - three octaves and a major third above
  296.                       B -  "       "     "  "   "     "     "
  297.                       C - three octaves and a fifth above
  298.                       D -   "      "     "  "   "     "
  299.                       E - three octaves and a major seventh above
  300.                       F -   "      "     "  "   "      "      "
  301.                   
  302.  
  303. Bytes 40-55 - Level Key Scaling / Total Level
  304.  
  305.         7     6     5     4     3     2     1     0
  306.      +-----+-----+-----+-----+-----+-----+-----+-----+
  307.      |  Scaling  |             Total Level           |
  308.      |   Level   | 24    12     6     3    1.5   .75 | <-- dB
  309.      +-----+-----+-----+-----+-----+-----+-----+-----+
  310.  
  311.           bits 7-6 - causes output levels to decrease as the frequency
  312.                      rises:
  313.  
  314.                           00   -  no change
  315.                           10   -  1.5 dB/8ve
  316.                           01   -  3 dB/8ve
  317.                           11   -  6 dB/8ve
  318.  
  319.           bits 5-0 - controls the total output level of the operator.
  320.                      all bits CLEAR is loudest; all bits SET is the
  321.                      softest.  Don't ask me why.
  322.  
  323.  
  324. Bytes 60-75 - Attack Rate / Decay Rate
  325.  
  326.         7     6     5     4     3     2     1     0
  327.      +-----+-----+-----+-----+-----+-----+-----+-----+
  328.      |         Attack        |          Decay        |
  329.      |          Rate         |          Rate         |
  330.      +-----+-----+-----+-----+-----+-----+-----+-----+
  331.  
  332.           bits 7-4 - Attack rate.  0 is the slowest, F is the fastest.
  333.           bits 3-0 - Decay rate.  0 is the slowest, F is the fastest.
  334.  
  335.  
  336. Bytes 80-95 - Sustain Level / Release Rate
  337.  
  338.         7     6     5     4     3     2     1     0
  339.      +-----+-----+-----+-----+-----+-----+-----+-----+
  340.      |     Sustain Level     |         Release       |
  341.      | 24    12     6     3  |          Rate         |
  342.      +-----+-----+-----+-----+-----+-----+-----+-----+
  343.  
  344.           bits 7-4 - Sustain Level.  0 is the loudest, F is the softest.
  345.           bits 3-0 - Release Rate.  0 is the slowest, F is the fastest.
  346.  
  347.  
  348. Bytes A0-B8 - Octave / F-Number / Key-On
  349.  
  350.         7     6     5     4     3     2     1     0
  351.      +-----+-----+-----+-----+-----+-----+-----+-----+
  352.      |        F-Number (least significant byte)      |  (A0-A8)
  353.      |                                               |
  354.      +-----+-----+-----+-----+-----+-----+-----+-----+
  355.  
  356.         7     6     5     4     3     2     1     0
  357.      +-----+-----+-----+-----+-----+-----+-----+-----+
  358.      |  Unused   | Key |    Octave       | F-Number  |  (B0-B8)
  359.      |           | On  |                 | most sig. |
  360.      +-----+-----+-----+-----+-----+-----+-----+-----+
  361.  
  362.           bit   5  - Channel is voiced when set, silent when clear.
  363.           bits 4-2 - Octave (0-7).  0 is lowest, 7 is highest.
  364.           bits 1-0 - Most significant bits of F-number.
  365.  
  366.      In octave 4, the F-number values for the chromatic scale and their 
  367.      corresponding frequencies would be:
  368.  
  369.         F Number     Frequency     Note
  370.            16B          277.2       C#
  371.            181          293.7       D
  372.            198          311.1       D#
  373.            1B0          329.6       E
  374.            1CA          349.2       F
  375.            1E5          370.0       F#
  376.            202          392.0       G
  377.            220          415.3       G#
  378.            241          440.0       A
  379.            263          466.2       A#
  380.            287          493.9       B
  381.            2AE          523.3       C
  382.      It is also known 
  383.             16.4        C in octave 0
  384.             27.57359    A in octave 0    
  385.      and t=1.05942975
  386.     
  387.  
  388. Bytes C0-C8 - Feedback / Algorithm
  389.  
  390.         7     6     5     4     3     2     1     0
  391.      +-----+-----+-----+-----+-----+-----+-----+-----+
  392.      |         unused        |    Feedback     | Alg |
  393.      |                       |                 |     |
  394.      +-----+-----+-----+-----+-----+-----+-----+-----+
  395.  
  396.           bits 3-1 - Feedback strength.  If all three bits are set to
  397.                      zero, no feedback is present.  With values 1-7,
  398.                      operator 1 will send a portion of its output back
  399.                      into itself.  1 is the least amount of feedback,
  400.                      7 is the most.
  401.           bit 0    - If set to 0, operator 1 modulates operator 2.  In this
  402.                      case, operator 2 is the only one producing sound.
  403.                      If set to 1, both operators produce sound directly.
  404.                      Complex sounds are more easily created if the algorithm
  405.                      is set to 0.
  406.  
  407.  
  408. Byte BD - Amplitude Modulation Depth / Vibrato Depth / Rhythm
  409.  
  410.         7     6     5     4     3     2     1     0
  411.      +-----+-----+-----+-----+-----+-----+-----+-----+
  412.      | AM  | Vib | Rhy | BD  | SD  | TOM | Top | HH  |
  413.      | Dep | Dep | Ena |     |     |     | Cym |     |
  414.      +-----+-----+-----+-----+-----+-----+-----+-----+
  415.  
  416.           bit 7 - Set:    AM depth is 4.8dB
  417.                   Clear:  AM depth is 1 dB
  418.           bit 6 - Set:    Vibrato depth is 14 cent
  419.                   Clear:  Vibrato depth is 7 cent
  420.           bit 5 - Set:    Rhythm enabled  (6 melodic voices) 
  421.                   Clear:  Rhythm disabled (9 melodic voices)
  422.           bit 4 - Bass drum on/off
  423.           bit 3 - Snare drum on/off
  424.           bit 2 - Tom tom on/off
  425.           bit 1 - Cymbal on/off
  426.           bit 0 - Hi Hat on/off
  427.  
  428.           Note:  KEY-ON registers for channels 06, 07, and 08 must be OFF
  429.                  in order to use the rhythm section.  Other parameters
  430.                  such as attack/decay/sustain/release must also be set
  431.                  appropriately.
  432.  
  433.  
  434. Bytes E0-F5 - Waveform Select
  435.  
  436.         7     6     5     4     3     2     1     0
  437.      +-----+-----+-----+-----+-----+-----+-----+-----+
  438.      |               unused              |  Waveform |
  439.      |                                   |  Select   |
  440.      +-----+-----+-----+-----+-----+-----+-----+-----+
  441.  
  442.           bits 1-0 - When bit 5 of address 01 is set, the output waveform
  443.                      will be distorted according to the waveform indicated
  444.                      by these two bits.  I'll try to diagram them here,
  445.                      but this medium is fairly restrictive.
  446.  
  447.          ___              ___            ___    ___       _      _
  448.         /   \            /   \          /   \  /   \     / |    / |
  449.        /_____\_______   /_____\_____   /_____\/_____\   /__|___/__|___
  450.               \     /
  451.                \___/
  452.  
  453.             00              01               10               11
  454.  
  455.  
  456.  
  457.  |                          Detecting a Sound Card
  458.  |
  459.  |   According to the AdLib manual, the 'official' method of checking for a 
  460.  |   sound card is as follows:
  461.  |
  462.  |      1)  Reset both timers by writing 60h to register 4.
  463.  |      2)  Enable the interrupts by writing 80h to register 4.  NOTE: this
  464.  |          must be a separate step from number 1.
  465.  |      3)  Read the status register (port 388h).  Store the result.
  466.  |      4)  Write FFh to register 2 (Timer 1).
  467.  |      5)  Start timer 1 by writing 21h to register 4.
  468.  |      6)  Delay for at least 80 microseconds.
  469.  |      7)  Read the status register (port 388h).  Store the result.
  470.  |      8)  Reset both timers and interrupts (see steps 1 and 2).
  471.  |      9)  Test the stored results of steps 3 and 7 by ANDing them
  472.  |          with E0h.  The result of step 3 should be 00h, and the 
  473.  |          result of step 7 should be C0h.  If both are correct, an
  474.  |          AdLib-compatible board is installed in the computer.
  475.  |
  476.  |
  477.  |                              Making a Sound
  478.  | 
  479.  |   Many people have asked me, upon reading this document, what the proper
  480.  |   register values should be to make a simple sound.  Well, here they are.
  481.  | 
  482.  |   First, clear out all of the registers by setting all of them to zero.
  483.  |   This is the quick-and-dirty method of resetting the sound card, but it
  484.  |   works.  Note that if you wish to use different waveforms, you must then
  485.  |   turn on bit 5 of register 1.  (This reset need be done only once, at the
  486.  |   start of the program, and optionally when the program exits, just to 
  487.  |   make sure that your program doesn't leave any notes on when it exits.)
  488.  |
  489.  |   Now, set the following registers to the indicated value:
  490.  |
  491.  |     REGISTER     VALUE     DESCRIPTION
  492.  |        20          01      Set the modulator's multiple to 1
  493.  |        40          10      Set the modulator's level to about 40 dB
  494.  |        60          F0      Modulator attack:  quick;   decay:   long
  495.  |        80          77      Modulator sustain: medium;  release: medium
  496.  |        A0          98      Set voice frequency's LSB (it'll be a D#)
  497.  |        23          01      Set the carrier's multiple to 1
  498.  |        43          00      Set the carrier to maximum volume (about 47 dB)
  499.  |        63          F0      Carrier attack:  quick;   decay:   long
  500.  |        83          77      Carrier sustain: medium;  release: medium
  501.  |        B0          31      Turn the voice on; set the octave and freq MSB
  502.  |
  503.  |   To turn the voice off, set register B0h to 11h (or, in fact, any value 
  504.  |   which leaves bit 5 clear).  It's generally preferable, of course, to
  505.  |   induce a delay before doing so.
  506.  |
  507.  |
  508.  |                             Acknowledgements
  509.  |
  510.  |   Thanks are due to the following people:
  511.  |
  512.  |   Ezra M. Dreisbach (ed10+@andrew.cmu.edu), for providing the information
  513.  |     about the recommended port write delay from the AdLib manual, and the
  514.  |     'official' method of detecting an AdLib-compatible sound card.
  515.  |
  516.  |   Nathan Isaac Laredo (gt7080a@prism.gatech.edu), for providing the
  517.  |     port numbers for stereo sound on the Sound Blaster Pro.
  518.