📄 sbprog.doc
字号:
Xref: mork comp.os.msdos.programmer:12918 comp.music:6191 rec.games.programmer:5211Path: mork!netcomsv!decwrl!mips!zaphod.mps.ohio-state.edu!usc!news.bbn.com!noc.near.net!uhasun!smylex!jleeFrom: jlee@smylex.UUCP (Jeff Lee)Newsgroups: comp.os.msdos.programmer,comp.music,rec.games.programmerSubject: Programming the AdLib/Sound BlasterMessage-ID: <250-JNEWS-1.2@smylex.UUCP>Date: 25 Feb 92 15:02:02 GMTSender: jlee@smylex.UUCPOrganization: Shipbrook Software (Newington, CT)Lines: 484Hello, all. I've updated my doc file on programming the AdLib/Sound Blastercards, and since I'm still getting requests for the original, I decided thatit would save time to post it here. Apologies to those who aren't interested.------------------------------------------------------------------------------- Programming the AdLib/Sound Blaster FM Music Chips Version 2.0 (24 Feb 1992) Copyright (c) 1991, 1992 by Jeffrey S. Lee jlee@smylex.uucp Warranty and Copyright Policy This document is provided on an "as-is" basis, and its author makes no warranty or representation, express or implied, with respect to its quality performance or fitness for a particular purpose. In no event will the author of this document be liable for direct, indirect, special, incidental, or consequential damages arising out of the use or inability to use the information contained within. Use of this document is at your own risk. This file may be used and copied freely so long as the applicable copyright notices are retained, and no modifications are made to the text of the document. No money shall be charged for its distribution beyond reasonable shipping, handling and duplication costs, nor shall proprietary changes be made to this document so that it cannot be distributed freely. This document may not be included in published material or commercial packages without the written consent of its author. Overview Two of the most popular sound cards for the IBM-PC, the AdLib and the Sound Blaster, suffer from a real dearth of clear documentation for programmers. AdLib Inc. and Creative Labs, Inc. both sell developers' kits for their sound cards, but these are expensive, and (in the case of the Sound Blaster developers' kit) can be extremely cryptic. This document is intended to provide programmers with a FREE source of information about the programming of these sound cards. The information contained in this document is a combination of information found in the Sound Blaster Software Developer's Kit, and that learned by painful experience. Some of the information may not be valid for AdLib cards; if this is so, I apologize in advance. Please note that numbers will be given in hexadecimal, unless otherwise indicated. If a number is written out longhand (sixteen instead of 16) it is in decimal. | Changes from Version 1 of the file will be indicated by the use of change | bars in the left-hand margin. Chapter One - Sound Card I/O The sound card is programmed by sending data to its internal registers via its two I/O ports: 0388 (hex) - Address/Status port (R/W) 0389 (hex) - Data port (W/O) | The Sound Blaster Pro is capable of stereo FM music, which is accessed | in exactly the same manner. Ports 0220 and 0221 (hex) are the address/ | data ports for the left speaker, and ports 0222 and 0223 (hex) are the | ports for the right speaker. Ports 0388 and 0389 (hex) will cause both | speakers to output sound. The sound card possesses an array of two hundred forty-four registers; to write to a particular register, send the register number (01-F5) to the address port, and the desired value to the data port. After writing to the register port, you must wait twelve cycles before sending the data; after writing the data, eighty-four cycles must elapse before any other sound card operation may be performed. | The AdLib manual gives the wait times in microseconds: three point three | (3.3) microseconds for the address, and twenty-three (23) microseconds | for the data. | | The most accurate method of producing the delay is to read the register | port six times after writing to the register port, and read the register | port thirty-five times after writing to the data port. The sound card registers are write-only. The address port also functions as a sound card status byte. To retrieve the sound card's status, simply read port 388. The status byte has the following structure: 7 6 5 4 3 2 1 0 +------+------+------+------+------+------+------+------+ | both | tmr | tmr | unused | | tmrs | 1 | 2 | | +------+------+------+------+------+------+------+------+ Bit 7 - set if either timer has expired. 6 - set if timer 1 has expired. 5 - set if timer 2 has expired. Chapter Two - The RegistersThe following table shows the function of each register in the sound card. Registers will be explained in detail after the table. Registersnot listed are unused. Address Function ------- ---------------------------------------------------- 01 Test LSI / Enable waveform control 02 Timer 1 data 03 Timer 2 data 04 Timer control flags 08 Speech synthesis mode / Keyboard split note select 20..35 Amp Mod / Vibrato / EG type / Key Scaling / Multiple 40..55 Key scaling level / Operator output level 60..75 Attack Rate / Decay Rate 80..95 Sustain Level / Release Rate A0..A8 Frequency (low 8 bits) B0..B8 Key On / Octave / Frequency (high 2 bits) BD AM depth / Vibrato depth / Rhythm control C0..C8 Feedback strength / Connection type E0..F5 Wave SelectThe groupings of twenty-two registers (20-35, 40-55, etc.) have an oddorder due to the use of two operators for each FM voice. The followingtable shows the offsets within each group of registers for each operator. Channel 1 2 3 4 5 6 7 8 9 Operator 1 00 01 02 08 09 0A 10 11 12 Operator 2 03 04 05 0B 0C 0D 13 14 15Thus, the addresses of the attack/decay bytes for channel 3 are 62 forthe first operator, and 65 for the second. (The address of the secondoperator is always the address of the first operator plus three).To further illustrate the relationship, the addresses needed to controlchannel 5 are: 29 - Operator 1 AM/VIB/EG/KSR/Multiplier 2C - Operator 2 AM/VIB/EG/KSR/Multiplier 49 - Operator 1 KSL/Output Level 4C - Operator 2 KSL/Output Level 69 - Operator 1 Attack/Decay 6C - Operator 2 Attack/Decay 89 - Operator 1 Sustain/Release 8C - Operator 2 Sustain/Release A4 - Frequency (low 8 bits) B4 - Key On/Octave/Frequency (high 2 bits) C4 - Feedback/Connection Type E9 - Operator 1 Waveform EC - Operator 2 Waveform Explanations of RegistersByte 01 - This byte is normally used to test the LSI device. All bits should normally be zero. Bit 5, if enabled, allows the FM chips to control the waveform of each operator. 7 6 5 4 3 2 1 0 +-----+-----+-----+-----+-----+-----+-----+-----+ | unused | WS | unused | +-----+-----+-----+-----+-----+-----+-----+-----+Byte 02 - Timer 1 Data. If Timer 1 is enabled, the value in this register will be incremented until it overflows. Upon overflow, the sound card will signal a TIMER interrupt (INT 08) and set bits 7 and 6 in its status byte. The value for this timer is incremented every eighty (80) microseconds.Byte 03 - Timer 2 Data. If Timer 2 is enabled, the value in this register will be incremented until it overflows. Upon overflow, the sound card will signal a TIMER interrupt (INT 08) and set bits 7 and 5 in its status byte. The value for this timer is incremented every three hundred twenty (320) microseconds.Byte 04 - Timer Control Byte 7 6 5 4 3 2 1 0 +-----+-----+-----+-----+-----+-----+-----+-----+ | IRQ | T1 | T2 | unused | T2 | T1 | | RST | MSK | MSK | | CTL | CTL | +-----+-----+-----+-----+-----+-----+-----+-----+ bit 7 - Resets the flags for timers 1 & 2. If set, all other bits are ignored. bit 6 - Masks Timer 1. If set, bit 0 is ignored. bit 5 - Masks Timer 2. If set, bit 1 is ignored. bit 1 - When clear, Timer 2 does not operate. When set, the value from byte 03 is loaded into Timer 2, and incrementation begins. bit 0 - When clear, Timer 1 does not operate. When set, the value from byte 02 is loaded into Timer 1, and incrementation begins.Byte 08 - CSM Mode / Keyboard Split. 7 6 5 4 3 2 1 0 +-----+-----+-----+-----+-----+-----+-----+-----+ | CSM | Key | unused | | sel | Spl | | +-----+-----+-----+-----+-----+-----+-----+-----+ bit 7 - When set, selects composite sine-wave speech synthesis mode (all KEY-ON bits must be clear). When clear, selects FM music mode. bit 6 - Selects the keyboard split point (in conjunction with the F-Number data). The documentation in the Sound Blaster manual is utterly incomprehensible on this; I can't reproduce it without violating their copyright.Bytes 20-35 - Amplitude Modulation / Vibrato / Envelope Generator Type / Keyboard Scaling Rate / Modulator Frequency Multiple 7 6 5 4 3 2 1 0 +-----+-----+-----+-----+-----+-----+-----+-----+ | Amp | Vib | EG | KSR | Modulator Frequency | | Mod | | Typ | | Multiple |
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -