<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://moddingwiki.shikadi.net/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kermes</id>
	<title>ModdingWiki - User contributions [en-gb]</title>
	<link rel="self" type="application/atom+xml" href="https://moddingwiki.shikadi.net/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kermes"/>
	<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/wiki/Special:Contributions/Kermes"/>
	<updated>2026-05-15T11:21:38Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.11</generator>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=EGA_Palette&amp;diff=9891</id>
		<title>EGA Palette</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=EGA_Palette&amp;diff=9891"/>
		<updated>2021-07-12T19:33:36Z</updated>

		<summary type="html">&lt;p&gt;Kermes: Fix an extra character in palette entry 8&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Palette Infobox&lt;br /&gt;
 | Hardware = EGA&lt;br /&gt;
 | Depth = 6-bit&lt;br /&gt;
 | Count = 16&lt;br /&gt;
&amp;lt;!-- Only list games that have 16-byte palette files --&amp;gt;&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Monster Bash}}&lt;br /&gt;
   {{Game|Scubaventure}}&lt;br /&gt;
}}&lt;br /&gt;
While the EGA can only display up to 16 colours at a time, those 16 can be chosen from a selection of 64 possible colours.  Effectively this allows each of the red, green and blue channels to be independently set at four different levels (off, low, medium and high.)&lt;br /&gt;
&lt;br /&gt;
While it has always been possible to change the EGA palette in high resolution graphics mode, very few games ever did. Some notable exceptions include [[Corruption]], [[Fish]], [[SimAnt]], and [[SimFarm]]. [[Rambo III]] was able to change the palette in low resolution with a trick that requires a multi-scan monitor. [[Duke Nukem II]] is notable as it is an EGA game which changed the [[VGA Palette]] instead.&lt;br /&gt;
&lt;br /&gt;
== Default Palette ==&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot; style=&amp;quot;border-style: none; text-align:center; hspace=10px; float:right; margin: 1em;&amp;quot; border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;5&amp;quot; | Default EGA 16-Color Palette&amp;lt;br/&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Color !! Name !! RGB !! Binary !! Decimal&lt;br /&gt;
|- style=&amp;quot;color: white; background-color: #000000&amp;quot;&lt;br /&gt;
|| 0 || black || #000000 || 000000 || 0&lt;br /&gt;
|- style=&amp;quot;color: white; background-color: #0000AA&amp;quot;&lt;br /&gt;
|| 1 || blue || #0000AA || 000001 || 1&lt;br /&gt;
|- style=&amp;quot;color: white; background-color: #00AA00&amp;quot;&lt;br /&gt;
|| 2 || green || #00AA00 || 000010 || 2&lt;br /&gt;
|- style=&amp;quot;color: white; background-color: #00AAAA&amp;quot;&lt;br /&gt;
|| 3 || cyan || #00AAAA || 000011 || 3&lt;br /&gt;
|- style=&amp;quot;color: white; background-color: #AA0000&amp;quot;&lt;br /&gt;
|| 4 || red || #AA0000 || 000100 || 4&lt;br /&gt;
|- style=&amp;quot;color: white; background-color: #AA00AA&amp;quot;&lt;br /&gt;
|| 5 || magenta || #AA00AA || 000101 || 5&lt;br /&gt;
|- style=&amp;quot;color: white; background-color: #AA5500&amp;quot;&lt;br /&gt;
|| 6 || yellow / brown || #AA5500 || 010100 || 20&lt;br /&gt;
|- style=&amp;quot;color: black; background-color: #AAAAAA&amp;quot;&lt;br /&gt;
|| 7 || white / light gray || #AAAAAA || 000111 || 7&lt;br /&gt;
|- style=&amp;quot;color: white; background-color: #555555&amp;quot;&lt;br /&gt;
|| 8 || dark gray / bright black || #555555 || 111000 || 56&lt;br /&gt;
|- style=&amp;quot;color: white; background-color: #5555FF&amp;quot;&lt;br /&gt;
|| 9 || bright blue || #5555FF || 111001 || 57&lt;br /&gt;
|- style=&amp;quot;color: black; background-color: #55FF55&amp;quot;&lt;br /&gt;
|| 10 || bright green || #55FF55 || 111010 || 58&lt;br /&gt;
|- style=&amp;quot;color: black; background-color: #55FFFF&amp;quot;&lt;br /&gt;
|| 11 || bright cyan || #55FFFF || 111011 || 59&lt;br /&gt;
|- style=&amp;quot;color: black; background-color: #FF5555&amp;quot;&lt;br /&gt;
|| 12 || bright red || #FF5555 || 111100 || 60&lt;br /&gt;
|- style=&amp;quot;color: black; background-color: #FF55FF&amp;quot;&lt;br /&gt;
|| 13 || bright magenta || #FF55FF || 111101 || 61&lt;br /&gt;
|- style=&amp;quot;color: black; background-color: #FFFF55&amp;quot;&lt;br /&gt;
|| 14 || bright yellow || #FFFF55 || 111110 || 62&lt;br /&gt;
|- style=&amp;quot;color: black; background-color: #FFFFFF&amp;quot;&lt;br /&gt;
|| 15 || bright white || #FFFFFF || 111111 || 63&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The default EGA palette found in most DOS games is shown on the right.  This is set up to be backwards-compatible with the 16 colours available in text mode on the original CGA.  Notice that colour entry #6 (brown) doesn&#039;t fit in sequence with the other entries.  This is because the CGA had additional circuitry to make this colour appear &amp;quot;more visually pleasing.&amp;quot;  The introduction of the EGA palette meant this adjustment no longer required additional hardware.  Setting palette entry #6 to the in-sequence value of 6 (&amp;lt;span style=&amp;quot;background-color: #AAAA00;&amp;quot;&amp;gt;#AAAA00&amp;lt;/span&amp;gt;) instead of 20 reveals the &amp;quot;dark yellow&amp;quot; colour found in cheaper clone CGA monitors lacking the additional circuitry.&lt;br /&gt;
&lt;br /&gt;
== The default format ==&lt;br /&gt;
&lt;br /&gt;
As there are 16 colours to change, it is easiest to write these values out as 16 bytes.  In this case, the palette file is only 16 bytes long.&lt;br /&gt;
&lt;br /&gt;
== Conversion ==&lt;br /&gt;
&lt;br /&gt;
To convert from an EGA palette to RGB values, each 2-bit EGA red, green or blue value should be multiplied by 85, to produce the values 0, 85, 170 and 255.&lt;br /&gt;
&lt;br /&gt;
To obtain the 2-bit value, the bits must be extracted as shown in the following table (where -H is the high bit and -L is the low bit, for each colour.)&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Bit&lt;br /&gt;
| 7 || 6 || 5 || 4 || 3 || 2 || 1 || 0&lt;br /&gt;
|-&lt;br /&gt;
! Purpose&lt;br /&gt;
| Unused || Unused || Red-L || Green-L || Blue-L|| Red-H || Green-H || Blue-H&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Or as a formula:&lt;br /&gt;
&lt;br /&gt;
 red   = 85 * (((ega &amp;gt;&amp;gt; 1) &amp;amp; 2) | (ega &amp;gt;&amp;gt; 5) &amp;amp; 1)&lt;br /&gt;
 green = 85 * (( ega       &amp;amp; 2) | (ega &amp;gt;&amp;gt; 4) &amp;amp; 1)&lt;br /&gt;
 blue  = 85 * (((ega &amp;lt;&amp;lt; 1) &amp;amp; 2) | (ega &amp;gt;&amp;gt; 3) &amp;amp; 1)&lt;br /&gt;
&lt;br /&gt;
[[File:EGA_Table_Hex.svg|thumb|The full 64-colour EGA gamut.]]&lt;br /&gt;
&lt;br /&gt;
== Detection ==&lt;br /&gt;
&lt;br /&gt;
There are not many EGA palettes in existence on account of so few games bothering to change the palette, and any palette is so short detection is difficult.  Typically the first entry will be black (0x00) and the 16th white (0x3F) however even this is not guaranteed.  Any value larger than 0x3F is invalid and can be used to identify files that are definitely not palettes.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* [[wp:Enhanced Graphics Adapter|EGA article]] on Wikipedia&lt;br /&gt;
* [[CGA Palette]]&lt;br /&gt;
* [[VGA Palette]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Articles]]&lt;/div&gt;</summary>
		<author><name>Kermes</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Talk:OPL_chip&amp;diff=4997</id>
		<title>Talk:OPL chip</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Talk:OPL_chip&amp;diff=4997"/>
		<updated>2013-10-25T19:10:16Z</updated>

		<summary type="html">&lt;p&gt;Kermes: Corrected typos. 96 notes is 8 octaves, not 12. There are 12 notes per octave though.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Does changing the frequency just after a note-off cause a pitch bend for those instruments with lengthy release rates? ==&lt;br /&gt;
&lt;br /&gt;
I have not verified myself, but I am pretty confident that triggering a note-off only affects the envelope generator, not the phase generator. Thus changing the frequency register should always affect the frequency. This is how every emulator I have seen works. It should be easy to test and verify with Scream Tracker for example.&lt;br /&gt;
&lt;br /&gt;
: You might have to be careful with Scream Tracker - its Adlib support seems a bit weird.  The F-Numbers seem a bit off and other strangeness.  I think you are right though, I just would like to test it for real to confirm. -- [[User:Malvineous|Malvineous]] ([[User talk:Malvineous|talk]]) 03:14, 20 July 2013 (GMT)&lt;br /&gt;
&lt;br /&gt;
:: Confirmed by directly poking registers that after turning the key-on bit off and changing f-num of decaying sound, the sound frequency does change. --[[User:Kermes|Kermes]] ([[User talk:Kermes|talk]]) 18:58, 25 October 2013 (GMT)&lt;br /&gt;
&lt;br /&gt;
== About frequency/block/multiplier numbers ==&lt;br /&gt;
&lt;br /&gt;
It is true that for best match of any arbitrary frequency, one should select FNUM as high as possible and adjust BLOCK accordingly to get the correct octave. But since the chip is most often playing musical notes with 12 notes per octave, a simple music player could just have a 12-entry FNUM table where note A equals to FNUM 580. Then the selected octave is just selected with BLOCK value, for example 440Hz note A-4 is FNUM 580 at BLOCK 4, and 880 Hz note A-5 is FNUM 580 at BLOCK 5. Taking a look at how the key level scaling and key rate scaling are done with different BLOCK and FNUM ranges, the chip is really meant to be used like this, and it is also the easiest way. The hardest part is to decide the NOTESEL bit, which decides whether to use FNUM bit 8 or bit 9 to determine if a note belongs to upper or lower half within an octave. Some music players may just ignore these hardware octave split points and just use 8-bit FNUM values with high FNUM bits being always 0b00 or 0b01, most likely not many will hear the difference of lower frequency granularity.&lt;br /&gt;
&lt;br /&gt;
Coarseness of frequencies is not an issue with musical notes, as difference between two notes at octave 5 is relatively larger than in octave 4 anyway, so changing FNUM value by +/- X always results into pitch bend of +/- Y cents regardless of octave. This method allows a span of 8 octaves (96 notes) out of MIDI&#039;s 128 notes (nearly 11 octaves that start from -1). To extend the scale for lower notes it is always possible by scaling FNUM values down, but it is not possible to have higher notes like A-8 just by changing FNUM and BLOCK. There is a catch though, explained below.&lt;br /&gt;
&lt;br /&gt;
Basically the chip calculates a per-channel phase increment from FNUM and BLOCK values, and each operator has separate operator multiplier for the channel increment. When BLOCK is 1, the FNUM is directly used, and when BLOCK is 0 the FNUM is halved, one bit shifted away. So a tone with BLOCK 0 FNUM 1 would not advance at all, while FNUM 4 BLOCK 0 would equal to FNUM 2 BLOCK 1 for example. If higher tones like A-8 is wanted, just set the FNUM and BLOCK to A-7 and use operator multipliers to scale the modulator and carrier frequencies up by 2. Equally A-9 is just A-7 base tone with a timbre that is multiplied by 4. This sort of matches real instruments or MIDI sounds nicely, as single patch or timbre does not always span full 128 notes. A bass guitar could span 8 lower octaves only and lead guitar could span 8 higher octaves only. Setting the multiplier to 0.5 will again just shift away one bit from the per-channel base increment, while 1x multiplier just uses the base increment as-is. So even a tone with FNUM 3 BLOCK 0 MULTI 0.5 won&#039;t advance at all as the two FNUM bits are lost.&lt;br /&gt;
&lt;br /&gt;
: Very interesting, thanks for the explanation!  I had not even thought of using the chip in this manner.  I hope you will consider adding this to the article - if not I will try. -- [[User:Malvineous|Malvineous]] ([[User talk:Malvineous|talk]]) 03:14, 20 July 2013 (GMT)&lt;/div&gt;</summary>
		<author><name>Kermes</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Talk:OPL_chip&amp;diff=4996</id>
		<title>Talk:OPL chip</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Talk:OPL_chip&amp;diff=4996"/>
		<updated>2013-10-25T18:58:02Z</updated>

		<summary type="html">&lt;p&gt;Kermes: Verified it is possible to change frequency of decaying sound.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Does changing the frequency just after a note-off cause a pitch bend for those instruments with lengthy release rates? ==&lt;br /&gt;
&lt;br /&gt;
I have not verified myself, but I am pretty confident that triggering a note-off only affects the envelope generator, not the phase generator. Thus changing the frequency register should always affect the frequency. This is how every emulator I have seen works. It should be easy to test and verify with Scream Tracker for example.&lt;br /&gt;
&lt;br /&gt;
: You might have to be careful with Scream Tracker - its Adlib support seems a bit weird.  The F-Numbers seem a bit off and other strangeness.  I think you are right though, I just would like to test it for real to confirm. -- [[User:Malvineous|Malvineous]] ([[User talk:Malvineous|talk]]) 03:14, 20 July 2013 (GMT)&lt;br /&gt;
&lt;br /&gt;
:: Confirmed by directly poking registers that after turning the key-on bit off and changing f-num of decaying sound, the sound frequency does change. --[[User:Kermes|Kermes]] ([[User talk:Kermes|talk]]) 18:58, 25 October 2013 (GMT)&lt;br /&gt;
&lt;br /&gt;
== About frequency/block/multiplier numbers ==&lt;br /&gt;
&lt;br /&gt;
It is true that for best match of any arbitrary frequency, one should select FNUM as high as possible and adjust BLOCK accordingly to get the correct octave. But since the chip is most often playing musical notes with 12 notes per octave, a simple music player could just have a 12-entry FNUM table where note A equals to FNUM 580. Then the selected octave is just selected with BLOCK value, for example 440Hz note A-4 is FNUM 580 at BLOCK 4, and 880 Hz note A-5 is FNUM 580 at BLOCK 5. Taking a look at how the key level scaling and key rate scaling is done with different BLOCK and FNUM ranges, the chip is really meant to be used like this, and it is also the easiest way. The hardest part is to decide the NOTESEL bit, which decides whether to use FNUM bit 8 or bit 9 to determine if a note belongs to upper or lower half within an octave. Some music players may just ignore these hardware octave split points and just use 8-bit FNUM values with high FNUM bits being always 0b00 or 0b01, most likely not many will hear the difference of lower frequency granularity.&lt;br /&gt;
&lt;br /&gt;
Coarseness of frequencies is not an issue with musical notes, as difference between two notes at octave 5 is relatively larger than in octave 4 anyway, so changing FNUM value by +/- X always results into pitch bend of +/- Y cents regardless of octave. This method allows a span of 12 octaves (96 notes) out of MIDI&#039;s 128 notes (nearly 11 octaves that start from -1). To extend the scale for lower notes it is always possible by scaling FNUM values down, but it is not possible to have higher notes like A-8 just by changing FNUM and BLOCK. There is a catch though, explained below.&lt;br /&gt;
&lt;br /&gt;
Basically the chip calculates a per-channel phase increment from FNUM and BLOCK values, and each operator has separate operator multiplier for the channel increment. When BLOCK is 1, the FNUM is directly used, and when BLOCK is 0 the FNUM is halved, one bit shifted away. So a tone with BLOCK 0 FNUM 1 would not advance at all, while FNUM 4 BLOCK 0 would equal to FNUM 2 BLOCK 1 for example. If higher tones like A-8 is wanted, just set the FNUM and BLOCK to A-7 and use operator multipliers to scale the modulator and carrier frequencies up by 2. Equally A-9 is just A-7 base tone with a timbre that is multiplied by 4. This sort of matches real instruments or MIDI sounds nicely, as single patch or timbre does not always span full 128 notes. A bass guitar could span 8 lower octaves only and lead guitar could span 8 higher octaves only. Setting the multiplier to 0.5 will again just shift away one bit from the per-channel base increment, while 1x multiplier just uses the base increment as-is. So even a tone with FNUM 3 BLOCK 0 MULTI 0.5 won&#039;t advance at all as the two FNUM bits are lost.&lt;br /&gt;
&lt;br /&gt;
: Very interesting, thanks for the explanation!  I had not even thought of using the chip in this manner.  I hope you will consider adding this to the article - if not I will try. -- [[User:Malvineous|Malvineous]] ([[User talk:Malvineous|talk]]) 03:14, 20 July 2013 (GMT)&lt;/div&gt;</summary>
		<author><name>Kermes</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Talk:OPL_chip&amp;diff=4739</id>
		<title>Talk:OPL chip</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Talk:OPL_chip&amp;diff=4739"/>
		<updated>2013-07-12T22:03:59Z</updated>

		<summary type="html">&lt;p&gt;Kermes: Explanation of FNUM/BLOCK values in many music player applications&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Does changing the frequency just after a note-off cause a pitch bend for those instruments with lengthy release rates? ==&lt;br /&gt;
&lt;br /&gt;
I have not verified myself, but I am pretty confident that triggering a note-off only affects the envelope generator, not the phase generator. Thus changing the frequency register should always affect the frequency. This is how every emulator I have seen works. It should be easy to test and verify with Scream Tracker for example.&lt;br /&gt;
&lt;br /&gt;
== About frequency/block/multiplier numbers ==&lt;br /&gt;
&lt;br /&gt;
It is true that for best match of any arbitrary frequency, one should select FNUM as high as possible and adjust BLOCK accordingly to get the correct octave. But since the chip is most often playing musical notes with 12 notes per octave, a simple music player could just have a 12-entry FNUM table where note A equals to FNUM 580. Then the selected octave is just selected with BLOCK value, for example 440Hz note A-4 is FNUM 580 at BLOCK 4, and 880 Hz note A-5 is FNUM 580 at BLOCK 5. Taking a look at how the key level scaling and key rate scaling is done with different BLOCK and FNUM ranges, the chip is really meant to be used like this, and it is also the easiest way. The hardest part is to decide the NOTESEL bit, which decides whether to use FNUM bit 8 or bit 9 to determine if a note belongs to upper or lower half within an octave. Some music players may just ignore these hardware octave split points and just use 8-bit FNUM values with high FNUM bits being always 0b00 or 0b01, most likely not many will hear the difference of lower frequency granularity.&lt;br /&gt;
&lt;br /&gt;
Coarseness of frequencies is not an issue with musical notes, as difference between two notes at octave 5 is relatively larger than in octave 4 anyway, so changing FNUM value by +/- X always results into pitch bend of +/- Y cents regardless of octave. This method allows a span of 12 octaves (96 notes) out of MIDI&#039;s 128 notes (nearly 11 octaves that start from -1). To extend the scale for lower notes it is always possible by scaling FNUM values down, but it is not possible to have higher notes like A-8 just by changing FNUM and BLOCK. There is a catch though, explained below.&lt;br /&gt;
&lt;br /&gt;
Basically the chip calculates a per-channel phase increment from FNUM and BLOCK values, and each operator has separate operator multiplier for the channel increment. When BLOCK is 1, the FNUM is directly used, and when BLOCK is 0 the FNUM is halved, one bit shifted away. So a tone with BLOCK 0 FNUM 1 would not advance at all, while FNUM 4 BLOCK 0 would equal to FNUM 2 BLOCK 1 for example. If higher tones like A-8 is wanted, just set the FNUM and BLOCK to A-7 and use operator multipliers to scale the modulator and carrier frequencies up by 2. Equally A-9 is just A-7 base tone with a timbre that is multiplied by 4. This sort of matches real instruments or MIDI sounds nicely, as single patch or timbre does not always span full 128 notes. A bass guitar could span 8 lower octaves only and lead guitar could span 8 higher octaves only. Setting the multiplier to 0.5 will again just shift away one bit from the per-channel base increment, while 1x multiplier just uses the base increment as-is. So even a tone with FNUM 3 BLOCK 0 MULTI 0.5 won&#039;t advance at all as the two FNUM bits are lost.&lt;/div&gt;</summary>
		<author><name>Kermes</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Talk:OPL_chip&amp;diff=4738</id>
		<title>Talk:OPL chip</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Talk:OPL_chip&amp;diff=4738"/>
		<updated>2013-07-12T19:39:56Z</updated>

		<summary type="html">&lt;p&gt;Kermes: Added page, noteoff discussion&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Does changing the frequency just after a note-off cause a pitch bend for those instruments with lengthy release rates? ==&lt;br /&gt;
&lt;br /&gt;
I have not verified myself, but I am pretty confident that triggering a note-off only affects the envelope generator, not the phase generator. Thus changing the frequency register should always affect the frequency. This is how every emulator I have seen works. It should be easy to test and verify with Scream Tracker for example.&lt;/div&gt;</summary>
		<author><name>Kermes</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4338</id>
		<title>OPL chip</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4338"/>
		<updated>2012-08-05T21:34:13Z</updated>

		<summary type="html">&lt;p&gt;Kermes: /* 08: CSW / NOTE-SEL */ Explain how the NTS bit is used to select what kind of F-NUM values are expected within an octave.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Programmer&#039;s Guide to Yamaha YMF 262/OPL3 FM Music Synthesizer =&lt;br /&gt;
Version 1.00  Nov-24-1994&lt;br /&gt;
&lt;br /&gt;
Written by Vladimir Arnost, QA-Software&lt;br /&gt;
Internet:  xarnos00@dcse.fee.vutbr.cz&lt;br /&gt;
&lt;br /&gt;
This manual can be distributed freely if not modified.&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer ===&lt;br /&gt;
&lt;br /&gt;
I assume no responsibility for any damages arising out of use or inability to use this text. No warranty is provided about correctness of any information in this file. You are on your own.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The chip I am going to describe is getting more and more common, but programming information is still scarce, so I have decided to fill in this gap. All information contained in this file is a result of my experience in Adlib programming, research (read: reverse engineering) and finally of my effort to write down everything necessary to understand and use this piece of hardware. No official sources (i.e. development kits, books about this topic, etc.) were available to me except:&lt;br /&gt;
&lt;br /&gt;
: Adlib Programming Guide - by Tero Töttö, and&lt;br /&gt;
: The PC Games Programmers Encyclopedia V1.0&lt;br /&gt;
&lt;br /&gt;
The information below is a combination of known features of Adlib (alias Yamaha YM 3812/OPL2) and my own uncountable experiments and failures, which brought out a lot of important details you have to know about the chip.&lt;br /&gt;
&lt;br /&gt;
As far as I know, there are four major sound cards based on OPL3 chip:&lt;br /&gt;
&lt;br /&gt;
* Sound Blaster Pro II (not Sound Blaster Pro I)&lt;br /&gt;
* Sound Blaster 16&lt;br /&gt;
* Adlib Gold&lt;br /&gt;
* Pro Audio Spectrum Plus/16&lt;br /&gt;
&lt;br /&gt;
I currently have a Sound Blaster Pro II-compatible card only, so all the programming info I provide will be based on this card. (The other cards are quite similar, however. They are just wired at different I/O-port addresses.)&lt;br /&gt;
&lt;br /&gt;
Note: I assume some knowledge of FM music programming (mainly Adlib FM synthesizer) in this manual. If you are new to this topic I recommend you try Adlib first before going higher. Anyway, OPL3 is a direct descendant of OPL2 (what a surprise), so most features of OPL2 are also present on OPL3.&lt;br /&gt;
&lt;br /&gt;
== Description of the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
My card&#039;s user manual says: &amp;quot;[this card contains] ... a stereo music FM synthesizer with 20 channels consisting of four (4) operators each ... &amp;quot; I thought: &amp;quot;Wow -- that&#039;s together eighty operators. This must be a GOOD sound-card.&amp;quot; I was wrong. Just another advertising lie.&lt;br /&gt;
&lt;br /&gt;
So let&#039;s clear some facts. First, OPL3 has only thirty-six (36) operators which can be combined in several ways:&lt;br /&gt;
&lt;br /&gt;
* 18 FM channels (36 operators), or&lt;br /&gt;
* 15 FM channels (30 ops) and 5 percussion instruments (6 ops), giving us 20 channels altogether, or&lt;br /&gt;
* up to 6 four-operator FM channels (max 24 ops), the rest again being divided into two-operator FM channels and drums.&lt;br /&gt;
&lt;br /&gt;
From the table above you can see that not all channels can be used in four-operator (4-OP) mode -- only a part of the synthesizer is really capable of making 4-OP sounds -- the rest uses traditional two-operator (2-OP) mode.&lt;br /&gt;
&lt;br /&gt;
Second, the manual states this card is capable of &amp;quot;stereo&amp;quot; music. Yes, the quotes are necessary, because the stereo capabilities are very limited. You are given ability to control output going to left or right channel by turning it on and off. That&#039;s all. So the sound can flow from very left side, center and very right side. No sound panning, no special stereo effects. :-(&lt;br /&gt;
&lt;br /&gt;
Well, flaming apart, back to the main topic.&lt;br /&gt;
&lt;br /&gt;
The OPL3 chip is capable of making sounds in several ways:&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Additive Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output of both operators is simply added. It is the simplest way to make any sound, and it works on both OPL2 and OPL3. The diagram should make it clear.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐&lt;br /&gt;
	│            │&lt;br /&gt;
	│ Operator 1 ├────────┐&lt;br /&gt;
	│            │        │&lt;br /&gt;
	└────────────┘        │&lt;br /&gt;
			      ├────────&amp;gt; Output&lt;br /&gt;
	┌────────────┐        │&lt;br /&gt;
	│            │        │&lt;br /&gt;
	│ Operator 2 ├────────┘&lt;br /&gt;
	│            │&lt;br /&gt;
	└────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Frequency Modulation (FM) Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output from the first operator (Modulator) is sent to the input of the second one (Carrier) and is used to modulate (alter) frequency of the second operator. Only the second operator produces sound. Most of interesting sounds are made this way. This also works on OPL2. Hope the picture helps.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐         ┌────────────┐&lt;br /&gt;
	│            │         │            │&lt;br /&gt;
	│ Operator 1 ├────────&amp;gt;│ Operator 2 ├────────&amp;gt; Output&lt;br /&gt;
	│(Modulator) │         │ (Carrier)  │&lt;br /&gt;
	└────────────┘         └────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Four-operator &amp;quot;Mess&amp;quot; Modulation Synthesis ===&lt;br /&gt;
&lt;br /&gt;
All of OPL3&#039;s 4-OP configurations are combinations of the above two modes of synthesis. OPL3 combines these two modes in four ways. I have no words to describe these four ways. Only the pictures can show their principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   a) FM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   b) AM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├───────────────────────────────────┐&lt;br /&gt;
	│       │                                   │&lt;br /&gt;
	└───────┘                                   │&lt;br /&gt;
						    │&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┴─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   c) FM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────┐&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     ├─────&amp;gt; Output&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┘&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	└───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   d) AM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├────────────────────┐&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	└───────┘                    │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────┼─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐                    │&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	│ Op. 4 ├────────────────────┘&lt;br /&gt;
	│       │&lt;br /&gt;
	└───────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Nice, aren&#039;t they?&lt;br /&gt;
&lt;br /&gt;
The only way I think this can be written is a math formula. Symbol + (plus) means additive synthesis, and * (asterisk) means frequency modulation (Op1 * Op2 means operator 1 modulates operator 2, not vice versa). Here they are:&lt;br /&gt;
&lt;br /&gt;
# FM-FM Mode:	 (Op1 * Op2 * Op3 * Op4) ────&amp;gt; Output&lt;br /&gt;
# AM-FM Mode:	  Op1 + (Op2 * Op3 * Op4) ───&amp;gt; Output&lt;br /&gt;
# FM-AM Mode:	 (Op1 * Op2) + (Op3 * Op4) ──&amp;gt; Output&lt;br /&gt;
# AM-AM Mode:	  Op1 + (Op2 * Op3) + Op4 ───&amp;gt; Output&lt;br /&gt;
&lt;br /&gt;
=== Percussion Mode ===&lt;br /&gt;
&lt;br /&gt;
In this mode 6 operators are used to produce five different percussion instruments:&lt;br /&gt;
&lt;br /&gt;
* Bass Drum (2 operators)&lt;br /&gt;
* Snare Drum (1 operator)&lt;br /&gt;
* Tom-Tom (1 operator)&lt;br /&gt;
* Cymbal (1 operator)&lt;br /&gt;
* Hi-Hat (1 operator)&lt;br /&gt;
&lt;br /&gt;
Because these instruments occupy only three melodic channels, only Bass Drum, Snare Drum and Tom-Tom frequencies can be set. Cymbal and Hi-Hat frequencies are fixed.  {{TODO|It seems it&#039;s actually the cymbal and snare frequencies that are fixed, try to confirm this -- [[User:Malvineous|Malvineous]] 13:34, 3 June 2012 (GMT)}}&lt;br /&gt;
&lt;br /&gt;
This mode is identical with that of OPL2. For more details see ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
== Programming the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
OPL3 may be found at the following addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| Sound Blaster Pro II || 220h or 240h (selectable), also 388h&lt;br /&gt;
|-&lt;br /&gt;
| Adlib Gold || 388h&lt;br /&gt;
|-&lt;br /&gt;
| Pro Audio Spectrum Plus/16 || ? (if you have a PAS you should know it)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The base address of the synthesizer will be called &amp;quot;base&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The chip occupies four I/O addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| base+0 || Primary index register (write), Status register (read)&lt;br /&gt;
|-&lt;br /&gt;
| base+1 || Primary data register (write-only)&lt;br /&gt;
|-&lt;br /&gt;
| base+2 || Secondary index register (write)&lt;br /&gt;
|-&lt;br /&gt;
| base+3 || Secondary data register (write-only)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The index registers are used to select internal registers and data registers are used to write to them. Status register returns the state of two timers built in the chip.&lt;br /&gt;
&lt;br /&gt;
OPL3 contains two sets of registers. The Primary set maps to channels 0-8 (operators 0-17) and the secondary maps to channels 9-17 (operators 18-35). The reason for this is simple: all these registers wouldn&#039;t fit into single register set.&lt;br /&gt;
&lt;br /&gt;
Unlike Adlib (OPL2), OPL3 doesn&#039;t need delay between register writes. With OPL2 you had to wait 3.3 µs after index register write and another 23 µs after data register write. On the contrary OPL3 doesn&#039;t need (almost) any delay after index register write and only 0.28 µs after data register write. This means you can neglect the delays and slightly speed up your music driver. But using reasonable delays will certainly do no harm.&lt;br /&gt;
&lt;br /&gt;
The data registers can&#039;t be read (they are write-only) on both OPL2 and OPL3.&lt;br /&gt;
&lt;br /&gt;
== Register Map ==&lt;br /&gt;
&lt;br /&gt;
The registers are grouped in the same manner as in the OPL2 chip. Programs using both OPL2 and OPL3 chips may use the same code provided that their direct I/O interface is well written. The only thing you have to change is operator-to-register mapping, which must accomodate the fact that registers are spread between two register sets.&lt;br /&gt;
&lt;br /&gt;
(The register map is nearly the same so I dared to copy it from ADLIB.DOC.)&lt;br /&gt;
&lt;br /&gt;
=== Status Register (base+0) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
!    D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQFlag || T1Flag || T2Flag ||        ||        ||        ||        ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Data Registers (base+1, base+3) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! REG   !!   D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| 01    ||colspan=2| Test Register ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|(WSEnable)||colspan=5| Test Register&lt;br /&gt;
|-&lt;br /&gt;
| 02    ||colspan=8| Timer 1 Count (80 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 03    ||colspan=8| Timer 2 Count (320 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 04*   ||IRQReset|| T1Mask || T2Mask ||colspan=3|                  ||T2 Start||T1 Start&lt;br /&gt;
|-&lt;br /&gt;
| 04**  ||colspan=2|        ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP B-E||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP A-D||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 9-C||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 2-5||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 1-4||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 0-3&lt;br /&gt;
|-&lt;br /&gt;
| 05**  ||colspan=7|                                                           ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;| OPL3&lt;br /&gt;
|-&lt;br /&gt;
| 08    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;| (CSW)  ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|NOTE-SEL||colspan=6|&lt;br /&gt;
|-&lt;br /&gt;
| 20-35 ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Tremolo ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Vibrato ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Sustain ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|  KSR   ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Frequency Multiplication Factor&lt;br /&gt;
|-&lt;br /&gt;
| 40-55 ||colspan=2 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Key Scale Level ||colspan=6 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 60-75 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Attack Rate ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 80-95 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Sustain Level ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A0-A8 ||colspan=8 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Frequency Number  (Lower 8 bits)&lt;br /&gt;
|-&lt;br /&gt;
| B0-B8 ||colspan=2|        ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| KEY-ON ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Block Number ||colspan=2 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| F-Num (hi bits)&lt;br /&gt;
|-&lt;br /&gt;
| BD    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Trem Dep||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Vibr Dep||style=&amp;quot;background-color: #FFCCDD;&amp;quot;|PercMode||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| BD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| SD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| TT On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| CY On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| HH On&lt;br /&gt;
|-&lt;br /&gt;
| C0-C8 ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| OutCh_D ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| OutCh_C ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Right  ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Left   ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;|FeedBack Modulation Factor||style=&amp;quot;background-color: #FFE0CC;&amp;quot;|SynthTyp&lt;br /&gt;
|-&lt;br /&gt;
| E0-F5 ||colspan=5|                                      ||colspan=3 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|style=&amp;quot;background-color: #CCFFCC;&amp;quot;| Chip-wide setting&lt;br /&gt;
|style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Per operator&lt;br /&gt;
|style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Per channel&lt;br /&gt;
|style=&amp;quot;background-color: #FFCCDD;&amp;quot;| Rhythm-mode only&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt; This applies only to port base+1&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;**&amp;lt;/nowiki&amp;gt; This applies only to port base+3&lt;br /&gt;
&lt;br /&gt;
For register bases A0, B0 and C0 there is one register per output channel. The primary register set holds the first nine channels (0-8) and the secondary holds last nine channels (9-17). For bases 20, 40, 60, 80 and E0 there are two registers per channel. Each register maps to one operator. Unfortunately the operator&#039;s register numbers are not continuous. The following table shows which operator maps to which register set and offset (in hex).&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Op. !! Set/Offset !! Op. !! Set/Offset&lt;br /&gt;
|-&lt;br /&gt;
| 0  || 0/00 || 18 || 1/00&lt;br /&gt;
|-&lt;br /&gt;
| 1  || 0/01 || 19 || 1/01&lt;br /&gt;
|-&lt;br /&gt;
| 2  || 0/02 || 20 || 1/02&lt;br /&gt;
|-&lt;br /&gt;
| 3  || 0/03 || 21 || 1/03&lt;br /&gt;
|-&lt;br /&gt;
| 4  || 0/04 || 22 || 1/04&lt;br /&gt;
|-&lt;br /&gt;
| 5  || 0/05 || 23 || 1/05&lt;br /&gt;
|-&lt;br /&gt;
| 6  || 0/08 || 24 || 1/08&lt;br /&gt;
|-&lt;br /&gt;
| 7  || 0/09 || 25 || 1/09&lt;br /&gt;
|-&lt;br /&gt;
| 8  || 0/0A || 26 || 1/0A&lt;br /&gt;
|-&lt;br /&gt;
| 9  || 0/0B || 27 || 1/0B&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 0/0C || 28 || 1/0C&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 0/0D || 29 || 1/0D&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 0/10 || 30 || 1/10&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 0/11 || 31 || 1/11&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 0/12 || 32 || 1/12&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 0/13 || 33 || 1/13&lt;br /&gt;
|-&lt;br /&gt;
| 16 || 0/14 || 34 || 1/14&lt;br /&gt;
|-&lt;br /&gt;
| 17 || 0/15 || 35 || 1/15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following tables summarize which operators form a channel in various modes:&lt;br /&gt;
&lt;br /&gt;
1. Two-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel    !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 13 || 14 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 || 16 || 17 || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
2. Two-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 ||colspan=4| - || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
3. Four-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 13 || 14 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 || 16 || 17 || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=3| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=3| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Channels 3, 4, 5 and 12, 13, 14 can&#039;t be used separately because their operators became part of channels 0, 1, 2 and 9, 10, 11 respectively. For instance a four-operator channel 1 consists of two two-operator channels number 1 and 4. (The second 2-OP channel number is always the first 2-OP channel number plus three.)&lt;br /&gt;
&lt;br /&gt;
OPL3 allows you to enable/disable 4-OP mode separately for any of channels 0, 1, 2, 9, 10 and 11 (see register 104h in the reference below). This means for instance when you switch only channel 2 into 4-OP mode, channels number 0, 1, 3, 4, 6, 7, 8, 9, etc. will be still independent 2-OP channels.&lt;br /&gt;
&lt;br /&gt;
Channels 6, 7, 8 and 15, 16, 17 are always two-operator ones. They can&#039;t be grouped to form four-operator channels.&lt;br /&gt;
&lt;br /&gt;
4. Four-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 ||colspan=4| - || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=5| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=5| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
Two-operator channel #14 consists of operators 26 and 29 which occupy these registers (all are in the secondary register set):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| 12A || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 12D || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 14A || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 14D || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 16A || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 16D || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18A || Operator 1 ||Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18D || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 1A5 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| 1B5 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| 1C5 ||            || FeedBack/Synthesis Type&lt;br /&gt;
|-&lt;br /&gt;
| 1EA || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| 1ED || Operator 2 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Four-operator channel #1 consists of operators 1, 4, 7 and 10. All registers except register 104h are in the primary set:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 104 || bit 1 = 1  || Enable Four-Operator Synthesis in channel #1&lt;br /&gt;
|-&lt;br /&gt;
| 21 || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 24 || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 29 || Operator 3 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 2C || Operator 4 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 41 || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 44 || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 49 || Operator 3 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 4C || Operator 4 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 61 || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 64 || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 69 || Operator 3 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 6C || Operator 4 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 81 || Operator 1 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 84 || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 89 || Operator 3 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 8C || Operator 4 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A1 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| A4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| B1 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| B4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| C1 ||            || FeedBack/Synthesis Type (part 1)&lt;br /&gt;
|-&lt;br /&gt;
| C4 ||            || Synthesis Type (part 2)&lt;br /&gt;
|-&lt;br /&gt;
| E1 || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E4 || Operator 2 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E9 || Operator 3 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| EC || Operator 4 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
NOTE: If a register number is greater than 100h, then it belongs into the secondary register set. (I use this numbering to emphasize the fact that the particular register MUST be written to the secondary set.) See the example code below for details.&lt;br /&gt;
&lt;br /&gt;
== OPL3 Register Reference ==&lt;br /&gt;
&lt;br /&gt;
Because the registers of OPL3 are almost the same as of OPL2, I have copied their descriptions from file ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
=== Status Register ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQ || T1 || T2 ||colspan=5| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ Flag. Set whenever any timer has elapsed.&lt;br /&gt;
* bit 6: Timer 1 Flag. Set every time the preset time in Timer 1 has elapsed.&lt;br /&gt;
* bit 5: Timer 2 Flag. Set every time the preset time in Timer 2 has elapsed.&lt;br /&gt;
&lt;br /&gt;
Timer interrupts are not wired to any IRQ (why??). The timers can be used to detect the OPL2/OPL3 chip (see Appendix B).&lt;br /&gt;
&lt;br /&gt;
=== Data Registers ===&lt;br /&gt;
&lt;br /&gt;
==== 01: Test Register / Waveform Select Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| Test Register&lt;br /&gt;
| (WSE)&lt;br /&gt;
|colspan=5| Test Register&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 7-6: Test Register. Must be reset to zero before any operation.&lt;br /&gt;
* bit 5: Waveform Select Enable. If clear, all channels will use normal sine wave. If set, register E0-F5 (Waveform Select) contents will be used.&lt;br /&gt;
* bits 0-4: Test Register. Must be reset to zero before any operation.&lt;br /&gt;
&lt;br /&gt;
OPL3 does not implement WSE bit, and it should be left clear. In OPL2 mode all four waveforms are always available, and in OPL3 mode all eight waveforms are always available. For compatibility with OPL2, when a program is finished using an OPL3, the waveform select registers should be set to 0, if the next program assumes that by setting WSE bit to 0 the waveform is always sine like on a real OPL2.&lt;br /&gt;
&lt;br /&gt;
==== 02: Timer 1 Count ====&lt;br /&gt;
&lt;br /&gt;
Upward 8 bit counter with a resolution of 80 µsec. If an overflow occurs, the status register bit is set, and the preset value is loaded into the timer again.&lt;br /&gt;
&lt;br /&gt;
==== 03: Timer 2 Count ====&lt;br /&gt;
&lt;br /&gt;
Same as Timer 1, but with a resolution of 320 µsec.&lt;br /&gt;
&lt;br /&gt;
==== 004 (port: base+1): IRQ-Reset / Mask / Start ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Rst&lt;br /&gt;
| T1M&lt;br /&gt;
| T2M&lt;br /&gt;
|colspan=3| -&lt;br /&gt;
| T2S&lt;br /&gt;
| T1S&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ-Reset. Resets timer and IRQ flags in status register. All other bits are ignored when this bit is set.&lt;br /&gt;
* bit 6: Timer 1 Mask. If 1, status register is not affected in overflow.&lt;br /&gt;
* bit 5: Timer 2 Mask. Same as above.&lt;br /&gt;
* bit 1: Timer 2 Start. Timer on/off.&lt;br /&gt;
* bit 0: Timer 1 Start. Same as above.&lt;br /&gt;
&lt;br /&gt;
==== 104 (port: base+3): Four-Operator Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| ChB&lt;br /&gt;
| ChA&lt;br /&gt;
| Ch9&lt;br /&gt;
| Ch2&lt;br /&gt;
| Ch1&lt;br /&gt;
| Ch0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: Enable four-operator synthesis for channel pair 11 - 14 (decimal).&lt;br /&gt;
* bit 4: Same as above for channel pair 10 - 13.&lt;br /&gt;
* bit 3: Same as above for channel pair 9 - 12.&lt;br /&gt;
* bit 2: Same as above for channel pair 2 - 5.&lt;br /&gt;
* bit 1: Same as above for channel pair 1 - 4.&lt;br /&gt;
* bit 0: Same as above for channel pair 0 - 3.&lt;br /&gt;
&lt;br /&gt;
If reset to zero, OPL3 can produce 18 two-operator sounds at a time. If nonzero, OPL3 produces four-operator sound in appropriate channel pair.&lt;br /&gt;
&lt;br /&gt;
==== 105 (port: base+3): OPL3 Mode Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=7| -&lt;br /&gt;
| OPL3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 0: OPL3 Mode Enable. When set, OPL3 extensions (36 operators, 4-OP synthesis, 8 waveforms, stereo output) can be used. When reset, the chip behaves as an ordinary OPL2. This bit is zero by default for compatibility with OPL2.&lt;br /&gt;
&lt;br /&gt;
==== 08: CSW / NOTE-SEL ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| (CSW)&lt;br /&gt;
| N-S&lt;br /&gt;
|colspan=6| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: Composite sine wave mode on/off. All KEY-ON bits must be clear in order to use this mode. The card is unable to create any other sound when in CSW mode. (Unfortunately, I have no info how to use this mode :-&amp;lt; ). The CSW mode is not implemented on an OPL3 and this bit is ignored.&lt;br /&gt;
* bit 6: NOTE-SEL. Controls the split point of the keyboard. When 0, the keyboard split is the second bit from the bit 8 of the F-Number. When 1, the MSb of the F-Number is used. (???)&lt;br /&gt;
&lt;br /&gt;
The Note Select bit defines what kind of F-NUM values are used within an octave so the chip knows how to split an octave into two parts. When Note Select bit is 0, F-NUM values used within an octave all have their MSB bit (bit 9) set, ranging from 0x200 to 0x3FF, so the second most significant bit, bit 8 is used to determine if currently playing note belongs to lower (0x200-0x2FF) or upper (0x300-0x3FF) half within an octave. When Note Select bit is 1, the F-NUM value MSB bit, bit 9, is used to determine if the note belongs to lower (0x000-0x1FF) or upper (0x200-0x3FF) half within an octave.&lt;br /&gt;
&lt;br /&gt;
==== 20-35: Tremolo / Vibrato / Sustain / KSR / Frequency Multiplication Factor ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Sus&lt;br /&gt;
| KSR&lt;br /&gt;
|colspan=4| Multiplication&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude vibrato) on/off.&lt;br /&gt;
* bit 6:    Frequency vibrato on/off.&lt;br /&gt;
* bit 5:    Sound Sustaining. When 1, operator&#039;s output level will be held at its sustain level until a KEY-OFF is done.&lt;br /&gt;
* bit 4:    Envelope scaling (KSR) on/off. When 1, higher notes are shorter than lower notes.&lt;br /&gt;
* bits 0-3: Frequency Multiplication Factor (MULTI). Operator&#039;s frequency is set to (see registers A0, B0) F-Number * Factor.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! MULTI !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0.5&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 2&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 3&lt;br /&gt;
|-&lt;br /&gt;
| 4 || 4&lt;br /&gt;
|-&lt;br /&gt;
| 5 || 5&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 6&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 7&lt;br /&gt;
|-&lt;br /&gt;
| 8 || 8&lt;br /&gt;
|-&lt;br /&gt;
| 9 || 9&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 40-55: Key Scale Level / Output Level ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| KSL&lt;br /&gt;
|colspan=6| Output level&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 6-7: Key Scale Level. Attenuates output level towards higher pitch:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! KSL !! Attenuation&lt;br /&gt;
|-&lt;br /&gt;
| 0 || -&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 3.0 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 1.5 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 6.0 dB/oct&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The attenuation level is based on the 3-bit octave (block number) value and top four bits of the FNUM value, so each octave is subdivided into 16 parts.&lt;br /&gt;
&lt;br /&gt;
* bits 0-5: Output Level. Attenuates the operator output level. 0 is the loudest, 3F is the softest. Attenuation range is 48dB with 0.75dB resolution.&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| 24dB || 12dB || 6dB || 3dB || 1.5dB || 0.75dB&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* In additive synthesis, varying the output level of any operator varies the volume of its corresponding channel. In FM synthesis, varying the output level of the carrier varies the volume of the channel. Varying the output of the modulator will change the frequency spectrum produced by the carrier. The following table summarizes which operators&#039; output levels should be updated when trying to change channel output level.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Mode !! Op 1 !! Op 2 !! Op 3 !! Op 4&lt;br /&gt;
|-&lt;br /&gt;
| AM    || Y || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM    || - || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM-FM || - || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-FM || Y || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| FM-AM || - || Y || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-AM || Y || - || Y   || Y&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 60-75: Attack Rate / Decay Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Attack rate&lt;br /&gt;
|colspan=4| Decay rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Attack Rate. Determines the rising time for the sound. The higher the value, the faster the attack. If value is 0, the sound will never attack, and if value is 15, the volume jumps directly from minimum to maximum.&lt;br /&gt;
* bits 0-3: Decay Rate. Determines the diminishing time for the sound. The higher the value, the shorter the decay. If value is 0, the sound does not decay towards sustain level and stays at maximum volume after attack.&lt;br /&gt;
&lt;br /&gt;
==== 80-95: Sustain Level / Release Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Sustain level&lt;br /&gt;
|colspan=4| Release rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Sustain Level. Determines the point at which the sound ceases to decay and chages to a sound having a constant level. The sustain level is expressed as a fraction of the maximum level. 15 is the softest and 0 is the loudest sustain level. Note that the Sustain-bit in the register 20-35 must be set for this to have an effect. Otherwise the sound will continue with release phase after hitting sustain level.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! SL3 !! SL2 !! SL1 !! SL0&lt;br /&gt;
|-&lt;br /&gt;
| -24dB || -12dB || -6dB || -3dB&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
There is an exception when all bits are set (value=15), the actual level is -93dB instead, matching as if the value were 31.&lt;br /&gt;
&lt;br /&gt;
* bits 0-3: Release Rate. Determines the rate at which the sound disappears after KEY-OFF. The higher the value, the shorter the release. Value of 0 causes the sound not to release at all, it will continue to produce sound at level before KEY-OFF.&lt;br /&gt;
&lt;br /&gt;
==== A0-A8: Frequency Number ====&lt;br /&gt;
&lt;br /&gt;
Determines the pitch of the note. Highest bits of F-Number are stored in the register below.&lt;br /&gt;
&lt;br /&gt;
==== B0-B8: Key On / Block Number / F-Number(hi bits) ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| KEY&lt;br /&gt;
|colspan=3| Block num.&lt;br /&gt;
|colspan=2| Freq&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: KEY-ON. When 1, channel output is enabled.&lt;br /&gt;
* bits 2-4: Block Number. Roughly determines the octave.&lt;br /&gt;
* bits 0-1: Frequency Number. 2 highest bits of the above register.  The following formula is used to determine F-Number and Block:&lt;br /&gt;
: F-Number = Music Frequency * 2^(20-Block) / 49716 Hz&lt;br /&gt;
&lt;br /&gt;
The sampling frequency of OPL2 and OPL3 chips is approximately 49716 Hz. OPL2 cards like Adlib and early Sound Blasters used the 14.31818 MHz oscillator signal from ISA bus slot and divided it by four on card, thus running the OPL2 chip at 3.579545 MHz, which gets divided internally by 72 to get the sampling rate. OPL3 cards had to be compatible, and mostly the sound cards have separate 14.31818 MHz oscillator on board which the OPL3 uses directly, and this gets divided internally by 288 to get the sampling rate.&lt;br /&gt;
&lt;br /&gt;
NOTE: In four-operator mode only the register value of Operators 1 and 2 is used, value of Operators 3 and 4 in this register is ignored. In other words: one channel uses only one frequency, block and KEY-ON value at a time, regardless whether it is a two- or four-operator channel.&lt;br /&gt;
&lt;br /&gt;
==== BD: Tremolo Depth / Vibrato Depth / Percussion Mode / BD/SD/TT/CY/HH On ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Per&lt;br /&gt;
| BD&lt;br /&gt;
| SD&lt;br /&gt;
| TT&lt;br /&gt;
| CY&lt;br /&gt;
| HH&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude Vibrato) Depth. 0 = 1.0dB, 1 = 4.8dB.&lt;br /&gt;
* bit 6:    Frequency Vibrato Depth. 0 = 7 cents, 1 = 14 cents. A &amp;quot;cent&amp;quot; is 1/100 of a semi-tone.&lt;br /&gt;
* bit 5:    Percussion Mode. 0 = Melodic Mode, 1 = Percussion Mode.&lt;br /&gt;
* bit 4:    BD On. KEY-ON of the Bass Drum channel.&lt;br /&gt;
* bit 3:    SD On. KEY-ON of the Snare Drum channel.&lt;br /&gt;
* bit 2:    TT On. KEY-ON of the Tom-Tom channel.&lt;br /&gt;
* bit 1:    CY On. KEY-ON of the Cymbal channel.&lt;br /&gt;
* bit 0:    HH On. KEY-ON of the Hi-Hat channel.&lt;br /&gt;
&lt;br /&gt;
NOTE: KEY-ON bits of channels 6, 7 and 8 must be clear and their F-Nums, Attack/Decay/Release rates, etc. must be set properly to use percussion mode.&lt;br /&gt;
&lt;br /&gt;
==== C0-C8: FeedBack Modulation Factor / Synthesis Type ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| OutCh_D&lt;br /&gt;
| OutCh_C&lt;br /&gt;
| R&lt;br /&gt;
| L&lt;br /&gt;
|colspan=3| Feedback&lt;br /&gt;
| Syn&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: CHD, Output Channel D Enable. When set, channel output goes to fourth digital audio output channel.&lt;br /&gt;
* bit 6: CHC, Output Channel C Enable. When set, channel output goes to third digital audio output channel.&lt;br /&gt;
* bit 5:    Right Speaker Enable. When set, channel output goes to second digital audio output channel, connected to right speaker.&lt;br /&gt;
* bit 4:    Left Speaker Enable. When set, channel output goes to first digital audio output channel, connected to left speaker.&lt;br /&gt;
** In OPL3 mode, at least one of the left/right bits must be set to hear the channel.&lt;br /&gt;
** In OPL2 mode, these bits are ignored and audio is sent to all channels for compatibility reasons.&lt;br /&gt;
** Left/Right bits can be used to realize sound &amp;quot;panning&amp;quot;, but this method offers only three pan positions (left/center/right).&lt;br /&gt;
** These bits apply only to operators producing sound (Carriers). Modulators are not affected by their setting.&lt;br /&gt;
** Sound cards use only one stereo DAC, so only two of the four digital output channels are available.&lt;br /&gt;
* bits 1-3: FeedBack Modulation Factor. If 0, no feedback is present. If 1-7, operator 1 will send a portion of its output back into itself.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! FeedBack !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;amp;pi;/16&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;amp;pi;/8&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;amp;pi;/4&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;amp;pi;/2&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 2&amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 4&amp;amp;pi;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
When in four-operator mode, the FeedBack value is used only by Operator 1, value of Operators 2, 3 and 4 is ignored.&lt;br /&gt;
&lt;br /&gt;
* bit 0: Synthesis Type. 1 = Additive synthesis, 0 = Frequency Modulation.  In four-operator mode, there are two bits controlling the synthesis type. Both are the bit 0 of register C0, one of Operators 1 and 2 and the second of Operators 3 and 4.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Op 1&amp;amp;2 !! Op 3&amp;amp;4 !! Type&lt;br /&gt;
|-&lt;br /&gt;
| 0 || NONE || FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || NONE || AM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || FM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || AM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || FM-AM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || AM-AM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== E0-F5: Waveform Select ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=5| -&lt;br /&gt;
|colspan=3| Waveform&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 0-2: WaveForm Select (WS): &amp;lt;gallery widths=261px perrow=4&amp;gt;&lt;br /&gt;
Image:OPL_Wave0.png|Waveform 0: Sine&lt;br /&gt;
Image:OPL_Wave1.png|Waveform 1: Half-sine&lt;br /&gt;
Image:OPL_Wave2.png|Waveform 2: Abs-sine&lt;br /&gt;
Image:OPL_Wave3.png|Waveform 3: Pulse-sine&lt;br /&gt;
Image:OPL_Wave4.png|Waveform 4: Sine - even periods only&lt;br /&gt;
Image:OPL_Wave5.png|Waveform 5: Abs-sine - even periods only&lt;br /&gt;
Image:OPL_Wave6.png|Waveform 6: Square&lt;br /&gt;
Image:OPL_Wave7.png|Waveform 7: Derived square&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* NOTE: Bit 5 of register 01 must be set to use waveforms other than sine. Waveforms 4-7 are available only on OPL3. See files WAVEn.GIF for real waveforms, where n is a number between 0 and 7.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
These examples show a few working routines used in my MUS Player. They are written in Borland C++ 3.1 but should be easy to translate to any other language.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
// I prefer using these Assembler-like types&lt;br /&gt;
typedef unsigned int  WORD;&lt;br /&gt;
typedef unsigned char BYTE;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * FM Synthesizer base port. SB Pro II - 0x220, Adlib 0x388&lt;br /&gt;
 */&lt;br /&gt;
WORD FMport = 0x220;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Enables OPL3 extensions.&lt;br /&gt;
 */&lt;br /&gt;
WORD OPL3 = 1;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Direct write to any Adlib/SB Pro II FM synthetiser register.&lt;br /&gt;
 *   reg - register number (range 0x001-0x0F5 and 0x101-0x1F5). When high byte&lt;br /&gt;
 *         of reg is zero, data go to port FMport, otherwise to FMport+2&lt;br /&gt;
 *   data - register value to be written&lt;br /&gt;
 */&lt;br /&gt;
BYTE FMwriteReg(WORD reg, BYTE data)&lt;br /&gt;
{&lt;br /&gt;
    asm {&lt;br /&gt;
	mov	dx,FMport&lt;br /&gt;
	mov	ax,reg&lt;br /&gt;
	or	ah,ah		// high byte is nonzero -- write to port base+2&lt;br /&gt;
	jz	out1&lt;br /&gt;
	inc	dx&lt;br /&gt;
	inc	dx&lt;br /&gt;
    }&lt;br /&gt;
out1: asm {&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	mov	cx,6&lt;br /&gt;
    }&lt;br /&gt;
loop1:asm {			// delay between writes&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop1&lt;br /&gt;
&lt;br /&gt;
	inc	dx&lt;br /&gt;
	mov	al,data&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	dec	dx&lt;br /&gt;
	mov	cx,36&lt;br /&gt;
    }&lt;br /&gt;
loop2:asm {			// delay after data write&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop2&lt;br /&gt;
    }&lt;br /&gt;
    return _AL;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to an operator pair. To be used for register bases of 0x20, 0x40,&lt;br /&gt;
 * 0x60, 0x80 and 0xE0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteChannel(BYTE regbase, BYTE channel, BYTE data1, BYTE data2)&lt;br /&gt;
{&lt;br /&gt;
    static BYTE adlib_op[] = {0, 1, 2, 8, 9, 10, 16, 17, 18};&lt;br /&gt;
    static BYTE sbpro_op[] = { 0,  1,  2,   6,  7,  8,  12, 13, 14,&lt;br /&gt;
			      18, 19, 20,  24, 25, 26,  30, 31, 32};&lt;br /&gt;
    static WORD rg[] = {0x000,0x001,0x002,0x003,0x004,0x005,&lt;br /&gt;
			0x008,0x009,0x00A,0x00B,0x00C,0x00D,&lt;br /&gt;
			0x010,0x011,0x012,0x013,0x014,0x015,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,&lt;br /&gt;
			0x108,0x109,0x10A,0x10B,0x10C,0x10D,&lt;br /&gt;
			0x110,0x111,0x112,0x113,0x114,0x115};&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
    {&lt;br /&gt;
	register WORD reg = sbpro_op[channel];&lt;br /&gt;
	FMwriteReg(rg[reg]+regbase, data1);&lt;br /&gt;
	FMwriteReg(rg[reg+3]+regbase, data2);&lt;br /&gt;
    } else {&lt;br /&gt;
	register WORD reg = regbase+adlib_op[channel];&lt;br /&gt;
	FMwriteReg(reg, data1);&lt;br /&gt;
	FMwriteReg(reg+3, data2);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to channel a single value. To be used for register bases of&lt;br /&gt;
 * 0xA0, 0xB0 and 0xC0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteValue(BYTE regbase, BYTE channel, BYTE value)&lt;br /&gt;
{&lt;br /&gt;
    static WORD ch[] = {0x000,0x001,0x002,0x003,0x004,0x005,0x006,0x007,0x008,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,0x106,0x107,0x108};&lt;br /&gt;
    register WORD chan;&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
	chan = ch[channel];&lt;br /&gt;
    else&lt;br /&gt;
	chan = channel;&lt;br /&gt;
    FMwriteReg(regbase + chan, value);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Detection Methods ==&lt;br /&gt;
&lt;br /&gt;
An official method of Adlib (OPL2) detection is:&lt;br /&gt;
&lt;br /&gt;
# Reset Timer 1 and Timer 2: write 60h to register 4.&lt;br /&gt;
# Reset the IRQ: write 80h to register 4.&lt;br /&gt;
#* NOTE: Steps 1 and 2 can&#039;t be combined together.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Set Timer 1 to FFh: write FFh to register 2.&lt;br /&gt;
# Unmask and start Timer 1: write 21h to register 4.&lt;br /&gt;
# Wait in a delay loop for at least 80 µsec.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Reset Timer 1, Timer 2 and IRQ as in steps 1 and 2.&lt;br /&gt;
# Test the results of the two reads: the first should be 0, the second should be C0h. If either is incorrect, then the OPL2 is not present.&lt;br /&gt;
&lt;br /&gt;
* NOTE1: You should AND the result bytes with E0h because the unused bits are undefined.&lt;br /&gt;
* NOTE2: This testing method doesn&#039;t work in some SoundBlaster compatible cards.&lt;br /&gt;
&lt;br /&gt;
=== OPL3 Detection ===&lt;br /&gt;
--------------&lt;br /&gt;
&lt;br /&gt;
# Detect OPL2. If present, continue.&lt;br /&gt;
# Read status register: read port base+0.&lt;br /&gt;
# AND the result with 06h.&lt;br /&gt;
# If the result is zero, you have OPL3, otherwise OPL2.&lt;br /&gt;
&lt;br /&gt;
* NOTE: This is NOT an official method. I have dug it out of a sound driver. I haven&#039;t tested it, because I haven&#039;t an OPL2 card (Adlib, SB Pro I). Nevertheless it &amp;quot;detects&amp;quot; my SB Pro II properly. ;-)&lt;br /&gt;
&lt;br /&gt;
Another possible detection method for distinguishing between SB Pro I and SB Pro II would be to try to detect OPL2 at I/O port base+0 and then at port base+2. The first test should succeed and the second should fail if OPL3 is present. (Remember: SB Pro I contains twin OPL2 chips at addresses base+0 and base+2, while SB Pro II contains one OPL3 chip at I/O address base+0 thru base+3).&lt;br /&gt;
&lt;br /&gt;
== BLASTER Environment Variable ==&lt;br /&gt;
&lt;br /&gt;
Perhaps the most recommended &amp;quot;detection&amp;quot; method. Reading this variable avoids blindfold I/O port scanning and possible device conflicts. The user is responsible for its proper setting.&lt;br /&gt;
&lt;br /&gt;
The variable has this format:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=Aaddr Iirq Ddma Ttype&lt;br /&gt;
&lt;br /&gt;
* A: Base I/O address given in hex. For most Sound Blasters the default is 220.&lt;br /&gt;
* I: IRQ Number (decimal). Default 7.&lt;br /&gt;
* D: DMA Number (decimal). Default 1.&lt;br /&gt;
* T: Card Type (decimal):&lt;br /&gt;
** 1 - Sound Blaster 1.5&lt;br /&gt;
** 2 - Sound Blaster Pro I&lt;br /&gt;
** 3 - Sound Blaster 2.0&lt;br /&gt;
** 4 - Sound Blaster Pro II&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=A220 I7 D1 T4&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The PC Games Programmers Encyclopedia&#039;&#039;, Mark Feldman and many others on Usenet and Internet, ftp://teeri.oulu.fi/pub/msdos/programming/gpe&lt;br /&gt;
: ... you can find (almost) everything you need there&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Sound Blaster - The Official Book&#039;&#039;, Richard Heimlich, David M. Golden, Ivan Luk, Peter M. Ridge, Osborne/McGraw Hill, ISBN 0-07-881907-5&lt;br /&gt;
: ... this is a number-one in my book-wishlist. If anyone wanted to get rid of the book, I wouldn&#039;t scorn it ... :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The SoundBlaster Developer Kit&#039;&#039;, Creative Labs Inc, Creative Technology PTE LTD&lt;br /&gt;
: ... I wonder if you can find something comprehensible in that.&lt;/div&gt;</summary>
		<author><name>Kermes</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4337</id>
		<title>OPL chip</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4337"/>
		<updated>2012-08-05T20:46:12Z</updated>

		<summary type="html">&lt;p&gt;Kermes: /* B0-B8: Key On / Block Number / F-Number(hi bits) */ Explanation about sampling rate for F-NUM calculation.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Programmer&#039;s Guide to Yamaha YMF 262/OPL3 FM Music Synthesizer =&lt;br /&gt;
Version 1.00  Nov-24-1994&lt;br /&gt;
&lt;br /&gt;
Written by Vladimir Arnost, QA-Software&lt;br /&gt;
Internet:  xarnos00@dcse.fee.vutbr.cz&lt;br /&gt;
&lt;br /&gt;
This manual can be distributed freely if not modified.&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer ===&lt;br /&gt;
&lt;br /&gt;
I assume no responsibility for any damages arising out of use or inability to use this text. No warranty is provided about correctness of any information in this file. You are on your own.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The chip I am going to describe is getting more and more common, but programming information is still scarce, so I have decided to fill in this gap. All information contained in this file is a result of my experience in Adlib programming, research (read: reverse engineering) and finally of my effort to write down everything necessary to understand and use this piece of hardware. No official sources (i.e. development kits, books about this topic, etc.) were available to me except:&lt;br /&gt;
&lt;br /&gt;
: Adlib Programming Guide - by Tero Töttö, and&lt;br /&gt;
: The PC Games Programmers Encyclopedia V1.0&lt;br /&gt;
&lt;br /&gt;
The information below is a combination of known features of Adlib (alias Yamaha YM 3812/OPL2) and my own uncountable experiments and failures, which brought out a lot of important details you have to know about the chip.&lt;br /&gt;
&lt;br /&gt;
As far as I know, there are four major sound cards based on OPL3 chip:&lt;br /&gt;
&lt;br /&gt;
* Sound Blaster Pro II (not Sound Blaster Pro I)&lt;br /&gt;
* Sound Blaster 16&lt;br /&gt;
* Adlib Gold&lt;br /&gt;
* Pro Audio Spectrum Plus/16&lt;br /&gt;
&lt;br /&gt;
I currently have a Sound Blaster Pro II-compatible card only, so all the programming info I provide will be based on this card. (The other cards are quite similar, however. They are just wired at different I/O-port addresses.)&lt;br /&gt;
&lt;br /&gt;
Note: I assume some knowledge of FM music programming (mainly Adlib FM synthesizer) in this manual. If you are new to this topic I recommend you try Adlib first before going higher. Anyway, OPL3 is a direct descendant of OPL2 (what a surprise), so most features of OPL2 are also present on OPL3.&lt;br /&gt;
&lt;br /&gt;
== Description of the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
My card&#039;s user manual says: &amp;quot;[this card contains] ... a stereo music FM synthesizer with 20 channels consisting of four (4) operators each ... &amp;quot; I thought: &amp;quot;Wow -- that&#039;s together eighty operators. This must be a GOOD sound-card.&amp;quot; I was wrong. Just another advertising lie.&lt;br /&gt;
&lt;br /&gt;
So let&#039;s clear some facts. First, OPL3 has only thirty-six (36) operators which can be combined in several ways:&lt;br /&gt;
&lt;br /&gt;
* 18 FM channels (36 operators), or&lt;br /&gt;
* 15 FM channels (30 ops) and 5 percussion instruments (6 ops), giving us 20 channels altogether, or&lt;br /&gt;
* up to 6 four-operator FM channels (max 24 ops), the rest again being divided into two-operator FM channels and drums.&lt;br /&gt;
&lt;br /&gt;
From the table above you can see that not all channels can be used in four-operator (4-OP) mode -- only a part of the synthesizer is really capable of making 4-OP sounds -- the rest uses traditional two-operator (2-OP) mode.&lt;br /&gt;
&lt;br /&gt;
Second, the manual states this card is capable of &amp;quot;stereo&amp;quot; music. Yes, the quotes are necessary, because the stereo capabilities are very limited. You are given ability to control output going to left or right channel by turning it on and off. That&#039;s all. So the sound can flow from very left side, center and very right side. No sound panning, no special stereo effects. :-(&lt;br /&gt;
&lt;br /&gt;
Well, flaming apart, back to the main topic.&lt;br /&gt;
&lt;br /&gt;
The OPL3 chip is capable of making sounds in several ways:&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Additive Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output of both operators is simply added. It is the simplest way to make any sound, and it works on both OPL2 and OPL3. The diagram should make it clear.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐&lt;br /&gt;
	│            │&lt;br /&gt;
	│ Operator 1 ├────────┐&lt;br /&gt;
	│            │        │&lt;br /&gt;
	└────────────┘        │&lt;br /&gt;
			      ├────────&amp;gt; Output&lt;br /&gt;
	┌────────────┐        │&lt;br /&gt;
	│            │        │&lt;br /&gt;
	│ Operator 2 ├────────┘&lt;br /&gt;
	│            │&lt;br /&gt;
	└────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Frequency Modulation (FM) Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output from the first operator (Modulator) is sent to the input of the second one (Carrier) and is used to modulate (alter) frequency of the second operator. Only the second operator produces sound. Most of interesting sounds are made this way. This also works on OPL2. Hope the picture helps.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐         ┌────────────┐&lt;br /&gt;
	│            │         │            │&lt;br /&gt;
	│ Operator 1 ├────────&amp;gt;│ Operator 2 ├────────&amp;gt; Output&lt;br /&gt;
	│(Modulator) │         │ (Carrier)  │&lt;br /&gt;
	└────────────┘         └────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Four-operator &amp;quot;Mess&amp;quot; Modulation Synthesis ===&lt;br /&gt;
&lt;br /&gt;
All of OPL3&#039;s 4-OP configurations are combinations of the above two modes of synthesis. OPL3 combines these two modes in four ways. I have no words to describe these four ways. Only the pictures can show their principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   a) FM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   b) AM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├───────────────────────────────────┐&lt;br /&gt;
	│       │                                   │&lt;br /&gt;
	└───────┘                                   │&lt;br /&gt;
						    │&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┴─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   c) FM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────┐&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     ├─────&amp;gt; Output&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┘&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	└───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   d) AM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├────────────────────┐&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	└───────┘                    │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────┼─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐                    │&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	│ Op. 4 ├────────────────────┘&lt;br /&gt;
	│       │&lt;br /&gt;
	└───────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Nice, aren&#039;t they?&lt;br /&gt;
&lt;br /&gt;
The only way I think this can be written is a math formula. Symbol + (plus) means additive synthesis, and * (asterisk) means frequency modulation (Op1 * Op2 means operator 1 modulates operator 2, not vice versa). Here they are:&lt;br /&gt;
&lt;br /&gt;
# FM-FM Mode:	 (Op1 * Op2 * Op3 * Op4) ────&amp;gt; Output&lt;br /&gt;
# AM-FM Mode:	  Op1 + (Op2 * Op3 * Op4) ───&amp;gt; Output&lt;br /&gt;
# FM-AM Mode:	 (Op1 * Op2) + (Op3 * Op4) ──&amp;gt; Output&lt;br /&gt;
# AM-AM Mode:	  Op1 + (Op2 * Op3) + Op4 ───&amp;gt; Output&lt;br /&gt;
&lt;br /&gt;
=== Percussion Mode ===&lt;br /&gt;
&lt;br /&gt;
In this mode 6 operators are used to produce five different percussion instruments:&lt;br /&gt;
&lt;br /&gt;
* Bass Drum (2 operators)&lt;br /&gt;
* Snare Drum (1 operator)&lt;br /&gt;
* Tom-Tom (1 operator)&lt;br /&gt;
* Cymbal (1 operator)&lt;br /&gt;
* Hi-Hat (1 operator)&lt;br /&gt;
&lt;br /&gt;
Because these instruments occupy only three melodic channels, only Bass Drum, Snare Drum and Tom-Tom frequencies can be set. Cymbal and Hi-Hat frequencies are fixed.  {{TODO|It seems it&#039;s actually the cymbal and snare frequencies that are fixed, try to confirm this -- [[User:Malvineous|Malvineous]] 13:34, 3 June 2012 (GMT)}}&lt;br /&gt;
&lt;br /&gt;
This mode is identical with that of OPL2. For more details see ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
== Programming the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
OPL3 may be found at the following addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| Sound Blaster Pro II || 220h or 240h (selectable), also 388h&lt;br /&gt;
|-&lt;br /&gt;
| Adlib Gold || 388h&lt;br /&gt;
|-&lt;br /&gt;
| Pro Audio Spectrum Plus/16 || ? (if you have a PAS you should know it)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The base address of the synthesizer will be called &amp;quot;base&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The chip occupies four I/O addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| base+0 || Primary index register (write), Status register (read)&lt;br /&gt;
|-&lt;br /&gt;
| base+1 || Primary data register (write-only)&lt;br /&gt;
|-&lt;br /&gt;
| base+2 || Secondary index register (write)&lt;br /&gt;
|-&lt;br /&gt;
| base+3 || Secondary data register (write-only)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The index registers are used to select internal registers and data registers are used to write to them. Status register returns the state of two timers built in the chip.&lt;br /&gt;
&lt;br /&gt;
OPL3 contains two sets of registers. The Primary set maps to channels 0-8 (operators 0-17) and the secondary maps to channels 9-17 (operators 18-35). The reason for this is simple: all these registers wouldn&#039;t fit into single register set.&lt;br /&gt;
&lt;br /&gt;
Unlike Adlib (OPL2), OPL3 doesn&#039;t need delay between register writes. With OPL2 you had to wait 3.3 µs after index register write and another 23 µs after data register write. On the contrary OPL3 doesn&#039;t need (almost) any delay after index register write and only 0.28 µs after data register write. This means you can neglect the delays and slightly speed up your music driver. But using reasonable delays will certainly do no harm.&lt;br /&gt;
&lt;br /&gt;
The data registers can&#039;t be read (they are write-only) on both OPL2 and OPL3.&lt;br /&gt;
&lt;br /&gt;
== Register Map ==&lt;br /&gt;
&lt;br /&gt;
The registers are grouped in the same manner as in the OPL2 chip. Programs using both OPL2 and OPL3 chips may use the same code provided that their direct I/O interface is well written. The only thing you have to change is operator-to-register mapping, which must accomodate the fact that registers are spread between two register sets.&lt;br /&gt;
&lt;br /&gt;
(The register map is nearly the same so I dared to copy it from ADLIB.DOC.)&lt;br /&gt;
&lt;br /&gt;
=== Status Register (base+0) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
!    D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQFlag || T1Flag || T2Flag ||        ||        ||        ||        ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Data Registers (base+1, base+3) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! REG   !!   D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| 01    ||colspan=2| Test Register ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|(WSEnable)||colspan=5| Test Register&lt;br /&gt;
|-&lt;br /&gt;
| 02    ||colspan=8| Timer 1 Count (80 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 03    ||colspan=8| Timer 2 Count (320 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 04*   ||IRQReset|| T1Mask || T2Mask ||colspan=3|                  ||T2 Start||T1 Start&lt;br /&gt;
|-&lt;br /&gt;
| 04**  ||colspan=2|        ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP B-E||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP A-D||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 9-C||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 2-5||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 1-4||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 0-3&lt;br /&gt;
|-&lt;br /&gt;
| 05**  ||colspan=7|                                                           ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;| OPL3&lt;br /&gt;
|-&lt;br /&gt;
| 08    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;| (CSW)  ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|NOTE-SEL||colspan=6|&lt;br /&gt;
|-&lt;br /&gt;
| 20-35 ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Tremolo ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Vibrato ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Sustain ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|  KSR   ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Frequency Multiplication Factor&lt;br /&gt;
|-&lt;br /&gt;
| 40-55 ||colspan=2 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Key Scale Level ||colspan=6 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 60-75 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Attack Rate ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 80-95 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Sustain Level ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A0-A8 ||colspan=8 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Frequency Number  (Lower 8 bits)&lt;br /&gt;
|-&lt;br /&gt;
| B0-B8 ||colspan=2|        ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| KEY-ON ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Block Number ||colspan=2 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| F-Num (hi bits)&lt;br /&gt;
|-&lt;br /&gt;
| BD    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Trem Dep||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Vibr Dep||style=&amp;quot;background-color: #FFCCDD;&amp;quot;|PercMode||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| BD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| SD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| TT On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| CY On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| HH On&lt;br /&gt;
|-&lt;br /&gt;
| C0-C8 ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| OutCh_D ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| OutCh_C ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Right  ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Left   ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;|FeedBack Modulation Factor||style=&amp;quot;background-color: #FFE0CC;&amp;quot;|SynthTyp&lt;br /&gt;
|-&lt;br /&gt;
| E0-F5 ||colspan=5|                                      ||colspan=3 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|style=&amp;quot;background-color: #CCFFCC;&amp;quot;| Chip-wide setting&lt;br /&gt;
|style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Per operator&lt;br /&gt;
|style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Per channel&lt;br /&gt;
|style=&amp;quot;background-color: #FFCCDD;&amp;quot;| Rhythm-mode only&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt; This applies only to port base+1&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;**&amp;lt;/nowiki&amp;gt; This applies only to port base+3&lt;br /&gt;
&lt;br /&gt;
For register bases A0, B0 and C0 there is one register per output channel. The primary register set holds the first nine channels (0-8) and the secondary holds last nine channels (9-17). For bases 20, 40, 60, 80 and E0 there are two registers per channel. Each register maps to one operator. Unfortunately the operator&#039;s register numbers are not continuous. The following table shows which operator maps to which register set and offset (in hex).&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Op. !! Set/Offset !! Op. !! Set/Offset&lt;br /&gt;
|-&lt;br /&gt;
| 0  || 0/00 || 18 || 1/00&lt;br /&gt;
|-&lt;br /&gt;
| 1  || 0/01 || 19 || 1/01&lt;br /&gt;
|-&lt;br /&gt;
| 2  || 0/02 || 20 || 1/02&lt;br /&gt;
|-&lt;br /&gt;
| 3  || 0/03 || 21 || 1/03&lt;br /&gt;
|-&lt;br /&gt;
| 4  || 0/04 || 22 || 1/04&lt;br /&gt;
|-&lt;br /&gt;
| 5  || 0/05 || 23 || 1/05&lt;br /&gt;
|-&lt;br /&gt;
| 6  || 0/08 || 24 || 1/08&lt;br /&gt;
|-&lt;br /&gt;
| 7  || 0/09 || 25 || 1/09&lt;br /&gt;
|-&lt;br /&gt;
| 8  || 0/0A || 26 || 1/0A&lt;br /&gt;
|-&lt;br /&gt;
| 9  || 0/0B || 27 || 1/0B&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 0/0C || 28 || 1/0C&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 0/0D || 29 || 1/0D&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 0/10 || 30 || 1/10&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 0/11 || 31 || 1/11&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 0/12 || 32 || 1/12&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 0/13 || 33 || 1/13&lt;br /&gt;
|-&lt;br /&gt;
| 16 || 0/14 || 34 || 1/14&lt;br /&gt;
|-&lt;br /&gt;
| 17 || 0/15 || 35 || 1/15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following tables summarize which operators form a channel in various modes:&lt;br /&gt;
&lt;br /&gt;
1. Two-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel    !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 13 || 14 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 || 16 || 17 || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
2. Two-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 ||colspan=4| - || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
3. Four-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 13 || 14 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 || 16 || 17 || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=3| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=3| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Channels 3, 4, 5 and 12, 13, 14 can&#039;t be used separately because their operators became part of channels 0, 1, 2 and 9, 10, 11 respectively. For instance a four-operator channel 1 consists of two two-operator channels number 1 and 4. (The second 2-OP channel number is always the first 2-OP channel number plus three.)&lt;br /&gt;
&lt;br /&gt;
OPL3 allows you to enable/disable 4-OP mode separately for any of channels 0, 1, 2, 9, 10 and 11 (see register 104h in the reference below). This means for instance when you switch only channel 2 into 4-OP mode, channels number 0, 1, 3, 4, 6, 7, 8, 9, etc. will be still independent 2-OP channels.&lt;br /&gt;
&lt;br /&gt;
Channels 6, 7, 8 and 15, 16, 17 are always two-operator ones. They can&#039;t be grouped to form four-operator channels.&lt;br /&gt;
&lt;br /&gt;
4. Four-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 ||colspan=4| - || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=5| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=5| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
Two-operator channel #14 consists of operators 26 and 29 which occupy these registers (all are in the secondary register set):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| 12A || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 12D || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 14A || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 14D || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 16A || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 16D || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18A || Operator 1 ||Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18D || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 1A5 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| 1B5 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| 1C5 ||            || FeedBack/Synthesis Type&lt;br /&gt;
|-&lt;br /&gt;
| 1EA || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| 1ED || Operator 2 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Four-operator channel #1 consists of operators 1, 4, 7 and 10. All registers except register 104h are in the primary set:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 104 || bit 1 = 1  || Enable Four-Operator Synthesis in channel #1&lt;br /&gt;
|-&lt;br /&gt;
| 21 || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 24 || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 29 || Operator 3 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 2C || Operator 4 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 41 || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 44 || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 49 || Operator 3 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 4C || Operator 4 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 61 || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 64 || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 69 || Operator 3 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 6C || Operator 4 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 81 || Operator 1 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 84 || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 89 || Operator 3 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 8C || Operator 4 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A1 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| A4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| B1 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| B4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| C1 ||            || FeedBack/Synthesis Type (part 1)&lt;br /&gt;
|-&lt;br /&gt;
| C4 ||            || Synthesis Type (part 2)&lt;br /&gt;
|-&lt;br /&gt;
| E1 || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E4 || Operator 2 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E9 || Operator 3 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| EC || Operator 4 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
NOTE: If a register number is greater than 100h, then it belongs into the secondary register set. (I use this numbering to emphasize the fact that the particular register MUST be written to the secondary set.) See the example code below for details.&lt;br /&gt;
&lt;br /&gt;
== OPL3 Register Reference ==&lt;br /&gt;
&lt;br /&gt;
Because the registers of OPL3 are almost the same as of OPL2, I have copied their descriptions from file ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
=== Status Register ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQ || T1 || T2 ||colspan=5| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ Flag. Set whenever any timer has elapsed.&lt;br /&gt;
* bit 6: Timer 1 Flag. Set every time the preset time in Timer 1 has elapsed.&lt;br /&gt;
* bit 5: Timer 2 Flag. Set every time the preset time in Timer 2 has elapsed.&lt;br /&gt;
&lt;br /&gt;
Timer interrupts are not wired to any IRQ (why??). The timers can be used to detect the OPL2/OPL3 chip (see Appendix B).&lt;br /&gt;
&lt;br /&gt;
=== Data Registers ===&lt;br /&gt;
&lt;br /&gt;
==== 01: Test Register / Waveform Select Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| Test Register&lt;br /&gt;
| (WSE)&lt;br /&gt;
|colspan=5| Test Register&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 7-6: Test Register. Must be reset to zero before any operation.&lt;br /&gt;
* bit 5: Waveform Select Enable. If clear, all channels will use normal sine wave. If set, register E0-F5 (Waveform Select) contents will be used.&lt;br /&gt;
* bits 0-4: Test Register. Must be reset to zero before any operation.&lt;br /&gt;
&lt;br /&gt;
OPL3 does not implement WSE bit, and it should be left clear. In OPL2 mode all four waveforms are always available, and in OPL3 mode all eight waveforms are always available. For compatibility with OPL2, when a program is finished using an OPL3, the waveform select registers should be set to 0, if the next program assumes that by setting WSE bit to 0 the waveform is always sine like on a real OPL2.&lt;br /&gt;
&lt;br /&gt;
==== 02: Timer 1 Count ====&lt;br /&gt;
&lt;br /&gt;
Upward 8 bit counter with a resolution of 80 µsec. If an overflow occurs, the status register bit is set, and the preset value is loaded into the timer again.&lt;br /&gt;
&lt;br /&gt;
==== 03: Timer 2 Count ====&lt;br /&gt;
&lt;br /&gt;
Same as Timer 1, but with a resolution of 320 µsec.&lt;br /&gt;
&lt;br /&gt;
==== 004 (port: base+1): IRQ-Reset / Mask / Start ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Rst&lt;br /&gt;
| T1M&lt;br /&gt;
| T2M&lt;br /&gt;
|colspan=3| -&lt;br /&gt;
| T2S&lt;br /&gt;
| T1S&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ-Reset. Resets timer and IRQ flags in status register. All other bits are ignored when this bit is set.&lt;br /&gt;
* bit 6: Timer 1 Mask. If 1, status register is not affected in overflow.&lt;br /&gt;
* bit 5: Timer 2 Mask. Same as above.&lt;br /&gt;
* bit 1: Timer 2 Start. Timer on/off.&lt;br /&gt;
* bit 0: Timer 1 Start. Same as above.&lt;br /&gt;
&lt;br /&gt;
==== 104 (port: base+3): Four-Operator Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| ChB&lt;br /&gt;
| ChA&lt;br /&gt;
| Ch9&lt;br /&gt;
| Ch2&lt;br /&gt;
| Ch1&lt;br /&gt;
| Ch0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: Enable four-operator synthesis for channel pair 11 - 14 (decimal).&lt;br /&gt;
* bit 4: Same as above for channel pair 10 - 13.&lt;br /&gt;
* bit 3: Same as above for channel pair 9 - 12.&lt;br /&gt;
* bit 2: Same as above for channel pair 2 - 5.&lt;br /&gt;
* bit 1: Same as above for channel pair 1 - 4.&lt;br /&gt;
* bit 0: Same as above for channel pair 0 - 3.&lt;br /&gt;
&lt;br /&gt;
If reset to zero, OPL3 can produce 18 two-operator sounds at a time. If nonzero, OPL3 produces four-operator sound in appropriate channel pair.&lt;br /&gt;
&lt;br /&gt;
==== 105 (port: base+3): OPL3 Mode Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=7| -&lt;br /&gt;
| OPL3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 0: OPL3 Mode Enable. When set, OPL3 extensions (36 operators, 4-OP synthesis, 8 waveforms, stereo output) can be used. When reset, the chip behaves as an ordinary OPL2. This bit is zero by default for compatibility with OPL2.&lt;br /&gt;
&lt;br /&gt;
==== 08: CSW / NOTE-SEL ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| (CSW)&lt;br /&gt;
| N-S&lt;br /&gt;
|colspan=6| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: Composite sine wave mode on/off. All KEY-ON bits must be clear in order to use this mode. The card is unable to create any other sound when in CSW mode. (Unfortunately, I have no info how to use this mode :-&amp;lt; ). The CSW mode is not implemented on an OPL3 and this bit is ignored.&lt;br /&gt;
* bit 6: NOTE-SEL. Controls the split point of the keyboard. When 0, the keyboard split is the second bit from the bit 8 of the F-Number. When 1, the MSb of the F-Number is used. (???)&lt;br /&gt;
&lt;br /&gt;
==== 20-35: Tremolo / Vibrato / Sustain / KSR / Frequency Multiplication Factor ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Sus&lt;br /&gt;
| KSR&lt;br /&gt;
|colspan=4| Multiplication&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude vibrato) on/off.&lt;br /&gt;
* bit 6:    Frequency vibrato on/off.&lt;br /&gt;
* bit 5:    Sound Sustaining. When 1, operator&#039;s output level will be held at its sustain level until a KEY-OFF is done.&lt;br /&gt;
* bit 4:    Envelope scaling (KSR) on/off. When 1, higher notes are shorter than lower notes.&lt;br /&gt;
* bits 0-3: Frequency Multiplication Factor (MULTI). Operator&#039;s frequency is set to (see registers A0, B0) F-Number * Factor.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! MULTI !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0.5&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 2&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 3&lt;br /&gt;
|-&lt;br /&gt;
| 4 || 4&lt;br /&gt;
|-&lt;br /&gt;
| 5 || 5&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 6&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 7&lt;br /&gt;
|-&lt;br /&gt;
| 8 || 8&lt;br /&gt;
|-&lt;br /&gt;
| 9 || 9&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 40-55: Key Scale Level / Output Level ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| KSL&lt;br /&gt;
|colspan=6| Output level&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 6-7: Key Scale Level. Attenuates output level towards higher pitch:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! KSL !! Attenuation&lt;br /&gt;
|-&lt;br /&gt;
| 0 || -&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 3.0 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 1.5 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 6.0 dB/oct&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The attenuation level is based on the 3-bit octave (block number) value and top four bits of the FNUM value, so each octave is subdivided into 16 parts.&lt;br /&gt;
&lt;br /&gt;
* bits 0-5: Output Level. Attenuates the operator output level. 0 is the loudest, 3F is the softest. Attenuation range is 48dB with 0.75dB resolution.&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| 24dB || 12dB || 6dB || 3dB || 1.5dB || 0.75dB&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* In additive synthesis, varying the output level of any operator varies the volume of its corresponding channel. In FM synthesis, varying the output level of the carrier varies the volume of the channel. Varying the output of the modulator will change the frequency spectrum produced by the carrier. The following table summarizes which operators&#039; output levels should be updated when trying to change channel output level.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Mode !! Op 1 !! Op 2 !! Op 3 !! Op 4&lt;br /&gt;
|-&lt;br /&gt;
| AM    || Y || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM    || - || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM-FM || - || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-FM || Y || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| FM-AM || - || Y || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-AM || Y || - || Y   || Y&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 60-75: Attack Rate / Decay Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Attack rate&lt;br /&gt;
|colspan=4| Decay rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Attack Rate. Determines the rising time for the sound. The higher the value, the faster the attack. If value is 0, the sound will never attack, and if value is 15, the volume jumps directly from minimum to maximum.&lt;br /&gt;
* bits 0-3: Decay Rate. Determines the diminishing time for the sound. The higher the value, the shorter the decay. If value is 0, the sound does not decay towards sustain level and stays at maximum volume after attack.&lt;br /&gt;
&lt;br /&gt;
==== 80-95: Sustain Level / Release Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Sustain level&lt;br /&gt;
|colspan=4| Release rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Sustain Level. Determines the point at which the sound ceases to decay and chages to a sound having a constant level. The sustain level is expressed as a fraction of the maximum level. 15 is the softest and 0 is the loudest sustain level. Note that the Sustain-bit in the register 20-35 must be set for this to have an effect. Otherwise the sound will continue with release phase after hitting sustain level.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! SL3 !! SL2 !! SL1 !! SL0&lt;br /&gt;
|-&lt;br /&gt;
| -24dB || -12dB || -6dB || -3dB&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
There is an exception when all bits are set (value=15), the actual level is -93dB instead, matching as if the value were 31.&lt;br /&gt;
&lt;br /&gt;
* bits 0-3: Release Rate. Determines the rate at which the sound disappears after KEY-OFF. The higher the value, the shorter the release. Value of 0 causes the sound not to release at all, it will continue to produce sound at level before KEY-OFF.&lt;br /&gt;
&lt;br /&gt;
==== A0-A8: Frequency Number ====&lt;br /&gt;
&lt;br /&gt;
Determines the pitch of the note. Highest bits of F-Number are stored in the register below.&lt;br /&gt;
&lt;br /&gt;
==== B0-B8: Key On / Block Number / F-Number(hi bits) ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| KEY&lt;br /&gt;
|colspan=3| Block num.&lt;br /&gt;
|colspan=2| Freq&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: KEY-ON. When 1, channel output is enabled.&lt;br /&gt;
* bits 2-4: Block Number. Roughly determines the octave.&lt;br /&gt;
* bits 0-1: Frequency Number. 2 highest bits of the above register.  The following formula is used to determine F-Number and Block:&lt;br /&gt;
: F-Number = Music Frequency * 2^(20-Block) / 49716 Hz&lt;br /&gt;
&lt;br /&gt;
The sampling frequency of OPL2 and OPL3 chips is approximately 49716 Hz. OPL2 cards like Adlib and early Sound Blasters used the 14.31818 MHz oscillator signal from ISA bus slot and divided it by four on card, thus running the OPL2 chip at 3.579545 MHz, which gets divided internally by 72 to get the sampling rate. OPL3 cards had to be compatible, and mostly the sound cards have separate 14.31818 MHz oscillator on board which the OPL3 uses directly, and this gets divided internally by 288 to get the sampling rate.&lt;br /&gt;
&lt;br /&gt;
NOTE: In four-operator mode only the register value of Operators 1 and 2 is used, value of Operators 3 and 4 in this register is ignored. In other words: one channel uses only one frequency, block and KEY-ON value at a time, regardless whether it is a two- or four-operator channel.&lt;br /&gt;
&lt;br /&gt;
==== BD: Tremolo Depth / Vibrato Depth / Percussion Mode / BD/SD/TT/CY/HH On ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Per&lt;br /&gt;
| BD&lt;br /&gt;
| SD&lt;br /&gt;
| TT&lt;br /&gt;
| CY&lt;br /&gt;
| HH&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude Vibrato) Depth. 0 = 1.0dB, 1 = 4.8dB.&lt;br /&gt;
* bit 6:    Frequency Vibrato Depth. 0 = 7 cents, 1 = 14 cents. A &amp;quot;cent&amp;quot; is 1/100 of a semi-tone.&lt;br /&gt;
* bit 5:    Percussion Mode. 0 = Melodic Mode, 1 = Percussion Mode.&lt;br /&gt;
* bit 4:    BD On. KEY-ON of the Bass Drum channel.&lt;br /&gt;
* bit 3:    SD On. KEY-ON of the Snare Drum channel.&lt;br /&gt;
* bit 2:    TT On. KEY-ON of the Tom-Tom channel.&lt;br /&gt;
* bit 1:    CY On. KEY-ON of the Cymbal channel.&lt;br /&gt;
* bit 0:    HH On. KEY-ON of the Hi-Hat channel.&lt;br /&gt;
&lt;br /&gt;
NOTE: KEY-ON bits of channels 6, 7 and 8 must be clear and their F-Nums, Attack/Decay/Release rates, etc. must be set properly to use percussion mode.&lt;br /&gt;
&lt;br /&gt;
==== C0-C8: FeedBack Modulation Factor / Synthesis Type ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| OutCh_D&lt;br /&gt;
| OutCh_C&lt;br /&gt;
| R&lt;br /&gt;
| L&lt;br /&gt;
|colspan=3| Feedback&lt;br /&gt;
| Syn&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: CHD, Output Channel D Enable. When set, channel output goes to fourth digital audio output channel.&lt;br /&gt;
* bit 6: CHC, Output Channel C Enable. When set, channel output goes to third digital audio output channel.&lt;br /&gt;
* bit 5:    Right Speaker Enable. When set, channel output goes to second digital audio output channel, connected to right speaker.&lt;br /&gt;
* bit 4:    Left Speaker Enable. When set, channel output goes to first digital audio output channel, connected to left speaker.&lt;br /&gt;
** In OPL3 mode, at least one of the left/right bits must be set to hear the channel.&lt;br /&gt;
** In OPL2 mode, these bits are ignored and audio is sent to all channels for compatibility reasons.&lt;br /&gt;
** Left/Right bits can be used to realize sound &amp;quot;panning&amp;quot;, but this method offers only three pan positions (left/center/right).&lt;br /&gt;
** These bits apply only to operators producing sound (Carriers). Modulators are not affected by their setting.&lt;br /&gt;
** Sound cards use only one stereo DAC, so only two of the four digital output channels are available.&lt;br /&gt;
* bits 1-3: FeedBack Modulation Factor. If 0, no feedback is present. If 1-7, operator 1 will send a portion of its output back into itself.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! FeedBack !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;amp;pi;/16&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;amp;pi;/8&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;amp;pi;/4&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;amp;pi;/2&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 2&amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 4&amp;amp;pi;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
When in four-operator mode, the FeedBack value is used only by Operator 1, value of Operators 2, 3 and 4 is ignored.&lt;br /&gt;
&lt;br /&gt;
* bit 0: Synthesis Type. 1 = Additive synthesis, 0 = Frequency Modulation.  In four-operator mode, there are two bits controlling the synthesis type. Both are the bit 0 of register C0, one of Operators 1 and 2 and the second of Operators 3 and 4.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Op 1&amp;amp;2 !! Op 3&amp;amp;4 !! Type&lt;br /&gt;
|-&lt;br /&gt;
| 0 || NONE || FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || NONE || AM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || FM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || AM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || FM-AM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || AM-AM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== E0-F5: Waveform Select ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=5| -&lt;br /&gt;
|colspan=3| Waveform&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 0-2: WaveForm Select (WS): &amp;lt;gallery widths=261px perrow=4&amp;gt;&lt;br /&gt;
Image:OPL_Wave0.png|Waveform 0: Sine&lt;br /&gt;
Image:OPL_Wave1.png|Waveform 1: Half-sine&lt;br /&gt;
Image:OPL_Wave2.png|Waveform 2: Abs-sine&lt;br /&gt;
Image:OPL_Wave3.png|Waveform 3: Pulse-sine&lt;br /&gt;
Image:OPL_Wave4.png|Waveform 4: Sine - even periods only&lt;br /&gt;
Image:OPL_Wave5.png|Waveform 5: Abs-sine - even periods only&lt;br /&gt;
Image:OPL_Wave6.png|Waveform 6: Square&lt;br /&gt;
Image:OPL_Wave7.png|Waveform 7: Derived square&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* NOTE: Bit 5 of register 01 must be set to use waveforms other than sine. Waveforms 4-7 are available only on OPL3. See files WAVEn.GIF for real waveforms, where n is a number between 0 and 7.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
These examples show a few working routines used in my MUS Player. They are written in Borland C++ 3.1 but should be easy to translate to any other language.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
// I prefer using these Assembler-like types&lt;br /&gt;
typedef unsigned int  WORD;&lt;br /&gt;
typedef unsigned char BYTE;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * FM Synthesizer base port. SB Pro II - 0x220, Adlib 0x388&lt;br /&gt;
 */&lt;br /&gt;
WORD FMport = 0x220;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Enables OPL3 extensions.&lt;br /&gt;
 */&lt;br /&gt;
WORD OPL3 = 1;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Direct write to any Adlib/SB Pro II FM synthetiser register.&lt;br /&gt;
 *   reg - register number (range 0x001-0x0F5 and 0x101-0x1F5). When high byte&lt;br /&gt;
 *         of reg is zero, data go to port FMport, otherwise to FMport+2&lt;br /&gt;
 *   data - register value to be written&lt;br /&gt;
 */&lt;br /&gt;
BYTE FMwriteReg(WORD reg, BYTE data)&lt;br /&gt;
{&lt;br /&gt;
    asm {&lt;br /&gt;
	mov	dx,FMport&lt;br /&gt;
	mov	ax,reg&lt;br /&gt;
	or	ah,ah		// high byte is nonzero -- write to port base+2&lt;br /&gt;
	jz	out1&lt;br /&gt;
	inc	dx&lt;br /&gt;
	inc	dx&lt;br /&gt;
    }&lt;br /&gt;
out1: asm {&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	mov	cx,6&lt;br /&gt;
    }&lt;br /&gt;
loop1:asm {			// delay between writes&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop1&lt;br /&gt;
&lt;br /&gt;
	inc	dx&lt;br /&gt;
	mov	al,data&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	dec	dx&lt;br /&gt;
	mov	cx,36&lt;br /&gt;
    }&lt;br /&gt;
loop2:asm {			// delay after data write&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop2&lt;br /&gt;
    }&lt;br /&gt;
    return _AL;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to an operator pair. To be used for register bases of 0x20, 0x40,&lt;br /&gt;
 * 0x60, 0x80 and 0xE0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteChannel(BYTE regbase, BYTE channel, BYTE data1, BYTE data2)&lt;br /&gt;
{&lt;br /&gt;
    static BYTE adlib_op[] = {0, 1, 2, 8, 9, 10, 16, 17, 18};&lt;br /&gt;
    static BYTE sbpro_op[] = { 0,  1,  2,   6,  7,  8,  12, 13, 14,&lt;br /&gt;
			      18, 19, 20,  24, 25, 26,  30, 31, 32};&lt;br /&gt;
    static WORD rg[] = {0x000,0x001,0x002,0x003,0x004,0x005,&lt;br /&gt;
			0x008,0x009,0x00A,0x00B,0x00C,0x00D,&lt;br /&gt;
			0x010,0x011,0x012,0x013,0x014,0x015,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,&lt;br /&gt;
			0x108,0x109,0x10A,0x10B,0x10C,0x10D,&lt;br /&gt;
			0x110,0x111,0x112,0x113,0x114,0x115};&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
    {&lt;br /&gt;
	register WORD reg = sbpro_op[channel];&lt;br /&gt;
	FMwriteReg(rg[reg]+regbase, data1);&lt;br /&gt;
	FMwriteReg(rg[reg+3]+regbase, data2);&lt;br /&gt;
    } else {&lt;br /&gt;
	register WORD reg = regbase+adlib_op[channel];&lt;br /&gt;
	FMwriteReg(reg, data1);&lt;br /&gt;
	FMwriteReg(reg+3, data2);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to channel a single value. To be used for register bases of&lt;br /&gt;
 * 0xA0, 0xB0 and 0xC0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteValue(BYTE regbase, BYTE channel, BYTE value)&lt;br /&gt;
{&lt;br /&gt;
    static WORD ch[] = {0x000,0x001,0x002,0x003,0x004,0x005,0x006,0x007,0x008,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,0x106,0x107,0x108};&lt;br /&gt;
    register WORD chan;&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
	chan = ch[channel];&lt;br /&gt;
    else&lt;br /&gt;
	chan = channel;&lt;br /&gt;
    FMwriteReg(regbase + chan, value);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Detection Methods ==&lt;br /&gt;
&lt;br /&gt;
An official method of Adlib (OPL2) detection is:&lt;br /&gt;
&lt;br /&gt;
# Reset Timer 1 and Timer 2: write 60h to register 4.&lt;br /&gt;
# Reset the IRQ: write 80h to register 4.&lt;br /&gt;
#* NOTE: Steps 1 and 2 can&#039;t be combined together.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Set Timer 1 to FFh: write FFh to register 2.&lt;br /&gt;
# Unmask and start Timer 1: write 21h to register 4.&lt;br /&gt;
# Wait in a delay loop for at least 80 µsec.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Reset Timer 1, Timer 2 and IRQ as in steps 1 and 2.&lt;br /&gt;
# Test the results of the two reads: the first should be 0, the second should be C0h. If either is incorrect, then the OPL2 is not present.&lt;br /&gt;
&lt;br /&gt;
* NOTE1: You should AND the result bytes with E0h because the unused bits are undefined.&lt;br /&gt;
* NOTE2: This testing method doesn&#039;t work in some SoundBlaster compatible cards.&lt;br /&gt;
&lt;br /&gt;
=== OPL3 Detection ===&lt;br /&gt;
--------------&lt;br /&gt;
&lt;br /&gt;
# Detect OPL2. If present, continue.&lt;br /&gt;
# Read status register: read port base+0.&lt;br /&gt;
# AND the result with 06h.&lt;br /&gt;
# If the result is zero, you have OPL3, otherwise OPL2.&lt;br /&gt;
&lt;br /&gt;
* NOTE: This is NOT an official method. I have dug it out of a sound driver. I haven&#039;t tested it, because I haven&#039;t an OPL2 card (Adlib, SB Pro I). Nevertheless it &amp;quot;detects&amp;quot; my SB Pro II properly. ;-)&lt;br /&gt;
&lt;br /&gt;
Another possible detection method for distinguishing between SB Pro I and SB Pro II would be to try to detect OPL2 at I/O port base+0 and then at port base+2. The first test should succeed and the second should fail if OPL3 is present. (Remember: SB Pro I contains twin OPL2 chips at addresses base+0 and base+2, while SB Pro II contains one OPL3 chip at I/O address base+0 thru base+3).&lt;br /&gt;
&lt;br /&gt;
== BLASTER Environment Variable ==&lt;br /&gt;
&lt;br /&gt;
Perhaps the most recommended &amp;quot;detection&amp;quot; method. Reading this variable avoids blindfold I/O port scanning and possible device conflicts. The user is responsible for its proper setting.&lt;br /&gt;
&lt;br /&gt;
The variable has this format:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=Aaddr Iirq Ddma Ttype&lt;br /&gt;
&lt;br /&gt;
* A: Base I/O address given in hex. For most Sound Blasters the default is 220.&lt;br /&gt;
* I: IRQ Number (decimal). Default 7.&lt;br /&gt;
* D: DMA Number (decimal). Default 1.&lt;br /&gt;
* T: Card Type (decimal):&lt;br /&gt;
** 1 - Sound Blaster 1.5&lt;br /&gt;
** 2 - Sound Blaster Pro I&lt;br /&gt;
** 3 - Sound Blaster 2.0&lt;br /&gt;
** 4 - Sound Blaster Pro II&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=A220 I7 D1 T4&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The PC Games Programmers Encyclopedia&#039;&#039;, Mark Feldman and many others on Usenet and Internet, ftp://teeri.oulu.fi/pub/msdos/programming/gpe&lt;br /&gt;
: ... you can find (almost) everything you need there&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Sound Blaster - The Official Book&#039;&#039;, Richard Heimlich, David M. Golden, Ivan Luk, Peter M. Ridge, Osborne/McGraw Hill, ISBN 0-07-881907-5&lt;br /&gt;
: ... this is a number-one in my book-wishlist. If anyone wanted to get rid of the book, I wouldn&#039;t scorn it ... :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The SoundBlaster Developer Kit&#039;&#039;, Creative Labs Inc, Creative Technology PTE LTD&lt;br /&gt;
: ... I wonder if you can find something comprehensible in that.&lt;/div&gt;</summary>
		<author><name>Kermes</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4336</id>
		<title>OPL chip</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4336"/>
		<updated>2012-08-05T20:19:14Z</updated>

		<summary type="html">&lt;p&gt;Kermes: /* 80-95: Sustain Level / Release Rate */ Corrected error in sustain level example. Explained register more.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Programmer&#039;s Guide to Yamaha YMF 262/OPL3 FM Music Synthesizer =&lt;br /&gt;
Version 1.00  Nov-24-1994&lt;br /&gt;
&lt;br /&gt;
Written by Vladimir Arnost, QA-Software&lt;br /&gt;
Internet:  xarnos00@dcse.fee.vutbr.cz&lt;br /&gt;
&lt;br /&gt;
This manual can be distributed freely if not modified.&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer ===&lt;br /&gt;
&lt;br /&gt;
I assume no responsibility for any damages arising out of use or inability to use this text. No warranty is provided about correctness of any information in this file. You are on your own.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The chip I am going to describe is getting more and more common, but programming information is still scarce, so I have decided to fill in this gap. All information contained in this file is a result of my experience in Adlib programming, research (read: reverse engineering) and finally of my effort to write down everything necessary to understand and use this piece of hardware. No official sources (i.e. development kits, books about this topic, etc.) were available to me except:&lt;br /&gt;
&lt;br /&gt;
: Adlib Programming Guide - by Tero Töttö, and&lt;br /&gt;
: The PC Games Programmers Encyclopedia V1.0&lt;br /&gt;
&lt;br /&gt;
The information below is a combination of known features of Adlib (alias Yamaha YM 3812/OPL2) and my own uncountable experiments and failures, which brought out a lot of important details you have to know about the chip.&lt;br /&gt;
&lt;br /&gt;
As far as I know, there are four major sound cards based on OPL3 chip:&lt;br /&gt;
&lt;br /&gt;
* Sound Blaster Pro II (not Sound Blaster Pro I)&lt;br /&gt;
* Sound Blaster 16&lt;br /&gt;
* Adlib Gold&lt;br /&gt;
* Pro Audio Spectrum Plus/16&lt;br /&gt;
&lt;br /&gt;
I currently have a Sound Blaster Pro II-compatible card only, so all the programming info I provide will be based on this card. (The other cards are quite similar, however. They are just wired at different I/O-port addresses.)&lt;br /&gt;
&lt;br /&gt;
Note: I assume some knowledge of FM music programming (mainly Adlib FM synthesizer) in this manual. If you are new to this topic I recommend you try Adlib first before going higher. Anyway, OPL3 is a direct descendant of OPL2 (what a surprise), so most features of OPL2 are also present on OPL3.&lt;br /&gt;
&lt;br /&gt;
== Description of the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
My card&#039;s user manual says: &amp;quot;[this card contains] ... a stereo music FM synthesizer with 20 channels consisting of four (4) operators each ... &amp;quot; I thought: &amp;quot;Wow -- that&#039;s together eighty operators. This must be a GOOD sound-card.&amp;quot; I was wrong. Just another advertising lie.&lt;br /&gt;
&lt;br /&gt;
So let&#039;s clear some facts. First, OPL3 has only thirty-six (36) operators which can be combined in several ways:&lt;br /&gt;
&lt;br /&gt;
* 18 FM channels (36 operators), or&lt;br /&gt;
* 15 FM channels (30 ops) and 5 percussion instruments (6 ops), giving us 20 channels altogether, or&lt;br /&gt;
* up to 6 four-operator FM channels (max 24 ops), the rest again being divided into two-operator FM channels and drums.&lt;br /&gt;
&lt;br /&gt;
From the table above you can see that not all channels can be used in four-operator (4-OP) mode -- only a part of the synthesizer is really capable of making 4-OP sounds -- the rest uses traditional two-operator (2-OP) mode.&lt;br /&gt;
&lt;br /&gt;
Second, the manual states this card is capable of &amp;quot;stereo&amp;quot; music. Yes, the quotes are necessary, because the stereo capabilities are very limited. You are given ability to control output going to left or right channel by turning it on and off. That&#039;s all. So the sound can flow from very left side, center and very right side. No sound panning, no special stereo effects. :-(&lt;br /&gt;
&lt;br /&gt;
Well, flaming apart, back to the main topic.&lt;br /&gt;
&lt;br /&gt;
The OPL3 chip is capable of making sounds in several ways:&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Additive Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output of both operators is simply added. It is the simplest way to make any sound, and it works on both OPL2 and OPL3. The diagram should make it clear.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐&lt;br /&gt;
	│            │&lt;br /&gt;
	│ Operator 1 ├────────┐&lt;br /&gt;
	│            │        │&lt;br /&gt;
	└────────────┘        │&lt;br /&gt;
			      ├────────&amp;gt; Output&lt;br /&gt;
	┌────────────┐        │&lt;br /&gt;
	│            │        │&lt;br /&gt;
	│ Operator 2 ├────────┘&lt;br /&gt;
	│            │&lt;br /&gt;
	└────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Frequency Modulation (FM) Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output from the first operator (Modulator) is sent to the input of the second one (Carrier) and is used to modulate (alter) frequency of the second operator. Only the second operator produces sound. Most of interesting sounds are made this way. This also works on OPL2. Hope the picture helps.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐         ┌────────────┐&lt;br /&gt;
	│            │         │            │&lt;br /&gt;
	│ Operator 1 ├────────&amp;gt;│ Operator 2 ├────────&amp;gt; Output&lt;br /&gt;
	│(Modulator) │         │ (Carrier)  │&lt;br /&gt;
	└────────────┘         └────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Four-operator &amp;quot;Mess&amp;quot; Modulation Synthesis ===&lt;br /&gt;
&lt;br /&gt;
All of OPL3&#039;s 4-OP configurations are combinations of the above two modes of synthesis. OPL3 combines these two modes in four ways. I have no words to describe these four ways. Only the pictures can show their principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   a) FM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   b) AM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├───────────────────────────────────┐&lt;br /&gt;
	│       │                                   │&lt;br /&gt;
	└───────┘                                   │&lt;br /&gt;
						    │&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┴─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   c) FM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────┐&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     ├─────&amp;gt; Output&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┘&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	└───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   d) AM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├────────────────────┐&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	└───────┘                    │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────┼─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐                    │&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	│ Op. 4 ├────────────────────┘&lt;br /&gt;
	│       │&lt;br /&gt;
	└───────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Nice, aren&#039;t they?&lt;br /&gt;
&lt;br /&gt;
The only way I think this can be written is a math formula. Symbol + (plus) means additive synthesis, and * (asterisk) means frequency modulation (Op1 * Op2 means operator 1 modulates operator 2, not vice versa). Here they are:&lt;br /&gt;
&lt;br /&gt;
# FM-FM Mode:	 (Op1 * Op2 * Op3 * Op4) ────&amp;gt; Output&lt;br /&gt;
# AM-FM Mode:	  Op1 + (Op2 * Op3 * Op4) ───&amp;gt; Output&lt;br /&gt;
# FM-AM Mode:	 (Op1 * Op2) + (Op3 * Op4) ──&amp;gt; Output&lt;br /&gt;
# AM-AM Mode:	  Op1 + (Op2 * Op3) + Op4 ───&amp;gt; Output&lt;br /&gt;
&lt;br /&gt;
=== Percussion Mode ===&lt;br /&gt;
&lt;br /&gt;
In this mode 6 operators are used to produce five different percussion instruments:&lt;br /&gt;
&lt;br /&gt;
* Bass Drum (2 operators)&lt;br /&gt;
* Snare Drum (1 operator)&lt;br /&gt;
* Tom-Tom (1 operator)&lt;br /&gt;
* Cymbal (1 operator)&lt;br /&gt;
* Hi-Hat (1 operator)&lt;br /&gt;
&lt;br /&gt;
Because these instruments occupy only three melodic channels, only Bass Drum, Snare Drum and Tom-Tom frequencies can be set. Cymbal and Hi-Hat frequencies are fixed.  {{TODO|It seems it&#039;s actually the cymbal and snare frequencies that are fixed, try to confirm this -- [[User:Malvineous|Malvineous]] 13:34, 3 June 2012 (GMT)}}&lt;br /&gt;
&lt;br /&gt;
This mode is identical with that of OPL2. For more details see ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
== Programming the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
OPL3 may be found at the following addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| Sound Blaster Pro II || 220h or 240h (selectable), also 388h&lt;br /&gt;
|-&lt;br /&gt;
| Adlib Gold || 388h&lt;br /&gt;
|-&lt;br /&gt;
| Pro Audio Spectrum Plus/16 || ? (if you have a PAS you should know it)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The base address of the synthesizer will be called &amp;quot;base&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The chip occupies four I/O addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| base+0 || Primary index register (write), Status register (read)&lt;br /&gt;
|-&lt;br /&gt;
| base+1 || Primary data register (write-only)&lt;br /&gt;
|-&lt;br /&gt;
| base+2 || Secondary index register (write)&lt;br /&gt;
|-&lt;br /&gt;
| base+3 || Secondary data register (write-only)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The index registers are used to select internal registers and data registers are used to write to them. Status register returns the state of two timers built in the chip.&lt;br /&gt;
&lt;br /&gt;
OPL3 contains two sets of registers. The Primary set maps to channels 0-8 (operators 0-17) and the secondary maps to channels 9-17 (operators 18-35). The reason for this is simple: all these registers wouldn&#039;t fit into single register set.&lt;br /&gt;
&lt;br /&gt;
Unlike Adlib (OPL2), OPL3 doesn&#039;t need delay between register writes. With OPL2 you had to wait 3.3 µs after index register write and another 23 µs after data register write. On the contrary OPL3 doesn&#039;t need (almost) any delay after index register write and only 0.28 µs after data register write. This means you can neglect the delays and slightly speed up your music driver. But using reasonable delays will certainly do no harm.&lt;br /&gt;
&lt;br /&gt;
The data registers can&#039;t be read (they are write-only) on both OPL2 and OPL3.&lt;br /&gt;
&lt;br /&gt;
== Register Map ==&lt;br /&gt;
&lt;br /&gt;
The registers are grouped in the same manner as in the OPL2 chip. Programs using both OPL2 and OPL3 chips may use the same code provided that their direct I/O interface is well written. The only thing you have to change is operator-to-register mapping, which must accomodate the fact that registers are spread between two register sets.&lt;br /&gt;
&lt;br /&gt;
(The register map is nearly the same so I dared to copy it from ADLIB.DOC.)&lt;br /&gt;
&lt;br /&gt;
=== Status Register (base+0) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
!    D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQFlag || T1Flag || T2Flag ||        ||        ||        ||        ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Data Registers (base+1, base+3) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! REG   !!   D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| 01    ||colspan=2| Test Register ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|(WSEnable)||colspan=5| Test Register&lt;br /&gt;
|-&lt;br /&gt;
| 02    ||colspan=8| Timer 1 Count (80 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 03    ||colspan=8| Timer 2 Count (320 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 04*   ||IRQReset|| T1Mask || T2Mask ||colspan=3|                  ||T2 Start||T1 Start&lt;br /&gt;
|-&lt;br /&gt;
| 04**  ||colspan=2|        ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP B-E||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP A-D||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 9-C||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 2-5||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 1-4||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 0-3&lt;br /&gt;
|-&lt;br /&gt;
| 05**  ||colspan=7|                                                           ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;| OPL3&lt;br /&gt;
|-&lt;br /&gt;
| 08    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;| (CSW)  ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|NOTE-SEL||colspan=6|&lt;br /&gt;
|-&lt;br /&gt;
| 20-35 ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Tremolo ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Vibrato ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Sustain ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|  KSR   ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Frequency Multiplication Factor&lt;br /&gt;
|-&lt;br /&gt;
| 40-55 ||colspan=2 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Key Scale Level ||colspan=6 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 60-75 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Attack Rate ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 80-95 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Sustain Level ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A0-A8 ||colspan=8 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Frequency Number  (Lower 8 bits)&lt;br /&gt;
|-&lt;br /&gt;
| B0-B8 ||colspan=2|        ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| KEY-ON ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Block Number ||colspan=2 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| F-Num (hi bits)&lt;br /&gt;
|-&lt;br /&gt;
| BD    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Trem Dep||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Vibr Dep||style=&amp;quot;background-color: #FFCCDD;&amp;quot;|PercMode||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| BD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| SD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| TT On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| CY On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| HH On&lt;br /&gt;
|-&lt;br /&gt;
| C0-C8 ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| OutCh_D ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| OutCh_C ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Right  ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Left   ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;|FeedBack Modulation Factor||style=&amp;quot;background-color: #FFE0CC;&amp;quot;|SynthTyp&lt;br /&gt;
|-&lt;br /&gt;
| E0-F5 ||colspan=5|                                      ||colspan=3 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|style=&amp;quot;background-color: #CCFFCC;&amp;quot;| Chip-wide setting&lt;br /&gt;
|style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Per operator&lt;br /&gt;
|style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Per channel&lt;br /&gt;
|style=&amp;quot;background-color: #FFCCDD;&amp;quot;| Rhythm-mode only&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt; This applies only to port base+1&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;**&amp;lt;/nowiki&amp;gt; This applies only to port base+3&lt;br /&gt;
&lt;br /&gt;
For register bases A0, B0 and C0 there is one register per output channel. The primary register set holds the first nine channels (0-8) and the secondary holds last nine channels (9-17). For bases 20, 40, 60, 80 and E0 there are two registers per channel. Each register maps to one operator. Unfortunately the operator&#039;s register numbers are not continuous. The following table shows which operator maps to which register set and offset (in hex).&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Op. !! Set/Offset !! Op. !! Set/Offset&lt;br /&gt;
|-&lt;br /&gt;
| 0  || 0/00 || 18 || 1/00&lt;br /&gt;
|-&lt;br /&gt;
| 1  || 0/01 || 19 || 1/01&lt;br /&gt;
|-&lt;br /&gt;
| 2  || 0/02 || 20 || 1/02&lt;br /&gt;
|-&lt;br /&gt;
| 3  || 0/03 || 21 || 1/03&lt;br /&gt;
|-&lt;br /&gt;
| 4  || 0/04 || 22 || 1/04&lt;br /&gt;
|-&lt;br /&gt;
| 5  || 0/05 || 23 || 1/05&lt;br /&gt;
|-&lt;br /&gt;
| 6  || 0/08 || 24 || 1/08&lt;br /&gt;
|-&lt;br /&gt;
| 7  || 0/09 || 25 || 1/09&lt;br /&gt;
|-&lt;br /&gt;
| 8  || 0/0A || 26 || 1/0A&lt;br /&gt;
|-&lt;br /&gt;
| 9  || 0/0B || 27 || 1/0B&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 0/0C || 28 || 1/0C&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 0/0D || 29 || 1/0D&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 0/10 || 30 || 1/10&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 0/11 || 31 || 1/11&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 0/12 || 32 || 1/12&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 0/13 || 33 || 1/13&lt;br /&gt;
|-&lt;br /&gt;
| 16 || 0/14 || 34 || 1/14&lt;br /&gt;
|-&lt;br /&gt;
| 17 || 0/15 || 35 || 1/15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following tables summarize which operators form a channel in various modes:&lt;br /&gt;
&lt;br /&gt;
1. Two-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel    !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 13 || 14 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 || 16 || 17 || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
2. Two-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 ||colspan=4| - || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
3. Four-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 13 || 14 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 || 16 || 17 || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=3| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=3| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Channels 3, 4, 5 and 12, 13, 14 can&#039;t be used separately because their operators became part of channels 0, 1, 2 and 9, 10, 11 respectively. For instance a four-operator channel 1 consists of two two-operator channels number 1 and 4. (The second 2-OP channel number is always the first 2-OP channel number plus three.)&lt;br /&gt;
&lt;br /&gt;
OPL3 allows you to enable/disable 4-OP mode separately for any of channels 0, 1, 2, 9, 10 and 11 (see register 104h in the reference below). This means for instance when you switch only channel 2 into 4-OP mode, channels number 0, 1, 3, 4, 6, 7, 8, 9, etc. will be still independent 2-OP channels.&lt;br /&gt;
&lt;br /&gt;
Channels 6, 7, 8 and 15, 16, 17 are always two-operator ones. They can&#039;t be grouped to form four-operator channels.&lt;br /&gt;
&lt;br /&gt;
4. Four-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 ||colspan=4| - || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=5| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=5| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
Two-operator channel #14 consists of operators 26 and 29 which occupy these registers (all are in the secondary register set):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| 12A || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 12D || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 14A || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 14D || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 16A || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 16D || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18A || Operator 1 ||Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18D || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 1A5 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| 1B5 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| 1C5 ||            || FeedBack/Synthesis Type&lt;br /&gt;
|-&lt;br /&gt;
| 1EA || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| 1ED || Operator 2 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Four-operator channel #1 consists of operators 1, 4, 7 and 10. All registers except register 104h are in the primary set:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 104 || bit 1 = 1  || Enable Four-Operator Synthesis in channel #1&lt;br /&gt;
|-&lt;br /&gt;
| 21 || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 24 || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 29 || Operator 3 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 2C || Operator 4 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 41 || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 44 || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 49 || Operator 3 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 4C || Operator 4 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 61 || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 64 || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 69 || Operator 3 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 6C || Operator 4 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 81 || Operator 1 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 84 || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 89 || Operator 3 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 8C || Operator 4 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A1 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| A4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| B1 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| B4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| C1 ||            || FeedBack/Synthesis Type (part 1)&lt;br /&gt;
|-&lt;br /&gt;
| C4 ||            || Synthesis Type (part 2)&lt;br /&gt;
|-&lt;br /&gt;
| E1 || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E4 || Operator 2 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E9 || Operator 3 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| EC || Operator 4 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
NOTE: If a register number is greater than 100h, then it belongs into the secondary register set. (I use this numbering to emphasize the fact that the particular register MUST be written to the secondary set.) See the example code below for details.&lt;br /&gt;
&lt;br /&gt;
== OPL3 Register Reference ==&lt;br /&gt;
&lt;br /&gt;
Because the registers of OPL3 are almost the same as of OPL2, I have copied their descriptions from file ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
=== Status Register ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQ || T1 || T2 ||colspan=5| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ Flag. Set whenever any timer has elapsed.&lt;br /&gt;
* bit 6: Timer 1 Flag. Set every time the preset time in Timer 1 has elapsed.&lt;br /&gt;
* bit 5: Timer 2 Flag. Set every time the preset time in Timer 2 has elapsed.&lt;br /&gt;
&lt;br /&gt;
Timer interrupts are not wired to any IRQ (why??). The timers can be used to detect the OPL2/OPL3 chip (see Appendix B).&lt;br /&gt;
&lt;br /&gt;
=== Data Registers ===&lt;br /&gt;
&lt;br /&gt;
==== 01: Test Register / Waveform Select Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| Test Register&lt;br /&gt;
| (WSE)&lt;br /&gt;
|colspan=5| Test Register&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 7-6: Test Register. Must be reset to zero before any operation.&lt;br /&gt;
* bit 5: Waveform Select Enable. If clear, all channels will use normal sine wave. If set, register E0-F5 (Waveform Select) contents will be used.&lt;br /&gt;
* bits 0-4: Test Register. Must be reset to zero before any operation.&lt;br /&gt;
&lt;br /&gt;
OPL3 does not implement WSE bit, and it should be left clear. In OPL2 mode all four waveforms are always available, and in OPL3 mode all eight waveforms are always available. For compatibility with OPL2, when a program is finished using an OPL3, the waveform select registers should be set to 0, if the next program assumes that by setting WSE bit to 0 the waveform is always sine like on a real OPL2.&lt;br /&gt;
&lt;br /&gt;
==== 02: Timer 1 Count ====&lt;br /&gt;
&lt;br /&gt;
Upward 8 bit counter with a resolution of 80 µsec. If an overflow occurs, the status register bit is set, and the preset value is loaded into the timer again.&lt;br /&gt;
&lt;br /&gt;
==== 03: Timer 2 Count ====&lt;br /&gt;
&lt;br /&gt;
Same as Timer 1, but with a resolution of 320 µsec.&lt;br /&gt;
&lt;br /&gt;
==== 004 (port: base+1): IRQ-Reset / Mask / Start ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Rst&lt;br /&gt;
| T1M&lt;br /&gt;
| T2M&lt;br /&gt;
|colspan=3| -&lt;br /&gt;
| T2S&lt;br /&gt;
| T1S&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ-Reset. Resets timer and IRQ flags in status register. All other bits are ignored when this bit is set.&lt;br /&gt;
* bit 6: Timer 1 Mask. If 1, status register is not affected in overflow.&lt;br /&gt;
* bit 5: Timer 2 Mask. Same as above.&lt;br /&gt;
* bit 1: Timer 2 Start. Timer on/off.&lt;br /&gt;
* bit 0: Timer 1 Start. Same as above.&lt;br /&gt;
&lt;br /&gt;
==== 104 (port: base+3): Four-Operator Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| ChB&lt;br /&gt;
| ChA&lt;br /&gt;
| Ch9&lt;br /&gt;
| Ch2&lt;br /&gt;
| Ch1&lt;br /&gt;
| Ch0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: Enable four-operator synthesis for channel pair 11 - 14 (decimal).&lt;br /&gt;
* bit 4: Same as above for channel pair 10 - 13.&lt;br /&gt;
* bit 3: Same as above for channel pair 9 - 12.&lt;br /&gt;
* bit 2: Same as above for channel pair 2 - 5.&lt;br /&gt;
* bit 1: Same as above for channel pair 1 - 4.&lt;br /&gt;
* bit 0: Same as above for channel pair 0 - 3.&lt;br /&gt;
&lt;br /&gt;
If reset to zero, OPL3 can produce 18 two-operator sounds at a time. If nonzero, OPL3 produces four-operator sound in appropriate channel pair.&lt;br /&gt;
&lt;br /&gt;
==== 105 (port: base+3): OPL3 Mode Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=7| -&lt;br /&gt;
| OPL3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 0: OPL3 Mode Enable. When set, OPL3 extensions (36 operators, 4-OP synthesis, 8 waveforms, stereo output) can be used. When reset, the chip behaves as an ordinary OPL2. This bit is zero by default for compatibility with OPL2.&lt;br /&gt;
&lt;br /&gt;
==== 08: CSW / NOTE-SEL ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| (CSW)&lt;br /&gt;
| N-S&lt;br /&gt;
|colspan=6| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: Composite sine wave mode on/off. All KEY-ON bits must be clear in order to use this mode. The card is unable to create any other sound when in CSW mode. (Unfortunately, I have no info how to use this mode :-&amp;lt; ). The CSW mode is not implemented on an OPL3 and this bit is ignored.&lt;br /&gt;
* bit 6: NOTE-SEL. Controls the split point of the keyboard. When 0, the keyboard split is the second bit from the bit 8 of the F-Number. When 1, the MSb of the F-Number is used. (???)&lt;br /&gt;
&lt;br /&gt;
==== 20-35: Tremolo / Vibrato / Sustain / KSR / Frequency Multiplication Factor ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Sus&lt;br /&gt;
| KSR&lt;br /&gt;
|colspan=4| Multiplication&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude vibrato) on/off.&lt;br /&gt;
* bit 6:    Frequency vibrato on/off.&lt;br /&gt;
* bit 5:    Sound Sustaining. When 1, operator&#039;s output level will be held at its sustain level until a KEY-OFF is done.&lt;br /&gt;
* bit 4:    Envelope scaling (KSR) on/off. When 1, higher notes are shorter than lower notes.&lt;br /&gt;
* bits 0-3: Frequency Multiplication Factor (MULTI). Operator&#039;s frequency is set to (see registers A0, B0) F-Number * Factor.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! MULTI !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0.5&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 2&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 3&lt;br /&gt;
|-&lt;br /&gt;
| 4 || 4&lt;br /&gt;
|-&lt;br /&gt;
| 5 || 5&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 6&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 7&lt;br /&gt;
|-&lt;br /&gt;
| 8 || 8&lt;br /&gt;
|-&lt;br /&gt;
| 9 || 9&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 40-55: Key Scale Level / Output Level ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| KSL&lt;br /&gt;
|colspan=6| Output level&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 6-7: Key Scale Level. Attenuates output level towards higher pitch:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! KSL !! Attenuation&lt;br /&gt;
|-&lt;br /&gt;
| 0 || -&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 3.0 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 1.5 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 6.0 dB/oct&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The attenuation level is based on the 3-bit octave (block number) value and top four bits of the FNUM value, so each octave is subdivided into 16 parts.&lt;br /&gt;
&lt;br /&gt;
* bits 0-5: Output Level. Attenuates the operator output level. 0 is the loudest, 3F is the softest. Attenuation range is 48dB with 0.75dB resolution.&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| 24dB || 12dB || 6dB || 3dB || 1.5dB || 0.75dB&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* In additive synthesis, varying the output level of any operator varies the volume of its corresponding channel. In FM synthesis, varying the output level of the carrier varies the volume of the channel. Varying the output of the modulator will change the frequency spectrum produced by the carrier. The following table summarizes which operators&#039; output levels should be updated when trying to change channel output level.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Mode !! Op 1 !! Op 2 !! Op 3 !! Op 4&lt;br /&gt;
|-&lt;br /&gt;
| AM    || Y || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM    || - || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM-FM || - || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-FM || Y || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| FM-AM || - || Y || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-AM || Y || - || Y   || Y&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 60-75: Attack Rate / Decay Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Attack rate&lt;br /&gt;
|colspan=4| Decay rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Attack Rate. Determines the rising time for the sound. The higher the value, the faster the attack. If value is 0, the sound will never attack, and if value is 15, the volume jumps directly from minimum to maximum.&lt;br /&gt;
* bits 0-3: Decay Rate. Determines the diminishing time for the sound. The higher the value, the shorter the decay. If value is 0, the sound does not decay towards sustain level and stays at maximum volume after attack.&lt;br /&gt;
&lt;br /&gt;
==== 80-95: Sustain Level / Release Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Sustain level&lt;br /&gt;
|colspan=4| Release rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Sustain Level. Determines the point at which the sound ceases to decay and chages to a sound having a constant level. The sustain level is expressed as a fraction of the maximum level. 15 is the softest and 0 is the loudest sustain level. Note that the Sustain-bit in the register 20-35 must be set for this to have an effect. Otherwise the sound will continue with release phase after hitting sustain level.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! SL3 !! SL2 !! SL1 !! SL0&lt;br /&gt;
|-&lt;br /&gt;
| -24dB || -12dB || -6dB || -3dB&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
There is an exception when all bits are set (value=15), the actual level is -93dB instead, matching as if the value were 31.&lt;br /&gt;
&lt;br /&gt;
* bits 0-3: Release Rate. Determines the rate at which the sound disappears after KEY-OFF. The higher the value, the shorter the release. Value of 0 causes the sound not to release at all, it will continue to produce sound at level before KEY-OFF.&lt;br /&gt;
&lt;br /&gt;
==== A0-A8: Frequency Number ====&lt;br /&gt;
&lt;br /&gt;
Determines the pitch of the note. Highest bits of F-Number are stored in the register below.&lt;br /&gt;
&lt;br /&gt;
==== B0-B8: Key On / Block Number / F-Number(hi bits) ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| KEY&lt;br /&gt;
|colspan=3| Block num.&lt;br /&gt;
|colspan=2| Freq&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: KEY-ON. When 1, channel output is enabled.&lt;br /&gt;
* bits 2-4: Block Number. Roughly determines the octave.&lt;br /&gt;
* bits 0-1: Frequency Number. 2 highest bits of the above register.  The following formula is used to determine F-Number and Block:&lt;br /&gt;
: F-Number = Music Frequency * 2^(20-Block) / 49716 Hz&lt;br /&gt;
&lt;br /&gt;
NOTE: In four-operator mode only the register value of Operators 1 and 2 is used, value of Operators 3 and 4 in this register is ignored. In other words: one channel uses only one frequency, block and KEY-ON value at a time, regardless whether it is a two- or four-operator channel.&lt;br /&gt;
&lt;br /&gt;
==== BD: Tremolo Depth / Vibrato Depth / Percussion Mode / BD/SD/TT/CY/HH On ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Per&lt;br /&gt;
| BD&lt;br /&gt;
| SD&lt;br /&gt;
| TT&lt;br /&gt;
| CY&lt;br /&gt;
| HH&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude Vibrato) Depth. 0 = 1.0dB, 1 = 4.8dB.&lt;br /&gt;
* bit 6:    Frequency Vibrato Depth. 0 = 7 cents, 1 = 14 cents. A &amp;quot;cent&amp;quot; is 1/100 of a semi-tone.&lt;br /&gt;
* bit 5:    Percussion Mode. 0 = Melodic Mode, 1 = Percussion Mode.&lt;br /&gt;
* bit 4:    BD On. KEY-ON of the Bass Drum channel.&lt;br /&gt;
* bit 3:    SD On. KEY-ON of the Snare Drum channel.&lt;br /&gt;
* bit 2:    TT On. KEY-ON of the Tom-Tom channel.&lt;br /&gt;
* bit 1:    CY On. KEY-ON of the Cymbal channel.&lt;br /&gt;
* bit 0:    HH On. KEY-ON of the Hi-Hat channel.&lt;br /&gt;
&lt;br /&gt;
NOTE: KEY-ON bits of channels 6, 7 and 8 must be clear and their F-Nums, Attack/Decay/Release rates, etc. must be set properly to use percussion mode.&lt;br /&gt;
&lt;br /&gt;
==== C0-C8: FeedBack Modulation Factor / Synthesis Type ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| OutCh_D&lt;br /&gt;
| OutCh_C&lt;br /&gt;
| R&lt;br /&gt;
| L&lt;br /&gt;
|colspan=3| Feedback&lt;br /&gt;
| Syn&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: CHD, Output Channel D Enable. When set, channel output goes to fourth digital audio output channel.&lt;br /&gt;
* bit 6: CHC, Output Channel C Enable. When set, channel output goes to third digital audio output channel.&lt;br /&gt;
* bit 5:    Right Speaker Enable. When set, channel output goes to second digital audio output channel, connected to right speaker.&lt;br /&gt;
* bit 4:    Left Speaker Enable. When set, channel output goes to first digital audio output channel, connected to left speaker.&lt;br /&gt;
** In OPL3 mode, at least one of the left/right bits must be set to hear the channel.&lt;br /&gt;
** In OPL2 mode, these bits are ignored and audio is sent to all channels for compatibility reasons.&lt;br /&gt;
** Left/Right bits can be used to realize sound &amp;quot;panning&amp;quot;, but this method offers only three pan positions (left/center/right).&lt;br /&gt;
** These bits apply only to operators producing sound (Carriers). Modulators are not affected by their setting.&lt;br /&gt;
** Sound cards use only one stereo DAC, so only two of the four digital output channels are available.&lt;br /&gt;
* bits 1-3: FeedBack Modulation Factor. If 0, no feedback is present. If 1-7, operator 1 will send a portion of its output back into itself.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! FeedBack !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;amp;pi;/16&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;amp;pi;/8&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;amp;pi;/4&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;amp;pi;/2&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 2&amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 4&amp;amp;pi;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
When in four-operator mode, the FeedBack value is used only by Operator 1, value of Operators 2, 3 and 4 is ignored.&lt;br /&gt;
&lt;br /&gt;
* bit 0: Synthesis Type. 1 = Additive synthesis, 0 = Frequency Modulation.  In four-operator mode, there are two bits controlling the synthesis type. Both are the bit 0 of register C0, one of Operators 1 and 2 and the second of Operators 3 and 4.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Op 1&amp;amp;2 !! Op 3&amp;amp;4 !! Type&lt;br /&gt;
|-&lt;br /&gt;
| 0 || NONE || FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || NONE || AM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || FM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || AM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || FM-AM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || AM-AM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== E0-F5: Waveform Select ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=5| -&lt;br /&gt;
|colspan=3| Waveform&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 0-2: WaveForm Select (WS): &amp;lt;gallery widths=261px perrow=4&amp;gt;&lt;br /&gt;
Image:OPL_Wave0.png|Waveform 0: Sine&lt;br /&gt;
Image:OPL_Wave1.png|Waveform 1: Half-sine&lt;br /&gt;
Image:OPL_Wave2.png|Waveform 2: Abs-sine&lt;br /&gt;
Image:OPL_Wave3.png|Waveform 3: Pulse-sine&lt;br /&gt;
Image:OPL_Wave4.png|Waveform 4: Sine - even periods only&lt;br /&gt;
Image:OPL_Wave5.png|Waveform 5: Abs-sine - even periods only&lt;br /&gt;
Image:OPL_Wave6.png|Waveform 6: Square&lt;br /&gt;
Image:OPL_Wave7.png|Waveform 7: Derived square&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* NOTE: Bit 5 of register 01 must be set to use waveforms other than sine. Waveforms 4-7 are available only on OPL3. See files WAVEn.GIF for real waveforms, where n is a number between 0 and 7.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
These examples show a few working routines used in my MUS Player. They are written in Borland C++ 3.1 but should be easy to translate to any other language.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
// I prefer using these Assembler-like types&lt;br /&gt;
typedef unsigned int  WORD;&lt;br /&gt;
typedef unsigned char BYTE;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * FM Synthesizer base port. SB Pro II - 0x220, Adlib 0x388&lt;br /&gt;
 */&lt;br /&gt;
WORD FMport = 0x220;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Enables OPL3 extensions.&lt;br /&gt;
 */&lt;br /&gt;
WORD OPL3 = 1;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Direct write to any Adlib/SB Pro II FM synthetiser register.&lt;br /&gt;
 *   reg - register number (range 0x001-0x0F5 and 0x101-0x1F5). When high byte&lt;br /&gt;
 *         of reg is zero, data go to port FMport, otherwise to FMport+2&lt;br /&gt;
 *   data - register value to be written&lt;br /&gt;
 */&lt;br /&gt;
BYTE FMwriteReg(WORD reg, BYTE data)&lt;br /&gt;
{&lt;br /&gt;
    asm {&lt;br /&gt;
	mov	dx,FMport&lt;br /&gt;
	mov	ax,reg&lt;br /&gt;
	or	ah,ah		// high byte is nonzero -- write to port base+2&lt;br /&gt;
	jz	out1&lt;br /&gt;
	inc	dx&lt;br /&gt;
	inc	dx&lt;br /&gt;
    }&lt;br /&gt;
out1: asm {&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	mov	cx,6&lt;br /&gt;
    }&lt;br /&gt;
loop1:asm {			// delay between writes&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop1&lt;br /&gt;
&lt;br /&gt;
	inc	dx&lt;br /&gt;
	mov	al,data&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	dec	dx&lt;br /&gt;
	mov	cx,36&lt;br /&gt;
    }&lt;br /&gt;
loop2:asm {			// delay after data write&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop2&lt;br /&gt;
    }&lt;br /&gt;
    return _AL;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to an operator pair. To be used for register bases of 0x20, 0x40,&lt;br /&gt;
 * 0x60, 0x80 and 0xE0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteChannel(BYTE regbase, BYTE channel, BYTE data1, BYTE data2)&lt;br /&gt;
{&lt;br /&gt;
    static BYTE adlib_op[] = {0, 1, 2, 8, 9, 10, 16, 17, 18};&lt;br /&gt;
    static BYTE sbpro_op[] = { 0,  1,  2,   6,  7,  8,  12, 13, 14,&lt;br /&gt;
			      18, 19, 20,  24, 25, 26,  30, 31, 32};&lt;br /&gt;
    static WORD rg[] = {0x000,0x001,0x002,0x003,0x004,0x005,&lt;br /&gt;
			0x008,0x009,0x00A,0x00B,0x00C,0x00D,&lt;br /&gt;
			0x010,0x011,0x012,0x013,0x014,0x015,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,&lt;br /&gt;
			0x108,0x109,0x10A,0x10B,0x10C,0x10D,&lt;br /&gt;
			0x110,0x111,0x112,0x113,0x114,0x115};&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
    {&lt;br /&gt;
	register WORD reg = sbpro_op[channel];&lt;br /&gt;
	FMwriteReg(rg[reg]+regbase, data1);&lt;br /&gt;
	FMwriteReg(rg[reg+3]+regbase, data2);&lt;br /&gt;
    } else {&lt;br /&gt;
	register WORD reg = regbase+adlib_op[channel];&lt;br /&gt;
	FMwriteReg(reg, data1);&lt;br /&gt;
	FMwriteReg(reg+3, data2);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to channel a single value. To be used for register bases of&lt;br /&gt;
 * 0xA0, 0xB0 and 0xC0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteValue(BYTE regbase, BYTE channel, BYTE value)&lt;br /&gt;
{&lt;br /&gt;
    static WORD ch[] = {0x000,0x001,0x002,0x003,0x004,0x005,0x006,0x007,0x008,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,0x106,0x107,0x108};&lt;br /&gt;
    register WORD chan;&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
	chan = ch[channel];&lt;br /&gt;
    else&lt;br /&gt;
	chan = channel;&lt;br /&gt;
    FMwriteReg(regbase + chan, value);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Detection Methods ==&lt;br /&gt;
&lt;br /&gt;
An official method of Adlib (OPL2) detection is:&lt;br /&gt;
&lt;br /&gt;
# Reset Timer 1 and Timer 2: write 60h to register 4.&lt;br /&gt;
# Reset the IRQ: write 80h to register 4.&lt;br /&gt;
#* NOTE: Steps 1 and 2 can&#039;t be combined together.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Set Timer 1 to FFh: write FFh to register 2.&lt;br /&gt;
# Unmask and start Timer 1: write 21h to register 4.&lt;br /&gt;
# Wait in a delay loop for at least 80 µsec.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Reset Timer 1, Timer 2 and IRQ as in steps 1 and 2.&lt;br /&gt;
# Test the results of the two reads: the first should be 0, the second should be C0h. If either is incorrect, then the OPL2 is not present.&lt;br /&gt;
&lt;br /&gt;
* NOTE1: You should AND the result bytes with E0h because the unused bits are undefined.&lt;br /&gt;
* NOTE2: This testing method doesn&#039;t work in some SoundBlaster compatible cards.&lt;br /&gt;
&lt;br /&gt;
=== OPL3 Detection ===&lt;br /&gt;
--------------&lt;br /&gt;
&lt;br /&gt;
# Detect OPL2. If present, continue.&lt;br /&gt;
# Read status register: read port base+0.&lt;br /&gt;
# AND the result with 06h.&lt;br /&gt;
# If the result is zero, you have OPL3, otherwise OPL2.&lt;br /&gt;
&lt;br /&gt;
* NOTE: This is NOT an official method. I have dug it out of a sound driver. I haven&#039;t tested it, because I haven&#039;t an OPL2 card (Adlib, SB Pro I). Nevertheless it &amp;quot;detects&amp;quot; my SB Pro II properly. ;-)&lt;br /&gt;
&lt;br /&gt;
Another possible detection method for distinguishing between SB Pro I and SB Pro II would be to try to detect OPL2 at I/O port base+0 and then at port base+2. The first test should succeed and the second should fail if OPL3 is present. (Remember: SB Pro I contains twin OPL2 chips at addresses base+0 and base+2, while SB Pro II contains one OPL3 chip at I/O address base+0 thru base+3).&lt;br /&gt;
&lt;br /&gt;
== BLASTER Environment Variable ==&lt;br /&gt;
&lt;br /&gt;
Perhaps the most recommended &amp;quot;detection&amp;quot; method. Reading this variable avoids blindfold I/O port scanning and possible device conflicts. The user is responsible for its proper setting.&lt;br /&gt;
&lt;br /&gt;
The variable has this format:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=Aaddr Iirq Ddma Ttype&lt;br /&gt;
&lt;br /&gt;
* A: Base I/O address given in hex. For most Sound Blasters the default is 220.&lt;br /&gt;
* I: IRQ Number (decimal). Default 7.&lt;br /&gt;
* D: DMA Number (decimal). Default 1.&lt;br /&gt;
* T: Card Type (decimal):&lt;br /&gt;
** 1 - Sound Blaster 1.5&lt;br /&gt;
** 2 - Sound Blaster Pro I&lt;br /&gt;
** 3 - Sound Blaster 2.0&lt;br /&gt;
** 4 - Sound Blaster Pro II&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=A220 I7 D1 T4&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The PC Games Programmers Encyclopedia&#039;&#039;, Mark Feldman and many others on Usenet and Internet, ftp://teeri.oulu.fi/pub/msdos/programming/gpe&lt;br /&gt;
: ... you can find (almost) everything you need there&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Sound Blaster - The Official Book&#039;&#039;, Richard Heimlich, David M. Golden, Ivan Luk, Peter M. Ridge, Osborne/McGraw Hill, ISBN 0-07-881907-5&lt;br /&gt;
: ... this is a number-one in my book-wishlist. If anyone wanted to get rid of the book, I wouldn&#039;t scorn it ... :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The SoundBlaster Developer Kit&#039;&#039;, Creative Labs Inc, Creative Technology PTE LTD&lt;br /&gt;
: ... I wonder if you can find something comprehensible in that.&lt;/div&gt;</summary>
		<author><name>Kermes</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4335</id>
		<title>OPL chip</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4335"/>
		<updated>2012-08-05T17:43:03Z</updated>

		<summary type="html">&lt;p&gt;Kermes: /* 60-75: Attack Rate / Decay Rate */ Explain further special cases for rates.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Programmer&#039;s Guide to Yamaha YMF 262/OPL3 FM Music Synthesizer =&lt;br /&gt;
Version 1.00  Nov-24-1994&lt;br /&gt;
&lt;br /&gt;
Written by Vladimir Arnost, QA-Software&lt;br /&gt;
Internet:  xarnos00@dcse.fee.vutbr.cz&lt;br /&gt;
&lt;br /&gt;
This manual can be distributed freely if not modified.&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer ===&lt;br /&gt;
&lt;br /&gt;
I assume no responsibility for any damages arising out of use or inability to use this text. No warranty is provided about correctness of any information in this file. You are on your own.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The chip I am going to describe is getting more and more common, but programming information is still scarce, so I have decided to fill in this gap. All information contained in this file is a result of my experience in Adlib programming, research (read: reverse engineering) and finally of my effort to write down everything necessary to understand and use this piece of hardware. No official sources (i.e. development kits, books about this topic, etc.) were available to me except:&lt;br /&gt;
&lt;br /&gt;
: Adlib Programming Guide - by Tero Töttö, and&lt;br /&gt;
: The PC Games Programmers Encyclopedia V1.0&lt;br /&gt;
&lt;br /&gt;
The information below is a combination of known features of Adlib (alias Yamaha YM 3812/OPL2) and my own uncountable experiments and failures, which brought out a lot of important details you have to know about the chip.&lt;br /&gt;
&lt;br /&gt;
As far as I know, there are four major sound cards based on OPL3 chip:&lt;br /&gt;
&lt;br /&gt;
* Sound Blaster Pro II (not Sound Blaster Pro I)&lt;br /&gt;
* Sound Blaster 16&lt;br /&gt;
* Adlib Gold&lt;br /&gt;
* Pro Audio Spectrum Plus/16&lt;br /&gt;
&lt;br /&gt;
I currently have a Sound Blaster Pro II-compatible card only, so all the programming info I provide will be based on this card. (The other cards are quite similar, however. They are just wired at different I/O-port addresses.)&lt;br /&gt;
&lt;br /&gt;
Note: I assume some knowledge of FM music programming (mainly Adlib FM synthesizer) in this manual. If you are new to this topic I recommend you try Adlib first before going higher. Anyway, OPL3 is a direct descendant of OPL2 (what a surprise), so most features of OPL2 are also present on OPL3.&lt;br /&gt;
&lt;br /&gt;
== Description of the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
My card&#039;s user manual says: &amp;quot;[this card contains] ... a stereo music FM synthesizer with 20 channels consisting of four (4) operators each ... &amp;quot; I thought: &amp;quot;Wow -- that&#039;s together eighty operators. This must be a GOOD sound-card.&amp;quot; I was wrong. Just another advertising lie.&lt;br /&gt;
&lt;br /&gt;
So let&#039;s clear some facts. First, OPL3 has only thirty-six (36) operators which can be combined in several ways:&lt;br /&gt;
&lt;br /&gt;
* 18 FM channels (36 operators), or&lt;br /&gt;
* 15 FM channels (30 ops) and 5 percussion instruments (6 ops), giving us 20 channels altogether, or&lt;br /&gt;
* up to 6 four-operator FM channels (max 24 ops), the rest again being divided into two-operator FM channels and drums.&lt;br /&gt;
&lt;br /&gt;
From the table above you can see that not all channels can be used in four-operator (4-OP) mode -- only a part of the synthesizer is really capable of making 4-OP sounds -- the rest uses traditional two-operator (2-OP) mode.&lt;br /&gt;
&lt;br /&gt;
Second, the manual states this card is capable of &amp;quot;stereo&amp;quot; music. Yes, the quotes are necessary, because the stereo capabilities are very limited. You are given ability to control output going to left or right channel by turning it on and off. That&#039;s all. So the sound can flow from very left side, center and very right side. No sound panning, no special stereo effects. :-(&lt;br /&gt;
&lt;br /&gt;
Well, flaming apart, back to the main topic.&lt;br /&gt;
&lt;br /&gt;
The OPL3 chip is capable of making sounds in several ways:&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Additive Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output of both operators is simply added. It is the simplest way to make any sound, and it works on both OPL2 and OPL3. The diagram should make it clear.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐&lt;br /&gt;
	│            │&lt;br /&gt;
	│ Operator 1 ├────────┐&lt;br /&gt;
	│            │        │&lt;br /&gt;
	└────────────┘        │&lt;br /&gt;
			      ├────────&amp;gt; Output&lt;br /&gt;
	┌────────────┐        │&lt;br /&gt;
	│            │        │&lt;br /&gt;
	│ Operator 2 ├────────┘&lt;br /&gt;
	│            │&lt;br /&gt;
	└────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Frequency Modulation (FM) Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output from the first operator (Modulator) is sent to the input of the second one (Carrier) and is used to modulate (alter) frequency of the second operator. Only the second operator produces sound. Most of interesting sounds are made this way. This also works on OPL2. Hope the picture helps.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐         ┌────────────┐&lt;br /&gt;
	│            │         │            │&lt;br /&gt;
	│ Operator 1 ├────────&amp;gt;│ Operator 2 ├────────&amp;gt; Output&lt;br /&gt;
	│(Modulator) │         │ (Carrier)  │&lt;br /&gt;
	└────────────┘         └────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Four-operator &amp;quot;Mess&amp;quot; Modulation Synthesis ===&lt;br /&gt;
&lt;br /&gt;
All of OPL3&#039;s 4-OP configurations are combinations of the above two modes of synthesis. OPL3 combines these two modes in four ways. I have no words to describe these four ways. Only the pictures can show their principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   a) FM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   b) AM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├───────────────────────────────────┐&lt;br /&gt;
	│       │                                   │&lt;br /&gt;
	└───────┘                                   │&lt;br /&gt;
						    │&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┴─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   c) FM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────┐&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     ├─────&amp;gt; Output&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┘&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	└───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   d) AM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├────────────────────┐&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	└───────┘                    │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────┼─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐                    │&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	│ Op. 4 ├────────────────────┘&lt;br /&gt;
	│       │&lt;br /&gt;
	└───────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Nice, aren&#039;t they?&lt;br /&gt;
&lt;br /&gt;
The only way I think this can be written is a math formula. Symbol + (plus) means additive synthesis, and * (asterisk) means frequency modulation (Op1 * Op2 means operator 1 modulates operator 2, not vice versa). Here they are:&lt;br /&gt;
&lt;br /&gt;
# FM-FM Mode:	 (Op1 * Op2 * Op3 * Op4) ────&amp;gt; Output&lt;br /&gt;
# AM-FM Mode:	  Op1 + (Op2 * Op3 * Op4) ───&amp;gt; Output&lt;br /&gt;
# FM-AM Mode:	 (Op1 * Op2) + (Op3 * Op4) ──&amp;gt; Output&lt;br /&gt;
# AM-AM Mode:	  Op1 + (Op2 * Op3) + Op4 ───&amp;gt; Output&lt;br /&gt;
&lt;br /&gt;
=== Percussion Mode ===&lt;br /&gt;
&lt;br /&gt;
In this mode 6 operators are used to produce five different percussion instruments:&lt;br /&gt;
&lt;br /&gt;
* Bass Drum (2 operators)&lt;br /&gt;
* Snare Drum (1 operator)&lt;br /&gt;
* Tom-Tom (1 operator)&lt;br /&gt;
* Cymbal (1 operator)&lt;br /&gt;
* Hi-Hat (1 operator)&lt;br /&gt;
&lt;br /&gt;
Because these instruments occupy only three melodic channels, only Bass Drum, Snare Drum and Tom-Tom frequencies can be set. Cymbal and Hi-Hat frequencies are fixed.  {{TODO|It seems it&#039;s actually the cymbal and snare frequencies that are fixed, try to confirm this -- [[User:Malvineous|Malvineous]] 13:34, 3 June 2012 (GMT)}}&lt;br /&gt;
&lt;br /&gt;
This mode is identical with that of OPL2. For more details see ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
== Programming the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
OPL3 may be found at the following addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| Sound Blaster Pro II || 220h or 240h (selectable), also 388h&lt;br /&gt;
|-&lt;br /&gt;
| Adlib Gold || 388h&lt;br /&gt;
|-&lt;br /&gt;
| Pro Audio Spectrum Plus/16 || ? (if you have a PAS you should know it)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The base address of the synthesizer will be called &amp;quot;base&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The chip occupies four I/O addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| base+0 || Primary index register (write), Status register (read)&lt;br /&gt;
|-&lt;br /&gt;
| base+1 || Primary data register (write-only)&lt;br /&gt;
|-&lt;br /&gt;
| base+2 || Secondary index register (write)&lt;br /&gt;
|-&lt;br /&gt;
| base+3 || Secondary data register (write-only)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The index registers are used to select internal registers and data registers are used to write to them. Status register returns the state of two timers built in the chip.&lt;br /&gt;
&lt;br /&gt;
OPL3 contains two sets of registers. The Primary set maps to channels 0-8 (operators 0-17) and the secondary maps to channels 9-17 (operators 18-35). The reason for this is simple: all these registers wouldn&#039;t fit into single register set.&lt;br /&gt;
&lt;br /&gt;
Unlike Adlib (OPL2), OPL3 doesn&#039;t need delay between register writes. With OPL2 you had to wait 3.3 µs after index register write and another 23 µs after data register write. On the contrary OPL3 doesn&#039;t need (almost) any delay after index register write and only 0.28 µs after data register write. This means you can neglect the delays and slightly speed up your music driver. But using reasonable delays will certainly do no harm.&lt;br /&gt;
&lt;br /&gt;
The data registers can&#039;t be read (they are write-only) on both OPL2 and OPL3.&lt;br /&gt;
&lt;br /&gt;
== Register Map ==&lt;br /&gt;
&lt;br /&gt;
The registers are grouped in the same manner as in the OPL2 chip. Programs using both OPL2 and OPL3 chips may use the same code provided that their direct I/O interface is well written. The only thing you have to change is operator-to-register mapping, which must accomodate the fact that registers are spread between two register sets.&lt;br /&gt;
&lt;br /&gt;
(The register map is nearly the same so I dared to copy it from ADLIB.DOC.)&lt;br /&gt;
&lt;br /&gt;
=== Status Register (base+0) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
!    D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQFlag || T1Flag || T2Flag ||        ||        ||        ||        ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Data Registers (base+1, base+3) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! REG   !!   D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| 01    ||colspan=2| Test Register ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|(WSEnable)||colspan=5| Test Register&lt;br /&gt;
|-&lt;br /&gt;
| 02    ||colspan=8| Timer 1 Count (80 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 03    ||colspan=8| Timer 2 Count (320 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 04*   ||IRQReset|| T1Mask || T2Mask ||colspan=3|                  ||T2 Start||T1 Start&lt;br /&gt;
|-&lt;br /&gt;
| 04**  ||colspan=2|        ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP B-E||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP A-D||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 9-C||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 2-5||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 1-4||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 0-3&lt;br /&gt;
|-&lt;br /&gt;
| 05**  ||colspan=7|                                                           ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;| OPL3&lt;br /&gt;
|-&lt;br /&gt;
| 08    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;| (CSW)  ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|NOTE-SEL||colspan=6|&lt;br /&gt;
|-&lt;br /&gt;
| 20-35 ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Tremolo ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Vibrato ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Sustain ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|  KSR   ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Frequency Multiplication Factor&lt;br /&gt;
|-&lt;br /&gt;
| 40-55 ||colspan=2 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Key Scale Level ||colspan=6 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 60-75 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Attack Rate ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 80-95 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Sustain Level ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A0-A8 ||colspan=8 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Frequency Number  (Lower 8 bits)&lt;br /&gt;
|-&lt;br /&gt;
| B0-B8 ||colspan=2|        ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| KEY-ON ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Block Number ||colspan=2 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| F-Num (hi bits)&lt;br /&gt;
|-&lt;br /&gt;
| BD    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Trem Dep||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Vibr Dep||style=&amp;quot;background-color: #FFCCDD;&amp;quot;|PercMode||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| BD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| SD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| TT On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| CY On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| HH On&lt;br /&gt;
|-&lt;br /&gt;
| C0-C8 ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| OutCh_D ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| OutCh_C ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Right  ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Left   ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;|FeedBack Modulation Factor||style=&amp;quot;background-color: #FFE0CC;&amp;quot;|SynthTyp&lt;br /&gt;
|-&lt;br /&gt;
| E0-F5 ||colspan=5|                                      ||colspan=3 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|style=&amp;quot;background-color: #CCFFCC;&amp;quot;| Chip-wide setting&lt;br /&gt;
|style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Per operator&lt;br /&gt;
|style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Per channel&lt;br /&gt;
|style=&amp;quot;background-color: #FFCCDD;&amp;quot;| Rhythm-mode only&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt; This applies only to port base+1&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;**&amp;lt;/nowiki&amp;gt; This applies only to port base+3&lt;br /&gt;
&lt;br /&gt;
For register bases A0, B0 and C0 there is one register per output channel. The primary register set holds the first nine channels (0-8) and the secondary holds last nine channels (9-17). For bases 20, 40, 60, 80 and E0 there are two registers per channel. Each register maps to one operator. Unfortunately the operator&#039;s register numbers are not continuous. The following table shows which operator maps to which register set and offset (in hex).&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Op. !! Set/Offset !! Op. !! Set/Offset&lt;br /&gt;
|-&lt;br /&gt;
| 0  || 0/00 || 18 || 1/00&lt;br /&gt;
|-&lt;br /&gt;
| 1  || 0/01 || 19 || 1/01&lt;br /&gt;
|-&lt;br /&gt;
| 2  || 0/02 || 20 || 1/02&lt;br /&gt;
|-&lt;br /&gt;
| 3  || 0/03 || 21 || 1/03&lt;br /&gt;
|-&lt;br /&gt;
| 4  || 0/04 || 22 || 1/04&lt;br /&gt;
|-&lt;br /&gt;
| 5  || 0/05 || 23 || 1/05&lt;br /&gt;
|-&lt;br /&gt;
| 6  || 0/08 || 24 || 1/08&lt;br /&gt;
|-&lt;br /&gt;
| 7  || 0/09 || 25 || 1/09&lt;br /&gt;
|-&lt;br /&gt;
| 8  || 0/0A || 26 || 1/0A&lt;br /&gt;
|-&lt;br /&gt;
| 9  || 0/0B || 27 || 1/0B&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 0/0C || 28 || 1/0C&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 0/0D || 29 || 1/0D&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 0/10 || 30 || 1/10&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 0/11 || 31 || 1/11&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 0/12 || 32 || 1/12&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 0/13 || 33 || 1/13&lt;br /&gt;
|-&lt;br /&gt;
| 16 || 0/14 || 34 || 1/14&lt;br /&gt;
|-&lt;br /&gt;
| 17 || 0/15 || 35 || 1/15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following tables summarize which operators form a channel in various modes:&lt;br /&gt;
&lt;br /&gt;
1. Two-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel    !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 13 || 14 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 || 16 || 17 || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
2. Two-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 ||colspan=4| - || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
3. Four-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 13 || 14 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 || 16 || 17 || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=3| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=3| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Channels 3, 4, 5 and 12, 13, 14 can&#039;t be used separately because their operators became part of channels 0, 1, 2 and 9, 10, 11 respectively. For instance a four-operator channel 1 consists of two two-operator channels number 1 and 4. (The second 2-OP channel number is always the first 2-OP channel number plus three.)&lt;br /&gt;
&lt;br /&gt;
OPL3 allows you to enable/disable 4-OP mode separately for any of channels 0, 1, 2, 9, 10 and 11 (see register 104h in the reference below). This means for instance when you switch only channel 2 into 4-OP mode, channels number 0, 1, 3, 4, 6, 7, 8, 9, etc. will be still independent 2-OP channels.&lt;br /&gt;
&lt;br /&gt;
Channels 6, 7, 8 and 15, 16, 17 are always two-operator ones. They can&#039;t be grouped to form four-operator channels.&lt;br /&gt;
&lt;br /&gt;
4. Four-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 ||colspan=4| - || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=5| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=5| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
Two-operator channel #14 consists of operators 26 and 29 which occupy these registers (all are in the secondary register set):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| 12A || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 12D || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 14A || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 14D || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 16A || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 16D || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18A || Operator 1 ||Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18D || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 1A5 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| 1B5 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| 1C5 ||            || FeedBack/Synthesis Type&lt;br /&gt;
|-&lt;br /&gt;
| 1EA || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| 1ED || Operator 2 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Four-operator channel #1 consists of operators 1, 4, 7 and 10. All registers except register 104h are in the primary set:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 104 || bit 1 = 1  || Enable Four-Operator Synthesis in channel #1&lt;br /&gt;
|-&lt;br /&gt;
| 21 || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 24 || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 29 || Operator 3 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 2C || Operator 4 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 41 || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 44 || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 49 || Operator 3 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 4C || Operator 4 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 61 || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 64 || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 69 || Operator 3 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 6C || Operator 4 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 81 || Operator 1 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 84 || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 89 || Operator 3 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 8C || Operator 4 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A1 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| A4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| B1 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| B4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| C1 ||            || FeedBack/Synthesis Type (part 1)&lt;br /&gt;
|-&lt;br /&gt;
| C4 ||            || Synthesis Type (part 2)&lt;br /&gt;
|-&lt;br /&gt;
| E1 || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E4 || Operator 2 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E9 || Operator 3 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| EC || Operator 4 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
NOTE: If a register number is greater than 100h, then it belongs into the secondary register set. (I use this numbering to emphasize the fact that the particular register MUST be written to the secondary set.) See the example code below for details.&lt;br /&gt;
&lt;br /&gt;
== OPL3 Register Reference ==&lt;br /&gt;
&lt;br /&gt;
Because the registers of OPL3 are almost the same as of OPL2, I have copied their descriptions from file ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
=== Status Register ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQ || T1 || T2 ||colspan=5| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ Flag. Set whenever any timer has elapsed.&lt;br /&gt;
* bit 6: Timer 1 Flag. Set every time the preset time in Timer 1 has elapsed.&lt;br /&gt;
* bit 5: Timer 2 Flag. Set every time the preset time in Timer 2 has elapsed.&lt;br /&gt;
&lt;br /&gt;
Timer interrupts are not wired to any IRQ (why??). The timers can be used to detect the OPL2/OPL3 chip (see Appendix B).&lt;br /&gt;
&lt;br /&gt;
=== Data Registers ===&lt;br /&gt;
&lt;br /&gt;
==== 01: Test Register / Waveform Select Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| Test Register&lt;br /&gt;
| (WSE)&lt;br /&gt;
|colspan=5| Test Register&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 7-6: Test Register. Must be reset to zero before any operation.&lt;br /&gt;
* bit 5: Waveform Select Enable. If clear, all channels will use normal sine wave. If set, register E0-F5 (Waveform Select) contents will be used.&lt;br /&gt;
* bits 0-4: Test Register. Must be reset to zero before any operation.&lt;br /&gt;
&lt;br /&gt;
OPL3 does not implement WSE bit, and it should be left clear. In OPL2 mode all four waveforms are always available, and in OPL3 mode all eight waveforms are always available. For compatibility with OPL2, when a program is finished using an OPL3, the waveform select registers should be set to 0, if the next program assumes that by setting WSE bit to 0 the waveform is always sine like on a real OPL2.&lt;br /&gt;
&lt;br /&gt;
==== 02: Timer 1 Count ====&lt;br /&gt;
&lt;br /&gt;
Upward 8 bit counter with a resolution of 80 µsec. If an overflow occurs, the status register bit is set, and the preset value is loaded into the timer again.&lt;br /&gt;
&lt;br /&gt;
==== 03: Timer 2 Count ====&lt;br /&gt;
&lt;br /&gt;
Same as Timer 1, but with a resolution of 320 µsec.&lt;br /&gt;
&lt;br /&gt;
==== 004 (port: base+1): IRQ-Reset / Mask / Start ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Rst&lt;br /&gt;
| T1M&lt;br /&gt;
| T2M&lt;br /&gt;
|colspan=3| -&lt;br /&gt;
| T2S&lt;br /&gt;
| T1S&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ-Reset. Resets timer and IRQ flags in status register. All other bits are ignored when this bit is set.&lt;br /&gt;
* bit 6: Timer 1 Mask. If 1, status register is not affected in overflow.&lt;br /&gt;
* bit 5: Timer 2 Mask. Same as above.&lt;br /&gt;
* bit 1: Timer 2 Start. Timer on/off.&lt;br /&gt;
* bit 0: Timer 1 Start. Same as above.&lt;br /&gt;
&lt;br /&gt;
==== 104 (port: base+3): Four-Operator Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| ChB&lt;br /&gt;
| ChA&lt;br /&gt;
| Ch9&lt;br /&gt;
| Ch2&lt;br /&gt;
| Ch1&lt;br /&gt;
| Ch0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: Enable four-operator synthesis for channel pair 11 - 14 (decimal).&lt;br /&gt;
* bit 4: Same as above for channel pair 10 - 13.&lt;br /&gt;
* bit 3: Same as above for channel pair 9 - 12.&lt;br /&gt;
* bit 2: Same as above for channel pair 2 - 5.&lt;br /&gt;
* bit 1: Same as above for channel pair 1 - 4.&lt;br /&gt;
* bit 0: Same as above for channel pair 0 - 3.&lt;br /&gt;
&lt;br /&gt;
If reset to zero, OPL3 can produce 18 two-operator sounds at a time. If nonzero, OPL3 produces four-operator sound in appropriate channel pair.&lt;br /&gt;
&lt;br /&gt;
==== 105 (port: base+3): OPL3 Mode Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=7| -&lt;br /&gt;
| OPL3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 0: OPL3 Mode Enable. When set, OPL3 extensions (36 operators, 4-OP synthesis, 8 waveforms, stereo output) can be used. When reset, the chip behaves as an ordinary OPL2. This bit is zero by default for compatibility with OPL2.&lt;br /&gt;
&lt;br /&gt;
==== 08: CSW / NOTE-SEL ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| (CSW)&lt;br /&gt;
| N-S&lt;br /&gt;
|colspan=6| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: Composite sine wave mode on/off. All KEY-ON bits must be clear in order to use this mode. The card is unable to create any other sound when in CSW mode. (Unfortunately, I have no info how to use this mode :-&amp;lt; ). The CSW mode is not implemented on an OPL3 and this bit is ignored.&lt;br /&gt;
* bit 6: NOTE-SEL. Controls the split point of the keyboard. When 0, the keyboard split is the second bit from the bit 8 of the F-Number. When 1, the MSb of the F-Number is used. (???)&lt;br /&gt;
&lt;br /&gt;
==== 20-35: Tremolo / Vibrato / Sustain / KSR / Frequency Multiplication Factor ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Sus&lt;br /&gt;
| KSR&lt;br /&gt;
|colspan=4| Multiplication&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude vibrato) on/off.&lt;br /&gt;
* bit 6:    Frequency vibrato on/off.&lt;br /&gt;
* bit 5:    Sound Sustaining. When 1, operator&#039;s output level will be held at its sustain level until a KEY-OFF is done.&lt;br /&gt;
* bit 4:    Envelope scaling (KSR) on/off. When 1, higher notes are shorter than lower notes.&lt;br /&gt;
* bits 0-3: Frequency Multiplication Factor (MULTI). Operator&#039;s frequency is set to (see registers A0, B0) F-Number * Factor.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! MULTI !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0.5&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 2&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 3&lt;br /&gt;
|-&lt;br /&gt;
| 4 || 4&lt;br /&gt;
|-&lt;br /&gt;
| 5 || 5&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 6&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 7&lt;br /&gt;
|-&lt;br /&gt;
| 8 || 8&lt;br /&gt;
|-&lt;br /&gt;
| 9 || 9&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 40-55: Key Scale Level / Output Level ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| KSL&lt;br /&gt;
|colspan=6| Output level&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 6-7: Key Scale Level. Attenuates output level towards higher pitch:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! KSL !! Attenuation&lt;br /&gt;
|-&lt;br /&gt;
| 0 || -&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 3.0 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 1.5 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 6.0 dB/oct&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The attenuation level is based on the 3-bit octave (block number) value and top four bits of the FNUM value, so each octave is subdivided into 16 parts.&lt;br /&gt;
&lt;br /&gt;
* bits 0-5: Output Level. Attenuates the operator output level. 0 is the loudest, 3F is the softest. Attenuation range is 48dB with 0.75dB resolution.&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| 24dB || 12dB || 6dB || 3dB || 1.5dB || 0.75dB&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* In additive synthesis, varying the output level of any operator varies the volume of its corresponding channel. In FM synthesis, varying the output level of the carrier varies the volume of the channel. Varying the output of the modulator will change the frequency spectrum produced by the carrier. The following table summarizes which operators&#039; output levels should be updated when trying to change channel output level.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Mode !! Op 1 !! Op 2 !! Op 3 !! Op 4&lt;br /&gt;
|-&lt;br /&gt;
| AM    || Y || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM    || - || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM-FM || - || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-FM || Y || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| FM-AM || - || Y || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-AM || Y || - || Y   || Y&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 60-75: Attack Rate / Decay Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Attack rate&lt;br /&gt;
|colspan=4| Decay rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Attack Rate. Determines the rising time for the sound. The higher the value, the faster the attack. If value is 0, the sound will never attack, and if value is 15, the volume jumps directly from minimum to maximum.&lt;br /&gt;
* bits 0-3: Decay Rate. Determines the diminishing time for the sound. The higher the value, the shorter the decay. If value is 0, the sound does not decay towards sustain level and stays at maximum volume after attack.&lt;br /&gt;
&lt;br /&gt;
==== 80-95: Sustain Level / Release Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Sustain level&lt;br /&gt;
|colspan=4| Release rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Sustain Level. Determines the point at which the sound ceases to decay and chages to a sound having a constant level. The sustain level is expressed as a fraction of the maximum level. 0 is the softest and F is the loudest sustain level. Note that the Sustain-bit in the register 20-35 must be set for this to have an effect.&lt;br /&gt;
* bits 0-3: Release Rate. Determines the rate at which the sound disappears after KEY-OFF. The higher the value, the shorter the release.&lt;br /&gt;
&lt;br /&gt;
==== A0-A8: Frequency Number ====&lt;br /&gt;
&lt;br /&gt;
Determines the pitch of the note. Highest bits of F-Number are stored in the register below.&lt;br /&gt;
&lt;br /&gt;
==== B0-B8: Key On / Block Number / F-Number(hi bits) ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| KEY&lt;br /&gt;
|colspan=3| Block num.&lt;br /&gt;
|colspan=2| Freq&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: KEY-ON. When 1, channel output is enabled.&lt;br /&gt;
* bits 2-4: Block Number. Roughly determines the octave.&lt;br /&gt;
* bits 0-1: Frequency Number. 2 highest bits of the above register.  The following formula is used to determine F-Number and Block:&lt;br /&gt;
: F-Number = Music Frequency * 2^(20-Block) / 49716 Hz&lt;br /&gt;
&lt;br /&gt;
NOTE: In four-operator mode only the register value of Operators 1 and 2 is used, value of Operators 3 and 4 in this register is ignored. In other words: one channel uses only one frequency, block and KEY-ON value at a time, regardless whether it is a two- or four-operator channel.&lt;br /&gt;
&lt;br /&gt;
==== BD: Tremolo Depth / Vibrato Depth / Percussion Mode / BD/SD/TT/CY/HH On ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Per&lt;br /&gt;
| BD&lt;br /&gt;
| SD&lt;br /&gt;
| TT&lt;br /&gt;
| CY&lt;br /&gt;
| HH&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude Vibrato) Depth. 0 = 1.0dB, 1 = 4.8dB.&lt;br /&gt;
* bit 6:    Frequency Vibrato Depth. 0 = 7 cents, 1 = 14 cents. A &amp;quot;cent&amp;quot; is 1/100 of a semi-tone.&lt;br /&gt;
* bit 5:    Percussion Mode. 0 = Melodic Mode, 1 = Percussion Mode.&lt;br /&gt;
* bit 4:    BD On. KEY-ON of the Bass Drum channel.&lt;br /&gt;
* bit 3:    SD On. KEY-ON of the Snare Drum channel.&lt;br /&gt;
* bit 2:    TT On. KEY-ON of the Tom-Tom channel.&lt;br /&gt;
* bit 1:    CY On. KEY-ON of the Cymbal channel.&lt;br /&gt;
* bit 0:    HH On. KEY-ON of the Hi-Hat channel.&lt;br /&gt;
&lt;br /&gt;
NOTE: KEY-ON bits of channels 6, 7 and 8 must be clear and their F-Nums, Attack/Decay/Release rates, etc. must be set properly to use percussion mode.&lt;br /&gt;
&lt;br /&gt;
==== C0-C8: FeedBack Modulation Factor / Synthesis Type ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| OutCh_D&lt;br /&gt;
| OutCh_C&lt;br /&gt;
| R&lt;br /&gt;
| L&lt;br /&gt;
|colspan=3| Feedback&lt;br /&gt;
| Syn&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: CHD, Output Channel D Enable. When set, channel output goes to fourth digital audio output channel.&lt;br /&gt;
* bit 6: CHC, Output Channel C Enable. When set, channel output goes to third digital audio output channel.&lt;br /&gt;
* bit 5:    Right Speaker Enable. When set, channel output goes to second digital audio output channel, connected to right speaker.&lt;br /&gt;
* bit 4:    Left Speaker Enable. When set, channel output goes to first digital audio output channel, connected to left speaker.&lt;br /&gt;
** In OPL3 mode, at least one of the left/right bits must be set to hear the channel.&lt;br /&gt;
** In OPL2 mode, these bits are ignored and audio is sent to all channels for compatibility reasons.&lt;br /&gt;
** Left/Right bits can be used to realize sound &amp;quot;panning&amp;quot;, but this method offers only three pan positions (left/center/right).&lt;br /&gt;
** These bits apply only to operators producing sound (Carriers). Modulators are not affected by their setting.&lt;br /&gt;
** Sound cards use only one stereo DAC, so only two of the four digital output channels are available.&lt;br /&gt;
* bits 1-3: FeedBack Modulation Factor. If 0, no feedback is present. If 1-7, operator 1 will send a portion of its output back into itself.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! FeedBack !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;amp;pi;/16&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;amp;pi;/8&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;amp;pi;/4&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;amp;pi;/2&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 2&amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 4&amp;amp;pi;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
When in four-operator mode, the FeedBack value is used only by Operator 1, value of Operators 2, 3 and 4 is ignored.&lt;br /&gt;
&lt;br /&gt;
* bit 0: Synthesis Type. 1 = Additive synthesis, 0 = Frequency Modulation.  In four-operator mode, there are two bits controlling the synthesis type. Both are the bit 0 of register C0, one of Operators 1 and 2 and the second of Operators 3 and 4.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Op 1&amp;amp;2 !! Op 3&amp;amp;4 !! Type&lt;br /&gt;
|-&lt;br /&gt;
| 0 || NONE || FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || NONE || AM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || FM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || AM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || FM-AM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || AM-AM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== E0-F5: Waveform Select ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=5| -&lt;br /&gt;
|colspan=3| Waveform&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 0-2: WaveForm Select (WS): &amp;lt;gallery widths=261px perrow=4&amp;gt;&lt;br /&gt;
Image:OPL_Wave0.png|Waveform 0: Sine&lt;br /&gt;
Image:OPL_Wave1.png|Waveform 1: Half-sine&lt;br /&gt;
Image:OPL_Wave2.png|Waveform 2: Abs-sine&lt;br /&gt;
Image:OPL_Wave3.png|Waveform 3: Pulse-sine&lt;br /&gt;
Image:OPL_Wave4.png|Waveform 4: Sine - even periods only&lt;br /&gt;
Image:OPL_Wave5.png|Waveform 5: Abs-sine - even periods only&lt;br /&gt;
Image:OPL_Wave6.png|Waveform 6: Square&lt;br /&gt;
Image:OPL_Wave7.png|Waveform 7: Derived square&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* NOTE: Bit 5 of register 01 must be set to use waveforms other than sine. Waveforms 4-7 are available only on OPL3. See files WAVEn.GIF for real waveforms, where n is a number between 0 and 7.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
These examples show a few working routines used in my MUS Player. They are written in Borland C++ 3.1 but should be easy to translate to any other language.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
// I prefer using these Assembler-like types&lt;br /&gt;
typedef unsigned int  WORD;&lt;br /&gt;
typedef unsigned char BYTE;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * FM Synthesizer base port. SB Pro II - 0x220, Adlib 0x388&lt;br /&gt;
 */&lt;br /&gt;
WORD FMport = 0x220;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Enables OPL3 extensions.&lt;br /&gt;
 */&lt;br /&gt;
WORD OPL3 = 1;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Direct write to any Adlib/SB Pro II FM synthetiser register.&lt;br /&gt;
 *   reg - register number (range 0x001-0x0F5 and 0x101-0x1F5). When high byte&lt;br /&gt;
 *         of reg is zero, data go to port FMport, otherwise to FMport+2&lt;br /&gt;
 *   data - register value to be written&lt;br /&gt;
 */&lt;br /&gt;
BYTE FMwriteReg(WORD reg, BYTE data)&lt;br /&gt;
{&lt;br /&gt;
    asm {&lt;br /&gt;
	mov	dx,FMport&lt;br /&gt;
	mov	ax,reg&lt;br /&gt;
	or	ah,ah		// high byte is nonzero -- write to port base+2&lt;br /&gt;
	jz	out1&lt;br /&gt;
	inc	dx&lt;br /&gt;
	inc	dx&lt;br /&gt;
    }&lt;br /&gt;
out1: asm {&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	mov	cx,6&lt;br /&gt;
    }&lt;br /&gt;
loop1:asm {			// delay between writes&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop1&lt;br /&gt;
&lt;br /&gt;
	inc	dx&lt;br /&gt;
	mov	al,data&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	dec	dx&lt;br /&gt;
	mov	cx,36&lt;br /&gt;
    }&lt;br /&gt;
loop2:asm {			// delay after data write&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop2&lt;br /&gt;
    }&lt;br /&gt;
    return _AL;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to an operator pair. To be used for register bases of 0x20, 0x40,&lt;br /&gt;
 * 0x60, 0x80 and 0xE0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteChannel(BYTE regbase, BYTE channel, BYTE data1, BYTE data2)&lt;br /&gt;
{&lt;br /&gt;
    static BYTE adlib_op[] = {0, 1, 2, 8, 9, 10, 16, 17, 18};&lt;br /&gt;
    static BYTE sbpro_op[] = { 0,  1,  2,   6,  7,  8,  12, 13, 14,&lt;br /&gt;
			      18, 19, 20,  24, 25, 26,  30, 31, 32};&lt;br /&gt;
    static WORD rg[] = {0x000,0x001,0x002,0x003,0x004,0x005,&lt;br /&gt;
			0x008,0x009,0x00A,0x00B,0x00C,0x00D,&lt;br /&gt;
			0x010,0x011,0x012,0x013,0x014,0x015,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,&lt;br /&gt;
			0x108,0x109,0x10A,0x10B,0x10C,0x10D,&lt;br /&gt;
			0x110,0x111,0x112,0x113,0x114,0x115};&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
    {&lt;br /&gt;
	register WORD reg = sbpro_op[channel];&lt;br /&gt;
	FMwriteReg(rg[reg]+regbase, data1);&lt;br /&gt;
	FMwriteReg(rg[reg+3]+regbase, data2);&lt;br /&gt;
    } else {&lt;br /&gt;
	register WORD reg = regbase+adlib_op[channel];&lt;br /&gt;
	FMwriteReg(reg, data1);&lt;br /&gt;
	FMwriteReg(reg+3, data2);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to channel a single value. To be used for register bases of&lt;br /&gt;
 * 0xA0, 0xB0 and 0xC0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteValue(BYTE regbase, BYTE channel, BYTE value)&lt;br /&gt;
{&lt;br /&gt;
    static WORD ch[] = {0x000,0x001,0x002,0x003,0x004,0x005,0x006,0x007,0x008,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,0x106,0x107,0x108};&lt;br /&gt;
    register WORD chan;&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
	chan = ch[channel];&lt;br /&gt;
    else&lt;br /&gt;
	chan = channel;&lt;br /&gt;
    FMwriteReg(regbase + chan, value);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Detection Methods ==&lt;br /&gt;
&lt;br /&gt;
An official method of Adlib (OPL2) detection is:&lt;br /&gt;
&lt;br /&gt;
# Reset Timer 1 and Timer 2: write 60h to register 4.&lt;br /&gt;
# Reset the IRQ: write 80h to register 4.&lt;br /&gt;
#* NOTE: Steps 1 and 2 can&#039;t be combined together.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Set Timer 1 to FFh: write FFh to register 2.&lt;br /&gt;
# Unmask and start Timer 1: write 21h to register 4.&lt;br /&gt;
# Wait in a delay loop for at least 80 µsec.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Reset Timer 1, Timer 2 and IRQ as in steps 1 and 2.&lt;br /&gt;
# Test the results of the two reads: the first should be 0, the second should be C0h. If either is incorrect, then the OPL2 is not present.&lt;br /&gt;
&lt;br /&gt;
* NOTE1: You should AND the result bytes with E0h because the unused bits are undefined.&lt;br /&gt;
* NOTE2: This testing method doesn&#039;t work in some SoundBlaster compatible cards.&lt;br /&gt;
&lt;br /&gt;
=== OPL3 Detection ===&lt;br /&gt;
--------------&lt;br /&gt;
&lt;br /&gt;
# Detect OPL2. If present, continue.&lt;br /&gt;
# Read status register: read port base+0.&lt;br /&gt;
# AND the result with 06h.&lt;br /&gt;
# If the result is zero, you have OPL3, otherwise OPL2.&lt;br /&gt;
&lt;br /&gt;
* NOTE: This is NOT an official method. I have dug it out of a sound driver. I haven&#039;t tested it, because I haven&#039;t an OPL2 card (Adlib, SB Pro I). Nevertheless it &amp;quot;detects&amp;quot; my SB Pro II properly. ;-)&lt;br /&gt;
&lt;br /&gt;
Another possible detection method for distinguishing between SB Pro I and SB Pro II would be to try to detect OPL2 at I/O port base+0 and then at port base+2. The first test should succeed and the second should fail if OPL3 is present. (Remember: SB Pro I contains twin OPL2 chips at addresses base+0 and base+2, while SB Pro II contains one OPL3 chip at I/O address base+0 thru base+3).&lt;br /&gt;
&lt;br /&gt;
== BLASTER Environment Variable ==&lt;br /&gt;
&lt;br /&gt;
Perhaps the most recommended &amp;quot;detection&amp;quot; method. Reading this variable avoids blindfold I/O port scanning and possible device conflicts. The user is responsible for its proper setting.&lt;br /&gt;
&lt;br /&gt;
The variable has this format:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=Aaddr Iirq Ddma Ttype&lt;br /&gt;
&lt;br /&gt;
* A: Base I/O address given in hex. For most Sound Blasters the default is 220.&lt;br /&gt;
* I: IRQ Number (decimal). Default 7.&lt;br /&gt;
* D: DMA Number (decimal). Default 1.&lt;br /&gt;
* T: Card Type (decimal):&lt;br /&gt;
** 1 - Sound Blaster 1.5&lt;br /&gt;
** 2 - Sound Blaster Pro I&lt;br /&gt;
** 3 - Sound Blaster 2.0&lt;br /&gt;
** 4 - Sound Blaster Pro II&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=A220 I7 D1 T4&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The PC Games Programmers Encyclopedia&#039;&#039;, Mark Feldman and many others on Usenet and Internet, ftp://teeri.oulu.fi/pub/msdos/programming/gpe&lt;br /&gt;
: ... you can find (almost) everything you need there&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Sound Blaster - The Official Book&#039;&#039;, Richard Heimlich, David M. Golden, Ivan Luk, Peter M. Ridge, Osborne/McGraw Hill, ISBN 0-07-881907-5&lt;br /&gt;
: ... this is a number-one in my book-wishlist. If anyone wanted to get rid of the book, I wouldn&#039;t scorn it ... :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The SoundBlaster Developer Kit&#039;&#039;, Creative Labs Inc, Creative Technology PTE LTD&lt;br /&gt;
: ... I wonder if you can find something comprehensible in that.&lt;/div&gt;</summary>
		<author><name>Kermes</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4334</id>
		<title>OPL chip</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4334"/>
		<updated>2012-08-05T17:33:53Z</updated>

		<summary type="html">&lt;p&gt;Kermes: /* 40-55: Key Scale Level / Output Level */ Explain Output Level further in decibels&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Programmer&#039;s Guide to Yamaha YMF 262/OPL3 FM Music Synthesizer =&lt;br /&gt;
Version 1.00  Nov-24-1994&lt;br /&gt;
&lt;br /&gt;
Written by Vladimir Arnost, QA-Software&lt;br /&gt;
Internet:  xarnos00@dcse.fee.vutbr.cz&lt;br /&gt;
&lt;br /&gt;
This manual can be distributed freely if not modified.&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer ===&lt;br /&gt;
&lt;br /&gt;
I assume no responsibility for any damages arising out of use or inability to use this text. No warranty is provided about correctness of any information in this file. You are on your own.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The chip I am going to describe is getting more and more common, but programming information is still scarce, so I have decided to fill in this gap. All information contained in this file is a result of my experience in Adlib programming, research (read: reverse engineering) and finally of my effort to write down everything necessary to understand and use this piece of hardware. No official sources (i.e. development kits, books about this topic, etc.) were available to me except:&lt;br /&gt;
&lt;br /&gt;
: Adlib Programming Guide - by Tero Töttö, and&lt;br /&gt;
: The PC Games Programmers Encyclopedia V1.0&lt;br /&gt;
&lt;br /&gt;
The information below is a combination of known features of Adlib (alias Yamaha YM 3812/OPL2) and my own uncountable experiments and failures, which brought out a lot of important details you have to know about the chip.&lt;br /&gt;
&lt;br /&gt;
As far as I know, there are four major sound cards based on OPL3 chip:&lt;br /&gt;
&lt;br /&gt;
* Sound Blaster Pro II (not Sound Blaster Pro I)&lt;br /&gt;
* Sound Blaster 16&lt;br /&gt;
* Adlib Gold&lt;br /&gt;
* Pro Audio Spectrum Plus/16&lt;br /&gt;
&lt;br /&gt;
I currently have a Sound Blaster Pro II-compatible card only, so all the programming info I provide will be based on this card. (The other cards are quite similar, however. They are just wired at different I/O-port addresses.)&lt;br /&gt;
&lt;br /&gt;
Note: I assume some knowledge of FM music programming (mainly Adlib FM synthesizer) in this manual. If you are new to this topic I recommend you try Adlib first before going higher. Anyway, OPL3 is a direct descendant of OPL2 (what a surprise), so most features of OPL2 are also present on OPL3.&lt;br /&gt;
&lt;br /&gt;
== Description of the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
My card&#039;s user manual says: &amp;quot;[this card contains] ... a stereo music FM synthesizer with 20 channels consisting of four (4) operators each ... &amp;quot; I thought: &amp;quot;Wow -- that&#039;s together eighty operators. This must be a GOOD sound-card.&amp;quot; I was wrong. Just another advertising lie.&lt;br /&gt;
&lt;br /&gt;
So let&#039;s clear some facts. First, OPL3 has only thirty-six (36) operators which can be combined in several ways:&lt;br /&gt;
&lt;br /&gt;
* 18 FM channels (36 operators), or&lt;br /&gt;
* 15 FM channels (30 ops) and 5 percussion instruments (6 ops), giving us 20 channels altogether, or&lt;br /&gt;
* up to 6 four-operator FM channels (max 24 ops), the rest again being divided into two-operator FM channels and drums.&lt;br /&gt;
&lt;br /&gt;
From the table above you can see that not all channels can be used in four-operator (4-OP) mode -- only a part of the synthesizer is really capable of making 4-OP sounds -- the rest uses traditional two-operator (2-OP) mode.&lt;br /&gt;
&lt;br /&gt;
Second, the manual states this card is capable of &amp;quot;stereo&amp;quot; music. Yes, the quotes are necessary, because the stereo capabilities are very limited. You are given ability to control output going to left or right channel by turning it on and off. That&#039;s all. So the sound can flow from very left side, center and very right side. No sound panning, no special stereo effects. :-(&lt;br /&gt;
&lt;br /&gt;
Well, flaming apart, back to the main topic.&lt;br /&gt;
&lt;br /&gt;
The OPL3 chip is capable of making sounds in several ways:&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Additive Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output of both operators is simply added. It is the simplest way to make any sound, and it works on both OPL2 and OPL3. The diagram should make it clear.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐&lt;br /&gt;
	│            │&lt;br /&gt;
	│ Operator 1 ├────────┐&lt;br /&gt;
	│            │        │&lt;br /&gt;
	└────────────┘        │&lt;br /&gt;
			      ├────────&amp;gt; Output&lt;br /&gt;
	┌────────────┐        │&lt;br /&gt;
	│            │        │&lt;br /&gt;
	│ Operator 2 ├────────┘&lt;br /&gt;
	│            │&lt;br /&gt;
	└────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Frequency Modulation (FM) Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output from the first operator (Modulator) is sent to the input of the second one (Carrier) and is used to modulate (alter) frequency of the second operator. Only the second operator produces sound. Most of interesting sounds are made this way. This also works on OPL2. Hope the picture helps.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐         ┌────────────┐&lt;br /&gt;
	│            │         │            │&lt;br /&gt;
	│ Operator 1 ├────────&amp;gt;│ Operator 2 ├────────&amp;gt; Output&lt;br /&gt;
	│(Modulator) │         │ (Carrier)  │&lt;br /&gt;
	└────────────┘         └────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Four-operator &amp;quot;Mess&amp;quot; Modulation Synthesis ===&lt;br /&gt;
&lt;br /&gt;
All of OPL3&#039;s 4-OP configurations are combinations of the above two modes of synthesis. OPL3 combines these two modes in four ways. I have no words to describe these four ways. Only the pictures can show their principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   a) FM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   b) AM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├───────────────────────────────────┐&lt;br /&gt;
	│       │                                   │&lt;br /&gt;
	└───────┘                                   │&lt;br /&gt;
						    │&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┴─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   c) FM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────┐&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     ├─────&amp;gt; Output&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┘&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	└───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   d) AM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├────────────────────┐&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	└───────┘                    │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────┼─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐                    │&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	│ Op. 4 ├────────────────────┘&lt;br /&gt;
	│       │&lt;br /&gt;
	└───────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Nice, aren&#039;t they?&lt;br /&gt;
&lt;br /&gt;
The only way I think this can be written is a math formula. Symbol + (plus) means additive synthesis, and * (asterisk) means frequency modulation (Op1 * Op2 means operator 1 modulates operator 2, not vice versa). Here they are:&lt;br /&gt;
&lt;br /&gt;
# FM-FM Mode:	 (Op1 * Op2 * Op3 * Op4) ────&amp;gt; Output&lt;br /&gt;
# AM-FM Mode:	  Op1 + (Op2 * Op3 * Op4) ───&amp;gt; Output&lt;br /&gt;
# FM-AM Mode:	 (Op1 * Op2) + (Op3 * Op4) ──&amp;gt; Output&lt;br /&gt;
# AM-AM Mode:	  Op1 + (Op2 * Op3) + Op4 ───&amp;gt; Output&lt;br /&gt;
&lt;br /&gt;
=== Percussion Mode ===&lt;br /&gt;
&lt;br /&gt;
In this mode 6 operators are used to produce five different percussion instruments:&lt;br /&gt;
&lt;br /&gt;
* Bass Drum (2 operators)&lt;br /&gt;
* Snare Drum (1 operator)&lt;br /&gt;
* Tom-Tom (1 operator)&lt;br /&gt;
* Cymbal (1 operator)&lt;br /&gt;
* Hi-Hat (1 operator)&lt;br /&gt;
&lt;br /&gt;
Because these instruments occupy only three melodic channels, only Bass Drum, Snare Drum and Tom-Tom frequencies can be set. Cymbal and Hi-Hat frequencies are fixed.  {{TODO|It seems it&#039;s actually the cymbal and snare frequencies that are fixed, try to confirm this -- [[User:Malvineous|Malvineous]] 13:34, 3 June 2012 (GMT)}}&lt;br /&gt;
&lt;br /&gt;
This mode is identical with that of OPL2. For more details see ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
== Programming the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
OPL3 may be found at the following addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| Sound Blaster Pro II || 220h or 240h (selectable), also 388h&lt;br /&gt;
|-&lt;br /&gt;
| Adlib Gold || 388h&lt;br /&gt;
|-&lt;br /&gt;
| Pro Audio Spectrum Plus/16 || ? (if you have a PAS you should know it)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The base address of the synthesizer will be called &amp;quot;base&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The chip occupies four I/O addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| base+0 || Primary index register (write), Status register (read)&lt;br /&gt;
|-&lt;br /&gt;
| base+1 || Primary data register (write-only)&lt;br /&gt;
|-&lt;br /&gt;
| base+2 || Secondary index register (write)&lt;br /&gt;
|-&lt;br /&gt;
| base+3 || Secondary data register (write-only)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The index registers are used to select internal registers and data registers are used to write to them. Status register returns the state of two timers built in the chip.&lt;br /&gt;
&lt;br /&gt;
OPL3 contains two sets of registers. The Primary set maps to channels 0-8 (operators 0-17) and the secondary maps to channels 9-17 (operators 18-35). The reason for this is simple: all these registers wouldn&#039;t fit into single register set.&lt;br /&gt;
&lt;br /&gt;
Unlike Adlib (OPL2), OPL3 doesn&#039;t need delay between register writes. With OPL2 you had to wait 3.3 µs after index register write and another 23 µs after data register write. On the contrary OPL3 doesn&#039;t need (almost) any delay after index register write and only 0.28 µs after data register write. This means you can neglect the delays and slightly speed up your music driver. But using reasonable delays will certainly do no harm.&lt;br /&gt;
&lt;br /&gt;
The data registers can&#039;t be read (they are write-only) on both OPL2 and OPL3.&lt;br /&gt;
&lt;br /&gt;
== Register Map ==&lt;br /&gt;
&lt;br /&gt;
The registers are grouped in the same manner as in the OPL2 chip. Programs using both OPL2 and OPL3 chips may use the same code provided that their direct I/O interface is well written. The only thing you have to change is operator-to-register mapping, which must accomodate the fact that registers are spread between two register sets.&lt;br /&gt;
&lt;br /&gt;
(The register map is nearly the same so I dared to copy it from ADLIB.DOC.)&lt;br /&gt;
&lt;br /&gt;
=== Status Register (base+0) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
!    D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQFlag || T1Flag || T2Flag ||        ||        ||        ||        ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Data Registers (base+1, base+3) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! REG   !!   D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| 01    ||colspan=2| Test Register ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|(WSEnable)||colspan=5| Test Register&lt;br /&gt;
|-&lt;br /&gt;
| 02    ||colspan=8| Timer 1 Count (80 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 03    ||colspan=8| Timer 2 Count (320 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 04*   ||IRQReset|| T1Mask || T2Mask ||colspan=3|                  ||T2 Start||T1 Start&lt;br /&gt;
|-&lt;br /&gt;
| 04**  ||colspan=2|        ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP B-E||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP A-D||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 9-C||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 2-5||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 1-4||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 0-3&lt;br /&gt;
|-&lt;br /&gt;
| 05**  ||colspan=7|                                                           ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;| OPL3&lt;br /&gt;
|-&lt;br /&gt;
| 08    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;| (CSW)  ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|NOTE-SEL||colspan=6|&lt;br /&gt;
|-&lt;br /&gt;
| 20-35 ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Tremolo ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Vibrato ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Sustain ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|  KSR   ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Frequency Multiplication Factor&lt;br /&gt;
|-&lt;br /&gt;
| 40-55 ||colspan=2 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Key Scale Level ||colspan=6 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 60-75 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Attack Rate ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 80-95 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Sustain Level ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A0-A8 ||colspan=8 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Frequency Number  (Lower 8 bits)&lt;br /&gt;
|-&lt;br /&gt;
| B0-B8 ||colspan=2|        ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| KEY-ON ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Block Number ||colspan=2 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| F-Num (hi bits)&lt;br /&gt;
|-&lt;br /&gt;
| BD    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Trem Dep||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Vibr Dep||style=&amp;quot;background-color: #FFCCDD;&amp;quot;|PercMode||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| BD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| SD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| TT On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| CY On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| HH On&lt;br /&gt;
|-&lt;br /&gt;
| C0-C8 ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| OutCh_D ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| OutCh_C ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Right  ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Left   ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;|FeedBack Modulation Factor||style=&amp;quot;background-color: #FFE0CC;&amp;quot;|SynthTyp&lt;br /&gt;
|-&lt;br /&gt;
| E0-F5 ||colspan=5|                                      ||colspan=3 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|style=&amp;quot;background-color: #CCFFCC;&amp;quot;| Chip-wide setting&lt;br /&gt;
|style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Per operator&lt;br /&gt;
|style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Per channel&lt;br /&gt;
|style=&amp;quot;background-color: #FFCCDD;&amp;quot;| Rhythm-mode only&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt; This applies only to port base+1&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;**&amp;lt;/nowiki&amp;gt; This applies only to port base+3&lt;br /&gt;
&lt;br /&gt;
For register bases A0, B0 and C0 there is one register per output channel. The primary register set holds the first nine channels (0-8) and the secondary holds last nine channels (9-17). For bases 20, 40, 60, 80 and E0 there are two registers per channel. Each register maps to one operator. Unfortunately the operator&#039;s register numbers are not continuous. The following table shows which operator maps to which register set and offset (in hex).&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Op. !! Set/Offset !! Op. !! Set/Offset&lt;br /&gt;
|-&lt;br /&gt;
| 0  || 0/00 || 18 || 1/00&lt;br /&gt;
|-&lt;br /&gt;
| 1  || 0/01 || 19 || 1/01&lt;br /&gt;
|-&lt;br /&gt;
| 2  || 0/02 || 20 || 1/02&lt;br /&gt;
|-&lt;br /&gt;
| 3  || 0/03 || 21 || 1/03&lt;br /&gt;
|-&lt;br /&gt;
| 4  || 0/04 || 22 || 1/04&lt;br /&gt;
|-&lt;br /&gt;
| 5  || 0/05 || 23 || 1/05&lt;br /&gt;
|-&lt;br /&gt;
| 6  || 0/08 || 24 || 1/08&lt;br /&gt;
|-&lt;br /&gt;
| 7  || 0/09 || 25 || 1/09&lt;br /&gt;
|-&lt;br /&gt;
| 8  || 0/0A || 26 || 1/0A&lt;br /&gt;
|-&lt;br /&gt;
| 9  || 0/0B || 27 || 1/0B&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 0/0C || 28 || 1/0C&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 0/0D || 29 || 1/0D&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 0/10 || 30 || 1/10&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 0/11 || 31 || 1/11&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 0/12 || 32 || 1/12&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 0/13 || 33 || 1/13&lt;br /&gt;
|-&lt;br /&gt;
| 16 || 0/14 || 34 || 1/14&lt;br /&gt;
|-&lt;br /&gt;
| 17 || 0/15 || 35 || 1/15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following tables summarize which operators form a channel in various modes:&lt;br /&gt;
&lt;br /&gt;
1. Two-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel    !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 13 || 14 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 || 16 || 17 || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
2. Two-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 ||colspan=4| - || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
3. Four-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 13 || 14 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 || 16 || 17 || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=3| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=3| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Channels 3, 4, 5 and 12, 13, 14 can&#039;t be used separately because their operators became part of channels 0, 1, 2 and 9, 10, 11 respectively. For instance a four-operator channel 1 consists of two two-operator channels number 1 and 4. (The second 2-OP channel number is always the first 2-OP channel number plus three.)&lt;br /&gt;
&lt;br /&gt;
OPL3 allows you to enable/disable 4-OP mode separately for any of channels 0, 1, 2, 9, 10 and 11 (see register 104h in the reference below). This means for instance when you switch only channel 2 into 4-OP mode, channels number 0, 1, 3, 4, 6, 7, 8, 9, etc. will be still independent 2-OP channels.&lt;br /&gt;
&lt;br /&gt;
Channels 6, 7, 8 and 15, 16, 17 are always two-operator ones. They can&#039;t be grouped to form four-operator channels.&lt;br /&gt;
&lt;br /&gt;
4. Four-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 ||colspan=4| - || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=5| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=5| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
Two-operator channel #14 consists of operators 26 and 29 which occupy these registers (all are in the secondary register set):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| 12A || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 12D || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 14A || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 14D || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 16A || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 16D || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18A || Operator 1 ||Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18D || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 1A5 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| 1B5 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| 1C5 ||            || FeedBack/Synthesis Type&lt;br /&gt;
|-&lt;br /&gt;
| 1EA || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| 1ED || Operator 2 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Four-operator channel #1 consists of operators 1, 4, 7 and 10. All registers except register 104h are in the primary set:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 104 || bit 1 = 1  || Enable Four-Operator Synthesis in channel #1&lt;br /&gt;
|-&lt;br /&gt;
| 21 || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 24 || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 29 || Operator 3 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 2C || Operator 4 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 41 || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 44 || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 49 || Operator 3 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 4C || Operator 4 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 61 || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 64 || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 69 || Operator 3 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 6C || Operator 4 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 81 || Operator 1 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 84 || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 89 || Operator 3 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 8C || Operator 4 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A1 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| A4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| B1 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| B4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| C1 ||            || FeedBack/Synthesis Type (part 1)&lt;br /&gt;
|-&lt;br /&gt;
| C4 ||            || Synthesis Type (part 2)&lt;br /&gt;
|-&lt;br /&gt;
| E1 || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E4 || Operator 2 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E9 || Operator 3 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| EC || Operator 4 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
NOTE: If a register number is greater than 100h, then it belongs into the secondary register set. (I use this numbering to emphasize the fact that the particular register MUST be written to the secondary set.) See the example code below for details.&lt;br /&gt;
&lt;br /&gt;
== OPL3 Register Reference ==&lt;br /&gt;
&lt;br /&gt;
Because the registers of OPL3 are almost the same as of OPL2, I have copied their descriptions from file ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
=== Status Register ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQ || T1 || T2 ||colspan=5| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ Flag. Set whenever any timer has elapsed.&lt;br /&gt;
* bit 6: Timer 1 Flag. Set every time the preset time in Timer 1 has elapsed.&lt;br /&gt;
* bit 5: Timer 2 Flag. Set every time the preset time in Timer 2 has elapsed.&lt;br /&gt;
&lt;br /&gt;
Timer interrupts are not wired to any IRQ (why??). The timers can be used to detect the OPL2/OPL3 chip (see Appendix B).&lt;br /&gt;
&lt;br /&gt;
=== Data Registers ===&lt;br /&gt;
&lt;br /&gt;
==== 01: Test Register / Waveform Select Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| Test Register&lt;br /&gt;
| (WSE)&lt;br /&gt;
|colspan=5| Test Register&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 7-6: Test Register. Must be reset to zero before any operation.&lt;br /&gt;
* bit 5: Waveform Select Enable. If clear, all channels will use normal sine wave. If set, register E0-F5 (Waveform Select) contents will be used.&lt;br /&gt;
* bits 0-4: Test Register. Must be reset to zero before any operation.&lt;br /&gt;
&lt;br /&gt;
OPL3 does not implement WSE bit, and it should be left clear. In OPL2 mode all four waveforms are always available, and in OPL3 mode all eight waveforms are always available. For compatibility with OPL2, when a program is finished using an OPL3, the waveform select registers should be set to 0, if the next program assumes that by setting WSE bit to 0 the waveform is always sine like on a real OPL2.&lt;br /&gt;
&lt;br /&gt;
==== 02: Timer 1 Count ====&lt;br /&gt;
&lt;br /&gt;
Upward 8 bit counter with a resolution of 80 µsec. If an overflow occurs, the status register bit is set, and the preset value is loaded into the timer again.&lt;br /&gt;
&lt;br /&gt;
==== 03: Timer 2 Count ====&lt;br /&gt;
&lt;br /&gt;
Same as Timer 1, but with a resolution of 320 µsec.&lt;br /&gt;
&lt;br /&gt;
==== 004 (port: base+1): IRQ-Reset / Mask / Start ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Rst&lt;br /&gt;
| T1M&lt;br /&gt;
| T2M&lt;br /&gt;
|colspan=3| -&lt;br /&gt;
| T2S&lt;br /&gt;
| T1S&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ-Reset. Resets timer and IRQ flags in status register. All other bits are ignored when this bit is set.&lt;br /&gt;
* bit 6: Timer 1 Mask. If 1, status register is not affected in overflow.&lt;br /&gt;
* bit 5: Timer 2 Mask. Same as above.&lt;br /&gt;
* bit 1: Timer 2 Start. Timer on/off.&lt;br /&gt;
* bit 0: Timer 1 Start. Same as above.&lt;br /&gt;
&lt;br /&gt;
==== 104 (port: base+3): Four-Operator Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| ChB&lt;br /&gt;
| ChA&lt;br /&gt;
| Ch9&lt;br /&gt;
| Ch2&lt;br /&gt;
| Ch1&lt;br /&gt;
| Ch0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: Enable four-operator synthesis for channel pair 11 - 14 (decimal).&lt;br /&gt;
* bit 4: Same as above for channel pair 10 - 13.&lt;br /&gt;
* bit 3: Same as above for channel pair 9 - 12.&lt;br /&gt;
* bit 2: Same as above for channel pair 2 - 5.&lt;br /&gt;
* bit 1: Same as above for channel pair 1 - 4.&lt;br /&gt;
* bit 0: Same as above for channel pair 0 - 3.&lt;br /&gt;
&lt;br /&gt;
If reset to zero, OPL3 can produce 18 two-operator sounds at a time. If nonzero, OPL3 produces four-operator sound in appropriate channel pair.&lt;br /&gt;
&lt;br /&gt;
==== 105 (port: base+3): OPL3 Mode Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=7| -&lt;br /&gt;
| OPL3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 0: OPL3 Mode Enable. When set, OPL3 extensions (36 operators, 4-OP synthesis, 8 waveforms, stereo output) can be used. When reset, the chip behaves as an ordinary OPL2. This bit is zero by default for compatibility with OPL2.&lt;br /&gt;
&lt;br /&gt;
==== 08: CSW / NOTE-SEL ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| (CSW)&lt;br /&gt;
| N-S&lt;br /&gt;
|colspan=6| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: Composite sine wave mode on/off. All KEY-ON bits must be clear in order to use this mode. The card is unable to create any other sound when in CSW mode. (Unfortunately, I have no info how to use this mode :-&amp;lt; ). The CSW mode is not implemented on an OPL3 and this bit is ignored.&lt;br /&gt;
* bit 6: NOTE-SEL. Controls the split point of the keyboard. When 0, the keyboard split is the second bit from the bit 8 of the F-Number. When 1, the MSb of the F-Number is used. (???)&lt;br /&gt;
&lt;br /&gt;
==== 20-35: Tremolo / Vibrato / Sustain / KSR / Frequency Multiplication Factor ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Sus&lt;br /&gt;
| KSR&lt;br /&gt;
|colspan=4| Multiplication&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude vibrato) on/off.&lt;br /&gt;
* bit 6:    Frequency vibrato on/off.&lt;br /&gt;
* bit 5:    Sound Sustaining. When 1, operator&#039;s output level will be held at its sustain level until a KEY-OFF is done.&lt;br /&gt;
* bit 4:    Envelope scaling (KSR) on/off. When 1, higher notes are shorter than lower notes.&lt;br /&gt;
* bits 0-3: Frequency Multiplication Factor (MULTI). Operator&#039;s frequency is set to (see registers A0, B0) F-Number * Factor.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! MULTI !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0.5&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 2&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 3&lt;br /&gt;
|-&lt;br /&gt;
| 4 || 4&lt;br /&gt;
|-&lt;br /&gt;
| 5 || 5&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 6&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 7&lt;br /&gt;
|-&lt;br /&gt;
| 8 || 8&lt;br /&gt;
|-&lt;br /&gt;
| 9 || 9&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 40-55: Key Scale Level / Output Level ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| KSL&lt;br /&gt;
|colspan=6| Output level&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 6-7: Key Scale Level. Attenuates output level towards higher pitch:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! KSL !! Attenuation&lt;br /&gt;
|-&lt;br /&gt;
| 0 || -&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 3.0 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 1.5 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 6.0 dB/oct&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The attenuation level is based on the 3-bit octave (block number) value and top four bits of the FNUM value, so each octave is subdivided into 16 parts.&lt;br /&gt;
&lt;br /&gt;
* bits 0-5: Output Level. Attenuates the operator output level. 0 is the loudest, 3F is the softest. Attenuation range is 48dB with 0.75dB resolution.&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| 24dB || 12dB || 6dB || 3dB || 1.5dB || 0.75dB&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* In additive synthesis, varying the output level of any operator varies the volume of its corresponding channel. In FM synthesis, varying the output level of the carrier varies the volume of the channel. Varying the output of the modulator will change the frequency spectrum produced by the carrier. The following table summarizes which operators&#039; output levels should be updated when trying to change channel output level.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Mode !! Op 1 !! Op 2 !! Op 3 !! Op 4&lt;br /&gt;
|-&lt;br /&gt;
| AM    || Y || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM    || - || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM-FM || - || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-FM || Y || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| FM-AM || - || Y || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-AM || Y || - || Y   || Y&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 60-75: Attack Rate / Decay Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Attack rate&lt;br /&gt;
|colspan=4| Decay rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Attack Rate. Determines the rising time for the sound. The higher the value, the faster the attack.&lt;br /&gt;
* bits 0-3: Decay Rate. Determines the diminishing time for the sound. The higher the value, the shorter the decay.&lt;br /&gt;
&lt;br /&gt;
==== 80-95: Sustain Level / Release Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Sustain level&lt;br /&gt;
|colspan=4| Release rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Sustain Level. Determines the point at which the sound ceases to decay and chages to a sound having a constant level. The sustain level is expressed as a fraction of the maximum level. 0 is the softest and F is the loudest sustain level. Note that the Sustain-bit in the register 20-35 must be set for this to have an effect.&lt;br /&gt;
* bits 0-3: Release Rate. Determines the rate at which the sound disappears after KEY-OFF. The higher the value, the shorter the release.&lt;br /&gt;
&lt;br /&gt;
==== A0-A8: Frequency Number ====&lt;br /&gt;
&lt;br /&gt;
Determines the pitch of the note. Highest bits of F-Number are stored in the register below.&lt;br /&gt;
&lt;br /&gt;
==== B0-B8: Key On / Block Number / F-Number(hi bits) ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| KEY&lt;br /&gt;
|colspan=3| Block num.&lt;br /&gt;
|colspan=2| Freq&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: KEY-ON. When 1, channel output is enabled.&lt;br /&gt;
* bits 2-4: Block Number. Roughly determines the octave.&lt;br /&gt;
* bits 0-1: Frequency Number. 2 highest bits of the above register.  The following formula is used to determine F-Number and Block:&lt;br /&gt;
: F-Number = Music Frequency * 2^(20-Block) / 49716 Hz&lt;br /&gt;
&lt;br /&gt;
NOTE: In four-operator mode only the register value of Operators 1 and 2 is used, value of Operators 3 and 4 in this register is ignored. In other words: one channel uses only one frequency, block and KEY-ON value at a time, regardless whether it is a two- or four-operator channel.&lt;br /&gt;
&lt;br /&gt;
==== BD: Tremolo Depth / Vibrato Depth / Percussion Mode / BD/SD/TT/CY/HH On ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Per&lt;br /&gt;
| BD&lt;br /&gt;
| SD&lt;br /&gt;
| TT&lt;br /&gt;
| CY&lt;br /&gt;
| HH&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude Vibrato) Depth. 0 = 1.0dB, 1 = 4.8dB.&lt;br /&gt;
* bit 6:    Frequency Vibrato Depth. 0 = 7 cents, 1 = 14 cents. A &amp;quot;cent&amp;quot; is 1/100 of a semi-tone.&lt;br /&gt;
* bit 5:    Percussion Mode. 0 = Melodic Mode, 1 = Percussion Mode.&lt;br /&gt;
* bit 4:    BD On. KEY-ON of the Bass Drum channel.&lt;br /&gt;
* bit 3:    SD On. KEY-ON of the Snare Drum channel.&lt;br /&gt;
* bit 2:    TT On. KEY-ON of the Tom-Tom channel.&lt;br /&gt;
* bit 1:    CY On. KEY-ON of the Cymbal channel.&lt;br /&gt;
* bit 0:    HH On. KEY-ON of the Hi-Hat channel.&lt;br /&gt;
&lt;br /&gt;
NOTE: KEY-ON bits of channels 6, 7 and 8 must be clear and their F-Nums, Attack/Decay/Release rates, etc. must be set properly to use percussion mode.&lt;br /&gt;
&lt;br /&gt;
==== C0-C8: FeedBack Modulation Factor / Synthesis Type ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| OutCh_D&lt;br /&gt;
| OutCh_C&lt;br /&gt;
| R&lt;br /&gt;
| L&lt;br /&gt;
|colspan=3| Feedback&lt;br /&gt;
| Syn&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: CHD, Output Channel D Enable. When set, channel output goes to fourth digital audio output channel.&lt;br /&gt;
* bit 6: CHC, Output Channel C Enable. When set, channel output goes to third digital audio output channel.&lt;br /&gt;
* bit 5:    Right Speaker Enable. When set, channel output goes to second digital audio output channel, connected to right speaker.&lt;br /&gt;
* bit 4:    Left Speaker Enable. When set, channel output goes to first digital audio output channel, connected to left speaker.&lt;br /&gt;
** In OPL3 mode, at least one of the left/right bits must be set to hear the channel.&lt;br /&gt;
** In OPL2 mode, these bits are ignored and audio is sent to all channels for compatibility reasons.&lt;br /&gt;
** Left/Right bits can be used to realize sound &amp;quot;panning&amp;quot;, but this method offers only three pan positions (left/center/right).&lt;br /&gt;
** These bits apply only to operators producing sound (Carriers). Modulators are not affected by their setting.&lt;br /&gt;
** Sound cards use only one stereo DAC, so only two of the four digital output channels are available.&lt;br /&gt;
* bits 1-3: FeedBack Modulation Factor. If 0, no feedback is present. If 1-7, operator 1 will send a portion of its output back into itself.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! FeedBack !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;amp;pi;/16&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;amp;pi;/8&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;amp;pi;/4&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;amp;pi;/2&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 2&amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 4&amp;amp;pi;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
When in four-operator mode, the FeedBack value is used only by Operator 1, value of Operators 2, 3 and 4 is ignored.&lt;br /&gt;
&lt;br /&gt;
* bit 0: Synthesis Type. 1 = Additive synthesis, 0 = Frequency Modulation.  In four-operator mode, there are two bits controlling the synthesis type. Both are the bit 0 of register C0, one of Operators 1 and 2 and the second of Operators 3 and 4.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Op 1&amp;amp;2 !! Op 3&amp;amp;4 !! Type&lt;br /&gt;
|-&lt;br /&gt;
| 0 || NONE || FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || NONE || AM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || FM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || AM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || FM-AM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || AM-AM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== E0-F5: Waveform Select ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=5| -&lt;br /&gt;
|colspan=3| Waveform&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 0-2: WaveForm Select (WS): &amp;lt;gallery widths=261px perrow=4&amp;gt;&lt;br /&gt;
Image:OPL_Wave0.png|Waveform 0: Sine&lt;br /&gt;
Image:OPL_Wave1.png|Waveform 1: Half-sine&lt;br /&gt;
Image:OPL_Wave2.png|Waveform 2: Abs-sine&lt;br /&gt;
Image:OPL_Wave3.png|Waveform 3: Pulse-sine&lt;br /&gt;
Image:OPL_Wave4.png|Waveform 4: Sine - even periods only&lt;br /&gt;
Image:OPL_Wave5.png|Waveform 5: Abs-sine - even periods only&lt;br /&gt;
Image:OPL_Wave6.png|Waveform 6: Square&lt;br /&gt;
Image:OPL_Wave7.png|Waveform 7: Derived square&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* NOTE: Bit 5 of register 01 must be set to use waveforms other than sine. Waveforms 4-7 are available only on OPL3. See files WAVEn.GIF for real waveforms, where n is a number between 0 and 7.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
These examples show a few working routines used in my MUS Player. They are written in Borland C++ 3.1 but should be easy to translate to any other language.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
// I prefer using these Assembler-like types&lt;br /&gt;
typedef unsigned int  WORD;&lt;br /&gt;
typedef unsigned char BYTE;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * FM Synthesizer base port. SB Pro II - 0x220, Adlib 0x388&lt;br /&gt;
 */&lt;br /&gt;
WORD FMport = 0x220;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Enables OPL3 extensions.&lt;br /&gt;
 */&lt;br /&gt;
WORD OPL3 = 1;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Direct write to any Adlib/SB Pro II FM synthetiser register.&lt;br /&gt;
 *   reg - register number (range 0x001-0x0F5 and 0x101-0x1F5). When high byte&lt;br /&gt;
 *         of reg is zero, data go to port FMport, otherwise to FMport+2&lt;br /&gt;
 *   data - register value to be written&lt;br /&gt;
 */&lt;br /&gt;
BYTE FMwriteReg(WORD reg, BYTE data)&lt;br /&gt;
{&lt;br /&gt;
    asm {&lt;br /&gt;
	mov	dx,FMport&lt;br /&gt;
	mov	ax,reg&lt;br /&gt;
	or	ah,ah		// high byte is nonzero -- write to port base+2&lt;br /&gt;
	jz	out1&lt;br /&gt;
	inc	dx&lt;br /&gt;
	inc	dx&lt;br /&gt;
    }&lt;br /&gt;
out1: asm {&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	mov	cx,6&lt;br /&gt;
    }&lt;br /&gt;
loop1:asm {			// delay between writes&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop1&lt;br /&gt;
&lt;br /&gt;
	inc	dx&lt;br /&gt;
	mov	al,data&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	dec	dx&lt;br /&gt;
	mov	cx,36&lt;br /&gt;
    }&lt;br /&gt;
loop2:asm {			// delay after data write&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop2&lt;br /&gt;
    }&lt;br /&gt;
    return _AL;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to an operator pair. To be used for register bases of 0x20, 0x40,&lt;br /&gt;
 * 0x60, 0x80 and 0xE0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteChannel(BYTE regbase, BYTE channel, BYTE data1, BYTE data2)&lt;br /&gt;
{&lt;br /&gt;
    static BYTE adlib_op[] = {0, 1, 2, 8, 9, 10, 16, 17, 18};&lt;br /&gt;
    static BYTE sbpro_op[] = { 0,  1,  2,   6,  7,  8,  12, 13, 14,&lt;br /&gt;
			      18, 19, 20,  24, 25, 26,  30, 31, 32};&lt;br /&gt;
    static WORD rg[] = {0x000,0x001,0x002,0x003,0x004,0x005,&lt;br /&gt;
			0x008,0x009,0x00A,0x00B,0x00C,0x00D,&lt;br /&gt;
			0x010,0x011,0x012,0x013,0x014,0x015,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,&lt;br /&gt;
			0x108,0x109,0x10A,0x10B,0x10C,0x10D,&lt;br /&gt;
			0x110,0x111,0x112,0x113,0x114,0x115};&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
    {&lt;br /&gt;
	register WORD reg = sbpro_op[channel];&lt;br /&gt;
	FMwriteReg(rg[reg]+regbase, data1);&lt;br /&gt;
	FMwriteReg(rg[reg+3]+regbase, data2);&lt;br /&gt;
    } else {&lt;br /&gt;
	register WORD reg = regbase+adlib_op[channel];&lt;br /&gt;
	FMwriteReg(reg, data1);&lt;br /&gt;
	FMwriteReg(reg+3, data2);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to channel a single value. To be used for register bases of&lt;br /&gt;
 * 0xA0, 0xB0 and 0xC0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteValue(BYTE regbase, BYTE channel, BYTE value)&lt;br /&gt;
{&lt;br /&gt;
    static WORD ch[] = {0x000,0x001,0x002,0x003,0x004,0x005,0x006,0x007,0x008,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,0x106,0x107,0x108};&lt;br /&gt;
    register WORD chan;&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
	chan = ch[channel];&lt;br /&gt;
    else&lt;br /&gt;
	chan = channel;&lt;br /&gt;
    FMwriteReg(regbase + chan, value);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Detection Methods ==&lt;br /&gt;
&lt;br /&gt;
An official method of Adlib (OPL2) detection is:&lt;br /&gt;
&lt;br /&gt;
# Reset Timer 1 and Timer 2: write 60h to register 4.&lt;br /&gt;
# Reset the IRQ: write 80h to register 4.&lt;br /&gt;
#* NOTE: Steps 1 and 2 can&#039;t be combined together.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Set Timer 1 to FFh: write FFh to register 2.&lt;br /&gt;
# Unmask and start Timer 1: write 21h to register 4.&lt;br /&gt;
# Wait in a delay loop for at least 80 µsec.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Reset Timer 1, Timer 2 and IRQ as in steps 1 and 2.&lt;br /&gt;
# Test the results of the two reads: the first should be 0, the second should be C0h. If either is incorrect, then the OPL2 is not present.&lt;br /&gt;
&lt;br /&gt;
* NOTE1: You should AND the result bytes with E0h because the unused bits are undefined.&lt;br /&gt;
* NOTE2: This testing method doesn&#039;t work in some SoundBlaster compatible cards.&lt;br /&gt;
&lt;br /&gt;
=== OPL3 Detection ===&lt;br /&gt;
--------------&lt;br /&gt;
&lt;br /&gt;
# Detect OPL2. If present, continue.&lt;br /&gt;
# Read status register: read port base+0.&lt;br /&gt;
# AND the result with 06h.&lt;br /&gt;
# If the result is zero, you have OPL3, otherwise OPL2.&lt;br /&gt;
&lt;br /&gt;
* NOTE: This is NOT an official method. I have dug it out of a sound driver. I haven&#039;t tested it, because I haven&#039;t an OPL2 card (Adlib, SB Pro I). Nevertheless it &amp;quot;detects&amp;quot; my SB Pro II properly. ;-)&lt;br /&gt;
&lt;br /&gt;
Another possible detection method for distinguishing between SB Pro I and SB Pro II would be to try to detect OPL2 at I/O port base+0 and then at port base+2. The first test should succeed and the second should fail if OPL3 is present. (Remember: SB Pro I contains twin OPL2 chips at addresses base+0 and base+2, while SB Pro II contains one OPL3 chip at I/O address base+0 thru base+3).&lt;br /&gt;
&lt;br /&gt;
== BLASTER Environment Variable ==&lt;br /&gt;
&lt;br /&gt;
Perhaps the most recommended &amp;quot;detection&amp;quot; method. Reading this variable avoids blindfold I/O port scanning and possible device conflicts. The user is responsible for its proper setting.&lt;br /&gt;
&lt;br /&gt;
The variable has this format:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=Aaddr Iirq Ddma Ttype&lt;br /&gt;
&lt;br /&gt;
* A: Base I/O address given in hex. For most Sound Blasters the default is 220.&lt;br /&gt;
* I: IRQ Number (decimal). Default 7.&lt;br /&gt;
* D: DMA Number (decimal). Default 1.&lt;br /&gt;
* T: Card Type (decimal):&lt;br /&gt;
** 1 - Sound Blaster 1.5&lt;br /&gt;
** 2 - Sound Blaster Pro I&lt;br /&gt;
** 3 - Sound Blaster 2.0&lt;br /&gt;
** 4 - Sound Blaster Pro II&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=A220 I7 D1 T4&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The PC Games Programmers Encyclopedia&#039;&#039;, Mark Feldman and many others on Usenet and Internet, ftp://teeri.oulu.fi/pub/msdos/programming/gpe&lt;br /&gt;
: ... you can find (almost) everything you need there&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Sound Blaster - The Official Book&#039;&#039;, Richard Heimlich, David M. Golden, Ivan Luk, Peter M. Ridge, Osborne/McGraw Hill, ISBN 0-07-881907-5&lt;br /&gt;
: ... this is a number-one in my book-wishlist. If anyone wanted to get rid of the book, I wouldn&#039;t scorn it ... :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The SoundBlaster Developer Kit&#039;&#039;, Creative Labs Inc, Creative Technology PTE LTD&lt;br /&gt;
: ... I wonder if you can find something comprehensible in that.&lt;/div&gt;</summary>
		<author><name>Kermes</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4324</id>
		<title>OPL chip</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4324"/>
		<updated>2012-08-03T19:59:26Z</updated>

		<summary type="html">&lt;p&gt;Kermes: /* C0-C8: FeedBack Modulation Factor / Synthesis Type */ Added rest of channel output selection bits and explanation.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Programmer&#039;s Guide to Yamaha YMF 262/OPL3 FM Music Synthesizer =&lt;br /&gt;
Version 1.00  Nov-24-1994&lt;br /&gt;
&lt;br /&gt;
Written by Vladimir Arnost, QA-Software&lt;br /&gt;
Internet:  xarnos00@dcse.fee.vutbr.cz&lt;br /&gt;
&lt;br /&gt;
This manual can be distributed freely if not modified.&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer ===&lt;br /&gt;
&lt;br /&gt;
I assume no responsibility for any damages arising out of use or inability to use this text. No warranty is provided about correctness of any information in this file. You are on your own.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The chip I am going to describe is getting more and more common, but programming information is still scarce, so I have decided to fill in this gap. All information contained in this file is a result of my experience in Adlib programming, research (read: reverse engineering) and finally of my effort to write down everything necessary to understand and use this piece of hardware. No official sources (i.e. development kits, books about this topic, etc.) were available to me except:&lt;br /&gt;
&lt;br /&gt;
: Adlib Programming Guide - by Tero Töttö, and&lt;br /&gt;
: The PC Games Programmers Encyclopedia V1.0&lt;br /&gt;
&lt;br /&gt;
The information below is a combination of known features of Adlib (alias Yamaha YM 3812/OPL2) and my own uncountable experiments and failures, which brought out a lot of important details you have to know about the chip.&lt;br /&gt;
&lt;br /&gt;
As far as I know, there are four major sound cards based on OPL3 chip:&lt;br /&gt;
&lt;br /&gt;
* Sound Blaster Pro II (not Sound Blaster Pro I)&lt;br /&gt;
* Sound Blaster 16&lt;br /&gt;
* Adlib Gold&lt;br /&gt;
* Pro Audio Spectrum Plus/16&lt;br /&gt;
&lt;br /&gt;
I currently have a Sound Blaster Pro II-compatible card only, so all the programming info I provide will be based on this card. (The other cards are quite similar, however. They are just wired at different I/O-port addresses.)&lt;br /&gt;
&lt;br /&gt;
Note: I assume some knowledge of FM music programming (mainly Adlib FM synthesizer) in this manual. If you are new to this topic I recommend you try Adlib first before going higher. Anyway, OPL3 is a direct descendant of OPL2 (what a surprise), so most features of OPL2 are also present on OPL3.&lt;br /&gt;
&lt;br /&gt;
== Description of the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
My card&#039;s user manual says: &amp;quot;[this card contains] ... a stereo music FM synthesizer with 20 channels consisting of four (4) operators each ... &amp;quot; I thought: &amp;quot;Wow -- that&#039;s together eighty operators. This must be a GOOD sound-card.&amp;quot; I was wrong. Just another advertising lie.&lt;br /&gt;
&lt;br /&gt;
So let&#039;s clear some facts. First, OPL3 has only thirty-six (36) operators which can be combined in several ways:&lt;br /&gt;
&lt;br /&gt;
* 18 FM channels (36 operators), or&lt;br /&gt;
* 15 FM channels (30 ops) and 5 percussion instruments (6 ops), giving us 20 channels altogether, or&lt;br /&gt;
* up to 6 four-operator FM channels (max 24 ops), the rest again being divided into two-operator FM channels and drums.&lt;br /&gt;
&lt;br /&gt;
From the table above you can see that not all channels can be used in four-operator (4-OP) mode -- only a part of the synthesizer is really capable of making 4-OP sounds -- the rest uses traditional two-operator (2-OP) mode.&lt;br /&gt;
&lt;br /&gt;
Second, the manual states this card is capable of &amp;quot;stereo&amp;quot; music. Yes, the quotes are necessary, because the stereo capabilities are very limited. You are given ability to control output going to left or right channel by turning it on and off. That&#039;s all. So the sound can flow from very left side, center and very right side. No sound panning, no special stereo effects. :-(&lt;br /&gt;
&lt;br /&gt;
Well, flaming apart, back to the main topic.&lt;br /&gt;
&lt;br /&gt;
The OPL3 chip is capable of making sounds in several ways:&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Additive Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output of both operators is simply added. It is the simplest way to make any sound, and it works on both OPL2 and OPL3. The diagram should make it clear.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐&lt;br /&gt;
	│            │&lt;br /&gt;
	│ Operator 1 ├────────┐&lt;br /&gt;
	│            │        │&lt;br /&gt;
	└────────────┘        │&lt;br /&gt;
			      ├────────&amp;gt; Output&lt;br /&gt;
	┌────────────┐        │&lt;br /&gt;
	│            │        │&lt;br /&gt;
	│ Operator 2 ├────────┘&lt;br /&gt;
	│            │&lt;br /&gt;
	└────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Frequency Modulation (FM) Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output from the first operator (Modulator) is sent to the input of the second one (Carrier) and is used to modulate (alter) frequency of the second operator. Only the second operator produces sound. Most of interesting sounds are made this way. This also works on OPL2. Hope the picture helps.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐         ┌────────────┐&lt;br /&gt;
	│            │         │            │&lt;br /&gt;
	│ Operator 1 ├────────&amp;gt;│ Operator 2 ├────────&amp;gt; Output&lt;br /&gt;
	│(Modulator) │         │ (Carrier)  │&lt;br /&gt;
	└────────────┘         └────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Four-operator &amp;quot;Mess&amp;quot; Modulation Synthesis ===&lt;br /&gt;
&lt;br /&gt;
All of OPL3&#039;s 4-OP configurations are combinations of the above two modes of synthesis. OPL3 combines these two modes in four ways. I have no words to describe these four ways. Only the pictures can show their principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   a) FM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   b) AM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├───────────────────────────────────┐&lt;br /&gt;
	│       │                                   │&lt;br /&gt;
	└───────┘                                   │&lt;br /&gt;
						    │&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┴─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   c) FM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────┐&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     ├─────&amp;gt; Output&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┘&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	└───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   d) AM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├────────────────────┐&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	└───────┘                    │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────┼─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐                    │&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	│ Op. 4 ├────────────────────┘&lt;br /&gt;
	│       │&lt;br /&gt;
	└───────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Nice, aren&#039;t they?&lt;br /&gt;
&lt;br /&gt;
The only way I think this can be written is a math formula. Symbol + (plus) means additive synthesis, and * (asterisk) means frequency modulation (Op1 * Op2 means operator 1 modulates operator 2, not vice versa). Here they are:&lt;br /&gt;
&lt;br /&gt;
# FM-FM Mode:	 (Op1 * Op2 * Op3 * Op4) ────&amp;gt; Output&lt;br /&gt;
# AM-FM Mode:	  Op1 + (Op2 * Op3 * Op4) ───&amp;gt; Output&lt;br /&gt;
# FM-AM Mode:	 (Op1 * Op2) + (Op3 * Op4) ──&amp;gt; Output&lt;br /&gt;
# AM-AM Mode:	  Op1 + (Op2 * Op3) + Op4 ───&amp;gt; Output&lt;br /&gt;
&lt;br /&gt;
=== Percussion Mode ===&lt;br /&gt;
&lt;br /&gt;
In this mode 6 operators are used to produce five different percussion instruments:&lt;br /&gt;
&lt;br /&gt;
* Bass Drum (2 operators)&lt;br /&gt;
* Snare Drum (1 operator)&lt;br /&gt;
* Tom-Tom (1 operator)&lt;br /&gt;
* Cymbal (1 operator)&lt;br /&gt;
* Hi-Hat (1 operator)&lt;br /&gt;
&lt;br /&gt;
Because these instruments occupy only three melodic channels, only Bass Drum, Snare Drum and Tom-Tom frequencies can be set. Cymbal and Hi-Hat frequencies are fixed.  {{TODO|It seems it&#039;s actually the cymbal and snare frequencies that are fixed, try to confirm this -- [[User:Malvineous|Malvineous]] 13:34, 3 June 2012 (GMT)}}&lt;br /&gt;
&lt;br /&gt;
This mode is identical with that of OPL2. For more details see ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
== Programming the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
OPL3 may be found at the following addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| Sound Blaster Pro II || 220h or 240h (selectable), also 388h&lt;br /&gt;
|-&lt;br /&gt;
| Adlib Gold || 388h&lt;br /&gt;
|-&lt;br /&gt;
| Pro Audio Spectrum Plus/16 || ? (if you have a PAS you should know it)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The base address of the synthesizer will be called &amp;quot;base&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The chip occupies four I/O addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| base+0 || Primary index register (write), Status register (read)&lt;br /&gt;
|-&lt;br /&gt;
| base+1 || Primary data register (write-only)&lt;br /&gt;
|-&lt;br /&gt;
| base+2 || Secondary index register (write)&lt;br /&gt;
|-&lt;br /&gt;
| base+3 || Secondary data register (write-only)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The index registers are used to select internal registers and data registers are used to write to them. Status register returns the state of two timers built in the chip.&lt;br /&gt;
&lt;br /&gt;
OPL3 contains two sets of registers. The Primary set maps to channels 0-8 (operators 0-17) and the secondary maps to channels 9-17 (operators 18-35). The reason for this is simple: all these registers wouldn&#039;t fit into single register set.&lt;br /&gt;
&lt;br /&gt;
Unlike Adlib (OPL2), OPL3 doesn&#039;t need delay between register writes. With OPL2 you had to wait 3.3 µs after index register write and another 23 µs after data register write. On the contrary OPL3 doesn&#039;t need (almost) any delay after index register write and only 0.28 µs after data register write. This means you can neglect the delays and slightly speed up your music driver. But using reasonable delays will certainly do no harm.&lt;br /&gt;
&lt;br /&gt;
The data registers can&#039;t be read (they are write-only) on both OPL2 and OPL3.&lt;br /&gt;
&lt;br /&gt;
== Register Map ==&lt;br /&gt;
&lt;br /&gt;
The registers are grouped in the same manner as in the OPL2 chip. Programs using both OPL2 and OPL3 chips may use the same code provided that their direct I/O interface is well written. The only thing you have to change is operator-to-register mapping, which must accomodate the fact that registers are spread between two register sets.&lt;br /&gt;
&lt;br /&gt;
(The register map is nearly the same so I dared to copy it from ADLIB.DOC.)&lt;br /&gt;
&lt;br /&gt;
=== Status Register (base+0) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
!    D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQFlag || T1Flag || T2Flag ||        ||        ||        ||        ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Data Registers (base+1, base+3) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! REG   !!   D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| 01    ||colspan=2| Test Register ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|(WSEnable)||colspan=5| Test Register&lt;br /&gt;
|-&lt;br /&gt;
| 02    ||colspan=8| Timer 1 Count (80 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 03    ||colspan=8| Timer 2 Count (320 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 04*   ||IRQReset|| T1Mask || T2Mask ||colspan=3|                  ||T2 Start||T1 Start&lt;br /&gt;
|-&lt;br /&gt;
| 04**  ||colspan=2|        ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP B-E||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP A-D||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 9-C||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 2-5||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 1-4||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 0-3&lt;br /&gt;
|-&lt;br /&gt;
| 05**  ||colspan=7|                                                           ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;| OPL3&lt;br /&gt;
|-&lt;br /&gt;
| 08    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;| (CSW)  ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|NOTE-SEL||colspan=6|&lt;br /&gt;
|-&lt;br /&gt;
| 20-35 ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Tremolo ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Vibrato ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Sustain ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|  KSR   ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Frequency Multiplication Factor&lt;br /&gt;
|-&lt;br /&gt;
| 40-55 ||colspan=2 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Key Scale Level ||colspan=6 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 60-75 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Attack Rate ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 80-95 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Sustain Level ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A0-A8 ||colspan=8 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Frequency Number  (Lower 8 bits)&lt;br /&gt;
|-&lt;br /&gt;
| B0-B8 ||colspan=2|        ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| KEY-ON ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Block Number ||colspan=2 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| F-Num (hi bits)&lt;br /&gt;
|-&lt;br /&gt;
| BD    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Trem Dep||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Vibr Dep||style=&amp;quot;background-color: #FFCCDD;&amp;quot;|PercMode||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| BD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| SD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| TT On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| CY On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| HH On&lt;br /&gt;
|-&lt;br /&gt;
| C0-C8 ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| OutCh_D ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| OutCh_C ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Right  ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Left   ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;|FeedBack Modulation Factor||style=&amp;quot;background-color: #FFE0CC;&amp;quot;|SynthTyp&lt;br /&gt;
|-&lt;br /&gt;
| E0-F5 ||colspan=5|                                      ||colspan=3 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|style=&amp;quot;background-color: #CCFFCC;&amp;quot;| Chip-wide setting&lt;br /&gt;
|style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Per operator&lt;br /&gt;
|style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Per channel&lt;br /&gt;
|style=&amp;quot;background-color: #FFCCDD;&amp;quot;| Rhythm-mode only&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt; This applies only to port base+1&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;**&amp;lt;/nowiki&amp;gt; This applies only to port base+3&lt;br /&gt;
&lt;br /&gt;
For register bases A0, B0 and C0 there is one register per output channel. The primary register set holds the first nine channels (0-8) and the secondary holds last nine channels (9-17). For bases 20, 40, 60, 80 and E0 there are two registers per channel. Each register maps to one operator. Unfortunately the operator&#039;s register numbers are not continuous. The following table shows which operator maps to which register set and offset (in hex).&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Op. !! Set/Offset !! Op. !! Set/Offset&lt;br /&gt;
|-&lt;br /&gt;
| 0  || 0/00 || 18 || 1/00&lt;br /&gt;
|-&lt;br /&gt;
| 1  || 0/01 || 19 || 1/01&lt;br /&gt;
|-&lt;br /&gt;
| 2  || 0/02 || 20 || 1/02&lt;br /&gt;
|-&lt;br /&gt;
| 3  || 0/03 || 21 || 1/03&lt;br /&gt;
|-&lt;br /&gt;
| 4  || 0/04 || 22 || 1/04&lt;br /&gt;
|-&lt;br /&gt;
| 5  || 0/05 || 23 || 1/05&lt;br /&gt;
|-&lt;br /&gt;
| 6  || 0/08 || 24 || 1/08&lt;br /&gt;
|-&lt;br /&gt;
| 7  || 0/09 || 25 || 1/09&lt;br /&gt;
|-&lt;br /&gt;
| 8  || 0/0A || 26 || 1/0A&lt;br /&gt;
|-&lt;br /&gt;
| 9  || 0/0B || 27 || 1/0B&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 0/0C || 28 || 1/0C&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 0/0D || 29 || 1/0D&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 0/10 || 30 || 1/10&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 0/11 || 31 || 1/11&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 0/12 || 32 || 1/12&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 0/13 || 33 || 1/13&lt;br /&gt;
|-&lt;br /&gt;
| 16 || 0/14 || 34 || 1/14&lt;br /&gt;
|-&lt;br /&gt;
| 17 || 0/15 || 35 || 1/15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following tables summarize which operators form a channel in various modes:&lt;br /&gt;
&lt;br /&gt;
1. Two-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel    !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 13 || 14 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 || 16 || 17 || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
2. Two-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 ||colspan=4| - || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
3. Four-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 13 || 14 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 || 16 || 17 || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=3| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=3| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Channels 3, 4, 5 and 12, 13, 14 can&#039;t be used separately because their operators became part of channels 0, 1, 2 and 9, 10, 11 respectively. For instance a four-operator channel 1 consists of two two-operator channels number 1 and 4. (The second 2-OP channel number is always the first 2-OP channel number plus three.)&lt;br /&gt;
&lt;br /&gt;
OPL3 allows you to enable/disable 4-OP mode separately for any of channels 0, 1, 2, 9, 10 and 11 (see register 104h in the reference below). This means for instance when you switch only channel 2 into 4-OP mode, channels number 0, 1, 3, 4, 6, 7, 8, 9, etc. will be still independent 2-OP channels.&lt;br /&gt;
&lt;br /&gt;
Channels 6, 7, 8 and 15, 16, 17 are always two-operator ones. They can&#039;t be grouped to form four-operator channels.&lt;br /&gt;
&lt;br /&gt;
4. Four-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 ||colspan=4| - || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=5| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=5| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
Two-operator channel #14 consists of operators 26 and 29 which occupy these registers (all are in the secondary register set):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| 12A || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 12D || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 14A || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 14D || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 16A || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 16D || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18A || Operator 1 ||Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18D || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 1A5 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| 1B5 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| 1C5 ||            || FeedBack/Synthesis Type&lt;br /&gt;
|-&lt;br /&gt;
| 1EA || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| 1ED || Operator 2 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Four-operator channel #1 consists of operators 1, 4, 7 and 10. All registers except register 104h are in the primary set:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 104 || bit 1 = 1  || Enable Four-Operator Synthesis in channel #1&lt;br /&gt;
|-&lt;br /&gt;
| 21 || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 24 || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 29 || Operator 3 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 2C || Operator 4 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 41 || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 44 || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 49 || Operator 3 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 4C || Operator 4 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 61 || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 64 || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 69 || Operator 3 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 6C || Operator 4 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 81 || Operator 1 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 84 || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 89 || Operator 3 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 8C || Operator 4 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A1 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| A4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| B1 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| B4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| C1 ||            || FeedBack/Synthesis Type (part 1)&lt;br /&gt;
|-&lt;br /&gt;
| C4 ||            || Synthesis Type (part 2)&lt;br /&gt;
|-&lt;br /&gt;
| E1 || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E4 || Operator 2 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E9 || Operator 3 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| EC || Operator 4 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
NOTE: If a register number is greater than 100h, then it belongs into the secondary register set. (I use this numbering to emphasize the fact that the particular register MUST be written to the secondary set.) See the example code below for details.&lt;br /&gt;
&lt;br /&gt;
== OPL3 Register Reference ==&lt;br /&gt;
&lt;br /&gt;
Because the registers of OPL3 are almost the same as of OPL2, I have copied their descriptions from file ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
=== Status Register ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQ || T1 || T2 ||colspan=5| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ Flag. Set whenever any timer has elapsed.&lt;br /&gt;
* bit 6: Timer 1 Flag. Set every time the preset time in Timer 1 has elapsed.&lt;br /&gt;
* bit 5: Timer 2 Flag. Set every time the preset time in Timer 2 has elapsed.&lt;br /&gt;
&lt;br /&gt;
Timer interrupts are not wired to any IRQ (why??). The timers can be used to detect the OPL2/OPL3 chip (see Appendix B).&lt;br /&gt;
&lt;br /&gt;
=== Data Registers ===&lt;br /&gt;
&lt;br /&gt;
==== 01: Test Register / Waveform Select Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| Test Register&lt;br /&gt;
| (WSE)&lt;br /&gt;
|colspan=5| Test Register&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 7-6: Test Register. Must be reset to zero before any operation.&lt;br /&gt;
* bit 5: Waveform Select Enable. If clear, all channels will use normal sine wave. If set, register E0-F5 (Waveform Select) contents will be used.&lt;br /&gt;
* bits 0-4: Test Register. Must be reset to zero before any operation.&lt;br /&gt;
&lt;br /&gt;
OPL3 does not implement WSE bit, and it should be left clear. In OPL2 mode all four waveforms are always available, and in OPL3 mode all eight waveforms are always available. For compatibility with OPL2, when a program is finished using an OPL3, the waveform select registers should be set to 0, if the next program assumes that by setting WSE bit to 0 the waveform is always sine like on a real OPL2.&lt;br /&gt;
&lt;br /&gt;
==== 02: Timer 1 Count ====&lt;br /&gt;
&lt;br /&gt;
Upward 8 bit counter with a resolution of 80 µsec. If an overflow occurs, the status register bit is set, and the preset value is loaded into the timer again.&lt;br /&gt;
&lt;br /&gt;
==== 03: Timer 2 Count ====&lt;br /&gt;
&lt;br /&gt;
Same as Timer 1, but with a resolution of 320 µsec.&lt;br /&gt;
&lt;br /&gt;
==== 004 (port: base+1): IRQ-Reset / Mask / Start ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Rst&lt;br /&gt;
| T1M&lt;br /&gt;
| T2M&lt;br /&gt;
|colspan=3| -&lt;br /&gt;
| T2S&lt;br /&gt;
| T1S&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ-Reset. Resets timer and IRQ flags in status register. All other bits are ignored when this bit is set.&lt;br /&gt;
* bit 6: Timer 1 Mask. If 1, status register is not affected in overflow.&lt;br /&gt;
* bit 5: Timer 2 Mask. Same as above.&lt;br /&gt;
* bit 1: Timer 2 Start. Timer on/off.&lt;br /&gt;
* bit 0: Timer 1 Start. Same as above.&lt;br /&gt;
&lt;br /&gt;
==== 104 (port: base+3): Four-Operator Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| ChB&lt;br /&gt;
| ChA&lt;br /&gt;
| Ch9&lt;br /&gt;
| Ch2&lt;br /&gt;
| Ch1&lt;br /&gt;
| Ch0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: Enable four-operator synthesis for channel pair 11 - 14 (decimal).&lt;br /&gt;
* bit 4: Same as above for channel pair 10 - 13.&lt;br /&gt;
* bit 3: Same as above for channel pair 9 - 12.&lt;br /&gt;
* bit 2: Same as above for channel pair 2 - 5.&lt;br /&gt;
* bit 1: Same as above for channel pair 1 - 4.&lt;br /&gt;
* bit 0: Same as above for channel pair 0 - 3.&lt;br /&gt;
&lt;br /&gt;
If reset to zero, OPL3 can produce 18 two-operator sounds at a time. If nonzero, OPL3 produces four-operator sound in appropriate channel pair.&lt;br /&gt;
&lt;br /&gt;
==== 105 (port: base+3): OPL3 Mode Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=7| -&lt;br /&gt;
| OPL3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 0: OPL3 Mode Enable. When set, OPL3 extensions (36 operators, 4-OP synthesis, 8 waveforms, stereo output) can be used. When reset, the chip behaves as an ordinary OPL2. This bit is zero by default for compatibility with OPL2.&lt;br /&gt;
&lt;br /&gt;
==== 08: CSW / NOTE-SEL ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| (CSW)&lt;br /&gt;
| N-S&lt;br /&gt;
|colspan=6| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: Composite sine wave mode on/off. All KEY-ON bits must be clear in order to use this mode. The card is unable to create any other sound when in CSW mode. (Unfortunately, I have no info how to use this mode :-&amp;lt; ). The CSW mode is not implemented on an OPL3 and this bit is ignored.&lt;br /&gt;
* bit 6: NOTE-SEL. Controls the split point of the keyboard. When 0, the keyboard split is the second bit from the bit 8 of the F-Number. When 1, the MSb of the F-Number is used. (???)&lt;br /&gt;
&lt;br /&gt;
==== 20-35: Tremolo / Vibrato / Sustain / KSR / Frequency Multiplication Factor ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Sus&lt;br /&gt;
| KSR&lt;br /&gt;
|colspan=4| Multiplication&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude vibrato) on/off.&lt;br /&gt;
* bit 6:    Frequency vibrato on/off.&lt;br /&gt;
* bit 5:    Sound Sustaining. When 1, operator&#039;s output level will be held at its sustain level until a KEY-OFF is done.&lt;br /&gt;
* bit 4:    Envelope scaling (KSR) on/off. When 1, higher notes are shorter than lower notes.&lt;br /&gt;
* bits 0-3: Frequency Multiplication Factor (MULTI). Operator&#039;s frequency is set to (see registers A0, B0) F-Number * Factor.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! MULTI !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0.5&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 2&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 3&lt;br /&gt;
|-&lt;br /&gt;
| 4 || 4&lt;br /&gt;
|-&lt;br /&gt;
| 5 || 5&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 6&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 7&lt;br /&gt;
|-&lt;br /&gt;
| 8 || 8&lt;br /&gt;
|-&lt;br /&gt;
| 9 || 9&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 40-55: Key Scale Level / Output Level ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| KSL&lt;br /&gt;
|colspan=6| Output level&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 6-7: Key Scale Level. Attenuates output level towards higher pitch:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! KSL !! Attenuation&lt;br /&gt;
|-&lt;br /&gt;
| 0 || -&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 3.0 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 1.5 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 6.0 dB/oct&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The attenuation level is based on the 3-bit octave (block number) value and top four bits of the FNUM value, so each octave is subdivided into 16 parts.&lt;br /&gt;
&lt;br /&gt;
* bits 0-5: Output Level. Attenuates the operator output level. 0 is the loudest, 3F is the softest. In additive synthesis, varying the output level of any operator varies the volume of its corresponding channel. In FM synthesis, varying the output level of the carrier varies the volume of the channel. Varying the output of the modulator will change the frequency spectrum produced by the carrier. The following table summarizes which operators&#039; output levels should be updated when trying to change channel output level.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Mode !! Op 1 !! Op 2 !! Op 3 !! Op 4&lt;br /&gt;
|-&lt;br /&gt;
| AM    || Y || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM    || - || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM-FM || - || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-FM || Y || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| FM-AM || - || Y || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-AM || Y || - || Y   || Y&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 60-75: Attack Rate / Decay Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Attack rate&lt;br /&gt;
|colspan=4| Decay rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Attack Rate. Determines the rising time for the sound. The higher the value, the faster the attack.&lt;br /&gt;
* bits 0-3: Decay Rate. Determines the diminishing time for the sound. The higher the value, the shorter the decay.&lt;br /&gt;
&lt;br /&gt;
==== 80-95: Sustain Level / Release Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Sustain level&lt;br /&gt;
|colspan=4| Release rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Sustain Level. Determines the point at which the sound ceases to decay and chages to a sound having a constant level. The sustain level is expressed as a fraction of the maximum level. 0 is the softest and F is the loudest sustain level. Note that the Sustain-bit in the register 20-35 must be set for this to have an effect.&lt;br /&gt;
* bits 0-3: Release Rate. Determines the rate at which the sound disappears after KEY-OFF. The higher the value, the shorter the release.&lt;br /&gt;
&lt;br /&gt;
==== A0-A8: Frequency Number ====&lt;br /&gt;
&lt;br /&gt;
Determines the pitch of the note. Highest bits of F-Number are stored in the register below.&lt;br /&gt;
&lt;br /&gt;
==== B0-B8: Key On / Block Number / F-Number(hi bits) ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| KEY&lt;br /&gt;
|colspan=3| Block num.&lt;br /&gt;
|colspan=2| Freq&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: KEY-ON. When 1, channel output is enabled.&lt;br /&gt;
* bits 2-4: Block Number. Roughly determines the octave.&lt;br /&gt;
* bits 0-1: Frequency Number. 2 highest bits of the above register.  The following formula is used to determine F-Number and Block:&lt;br /&gt;
: F-Number = Music Frequency * 2^(20-Block) / 49716 Hz&lt;br /&gt;
&lt;br /&gt;
NOTE: In four-operator mode only the register value of Operators 1 and 2 is used, value of Operators 3 and 4 in this register is ignored. In other words: one channel uses only one frequency, block and KEY-ON value at a time, regardless whether it is a two- or four-operator channel.&lt;br /&gt;
&lt;br /&gt;
==== BD: Tremolo Depth / Vibrato Depth / Percussion Mode / BD/SD/TT/CY/HH On ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Per&lt;br /&gt;
| BD&lt;br /&gt;
| SD&lt;br /&gt;
| TT&lt;br /&gt;
| CY&lt;br /&gt;
| HH&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude Vibrato) Depth. 0 = 1.0dB, 1 = 4.8dB.&lt;br /&gt;
* bit 6:    Frequency Vibrato Depth. 0 = 7 cents, 1 = 14 cents. A &amp;quot;cent&amp;quot; is 1/100 of a semi-tone.&lt;br /&gt;
* bit 5:    Percussion Mode. 0 = Melodic Mode, 1 = Percussion Mode.&lt;br /&gt;
* bit 4:    BD On. KEY-ON of the Bass Drum channel.&lt;br /&gt;
* bit 3:    SD On. KEY-ON of the Snare Drum channel.&lt;br /&gt;
* bit 2:    TT On. KEY-ON of the Tom-Tom channel.&lt;br /&gt;
* bit 1:    CY On. KEY-ON of the Cymbal channel.&lt;br /&gt;
* bit 0:    HH On. KEY-ON of the Hi-Hat channel.&lt;br /&gt;
&lt;br /&gt;
NOTE: KEY-ON bits of channels 6, 7 and 8 must be clear and their F-Nums, Attack/Decay/Release rates, etc. must be set properly to use percussion mode.&lt;br /&gt;
&lt;br /&gt;
==== C0-C8: FeedBack Modulation Factor / Synthesis Type ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| OutCh_D&lt;br /&gt;
| OutCh_C&lt;br /&gt;
| R&lt;br /&gt;
| L&lt;br /&gt;
|colspan=3| Feedback&lt;br /&gt;
| Syn&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: CHD, Output Channel D Enable. When set, channel output goes to fourth digital audio output channel.&lt;br /&gt;
* bit 6: CHC, Output Channel C Enable. When set, channel output goes to third digital audio output channel.&lt;br /&gt;
* bit 5:    Right Speaker Enable. When set, channel output goes to second digital audio output channel, connected to right speaker.&lt;br /&gt;
* bit 4:    Left Speaker Enable. When set, channel output goes to first digital audio output channel, connected to left speaker.&lt;br /&gt;
** In OPL3 mode, at least one of the left/right bits must be set to hear the channel.&lt;br /&gt;
** In OPL2 mode, these bits are ignored and audio is sent to all channels for compatibility reasons.&lt;br /&gt;
** Left/Right bits can be used to realize sound &amp;quot;panning&amp;quot;, but this method offers only three pan positions (left/center/right).&lt;br /&gt;
** These bits apply only to operators producing sound (Carriers). Modulators are not affected by their setting.&lt;br /&gt;
** Sound cards use only one stereo DAC, so only two of the four digital output channels are available.&lt;br /&gt;
* bits 1-3: FeedBack Modulation Factor. If 0, no feedback is present. If 1-7, operator 1 will send a portion of its output back into itself.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! FeedBack !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;amp;pi;/16&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;amp;pi;/8&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;amp;pi;/4&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;amp;pi;/2&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 2&amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 4&amp;amp;pi;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
When in four-operator mode, the FeedBack value is used only by Operator 1, value of Operators 2, 3 and 4 is ignored.&lt;br /&gt;
&lt;br /&gt;
* bit 0: Synthesis Type. 1 = Additive synthesis, 0 = Frequency Modulation.  In four-operator mode, there are two bits controlling the synthesis type. Both are the bit 0 of register C0, one of Operators 1 and 2 and the second of Operators 3 and 4.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Op 1&amp;amp;2 !! Op 3&amp;amp;4 !! Type&lt;br /&gt;
|-&lt;br /&gt;
| 0 || NONE || FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || NONE || AM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || FM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || AM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || FM-AM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || AM-AM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== E0-F5: Waveform Select ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=5| -&lt;br /&gt;
|colspan=3| Waveform&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 0-2: WaveForm Select (WS): &amp;lt;gallery widths=261px perrow=4&amp;gt;&lt;br /&gt;
Image:OPL_Wave0.png|Waveform 0: Sine&lt;br /&gt;
Image:OPL_Wave1.png|Waveform 1: Half-sine&lt;br /&gt;
Image:OPL_Wave2.png|Waveform 2: Abs-sine&lt;br /&gt;
Image:OPL_Wave3.png|Waveform 3: Pulse-sine&lt;br /&gt;
Image:OPL_Wave4.png|Waveform 4: Sine - even periods only&lt;br /&gt;
Image:OPL_Wave5.png|Waveform 5: Abs-sine - even periods only&lt;br /&gt;
Image:OPL_Wave6.png|Waveform 6: Square&lt;br /&gt;
Image:OPL_Wave7.png|Waveform 7: Derived square&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* NOTE: Bit 5 of register 01 must be set to use waveforms other than sine. Waveforms 4-7 are available only on OPL3. See files WAVEn.GIF for real waveforms, where n is a number between 0 and 7.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
These examples show a few working routines used in my MUS Player. They are written in Borland C++ 3.1 but should be easy to translate to any other language.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
// I prefer using these Assembler-like types&lt;br /&gt;
typedef unsigned int  WORD;&lt;br /&gt;
typedef unsigned char BYTE;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * FM Synthesizer base port. SB Pro II - 0x220, Adlib 0x388&lt;br /&gt;
 */&lt;br /&gt;
WORD FMport = 0x220;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Enables OPL3 extensions.&lt;br /&gt;
 */&lt;br /&gt;
WORD OPL3 = 1;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Direct write to any Adlib/SB Pro II FM synthetiser register.&lt;br /&gt;
 *   reg - register number (range 0x001-0x0F5 and 0x101-0x1F5). When high byte&lt;br /&gt;
 *         of reg is zero, data go to port FMport, otherwise to FMport+2&lt;br /&gt;
 *   data - register value to be written&lt;br /&gt;
 */&lt;br /&gt;
BYTE FMwriteReg(WORD reg, BYTE data)&lt;br /&gt;
{&lt;br /&gt;
    asm {&lt;br /&gt;
	mov	dx,FMport&lt;br /&gt;
	mov	ax,reg&lt;br /&gt;
	or	ah,ah		// high byte is nonzero -- write to port base+2&lt;br /&gt;
	jz	out1&lt;br /&gt;
	inc	dx&lt;br /&gt;
	inc	dx&lt;br /&gt;
    }&lt;br /&gt;
out1: asm {&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	mov	cx,6&lt;br /&gt;
    }&lt;br /&gt;
loop1:asm {			// delay between writes&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop1&lt;br /&gt;
&lt;br /&gt;
	inc	dx&lt;br /&gt;
	mov	al,data&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	dec	dx&lt;br /&gt;
	mov	cx,36&lt;br /&gt;
    }&lt;br /&gt;
loop2:asm {			// delay after data write&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop2&lt;br /&gt;
    }&lt;br /&gt;
    return _AL;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to an operator pair. To be used for register bases of 0x20, 0x40,&lt;br /&gt;
 * 0x60, 0x80 and 0xE0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteChannel(BYTE regbase, BYTE channel, BYTE data1, BYTE data2)&lt;br /&gt;
{&lt;br /&gt;
    static BYTE adlib_op[] = {0, 1, 2, 8, 9, 10, 16, 17, 18};&lt;br /&gt;
    static BYTE sbpro_op[] = { 0,  1,  2,   6,  7,  8,  12, 13, 14,&lt;br /&gt;
			      18, 19, 20,  24, 25, 26,  30, 31, 32};&lt;br /&gt;
    static WORD rg[] = {0x000,0x001,0x002,0x003,0x004,0x005,&lt;br /&gt;
			0x008,0x009,0x00A,0x00B,0x00C,0x00D,&lt;br /&gt;
			0x010,0x011,0x012,0x013,0x014,0x015,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,&lt;br /&gt;
			0x108,0x109,0x10A,0x10B,0x10C,0x10D,&lt;br /&gt;
			0x110,0x111,0x112,0x113,0x114,0x115};&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
    {&lt;br /&gt;
	register WORD reg = sbpro_op[channel];&lt;br /&gt;
	FMwriteReg(rg[reg]+regbase, data1);&lt;br /&gt;
	FMwriteReg(rg[reg+3]+regbase, data2);&lt;br /&gt;
    } else {&lt;br /&gt;
	register WORD reg = regbase+adlib_op[channel];&lt;br /&gt;
	FMwriteReg(reg, data1);&lt;br /&gt;
	FMwriteReg(reg+3, data2);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to channel a single value. To be used for register bases of&lt;br /&gt;
 * 0xA0, 0xB0 and 0xC0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteValue(BYTE regbase, BYTE channel, BYTE value)&lt;br /&gt;
{&lt;br /&gt;
    static WORD ch[] = {0x000,0x001,0x002,0x003,0x004,0x005,0x006,0x007,0x008,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,0x106,0x107,0x108};&lt;br /&gt;
    register WORD chan;&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
	chan = ch[channel];&lt;br /&gt;
    else&lt;br /&gt;
	chan = channel;&lt;br /&gt;
    FMwriteReg(regbase + chan, value);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Detection Methods ==&lt;br /&gt;
&lt;br /&gt;
An official method of Adlib (OPL2) detection is:&lt;br /&gt;
&lt;br /&gt;
# Reset Timer 1 and Timer 2: write 60h to register 4.&lt;br /&gt;
# Reset the IRQ: write 80h to register 4.&lt;br /&gt;
#* NOTE: Steps 1 and 2 can&#039;t be combined together.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Set Timer 1 to FFh: write FFh to register 2.&lt;br /&gt;
# Unmask and start Timer 1: write 21h to register 4.&lt;br /&gt;
# Wait in a delay loop for at least 80 µsec.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Reset Timer 1, Timer 2 and IRQ as in steps 1 and 2.&lt;br /&gt;
# Test the results of the two reads: the first should be 0, the second should be C0h. If either is incorrect, then the OPL2 is not present.&lt;br /&gt;
&lt;br /&gt;
* NOTE1: You should AND the result bytes with E0h because the unused bits are undefined.&lt;br /&gt;
* NOTE2: This testing method doesn&#039;t work in some SoundBlaster compatible cards.&lt;br /&gt;
&lt;br /&gt;
=== OPL3 Detection ===&lt;br /&gt;
--------------&lt;br /&gt;
&lt;br /&gt;
# Detect OPL2. If present, continue.&lt;br /&gt;
# Read status register: read port base+0.&lt;br /&gt;
# AND the result with 06h.&lt;br /&gt;
# If the result is zero, you have OPL3, otherwise OPL2.&lt;br /&gt;
&lt;br /&gt;
* NOTE: This is NOT an official method. I have dug it out of a sound driver. I haven&#039;t tested it, because I haven&#039;t an OPL2 card (Adlib, SB Pro I). Nevertheless it &amp;quot;detects&amp;quot; my SB Pro II properly. ;-)&lt;br /&gt;
&lt;br /&gt;
Another possible detection method for distinguishing between SB Pro I and SB Pro II would be to try to detect OPL2 at I/O port base+0 and then at port base+2. The first test should succeed and the second should fail if OPL3 is present. (Remember: SB Pro I contains twin OPL2 chips at addresses base+0 and base+2, while SB Pro II contains one OPL3 chip at I/O address base+0 thru base+3).&lt;br /&gt;
&lt;br /&gt;
== BLASTER Environment Variable ==&lt;br /&gt;
&lt;br /&gt;
Perhaps the most recommended &amp;quot;detection&amp;quot; method. Reading this variable avoids blindfold I/O port scanning and possible device conflicts. The user is responsible for its proper setting.&lt;br /&gt;
&lt;br /&gt;
The variable has this format:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=Aaddr Iirq Ddma Ttype&lt;br /&gt;
&lt;br /&gt;
* A: Base I/O address given in hex. For most Sound Blasters the default is 220.&lt;br /&gt;
* I: IRQ Number (decimal). Default 7.&lt;br /&gt;
* D: DMA Number (decimal). Default 1.&lt;br /&gt;
* T: Card Type (decimal):&lt;br /&gt;
** 1 - Sound Blaster 1.5&lt;br /&gt;
** 2 - Sound Blaster Pro I&lt;br /&gt;
** 3 - Sound Blaster 2.0&lt;br /&gt;
** 4 - Sound Blaster Pro II&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=A220 I7 D1 T4&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The PC Games Programmers Encyclopedia&#039;&#039;, Mark Feldman and many others on Usenet and Internet, ftp://teeri.oulu.fi/pub/msdos/programming/gpe&lt;br /&gt;
: ... you can find (almost) everything you need there&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Sound Blaster - The Official Book&#039;&#039;, Richard Heimlich, David M. Golden, Ivan Luk, Peter M. Ridge, Osborne/McGraw Hill, ISBN 0-07-881907-5&lt;br /&gt;
: ... this is a number-one in my book-wishlist. If anyone wanted to get rid of the book, I wouldn&#039;t scorn it ... :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The SoundBlaster Developer Kit&#039;&#039;, Creative Labs Inc, Creative Technology PTE LTD&lt;br /&gt;
: ... I wonder if you can find something comprehensible in that.&lt;/div&gt;</summary>
		<author><name>Kermes</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4323</id>
		<title>OPL chip</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4323"/>
		<updated>2012-08-03T19:30:36Z</updated>

		<summary type="html">&lt;p&gt;Kermes: /* Data Registers (base+1, base+3) */ Update changes to CSW, WSE and audio output channel bits CHD and CHC.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Programmer&#039;s Guide to Yamaha YMF 262/OPL3 FM Music Synthesizer =&lt;br /&gt;
Version 1.00  Nov-24-1994&lt;br /&gt;
&lt;br /&gt;
Written by Vladimir Arnost, QA-Software&lt;br /&gt;
Internet:  xarnos00@dcse.fee.vutbr.cz&lt;br /&gt;
&lt;br /&gt;
This manual can be distributed freely if not modified.&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer ===&lt;br /&gt;
&lt;br /&gt;
I assume no responsibility for any damages arising out of use or inability to use this text. No warranty is provided about correctness of any information in this file. You are on your own.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The chip I am going to describe is getting more and more common, but programming information is still scarce, so I have decided to fill in this gap. All information contained in this file is a result of my experience in Adlib programming, research (read: reverse engineering) and finally of my effort to write down everything necessary to understand and use this piece of hardware. No official sources (i.e. development kits, books about this topic, etc.) were available to me except:&lt;br /&gt;
&lt;br /&gt;
: Adlib Programming Guide - by Tero Töttö, and&lt;br /&gt;
: The PC Games Programmers Encyclopedia V1.0&lt;br /&gt;
&lt;br /&gt;
The information below is a combination of known features of Adlib (alias Yamaha YM 3812/OPL2) and my own uncountable experiments and failures, which brought out a lot of important details you have to know about the chip.&lt;br /&gt;
&lt;br /&gt;
As far as I know, there are four major sound cards based on OPL3 chip:&lt;br /&gt;
&lt;br /&gt;
* Sound Blaster Pro II (not Sound Blaster Pro I)&lt;br /&gt;
* Sound Blaster 16&lt;br /&gt;
* Adlib Gold&lt;br /&gt;
* Pro Audio Spectrum Plus/16&lt;br /&gt;
&lt;br /&gt;
I currently have a Sound Blaster Pro II-compatible card only, so all the programming info I provide will be based on this card. (The other cards are quite similar, however. They are just wired at different I/O-port addresses.)&lt;br /&gt;
&lt;br /&gt;
Note: I assume some knowledge of FM music programming (mainly Adlib FM synthesizer) in this manual. If you are new to this topic I recommend you try Adlib first before going higher. Anyway, OPL3 is a direct descendant of OPL2 (what a surprise), so most features of OPL2 are also present on OPL3.&lt;br /&gt;
&lt;br /&gt;
== Description of the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
My card&#039;s user manual says: &amp;quot;[this card contains] ... a stereo music FM synthesizer with 20 channels consisting of four (4) operators each ... &amp;quot; I thought: &amp;quot;Wow -- that&#039;s together eighty operators. This must be a GOOD sound-card.&amp;quot; I was wrong. Just another advertising lie.&lt;br /&gt;
&lt;br /&gt;
So let&#039;s clear some facts. First, OPL3 has only thirty-six (36) operators which can be combined in several ways:&lt;br /&gt;
&lt;br /&gt;
* 18 FM channels (36 operators), or&lt;br /&gt;
* 15 FM channels (30 ops) and 5 percussion instruments (6 ops), giving us 20 channels altogether, or&lt;br /&gt;
* up to 6 four-operator FM channels (max 24 ops), the rest again being divided into two-operator FM channels and drums.&lt;br /&gt;
&lt;br /&gt;
From the table above you can see that not all channels can be used in four-operator (4-OP) mode -- only a part of the synthesizer is really capable of making 4-OP sounds -- the rest uses traditional two-operator (2-OP) mode.&lt;br /&gt;
&lt;br /&gt;
Second, the manual states this card is capable of &amp;quot;stereo&amp;quot; music. Yes, the quotes are necessary, because the stereo capabilities are very limited. You are given ability to control output going to left or right channel by turning it on and off. That&#039;s all. So the sound can flow from very left side, center and very right side. No sound panning, no special stereo effects. :-(&lt;br /&gt;
&lt;br /&gt;
Well, flaming apart, back to the main topic.&lt;br /&gt;
&lt;br /&gt;
The OPL3 chip is capable of making sounds in several ways:&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Additive Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output of both operators is simply added. It is the simplest way to make any sound, and it works on both OPL2 and OPL3. The diagram should make it clear.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐&lt;br /&gt;
	│            │&lt;br /&gt;
	│ Operator 1 ├────────┐&lt;br /&gt;
	│            │        │&lt;br /&gt;
	└────────────┘        │&lt;br /&gt;
			      ├────────&amp;gt; Output&lt;br /&gt;
	┌────────────┐        │&lt;br /&gt;
	│            │        │&lt;br /&gt;
	│ Operator 2 ├────────┘&lt;br /&gt;
	│            │&lt;br /&gt;
	└────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Frequency Modulation (FM) Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output from the first operator (Modulator) is sent to the input of the second one (Carrier) and is used to modulate (alter) frequency of the second operator. Only the second operator produces sound. Most of interesting sounds are made this way. This also works on OPL2. Hope the picture helps.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐         ┌────────────┐&lt;br /&gt;
	│            │         │            │&lt;br /&gt;
	│ Operator 1 ├────────&amp;gt;│ Operator 2 ├────────&amp;gt; Output&lt;br /&gt;
	│(Modulator) │         │ (Carrier)  │&lt;br /&gt;
	└────────────┘         └────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Four-operator &amp;quot;Mess&amp;quot; Modulation Synthesis ===&lt;br /&gt;
&lt;br /&gt;
All of OPL3&#039;s 4-OP configurations are combinations of the above two modes of synthesis. OPL3 combines these two modes in four ways. I have no words to describe these four ways. Only the pictures can show their principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   a) FM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   b) AM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├───────────────────────────────────┐&lt;br /&gt;
	│       │                                   │&lt;br /&gt;
	└───────┘                                   │&lt;br /&gt;
						    │&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┴─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   c) FM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────┐&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     ├─────&amp;gt; Output&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┘&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	└───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   d) AM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├────────────────────┐&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	└───────┘                    │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────┼─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐                    │&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	│ Op. 4 ├────────────────────┘&lt;br /&gt;
	│       │&lt;br /&gt;
	└───────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Nice, aren&#039;t they?&lt;br /&gt;
&lt;br /&gt;
The only way I think this can be written is a math formula. Symbol + (plus) means additive synthesis, and * (asterisk) means frequency modulation (Op1 * Op2 means operator 1 modulates operator 2, not vice versa). Here they are:&lt;br /&gt;
&lt;br /&gt;
# FM-FM Mode:	 (Op1 * Op2 * Op3 * Op4) ────&amp;gt; Output&lt;br /&gt;
# AM-FM Mode:	  Op1 + (Op2 * Op3 * Op4) ───&amp;gt; Output&lt;br /&gt;
# FM-AM Mode:	 (Op1 * Op2) + (Op3 * Op4) ──&amp;gt; Output&lt;br /&gt;
# AM-AM Mode:	  Op1 + (Op2 * Op3) + Op4 ───&amp;gt; Output&lt;br /&gt;
&lt;br /&gt;
=== Percussion Mode ===&lt;br /&gt;
&lt;br /&gt;
In this mode 6 operators are used to produce five different percussion instruments:&lt;br /&gt;
&lt;br /&gt;
* Bass Drum (2 operators)&lt;br /&gt;
* Snare Drum (1 operator)&lt;br /&gt;
* Tom-Tom (1 operator)&lt;br /&gt;
* Cymbal (1 operator)&lt;br /&gt;
* Hi-Hat (1 operator)&lt;br /&gt;
&lt;br /&gt;
Because these instruments occupy only three melodic channels, only Bass Drum, Snare Drum and Tom-Tom frequencies can be set. Cymbal and Hi-Hat frequencies are fixed.  {{TODO|It seems it&#039;s actually the cymbal and snare frequencies that are fixed, try to confirm this -- [[User:Malvineous|Malvineous]] 13:34, 3 June 2012 (GMT)}}&lt;br /&gt;
&lt;br /&gt;
This mode is identical with that of OPL2. For more details see ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
== Programming the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
OPL3 may be found at the following addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| Sound Blaster Pro II || 220h or 240h (selectable), also 388h&lt;br /&gt;
|-&lt;br /&gt;
| Adlib Gold || 388h&lt;br /&gt;
|-&lt;br /&gt;
| Pro Audio Spectrum Plus/16 || ? (if you have a PAS you should know it)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The base address of the synthesizer will be called &amp;quot;base&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The chip occupies four I/O addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| base+0 || Primary index register (write), Status register (read)&lt;br /&gt;
|-&lt;br /&gt;
| base+1 || Primary data register (write-only)&lt;br /&gt;
|-&lt;br /&gt;
| base+2 || Secondary index register (write)&lt;br /&gt;
|-&lt;br /&gt;
| base+3 || Secondary data register (write-only)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The index registers are used to select internal registers and data registers are used to write to them. Status register returns the state of two timers built in the chip.&lt;br /&gt;
&lt;br /&gt;
OPL3 contains two sets of registers. The Primary set maps to channels 0-8 (operators 0-17) and the secondary maps to channels 9-17 (operators 18-35). The reason for this is simple: all these registers wouldn&#039;t fit into single register set.&lt;br /&gt;
&lt;br /&gt;
Unlike Adlib (OPL2), OPL3 doesn&#039;t need delay between register writes. With OPL2 you had to wait 3.3 µs after index register write and another 23 µs after data register write. On the contrary OPL3 doesn&#039;t need (almost) any delay after index register write and only 0.28 µs after data register write. This means you can neglect the delays and slightly speed up your music driver. But using reasonable delays will certainly do no harm.&lt;br /&gt;
&lt;br /&gt;
The data registers can&#039;t be read (they are write-only) on both OPL2 and OPL3.&lt;br /&gt;
&lt;br /&gt;
== Register Map ==&lt;br /&gt;
&lt;br /&gt;
The registers are grouped in the same manner as in the OPL2 chip. Programs using both OPL2 and OPL3 chips may use the same code provided that their direct I/O interface is well written. The only thing you have to change is operator-to-register mapping, which must accomodate the fact that registers are spread between two register sets.&lt;br /&gt;
&lt;br /&gt;
(The register map is nearly the same so I dared to copy it from ADLIB.DOC.)&lt;br /&gt;
&lt;br /&gt;
=== Status Register (base+0) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
!    D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQFlag || T1Flag || T2Flag ||        ||        ||        ||        ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Data Registers (base+1, base+3) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! REG   !!   D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| 01    ||colspan=2| Test Register ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|(WSEnable)||colspan=5| Test Register&lt;br /&gt;
|-&lt;br /&gt;
| 02    ||colspan=8| Timer 1 Count (80 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 03    ||colspan=8| Timer 2 Count (320 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 04*   ||IRQReset|| T1Mask || T2Mask ||colspan=3|                  ||T2 Start||T1 Start&lt;br /&gt;
|-&lt;br /&gt;
| 04**  ||colspan=2|        ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP B-E||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP A-D||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 9-C||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 2-5||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 1-4||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 0-3&lt;br /&gt;
|-&lt;br /&gt;
| 05**  ||colspan=7|                                                           ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;| OPL3&lt;br /&gt;
|-&lt;br /&gt;
| 08    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;| (CSW)  ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|NOTE-SEL||colspan=6|&lt;br /&gt;
|-&lt;br /&gt;
| 20-35 ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Tremolo ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Vibrato ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Sustain ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|  KSR   ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Frequency Multiplication Factor&lt;br /&gt;
|-&lt;br /&gt;
| 40-55 ||colspan=2 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Key Scale Level ||colspan=6 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 60-75 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Attack Rate ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 80-95 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Sustain Level ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A0-A8 ||colspan=8 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Frequency Number  (Lower 8 bits)&lt;br /&gt;
|-&lt;br /&gt;
| B0-B8 ||colspan=2|        ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| KEY-ON ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Block Number ||colspan=2 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| F-Num (hi bits)&lt;br /&gt;
|-&lt;br /&gt;
| BD    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Trem Dep||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Vibr Dep||style=&amp;quot;background-color: #FFCCDD;&amp;quot;|PercMode||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| BD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| SD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| TT On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| CY On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| HH On&lt;br /&gt;
|-&lt;br /&gt;
| C0-C8 ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| OutCh_D ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| OutCh_C ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Right  ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Left   ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;|FeedBack Modulation Factor||style=&amp;quot;background-color: #FFE0CC;&amp;quot;|SynthTyp&lt;br /&gt;
|-&lt;br /&gt;
| E0-F5 ||colspan=5|                                      ||colspan=3 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|style=&amp;quot;background-color: #CCFFCC;&amp;quot;| Chip-wide setting&lt;br /&gt;
|style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Per operator&lt;br /&gt;
|style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Per channel&lt;br /&gt;
|style=&amp;quot;background-color: #FFCCDD;&amp;quot;| Rhythm-mode only&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt; This applies only to port base+1&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;**&amp;lt;/nowiki&amp;gt; This applies only to port base+3&lt;br /&gt;
&lt;br /&gt;
For register bases A0, B0 and C0 there is one register per output channel. The primary register set holds the first nine channels (0-8) and the secondary holds last nine channels (9-17). For bases 20, 40, 60, 80 and E0 there are two registers per channel. Each register maps to one operator. Unfortunately the operator&#039;s register numbers are not continuous. The following table shows which operator maps to which register set and offset (in hex).&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Op. !! Set/Offset !! Op. !! Set/Offset&lt;br /&gt;
|-&lt;br /&gt;
| 0  || 0/00 || 18 || 1/00&lt;br /&gt;
|-&lt;br /&gt;
| 1  || 0/01 || 19 || 1/01&lt;br /&gt;
|-&lt;br /&gt;
| 2  || 0/02 || 20 || 1/02&lt;br /&gt;
|-&lt;br /&gt;
| 3  || 0/03 || 21 || 1/03&lt;br /&gt;
|-&lt;br /&gt;
| 4  || 0/04 || 22 || 1/04&lt;br /&gt;
|-&lt;br /&gt;
| 5  || 0/05 || 23 || 1/05&lt;br /&gt;
|-&lt;br /&gt;
| 6  || 0/08 || 24 || 1/08&lt;br /&gt;
|-&lt;br /&gt;
| 7  || 0/09 || 25 || 1/09&lt;br /&gt;
|-&lt;br /&gt;
| 8  || 0/0A || 26 || 1/0A&lt;br /&gt;
|-&lt;br /&gt;
| 9  || 0/0B || 27 || 1/0B&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 0/0C || 28 || 1/0C&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 0/0D || 29 || 1/0D&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 0/10 || 30 || 1/10&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 0/11 || 31 || 1/11&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 0/12 || 32 || 1/12&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 0/13 || 33 || 1/13&lt;br /&gt;
|-&lt;br /&gt;
| 16 || 0/14 || 34 || 1/14&lt;br /&gt;
|-&lt;br /&gt;
| 17 || 0/15 || 35 || 1/15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following tables summarize which operators form a channel in various modes:&lt;br /&gt;
&lt;br /&gt;
1. Two-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel    !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 13 || 14 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 || 16 || 17 || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
2. Two-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 ||colspan=4| - || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
3. Four-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 13 || 14 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 || 16 || 17 || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=3| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=3| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Channels 3, 4, 5 and 12, 13, 14 can&#039;t be used separately because their operators became part of channels 0, 1, 2 and 9, 10, 11 respectively. For instance a four-operator channel 1 consists of two two-operator channels number 1 and 4. (The second 2-OP channel number is always the first 2-OP channel number plus three.)&lt;br /&gt;
&lt;br /&gt;
OPL3 allows you to enable/disable 4-OP mode separately for any of channels 0, 1, 2, 9, 10 and 11 (see register 104h in the reference below). This means for instance when you switch only channel 2 into 4-OP mode, channels number 0, 1, 3, 4, 6, 7, 8, 9, etc. will be still independent 2-OP channels.&lt;br /&gt;
&lt;br /&gt;
Channels 6, 7, 8 and 15, 16, 17 are always two-operator ones. They can&#039;t be grouped to form four-operator channels.&lt;br /&gt;
&lt;br /&gt;
4. Four-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 ||colspan=4| - || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=5| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=5| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
Two-operator channel #14 consists of operators 26 and 29 which occupy these registers (all are in the secondary register set):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| 12A || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 12D || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 14A || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 14D || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 16A || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 16D || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18A || Operator 1 ||Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18D || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 1A5 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| 1B5 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| 1C5 ||            || FeedBack/Synthesis Type&lt;br /&gt;
|-&lt;br /&gt;
| 1EA || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| 1ED || Operator 2 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Four-operator channel #1 consists of operators 1, 4, 7 and 10. All registers except register 104h are in the primary set:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 104 || bit 1 = 1  || Enable Four-Operator Synthesis in channel #1&lt;br /&gt;
|-&lt;br /&gt;
| 21 || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 24 || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 29 || Operator 3 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 2C || Operator 4 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 41 || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 44 || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 49 || Operator 3 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 4C || Operator 4 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 61 || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 64 || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 69 || Operator 3 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 6C || Operator 4 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 81 || Operator 1 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 84 || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 89 || Operator 3 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 8C || Operator 4 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A1 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| A4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| B1 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| B4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| C1 ||            || FeedBack/Synthesis Type (part 1)&lt;br /&gt;
|-&lt;br /&gt;
| C4 ||            || Synthesis Type (part 2)&lt;br /&gt;
|-&lt;br /&gt;
| E1 || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E4 || Operator 2 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E9 || Operator 3 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| EC || Operator 4 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
NOTE: If a register number is greater than 100h, then it belongs into the secondary register set. (I use this numbering to emphasize the fact that the particular register MUST be written to the secondary set.) See the example code below for details.&lt;br /&gt;
&lt;br /&gt;
== OPL3 Register Reference ==&lt;br /&gt;
&lt;br /&gt;
Because the registers of OPL3 are almost the same as of OPL2, I have copied their descriptions from file ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
=== Status Register ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQ || T1 || T2 ||colspan=5| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ Flag. Set whenever any timer has elapsed.&lt;br /&gt;
* bit 6: Timer 1 Flag. Set every time the preset time in Timer 1 has elapsed.&lt;br /&gt;
* bit 5: Timer 2 Flag. Set every time the preset time in Timer 2 has elapsed.&lt;br /&gt;
&lt;br /&gt;
Timer interrupts are not wired to any IRQ (why??). The timers can be used to detect the OPL2/OPL3 chip (see Appendix B).&lt;br /&gt;
&lt;br /&gt;
=== Data Registers ===&lt;br /&gt;
&lt;br /&gt;
==== 01: Test Register / Waveform Select Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| Test Register&lt;br /&gt;
| (WSE)&lt;br /&gt;
|colspan=5| Test Register&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 7-6: Test Register. Must be reset to zero before any operation.&lt;br /&gt;
* bit 5: Waveform Select Enable. If clear, all channels will use normal sine wave. If set, register E0-F5 (Waveform Select) contents will be used.&lt;br /&gt;
* bits 0-4: Test Register. Must be reset to zero before any operation.&lt;br /&gt;
&lt;br /&gt;
OPL3 does not implement WSE bit, and it should be left clear. In OPL2 mode all four waveforms are always available, and in OPL3 mode all eight waveforms are always available. For compatibility with OPL2, when a program is finished using an OPL3, the waveform select registers should be set to 0, if the next program assumes that by setting WSE bit to 0 the waveform is always sine like on a real OPL2.&lt;br /&gt;
&lt;br /&gt;
==== 02: Timer 1 Count ====&lt;br /&gt;
&lt;br /&gt;
Upward 8 bit counter with a resolution of 80 µsec. If an overflow occurs, the status register bit is set, and the preset value is loaded into the timer again.&lt;br /&gt;
&lt;br /&gt;
==== 03: Timer 2 Count ====&lt;br /&gt;
&lt;br /&gt;
Same as Timer 1, but with a resolution of 320 µsec.&lt;br /&gt;
&lt;br /&gt;
==== 004 (port: base+1): IRQ-Reset / Mask / Start ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Rst&lt;br /&gt;
| T1M&lt;br /&gt;
| T2M&lt;br /&gt;
|colspan=3| -&lt;br /&gt;
| T2S&lt;br /&gt;
| T1S&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ-Reset. Resets timer and IRQ flags in status register. All other bits are ignored when this bit is set.&lt;br /&gt;
* bit 6: Timer 1 Mask. If 1, status register is not affected in overflow.&lt;br /&gt;
* bit 5: Timer 2 Mask. Same as above.&lt;br /&gt;
* bit 1: Timer 2 Start. Timer on/off.&lt;br /&gt;
* bit 0: Timer 1 Start. Same as above.&lt;br /&gt;
&lt;br /&gt;
==== 104 (port: base+3): Four-Operator Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| ChB&lt;br /&gt;
| ChA&lt;br /&gt;
| Ch9&lt;br /&gt;
| Ch2&lt;br /&gt;
| Ch1&lt;br /&gt;
| Ch0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: Enable four-operator synthesis for channel pair 11 - 14 (decimal).&lt;br /&gt;
* bit 4: Same as above for channel pair 10 - 13.&lt;br /&gt;
* bit 3: Same as above for channel pair 9 - 12.&lt;br /&gt;
* bit 2: Same as above for channel pair 2 - 5.&lt;br /&gt;
* bit 1: Same as above for channel pair 1 - 4.&lt;br /&gt;
* bit 0: Same as above for channel pair 0 - 3.&lt;br /&gt;
&lt;br /&gt;
If reset to zero, OPL3 can produce 18 two-operator sounds at a time. If nonzero, OPL3 produces four-operator sound in appropriate channel pair.&lt;br /&gt;
&lt;br /&gt;
==== 105 (port: base+3): OPL3 Mode Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=7| -&lt;br /&gt;
| OPL3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 0: OPL3 Mode Enable. When set, OPL3 extensions (36 operators, 4-OP synthesis, 8 waveforms, stereo output) can be used. When reset, the chip behaves as an ordinary OPL2. This bit is zero by default for compatibility with OPL2.&lt;br /&gt;
&lt;br /&gt;
==== 08: CSW / NOTE-SEL ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| (CSW)&lt;br /&gt;
| N-S&lt;br /&gt;
|colspan=6| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: Composite sine wave mode on/off. All KEY-ON bits must be clear in order to use this mode. The card is unable to create any other sound when in CSW mode. (Unfortunately, I have no info how to use this mode :-&amp;lt; ). The CSW mode is not implemented on an OPL3 and this bit is ignored.&lt;br /&gt;
* bit 6: NOTE-SEL. Controls the split point of the keyboard. When 0, the keyboard split is the second bit from the bit 8 of the F-Number. When 1, the MSb of the F-Number is used. (???)&lt;br /&gt;
&lt;br /&gt;
==== 20-35: Tremolo / Vibrato / Sustain / KSR / Frequency Multiplication Factor ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Sus&lt;br /&gt;
| KSR&lt;br /&gt;
|colspan=4| Multiplication&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude vibrato) on/off.&lt;br /&gt;
* bit 6:    Frequency vibrato on/off.&lt;br /&gt;
* bit 5:    Sound Sustaining. When 1, operator&#039;s output level will be held at its sustain level until a KEY-OFF is done.&lt;br /&gt;
* bit 4:    Envelope scaling (KSR) on/off. When 1, higher notes are shorter than lower notes.&lt;br /&gt;
* bits 0-3: Frequency Multiplication Factor (MULTI). Operator&#039;s frequency is set to (see registers A0, B0) F-Number * Factor.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! MULTI !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0.5&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 2&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 3&lt;br /&gt;
|-&lt;br /&gt;
| 4 || 4&lt;br /&gt;
|-&lt;br /&gt;
| 5 || 5&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 6&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 7&lt;br /&gt;
|-&lt;br /&gt;
| 8 || 8&lt;br /&gt;
|-&lt;br /&gt;
| 9 || 9&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 40-55: Key Scale Level / Output Level ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| KSL&lt;br /&gt;
|colspan=6| Output level&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 6-7: Key Scale Level. Attenuates output level towards higher pitch:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! KSL !! Attenuation&lt;br /&gt;
|-&lt;br /&gt;
| 0 || -&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 3.0 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 1.5 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 6.0 dB/oct&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The attenuation level is based on the 3-bit octave (block number) value and top four bits of the FNUM value, so each octave is subdivided into 16 parts.&lt;br /&gt;
&lt;br /&gt;
* bits 0-5: Output Level. Attenuates the operator output level. 0 is the loudest, 3F is the softest. In additive synthesis, varying the output level of any operator varies the volume of its corresponding channel. In FM synthesis, varying the output level of the carrier varies the volume of the channel. Varying the output of the modulator will change the frequency spectrum produced by the carrier. The following table summarizes which operators&#039; output levels should be updated when trying to change channel output level.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Mode !! Op 1 !! Op 2 !! Op 3 !! Op 4&lt;br /&gt;
|-&lt;br /&gt;
| AM    || Y || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM    || - || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM-FM || - || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-FM || Y || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| FM-AM || - || Y || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-AM || Y || - || Y   || Y&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 60-75: Attack Rate / Decay Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Attack rate&lt;br /&gt;
|colspan=4| Decay rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Attack Rate. Determines the rising time for the sound. The higher the value, the faster the attack.&lt;br /&gt;
* bits 0-3: Decay Rate. Determines the diminishing time for the sound. The higher the value, the shorter the decay.&lt;br /&gt;
&lt;br /&gt;
==== 80-95: Sustain Level / Release Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Sustain level&lt;br /&gt;
|colspan=4| Release rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Sustain Level. Determines the point at which the sound ceases to decay and chages to a sound having a constant level. The sustain level is expressed as a fraction of the maximum level. 0 is the softest and F is the loudest sustain level. Note that the Sustain-bit in the register 20-35 must be set for this to have an effect.&lt;br /&gt;
* bits 0-3: Release Rate. Determines the rate at which the sound disappears after KEY-OFF. The higher the value, the shorter the release.&lt;br /&gt;
&lt;br /&gt;
==== A0-A8: Frequency Number ====&lt;br /&gt;
&lt;br /&gt;
Determines the pitch of the note. Highest bits of F-Number are stored in the register below.&lt;br /&gt;
&lt;br /&gt;
==== B0-B8: Key On / Block Number / F-Number(hi bits) ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| KEY&lt;br /&gt;
|colspan=3| Block num.&lt;br /&gt;
|colspan=2| Freq&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: KEY-ON. When 1, channel output is enabled.&lt;br /&gt;
* bits 2-4: Block Number. Roughly determines the octave.&lt;br /&gt;
* bits 0-1: Frequency Number. 2 highest bits of the above register.  The following formula is used to determine F-Number and Block:&lt;br /&gt;
: F-Number = Music Frequency * 2^(20-Block) / 49716 Hz&lt;br /&gt;
&lt;br /&gt;
NOTE: In four-operator mode only the register value of Operators 1 and 2 is used, value of Operators 3 and 4 in this register is ignored. In other words: one channel uses only one frequency, block and KEY-ON value at a time, regardless whether it is a two- or four-operator channel.&lt;br /&gt;
&lt;br /&gt;
==== BD: Tremolo Depth / Vibrato Depth / Percussion Mode / BD/SD/TT/CY/HH On ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Per&lt;br /&gt;
| BD&lt;br /&gt;
| SD&lt;br /&gt;
| TT&lt;br /&gt;
| CY&lt;br /&gt;
| HH&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude Vibrato) Depth. 0 = 1.0dB, 1 = 4.8dB.&lt;br /&gt;
* bit 6:    Frequency Vibrato Depth. 0 = 7 cents, 1 = 14 cents. A &amp;quot;cent&amp;quot; is 1/100 of a semi-tone.&lt;br /&gt;
* bit 5:    Percussion Mode. 0 = Melodic Mode, 1 = Percussion Mode.&lt;br /&gt;
* bit 4:    BD On. KEY-ON of the Bass Drum channel.&lt;br /&gt;
* bit 3:    SD On. KEY-ON of the Snare Drum channel.&lt;br /&gt;
* bit 2:    TT On. KEY-ON of the Tom-Tom channel.&lt;br /&gt;
* bit 1:    CY On. KEY-ON of the Cymbal channel.&lt;br /&gt;
* bit 0:    HH On. KEY-ON of the Hi-Hat channel.&lt;br /&gt;
&lt;br /&gt;
NOTE: KEY-ON bits of channels 6, 7 and 8 must be clear and their F-Nums, Attack/Decay/Release rates, etc. must be set properly to use percussion mode.&lt;br /&gt;
&lt;br /&gt;
==== C0-C8: FeedBack Modulation Factor / Synthesis Type ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2|&lt;br /&gt;
| R&lt;br /&gt;
| L&lt;br /&gt;
|colspan=3| Feedback&lt;br /&gt;
| Syn&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5:    Right Speaker Enable. When set, channel output goes to right speaker.&lt;br /&gt;
* bit 4:    Left Speaker Enable. When set, channel output goes to left speaker. At least one of these bits must be set to hear the channel.&lt;br /&gt;
** These two bits can be used to realize sound &amp;quot;panning&amp;quot;, but this method offers only three pan positions (left/center/right).&lt;br /&gt;
** These bits apply only to operators producing sound (Carriers). Modulators are not affected by their setting.&lt;br /&gt;
* bits 1-3: FeedBack Modulation Factor. If 0, no feedback is present. If 1-7, operator 1 will send a portion of its output back into itself.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! FeedBack !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;amp;pi;/16&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;amp;pi;/8&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;amp;pi;/4&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;amp;pi;/2&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 2&amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 4&amp;amp;pi;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
When in four-operator mode, the FeedBack value is used only by Operator 1, value of Operators 2, 3 and 4 is ignored.&lt;br /&gt;
&lt;br /&gt;
* bit 0: Synthesis Type. 1 = Additive synthesis, 0 = Frequency Modulation.  In four-operator mode, there are two bits controlling the synthesis type. Both are the bit 0 of register C0, one of Operators 1 and 2 and the second of Operators 3 and 4.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Op 1&amp;amp;2 !! Op 3&amp;amp;4 !! Type&lt;br /&gt;
|-&lt;br /&gt;
| 0 || NONE || FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || NONE || AM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || FM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || AM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || FM-AM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || AM-AM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== E0-F5: Waveform Select ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=5| -&lt;br /&gt;
|colspan=3| Waveform&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 0-2: WaveForm Select (WS): &amp;lt;gallery widths=261px perrow=4&amp;gt;&lt;br /&gt;
Image:OPL_Wave0.png|Waveform 0: Sine&lt;br /&gt;
Image:OPL_Wave1.png|Waveform 1: Half-sine&lt;br /&gt;
Image:OPL_Wave2.png|Waveform 2: Abs-sine&lt;br /&gt;
Image:OPL_Wave3.png|Waveform 3: Pulse-sine&lt;br /&gt;
Image:OPL_Wave4.png|Waveform 4: Sine - even periods only&lt;br /&gt;
Image:OPL_Wave5.png|Waveform 5: Abs-sine - even periods only&lt;br /&gt;
Image:OPL_Wave6.png|Waveform 6: Square&lt;br /&gt;
Image:OPL_Wave7.png|Waveform 7: Derived square&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* NOTE: Bit 5 of register 01 must be set to use waveforms other than sine. Waveforms 4-7 are available only on OPL3. See files WAVEn.GIF for real waveforms, where n is a number between 0 and 7.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
These examples show a few working routines used in my MUS Player. They are written in Borland C++ 3.1 but should be easy to translate to any other language.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
// I prefer using these Assembler-like types&lt;br /&gt;
typedef unsigned int  WORD;&lt;br /&gt;
typedef unsigned char BYTE;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * FM Synthesizer base port. SB Pro II - 0x220, Adlib 0x388&lt;br /&gt;
 */&lt;br /&gt;
WORD FMport = 0x220;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Enables OPL3 extensions.&lt;br /&gt;
 */&lt;br /&gt;
WORD OPL3 = 1;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Direct write to any Adlib/SB Pro II FM synthetiser register.&lt;br /&gt;
 *   reg - register number (range 0x001-0x0F5 and 0x101-0x1F5). When high byte&lt;br /&gt;
 *         of reg is zero, data go to port FMport, otherwise to FMport+2&lt;br /&gt;
 *   data - register value to be written&lt;br /&gt;
 */&lt;br /&gt;
BYTE FMwriteReg(WORD reg, BYTE data)&lt;br /&gt;
{&lt;br /&gt;
    asm {&lt;br /&gt;
	mov	dx,FMport&lt;br /&gt;
	mov	ax,reg&lt;br /&gt;
	or	ah,ah		// high byte is nonzero -- write to port base+2&lt;br /&gt;
	jz	out1&lt;br /&gt;
	inc	dx&lt;br /&gt;
	inc	dx&lt;br /&gt;
    }&lt;br /&gt;
out1: asm {&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	mov	cx,6&lt;br /&gt;
    }&lt;br /&gt;
loop1:asm {			// delay between writes&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop1&lt;br /&gt;
&lt;br /&gt;
	inc	dx&lt;br /&gt;
	mov	al,data&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	dec	dx&lt;br /&gt;
	mov	cx,36&lt;br /&gt;
    }&lt;br /&gt;
loop2:asm {			// delay after data write&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop2&lt;br /&gt;
    }&lt;br /&gt;
    return _AL;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to an operator pair. To be used for register bases of 0x20, 0x40,&lt;br /&gt;
 * 0x60, 0x80 and 0xE0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteChannel(BYTE regbase, BYTE channel, BYTE data1, BYTE data2)&lt;br /&gt;
{&lt;br /&gt;
    static BYTE adlib_op[] = {0, 1, 2, 8, 9, 10, 16, 17, 18};&lt;br /&gt;
    static BYTE sbpro_op[] = { 0,  1,  2,   6,  7,  8,  12, 13, 14,&lt;br /&gt;
			      18, 19, 20,  24, 25, 26,  30, 31, 32};&lt;br /&gt;
    static WORD rg[] = {0x000,0x001,0x002,0x003,0x004,0x005,&lt;br /&gt;
			0x008,0x009,0x00A,0x00B,0x00C,0x00D,&lt;br /&gt;
			0x010,0x011,0x012,0x013,0x014,0x015,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,&lt;br /&gt;
			0x108,0x109,0x10A,0x10B,0x10C,0x10D,&lt;br /&gt;
			0x110,0x111,0x112,0x113,0x114,0x115};&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
    {&lt;br /&gt;
	register WORD reg = sbpro_op[channel];&lt;br /&gt;
	FMwriteReg(rg[reg]+regbase, data1);&lt;br /&gt;
	FMwriteReg(rg[reg+3]+regbase, data2);&lt;br /&gt;
    } else {&lt;br /&gt;
	register WORD reg = regbase+adlib_op[channel];&lt;br /&gt;
	FMwriteReg(reg, data1);&lt;br /&gt;
	FMwriteReg(reg+3, data2);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to channel a single value. To be used for register bases of&lt;br /&gt;
 * 0xA0, 0xB0 and 0xC0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteValue(BYTE regbase, BYTE channel, BYTE value)&lt;br /&gt;
{&lt;br /&gt;
    static WORD ch[] = {0x000,0x001,0x002,0x003,0x004,0x005,0x006,0x007,0x008,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,0x106,0x107,0x108};&lt;br /&gt;
    register WORD chan;&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
	chan = ch[channel];&lt;br /&gt;
    else&lt;br /&gt;
	chan = channel;&lt;br /&gt;
    FMwriteReg(regbase + chan, value);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Detection Methods ==&lt;br /&gt;
&lt;br /&gt;
An official method of Adlib (OPL2) detection is:&lt;br /&gt;
&lt;br /&gt;
# Reset Timer 1 and Timer 2: write 60h to register 4.&lt;br /&gt;
# Reset the IRQ: write 80h to register 4.&lt;br /&gt;
#* NOTE: Steps 1 and 2 can&#039;t be combined together.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Set Timer 1 to FFh: write FFh to register 2.&lt;br /&gt;
# Unmask and start Timer 1: write 21h to register 4.&lt;br /&gt;
# Wait in a delay loop for at least 80 µsec.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Reset Timer 1, Timer 2 and IRQ as in steps 1 and 2.&lt;br /&gt;
# Test the results of the two reads: the first should be 0, the second should be C0h. If either is incorrect, then the OPL2 is not present.&lt;br /&gt;
&lt;br /&gt;
* NOTE1: You should AND the result bytes with E0h because the unused bits are undefined.&lt;br /&gt;
* NOTE2: This testing method doesn&#039;t work in some SoundBlaster compatible cards.&lt;br /&gt;
&lt;br /&gt;
=== OPL3 Detection ===&lt;br /&gt;
--------------&lt;br /&gt;
&lt;br /&gt;
# Detect OPL2. If present, continue.&lt;br /&gt;
# Read status register: read port base+0.&lt;br /&gt;
# AND the result with 06h.&lt;br /&gt;
# If the result is zero, you have OPL3, otherwise OPL2.&lt;br /&gt;
&lt;br /&gt;
* NOTE: This is NOT an official method. I have dug it out of a sound driver. I haven&#039;t tested it, because I haven&#039;t an OPL2 card (Adlib, SB Pro I). Nevertheless it &amp;quot;detects&amp;quot; my SB Pro II properly. ;-)&lt;br /&gt;
&lt;br /&gt;
Another possible detection method for distinguishing between SB Pro I and SB Pro II would be to try to detect OPL2 at I/O port base+0 and then at port base+2. The first test should succeed and the second should fail if OPL3 is present. (Remember: SB Pro I contains twin OPL2 chips at addresses base+0 and base+2, while SB Pro II contains one OPL3 chip at I/O address base+0 thru base+3).&lt;br /&gt;
&lt;br /&gt;
== BLASTER Environment Variable ==&lt;br /&gt;
&lt;br /&gt;
Perhaps the most recommended &amp;quot;detection&amp;quot; method. Reading this variable avoids blindfold I/O port scanning and possible device conflicts. The user is responsible for its proper setting.&lt;br /&gt;
&lt;br /&gt;
The variable has this format:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=Aaddr Iirq Ddma Ttype&lt;br /&gt;
&lt;br /&gt;
* A: Base I/O address given in hex. For most Sound Blasters the default is 220.&lt;br /&gt;
* I: IRQ Number (decimal). Default 7.&lt;br /&gt;
* D: DMA Number (decimal). Default 1.&lt;br /&gt;
* T: Card Type (decimal):&lt;br /&gt;
** 1 - Sound Blaster 1.5&lt;br /&gt;
** 2 - Sound Blaster Pro I&lt;br /&gt;
** 3 - Sound Blaster 2.0&lt;br /&gt;
** 4 - Sound Blaster Pro II&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=A220 I7 D1 T4&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The PC Games Programmers Encyclopedia&#039;&#039;, Mark Feldman and many others on Usenet and Internet, ftp://teeri.oulu.fi/pub/msdos/programming/gpe&lt;br /&gt;
: ... you can find (almost) everything you need there&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Sound Blaster - The Official Book&#039;&#039;, Richard Heimlich, David M. Golden, Ivan Luk, Peter M. Ridge, Osborne/McGraw Hill, ISBN 0-07-881907-5&lt;br /&gt;
: ... this is a number-one in my book-wishlist. If anyone wanted to get rid of the book, I wouldn&#039;t scorn it ... :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The SoundBlaster Developer Kit&#039;&#039;, Creative Labs Inc, Creative Technology PTE LTD&lt;br /&gt;
: ... I wonder if you can find something comprehensible in that.&lt;/div&gt;</summary>
		<author><name>Kermes</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4322</id>
		<title>OPL chip</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4322"/>
		<updated>2012-08-03T19:01:24Z</updated>

		<summary type="html">&lt;p&gt;Kermes: /* 01: Test Register / Waveform Select Enable */ OPL3 does not implement Waveform Select bit, explain operation.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Programmer&#039;s Guide to Yamaha YMF 262/OPL3 FM Music Synthesizer =&lt;br /&gt;
Version 1.00  Nov-24-1994&lt;br /&gt;
&lt;br /&gt;
Written by Vladimir Arnost, QA-Software&lt;br /&gt;
Internet:  xarnos00@dcse.fee.vutbr.cz&lt;br /&gt;
&lt;br /&gt;
This manual can be distributed freely if not modified.&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer ===&lt;br /&gt;
&lt;br /&gt;
I assume no responsibility for any damages arising out of use or inability to use this text. No warranty is provided about correctness of any information in this file. You are on your own.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The chip I am going to describe is getting more and more common, but programming information is still scarce, so I have decided to fill in this gap. All information contained in this file is a result of my experience in Adlib programming, research (read: reverse engineering) and finally of my effort to write down everything necessary to understand and use this piece of hardware. No official sources (i.e. development kits, books about this topic, etc.) were available to me except:&lt;br /&gt;
&lt;br /&gt;
: Adlib Programming Guide - by Tero Töttö, and&lt;br /&gt;
: The PC Games Programmers Encyclopedia V1.0&lt;br /&gt;
&lt;br /&gt;
The information below is a combination of known features of Adlib (alias Yamaha YM 3812/OPL2) and my own uncountable experiments and failures, which brought out a lot of important details you have to know about the chip.&lt;br /&gt;
&lt;br /&gt;
As far as I know, there are four major sound cards based on OPL3 chip:&lt;br /&gt;
&lt;br /&gt;
* Sound Blaster Pro II (not Sound Blaster Pro I)&lt;br /&gt;
* Sound Blaster 16&lt;br /&gt;
* Adlib Gold&lt;br /&gt;
* Pro Audio Spectrum Plus/16&lt;br /&gt;
&lt;br /&gt;
I currently have a Sound Blaster Pro II-compatible card only, so all the programming info I provide will be based on this card. (The other cards are quite similar, however. They are just wired at different I/O-port addresses.)&lt;br /&gt;
&lt;br /&gt;
Note: I assume some knowledge of FM music programming (mainly Adlib FM synthesizer) in this manual. If you are new to this topic I recommend you try Adlib first before going higher. Anyway, OPL3 is a direct descendant of OPL2 (what a surprise), so most features of OPL2 are also present on OPL3.&lt;br /&gt;
&lt;br /&gt;
== Description of the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
My card&#039;s user manual says: &amp;quot;[this card contains] ... a stereo music FM synthesizer with 20 channels consisting of four (4) operators each ... &amp;quot; I thought: &amp;quot;Wow -- that&#039;s together eighty operators. This must be a GOOD sound-card.&amp;quot; I was wrong. Just another advertising lie.&lt;br /&gt;
&lt;br /&gt;
So let&#039;s clear some facts. First, OPL3 has only thirty-six (36) operators which can be combined in several ways:&lt;br /&gt;
&lt;br /&gt;
* 18 FM channels (36 operators), or&lt;br /&gt;
* 15 FM channels (30 ops) and 5 percussion instruments (6 ops), giving us 20 channels altogether, or&lt;br /&gt;
* up to 6 four-operator FM channels (max 24 ops), the rest again being divided into two-operator FM channels and drums.&lt;br /&gt;
&lt;br /&gt;
From the table above you can see that not all channels can be used in four-operator (4-OP) mode -- only a part of the synthesizer is really capable of making 4-OP sounds -- the rest uses traditional two-operator (2-OP) mode.&lt;br /&gt;
&lt;br /&gt;
Second, the manual states this card is capable of &amp;quot;stereo&amp;quot; music. Yes, the quotes are necessary, because the stereo capabilities are very limited. You are given ability to control output going to left or right channel by turning it on and off. That&#039;s all. So the sound can flow from very left side, center and very right side. No sound panning, no special stereo effects. :-(&lt;br /&gt;
&lt;br /&gt;
Well, flaming apart, back to the main topic.&lt;br /&gt;
&lt;br /&gt;
The OPL3 chip is capable of making sounds in several ways:&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Additive Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output of both operators is simply added. It is the simplest way to make any sound, and it works on both OPL2 and OPL3. The diagram should make it clear.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐&lt;br /&gt;
	│            │&lt;br /&gt;
	│ Operator 1 ├────────┐&lt;br /&gt;
	│            │        │&lt;br /&gt;
	└────────────┘        │&lt;br /&gt;
			      ├────────&amp;gt; Output&lt;br /&gt;
	┌────────────┐        │&lt;br /&gt;
	│            │        │&lt;br /&gt;
	│ Operator 2 ├────────┘&lt;br /&gt;
	│            │&lt;br /&gt;
	└────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Frequency Modulation (FM) Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output from the first operator (Modulator) is sent to the input of the second one (Carrier) and is used to modulate (alter) frequency of the second operator. Only the second operator produces sound. Most of interesting sounds are made this way. This also works on OPL2. Hope the picture helps.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐         ┌────────────┐&lt;br /&gt;
	│            │         │            │&lt;br /&gt;
	│ Operator 1 ├────────&amp;gt;│ Operator 2 ├────────&amp;gt; Output&lt;br /&gt;
	│(Modulator) │         │ (Carrier)  │&lt;br /&gt;
	└────────────┘         └────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Four-operator &amp;quot;Mess&amp;quot; Modulation Synthesis ===&lt;br /&gt;
&lt;br /&gt;
All of OPL3&#039;s 4-OP configurations are combinations of the above two modes of synthesis. OPL3 combines these two modes in four ways. I have no words to describe these four ways. Only the pictures can show their principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   a) FM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   b) AM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├───────────────────────────────────┐&lt;br /&gt;
	│       │                                   │&lt;br /&gt;
	└───────┘                                   │&lt;br /&gt;
						    │&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┴─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   c) FM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────┐&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     ├─────&amp;gt; Output&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┘&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	└───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   d) AM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├────────────────────┐&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	└───────┘                    │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────┼─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐                    │&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	│ Op. 4 ├────────────────────┘&lt;br /&gt;
	│       │&lt;br /&gt;
	└───────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Nice, aren&#039;t they?&lt;br /&gt;
&lt;br /&gt;
The only way I think this can be written is a math formula. Symbol + (plus) means additive synthesis, and * (asterisk) means frequency modulation (Op1 * Op2 means operator 1 modulates operator 2, not vice versa). Here they are:&lt;br /&gt;
&lt;br /&gt;
# FM-FM Mode:	 (Op1 * Op2 * Op3 * Op4) ────&amp;gt; Output&lt;br /&gt;
# AM-FM Mode:	  Op1 + (Op2 * Op3 * Op4) ───&amp;gt; Output&lt;br /&gt;
# FM-AM Mode:	 (Op1 * Op2) + (Op3 * Op4) ──&amp;gt; Output&lt;br /&gt;
# AM-AM Mode:	  Op1 + (Op2 * Op3) + Op4 ───&amp;gt; Output&lt;br /&gt;
&lt;br /&gt;
=== Percussion Mode ===&lt;br /&gt;
&lt;br /&gt;
In this mode 6 operators are used to produce five different percussion instruments:&lt;br /&gt;
&lt;br /&gt;
* Bass Drum (2 operators)&lt;br /&gt;
* Snare Drum (1 operator)&lt;br /&gt;
* Tom-Tom (1 operator)&lt;br /&gt;
* Cymbal (1 operator)&lt;br /&gt;
* Hi-Hat (1 operator)&lt;br /&gt;
&lt;br /&gt;
Because these instruments occupy only three melodic channels, only Bass Drum, Snare Drum and Tom-Tom frequencies can be set. Cymbal and Hi-Hat frequencies are fixed.  {{TODO|It seems it&#039;s actually the cymbal and snare frequencies that are fixed, try to confirm this -- [[User:Malvineous|Malvineous]] 13:34, 3 June 2012 (GMT)}}&lt;br /&gt;
&lt;br /&gt;
This mode is identical with that of OPL2. For more details see ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
== Programming the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
OPL3 may be found at the following addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| Sound Blaster Pro II || 220h or 240h (selectable), also 388h&lt;br /&gt;
|-&lt;br /&gt;
| Adlib Gold || 388h&lt;br /&gt;
|-&lt;br /&gt;
| Pro Audio Spectrum Plus/16 || ? (if you have a PAS you should know it)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The base address of the synthesizer will be called &amp;quot;base&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The chip occupies four I/O addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| base+0 || Primary index register (write), Status register (read)&lt;br /&gt;
|-&lt;br /&gt;
| base+1 || Primary data register (write-only)&lt;br /&gt;
|-&lt;br /&gt;
| base+2 || Secondary index register (write)&lt;br /&gt;
|-&lt;br /&gt;
| base+3 || Secondary data register (write-only)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The index registers are used to select internal registers and data registers are used to write to them. Status register returns the state of two timers built in the chip.&lt;br /&gt;
&lt;br /&gt;
OPL3 contains two sets of registers. The Primary set maps to channels 0-8 (operators 0-17) and the secondary maps to channels 9-17 (operators 18-35). The reason for this is simple: all these registers wouldn&#039;t fit into single register set.&lt;br /&gt;
&lt;br /&gt;
Unlike Adlib (OPL2), OPL3 doesn&#039;t need delay between register writes. With OPL2 you had to wait 3.3 µs after index register write and another 23 µs after data register write. On the contrary OPL3 doesn&#039;t need (almost) any delay after index register write and only 0.28 µs after data register write. This means you can neglect the delays and slightly speed up your music driver. But using reasonable delays will certainly do no harm.&lt;br /&gt;
&lt;br /&gt;
The data registers can&#039;t be read (they are write-only) on both OPL2 and OPL3.&lt;br /&gt;
&lt;br /&gt;
== Register Map ==&lt;br /&gt;
&lt;br /&gt;
The registers are grouped in the same manner as in the OPL2 chip. Programs using both OPL2 and OPL3 chips may use the same code provided that their direct I/O interface is well written. The only thing you have to change is operator-to-register mapping, which must accomodate the fact that registers are spread between two register sets.&lt;br /&gt;
&lt;br /&gt;
(The register map is nearly the same so I dared to copy it from ADLIB.DOC.)&lt;br /&gt;
&lt;br /&gt;
=== Status Register (base+0) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
!    D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQFlag || T1Flag || T2Flag ||        ||        ||        ||        ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Data Registers (base+1, base+3) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! REG   !!   D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| 01    ||colspan=2|        ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|WSEnable||colspan=5| Test Register&lt;br /&gt;
|-&lt;br /&gt;
| 02    ||colspan=8| Timer 1 Count (80 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 03    ||colspan=8| Timer 2 Count (320 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 04*   ||IRQReset|| T1Mask || T2Mask ||colspan=3|                  ||T2 Start||T1 Start&lt;br /&gt;
|-&lt;br /&gt;
| 04**  ||colspan=2|        ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP B-E||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP A-D||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 9-C||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 2-5||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 1-4||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 0-3&lt;br /&gt;
|-&lt;br /&gt;
| 05**  ||colspan=7|                                                           ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;| OPL3&lt;br /&gt;
|-&lt;br /&gt;
| 08    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|  CSW   ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|NOTE-SEL||colspan=6|&lt;br /&gt;
|-&lt;br /&gt;
| 20-35 ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Tremolo ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Vibrato ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Sustain ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|  KSR   ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Frequency Multiplication Factor&lt;br /&gt;
|-&lt;br /&gt;
| 40-55 ||colspan=2 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Key Scale Level ||colspan=6 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 60-75 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Attack Rate ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 80-95 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Sustain Level ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A0-A8 ||colspan=8 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Frequency Number  (Lower 8 bits)&lt;br /&gt;
|-&lt;br /&gt;
| B0-B8 ||colspan=2|        ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| KEY-ON ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Block Number ||colspan=2 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| F-Num (hi bits)&lt;br /&gt;
|-&lt;br /&gt;
| BD    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Trem Dep||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Vibr Dep||style=&amp;quot;background-color: #FFCCDD;&amp;quot;|PercMode||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| BD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| SD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| TT On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| CY On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| HH On&lt;br /&gt;
|-&lt;br /&gt;
| C0-C8 ||colspan=2|        ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Right  ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Left   ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;|FeedBack Modulation Factor||style=&amp;quot;background-color: #FFE0CC;&amp;quot;|SynthTyp&lt;br /&gt;
|-&lt;br /&gt;
| E0-F5 ||colspan=5|                                      ||colspan=3 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|style=&amp;quot;background-color: #CCFFCC;&amp;quot;| Chip-wide setting&lt;br /&gt;
|style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Per operator&lt;br /&gt;
|style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Per channel&lt;br /&gt;
|style=&amp;quot;background-color: #FFCCDD;&amp;quot;| Rhythm-mode only&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt; This applies only to port base+1&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;**&amp;lt;/nowiki&amp;gt; This applies only to port base+3&lt;br /&gt;
&lt;br /&gt;
For register bases A0, B0 and C0 there is one register per output channel. The primary register set holds the first nine channels (0-8) and the secondary holds last nine channels (9-17). For bases 20, 40, 60, 80 and E0 there are two registers per channel. Each register maps to one operator. Unfortunately the operator&#039;s register numbers are not continuous. The following table shows which operator maps to which register set and offset (in hex).&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Op. !! Set/Offset !! Op. !! Set/Offset&lt;br /&gt;
|-&lt;br /&gt;
| 0  || 0/00 || 18 || 1/00&lt;br /&gt;
|-&lt;br /&gt;
| 1  || 0/01 || 19 || 1/01&lt;br /&gt;
|-&lt;br /&gt;
| 2  || 0/02 || 20 || 1/02&lt;br /&gt;
|-&lt;br /&gt;
| 3  || 0/03 || 21 || 1/03&lt;br /&gt;
|-&lt;br /&gt;
| 4  || 0/04 || 22 || 1/04&lt;br /&gt;
|-&lt;br /&gt;
| 5  || 0/05 || 23 || 1/05&lt;br /&gt;
|-&lt;br /&gt;
| 6  || 0/08 || 24 || 1/08&lt;br /&gt;
|-&lt;br /&gt;
| 7  || 0/09 || 25 || 1/09&lt;br /&gt;
|-&lt;br /&gt;
| 8  || 0/0A || 26 || 1/0A&lt;br /&gt;
|-&lt;br /&gt;
| 9  || 0/0B || 27 || 1/0B&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 0/0C || 28 || 1/0C&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 0/0D || 29 || 1/0D&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 0/10 || 30 || 1/10&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 0/11 || 31 || 1/11&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 0/12 || 32 || 1/12&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 0/13 || 33 || 1/13&lt;br /&gt;
|-&lt;br /&gt;
| 16 || 0/14 || 34 || 1/14&lt;br /&gt;
|-&lt;br /&gt;
| 17 || 0/15 || 35 || 1/15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following tables summarize which operators form a channel in various modes:&lt;br /&gt;
&lt;br /&gt;
1. Two-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel    !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 13 || 14 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 || 16 || 17 || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
2. Two-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 ||colspan=4| - || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
3. Four-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 13 || 14 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 || 16 || 17 || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=3| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=3| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Channels 3, 4, 5 and 12, 13, 14 can&#039;t be used separately because their operators became part of channels 0, 1, 2 and 9, 10, 11 respectively. For instance a four-operator channel 1 consists of two two-operator channels number 1 and 4. (The second 2-OP channel number is always the first 2-OP channel number plus three.)&lt;br /&gt;
&lt;br /&gt;
OPL3 allows you to enable/disable 4-OP mode separately for any of channels 0, 1, 2, 9, 10 and 11 (see register 104h in the reference below). This means for instance when you switch only channel 2 into 4-OP mode, channels number 0, 1, 3, 4, 6, 7, 8, 9, etc. will be still independent 2-OP channels.&lt;br /&gt;
&lt;br /&gt;
Channels 6, 7, 8 and 15, 16, 17 are always two-operator ones. They can&#039;t be grouped to form four-operator channels.&lt;br /&gt;
&lt;br /&gt;
4. Four-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 ||colspan=4| - || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=5| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=5| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
Two-operator channel #14 consists of operators 26 and 29 which occupy these registers (all are in the secondary register set):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| 12A || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 12D || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 14A || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 14D || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 16A || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 16D || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18A || Operator 1 ||Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18D || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 1A5 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| 1B5 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| 1C5 ||            || FeedBack/Synthesis Type&lt;br /&gt;
|-&lt;br /&gt;
| 1EA || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| 1ED || Operator 2 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Four-operator channel #1 consists of operators 1, 4, 7 and 10. All registers except register 104h are in the primary set:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 104 || bit 1 = 1  || Enable Four-Operator Synthesis in channel #1&lt;br /&gt;
|-&lt;br /&gt;
| 21 || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 24 || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 29 || Operator 3 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 2C || Operator 4 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 41 || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 44 || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 49 || Operator 3 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 4C || Operator 4 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 61 || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 64 || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 69 || Operator 3 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 6C || Operator 4 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 81 || Operator 1 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 84 || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 89 || Operator 3 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 8C || Operator 4 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A1 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| A4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| B1 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| B4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| C1 ||            || FeedBack/Synthesis Type (part 1)&lt;br /&gt;
|-&lt;br /&gt;
| C4 ||            || Synthesis Type (part 2)&lt;br /&gt;
|-&lt;br /&gt;
| E1 || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E4 || Operator 2 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E9 || Operator 3 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| EC || Operator 4 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
NOTE: If a register number is greater than 100h, then it belongs into the secondary register set. (I use this numbering to emphasize the fact that the particular register MUST be written to the secondary set.) See the example code below for details.&lt;br /&gt;
&lt;br /&gt;
== OPL3 Register Reference ==&lt;br /&gt;
&lt;br /&gt;
Because the registers of OPL3 are almost the same as of OPL2, I have copied their descriptions from file ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
=== Status Register ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQ || T1 || T2 ||colspan=5| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ Flag. Set whenever any timer has elapsed.&lt;br /&gt;
* bit 6: Timer 1 Flag. Set every time the preset time in Timer 1 has elapsed.&lt;br /&gt;
* bit 5: Timer 2 Flag. Set every time the preset time in Timer 2 has elapsed.&lt;br /&gt;
&lt;br /&gt;
Timer interrupts are not wired to any IRQ (why??). The timers can be used to detect the OPL2/OPL3 chip (see Appendix B).&lt;br /&gt;
&lt;br /&gt;
=== Data Registers ===&lt;br /&gt;
&lt;br /&gt;
==== 01: Test Register / Waveform Select Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| Test Register&lt;br /&gt;
| (WSE)&lt;br /&gt;
|colspan=5| Test Register&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 7-6: Test Register. Must be reset to zero before any operation.&lt;br /&gt;
* bit 5: Waveform Select Enable. If clear, all channels will use normal sine wave. If set, register E0-F5 (Waveform Select) contents will be used.&lt;br /&gt;
* bits 0-4: Test Register. Must be reset to zero before any operation.&lt;br /&gt;
&lt;br /&gt;
OPL3 does not implement WSE bit, and it should be left clear. In OPL2 mode all four waveforms are always available, and in OPL3 mode all eight waveforms are always available. For compatibility with OPL2, when a program is finished using an OPL3, the waveform select registers should be set to 0, if the next program assumes that by setting WSE bit to 0 the waveform is always sine like on a real OPL2.&lt;br /&gt;
&lt;br /&gt;
==== 02: Timer 1 Count ====&lt;br /&gt;
&lt;br /&gt;
Upward 8 bit counter with a resolution of 80 µsec. If an overflow occurs, the status register bit is set, and the preset value is loaded into the timer again.&lt;br /&gt;
&lt;br /&gt;
==== 03: Timer 2 Count ====&lt;br /&gt;
&lt;br /&gt;
Same as Timer 1, but with a resolution of 320 µsec.&lt;br /&gt;
&lt;br /&gt;
==== 004 (port: base+1): IRQ-Reset / Mask / Start ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Rst&lt;br /&gt;
| T1M&lt;br /&gt;
| T2M&lt;br /&gt;
|colspan=3| -&lt;br /&gt;
| T2S&lt;br /&gt;
| T1S&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ-Reset. Resets timer and IRQ flags in status register. All other bits are ignored when this bit is set.&lt;br /&gt;
* bit 6: Timer 1 Mask. If 1, status register is not affected in overflow.&lt;br /&gt;
* bit 5: Timer 2 Mask. Same as above.&lt;br /&gt;
* bit 1: Timer 2 Start. Timer on/off.&lt;br /&gt;
* bit 0: Timer 1 Start. Same as above.&lt;br /&gt;
&lt;br /&gt;
==== 104 (port: base+3): Four-Operator Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| ChB&lt;br /&gt;
| ChA&lt;br /&gt;
| Ch9&lt;br /&gt;
| Ch2&lt;br /&gt;
| Ch1&lt;br /&gt;
| Ch0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: Enable four-operator synthesis for channel pair 11 - 14 (decimal).&lt;br /&gt;
* bit 4: Same as above for channel pair 10 - 13.&lt;br /&gt;
* bit 3: Same as above for channel pair 9 - 12.&lt;br /&gt;
* bit 2: Same as above for channel pair 2 - 5.&lt;br /&gt;
* bit 1: Same as above for channel pair 1 - 4.&lt;br /&gt;
* bit 0: Same as above for channel pair 0 - 3.&lt;br /&gt;
&lt;br /&gt;
If reset to zero, OPL3 can produce 18 two-operator sounds at a time. If nonzero, OPL3 produces four-operator sound in appropriate channel pair.&lt;br /&gt;
&lt;br /&gt;
==== 105 (port: base+3): OPL3 Mode Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=7| -&lt;br /&gt;
| OPL3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 0: OPL3 Mode Enable. When set, OPL3 extensions (36 operators, 4-OP synthesis, 8 waveforms, stereo output) can be used. When reset, the chip behaves as an ordinary OPL2. This bit is zero by default for compatibility with OPL2.&lt;br /&gt;
&lt;br /&gt;
==== 08: CSW / NOTE-SEL ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| (CSW)&lt;br /&gt;
| N-S&lt;br /&gt;
|colspan=6| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: Composite sine wave mode on/off. All KEY-ON bits must be clear in order to use this mode. The card is unable to create any other sound when in CSW mode. (Unfortunately, I have no info how to use this mode :-&amp;lt; ). The CSW mode is not implemented on an OPL3 and this bit is ignored.&lt;br /&gt;
* bit 6: NOTE-SEL. Controls the split point of the keyboard. When 0, the keyboard split is the second bit from the bit 8 of the F-Number. When 1, the MSb of the F-Number is used. (???)&lt;br /&gt;
&lt;br /&gt;
==== 20-35: Tremolo / Vibrato / Sustain / KSR / Frequency Multiplication Factor ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Sus&lt;br /&gt;
| KSR&lt;br /&gt;
|colspan=4| Multiplication&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude vibrato) on/off.&lt;br /&gt;
* bit 6:    Frequency vibrato on/off.&lt;br /&gt;
* bit 5:    Sound Sustaining. When 1, operator&#039;s output level will be held at its sustain level until a KEY-OFF is done.&lt;br /&gt;
* bit 4:    Envelope scaling (KSR) on/off. When 1, higher notes are shorter than lower notes.&lt;br /&gt;
* bits 0-3: Frequency Multiplication Factor (MULTI). Operator&#039;s frequency is set to (see registers A0, B0) F-Number * Factor.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! MULTI !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0.5&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 2&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 3&lt;br /&gt;
|-&lt;br /&gt;
| 4 || 4&lt;br /&gt;
|-&lt;br /&gt;
| 5 || 5&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 6&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 7&lt;br /&gt;
|-&lt;br /&gt;
| 8 || 8&lt;br /&gt;
|-&lt;br /&gt;
| 9 || 9&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 40-55: Key Scale Level / Output Level ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| KSL&lt;br /&gt;
|colspan=6| Output level&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 6-7: Key Scale Level. Attenuates output level towards higher pitch:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! KSL !! Attenuation&lt;br /&gt;
|-&lt;br /&gt;
| 0 || -&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 3.0 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 1.5 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 6.0 dB/oct&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The attenuation level is based on the 3-bit octave (block number) value and top four bits of the FNUM value, so each octave is subdivided into 16 parts.&lt;br /&gt;
&lt;br /&gt;
* bits 0-5: Output Level. Attenuates the operator output level. 0 is the loudest, 3F is the softest. In additive synthesis, varying the output level of any operator varies the volume of its corresponding channel. In FM synthesis, varying the output level of the carrier varies the volume of the channel. Varying the output of the modulator will change the frequency spectrum produced by the carrier. The following table summarizes which operators&#039; output levels should be updated when trying to change channel output level.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Mode !! Op 1 !! Op 2 !! Op 3 !! Op 4&lt;br /&gt;
|-&lt;br /&gt;
| AM    || Y || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM    || - || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM-FM || - || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-FM || Y || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| FM-AM || - || Y || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-AM || Y || - || Y   || Y&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 60-75: Attack Rate / Decay Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Attack rate&lt;br /&gt;
|colspan=4| Decay rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Attack Rate. Determines the rising time for the sound. The higher the value, the faster the attack.&lt;br /&gt;
* bits 0-3: Decay Rate. Determines the diminishing time for the sound. The higher the value, the shorter the decay.&lt;br /&gt;
&lt;br /&gt;
==== 80-95: Sustain Level / Release Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Sustain level&lt;br /&gt;
|colspan=4| Release rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Sustain Level. Determines the point at which the sound ceases to decay and chages to a sound having a constant level. The sustain level is expressed as a fraction of the maximum level. 0 is the softest and F is the loudest sustain level. Note that the Sustain-bit in the register 20-35 must be set for this to have an effect.&lt;br /&gt;
* bits 0-3: Release Rate. Determines the rate at which the sound disappears after KEY-OFF. The higher the value, the shorter the release.&lt;br /&gt;
&lt;br /&gt;
==== A0-A8: Frequency Number ====&lt;br /&gt;
&lt;br /&gt;
Determines the pitch of the note. Highest bits of F-Number are stored in the register below.&lt;br /&gt;
&lt;br /&gt;
==== B0-B8: Key On / Block Number / F-Number(hi bits) ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| KEY&lt;br /&gt;
|colspan=3| Block num.&lt;br /&gt;
|colspan=2| Freq&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: KEY-ON. When 1, channel output is enabled.&lt;br /&gt;
* bits 2-4: Block Number. Roughly determines the octave.&lt;br /&gt;
* bits 0-1: Frequency Number. 2 highest bits of the above register.  The following formula is used to determine F-Number and Block:&lt;br /&gt;
: F-Number = Music Frequency * 2^(20-Block) / 49716 Hz&lt;br /&gt;
&lt;br /&gt;
NOTE: In four-operator mode only the register value of Operators 1 and 2 is used, value of Operators 3 and 4 in this register is ignored. In other words: one channel uses only one frequency, block and KEY-ON value at a time, regardless whether it is a two- or four-operator channel.&lt;br /&gt;
&lt;br /&gt;
==== BD: Tremolo Depth / Vibrato Depth / Percussion Mode / BD/SD/TT/CY/HH On ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Per&lt;br /&gt;
| BD&lt;br /&gt;
| SD&lt;br /&gt;
| TT&lt;br /&gt;
| CY&lt;br /&gt;
| HH&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude Vibrato) Depth. 0 = 1.0dB, 1 = 4.8dB.&lt;br /&gt;
* bit 6:    Frequency Vibrato Depth. 0 = 7 cents, 1 = 14 cents. A &amp;quot;cent&amp;quot; is 1/100 of a semi-tone.&lt;br /&gt;
* bit 5:    Percussion Mode. 0 = Melodic Mode, 1 = Percussion Mode.&lt;br /&gt;
* bit 4:    BD On. KEY-ON of the Bass Drum channel.&lt;br /&gt;
* bit 3:    SD On. KEY-ON of the Snare Drum channel.&lt;br /&gt;
* bit 2:    TT On. KEY-ON of the Tom-Tom channel.&lt;br /&gt;
* bit 1:    CY On. KEY-ON of the Cymbal channel.&lt;br /&gt;
* bit 0:    HH On. KEY-ON of the Hi-Hat channel.&lt;br /&gt;
&lt;br /&gt;
NOTE: KEY-ON bits of channels 6, 7 and 8 must be clear and their F-Nums, Attack/Decay/Release rates, etc. must be set properly to use percussion mode.&lt;br /&gt;
&lt;br /&gt;
==== C0-C8: FeedBack Modulation Factor / Synthesis Type ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2|&lt;br /&gt;
| R&lt;br /&gt;
| L&lt;br /&gt;
|colspan=3| Feedback&lt;br /&gt;
| Syn&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5:    Right Speaker Enable. When set, channel output goes to right speaker.&lt;br /&gt;
* bit 4:    Left Speaker Enable. When set, channel output goes to left speaker. At least one of these bits must be set to hear the channel.&lt;br /&gt;
** These two bits can be used to realize sound &amp;quot;panning&amp;quot;, but this method offers only three pan positions (left/center/right).&lt;br /&gt;
** These bits apply only to operators producing sound (Carriers). Modulators are not affected by their setting.&lt;br /&gt;
* bits 1-3: FeedBack Modulation Factor. If 0, no feedback is present. If 1-7, operator 1 will send a portion of its output back into itself.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! FeedBack !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;amp;pi;/16&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;amp;pi;/8&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;amp;pi;/4&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;amp;pi;/2&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 2&amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 4&amp;amp;pi;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
When in four-operator mode, the FeedBack value is used only by Operator 1, value of Operators 2, 3 and 4 is ignored.&lt;br /&gt;
&lt;br /&gt;
* bit 0: Synthesis Type. 1 = Additive synthesis, 0 = Frequency Modulation.  In four-operator mode, there are two bits controlling the synthesis type. Both are the bit 0 of register C0, one of Operators 1 and 2 and the second of Operators 3 and 4.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Op 1&amp;amp;2 !! Op 3&amp;amp;4 !! Type&lt;br /&gt;
|-&lt;br /&gt;
| 0 || NONE || FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || NONE || AM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || FM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || AM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || FM-AM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || AM-AM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== E0-F5: Waveform Select ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=5| -&lt;br /&gt;
|colspan=3| Waveform&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 0-2: WaveForm Select (WS): &amp;lt;gallery widths=261px perrow=4&amp;gt;&lt;br /&gt;
Image:OPL_Wave0.png|Waveform 0: Sine&lt;br /&gt;
Image:OPL_Wave1.png|Waveform 1: Half-sine&lt;br /&gt;
Image:OPL_Wave2.png|Waveform 2: Abs-sine&lt;br /&gt;
Image:OPL_Wave3.png|Waveform 3: Pulse-sine&lt;br /&gt;
Image:OPL_Wave4.png|Waveform 4: Sine - even periods only&lt;br /&gt;
Image:OPL_Wave5.png|Waveform 5: Abs-sine - even periods only&lt;br /&gt;
Image:OPL_Wave6.png|Waveform 6: Square&lt;br /&gt;
Image:OPL_Wave7.png|Waveform 7: Derived square&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* NOTE: Bit 5 of register 01 must be set to use waveforms other than sine. Waveforms 4-7 are available only on OPL3. See files WAVEn.GIF for real waveforms, where n is a number between 0 and 7.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
These examples show a few working routines used in my MUS Player. They are written in Borland C++ 3.1 but should be easy to translate to any other language.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
// I prefer using these Assembler-like types&lt;br /&gt;
typedef unsigned int  WORD;&lt;br /&gt;
typedef unsigned char BYTE;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * FM Synthesizer base port. SB Pro II - 0x220, Adlib 0x388&lt;br /&gt;
 */&lt;br /&gt;
WORD FMport = 0x220;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Enables OPL3 extensions.&lt;br /&gt;
 */&lt;br /&gt;
WORD OPL3 = 1;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Direct write to any Adlib/SB Pro II FM synthetiser register.&lt;br /&gt;
 *   reg - register number (range 0x001-0x0F5 and 0x101-0x1F5). When high byte&lt;br /&gt;
 *         of reg is zero, data go to port FMport, otherwise to FMport+2&lt;br /&gt;
 *   data - register value to be written&lt;br /&gt;
 */&lt;br /&gt;
BYTE FMwriteReg(WORD reg, BYTE data)&lt;br /&gt;
{&lt;br /&gt;
    asm {&lt;br /&gt;
	mov	dx,FMport&lt;br /&gt;
	mov	ax,reg&lt;br /&gt;
	or	ah,ah		// high byte is nonzero -- write to port base+2&lt;br /&gt;
	jz	out1&lt;br /&gt;
	inc	dx&lt;br /&gt;
	inc	dx&lt;br /&gt;
    }&lt;br /&gt;
out1: asm {&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	mov	cx,6&lt;br /&gt;
    }&lt;br /&gt;
loop1:asm {			// delay between writes&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop1&lt;br /&gt;
&lt;br /&gt;
	inc	dx&lt;br /&gt;
	mov	al,data&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	dec	dx&lt;br /&gt;
	mov	cx,36&lt;br /&gt;
    }&lt;br /&gt;
loop2:asm {			// delay after data write&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop2&lt;br /&gt;
    }&lt;br /&gt;
    return _AL;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to an operator pair. To be used for register bases of 0x20, 0x40,&lt;br /&gt;
 * 0x60, 0x80 and 0xE0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteChannel(BYTE regbase, BYTE channel, BYTE data1, BYTE data2)&lt;br /&gt;
{&lt;br /&gt;
    static BYTE adlib_op[] = {0, 1, 2, 8, 9, 10, 16, 17, 18};&lt;br /&gt;
    static BYTE sbpro_op[] = { 0,  1,  2,   6,  7,  8,  12, 13, 14,&lt;br /&gt;
			      18, 19, 20,  24, 25, 26,  30, 31, 32};&lt;br /&gt;
    static WORD rg[] = {0x000,0x001,0x002,0x003,0x004,0x005,&lt;br /&gt;
			0x008,0x009,0x00A,0x00B,0x00C,0x00D,&lt;br /&gt;
			0x010,0x011,0x012,0x013,0x014,0x015,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,&lt;br /&gt;
			0x108,0x109,0x10A,0x10B,0x10C,0x10D,&lt;br /&gt;
			0x110,0x111,0x112,0x113,0x114,0x115};&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
    {&lt;br /&gt;
	register WORD reg = sbpro_op[channel];&lt;br /&gt;
	FMwriteReg(rg[reg]+regbase, data1);&lt;br /&gt;
	FMwriteReg(rg[reg+3]+regbase, data2);&lt;br /&gt;
    } else {&lt;br /&gt;
	register WORD reg = regbase+adlib_op[channel];&lt;br /&gt;
	FMwriteReg(reg, data1);&lt;br /&gt;
	FMwriteReg(reg+3, data2);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to channel a single value. To be used for register bases of&lt;br /&gt;
 * 0xA0, 0xB0 and 0xC0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteValue(BYTE regbase, BYTE channel, BYTE value)&lt;br /&gt;
{&lt;br /&gt;
    static WORD ch[] = {0x000,0x001,0x002,0x003,0x004,0x005,0x006,0x007,0x008,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,0x106,0x107,0x108};&lt;br /&gt;
    register WORD chan;&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
	chan = ch[channel];&lt;br /&gt;
    else&lt;br /&gt;
	chan = channel;&lt;br /&gt;
    FMwriteReg(regbase + chan, value);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Detection Methods ==&lt;br /&gt;
&lt;br /&gt;
An official method of Adlib (OPL2) detection is:&lt;br /&gt;
&lt;br /&gt;
# Reset Timer 1 and Timer 2: write 60h to register 4.&lt;br /&gt;
# Reset the IRQ: write 80h to register 4.&lt;br /&gt;
#* NOTE: Steps 1 and 2 can&#039;t be combined together.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Set Timer 1 to FFh: write FFh to register 2.&lt;br /&gt;
# Unmask and start Timer 1: write 21h to register 4.&lt;br /&gt;
# Wait in a delay loop for at least 80 µsec.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Reset Timer 1, Timer 2 and IRQ as in steps 1 and 2.&lt;br /&gt;
# Test the results of the two reads: the first should be 0, the second should be C0h. If either is incorrect, then the OPL2 is not present.&lt;br /&gt;
&lt;br /&gt;
* NOTE1: You should AND the result bytes with E0h because the unused bits are undefined.&lt;br /&gt;
* NOTE2: This testing method doesn&#039;t work in some SoundBlaster compatible cards.&lt;br /&gt;
&lt;br /&gt;
=== OPL3 Detection ===&lt;br /&gt;
--------------&lt;br /&gt;
&lt;br /&gt;
# Detect OPL2. If present, continue.&lt;br /&gt;
# Read status register: read port base+0.&lt;br /&gt;
# AND the result with 06h.&lt;br /&gt;
# If the result is zero, you have OPL3, otherwise OPL2.&lt;br /&gt;
&lt;br /&gt;
* NOTE: This is NOT an official method. I have dug it out of a sound driver. I haven&#039;t tested it, because I haven&#039;t an OPL2 card (Adlib, SB Pro I). Nevertheless it &amp;quot;detects&amp;quot; my SB Pro II properly. ;-)&lt;br /&gt;
&lt;br /&gt;
Another possible detection method for distinguishing between SB Pro I and SB Pro II would be to try to detect OPL2 at I/O port base+0 and then at port base+2. The first test should succeed and the second should fail if OPL3 is present. (Remember: SB Pro I contains twin OPL2 chips at addresses base+0 and base+2, while SB Pro II contains one OPL3 chip at I/O address base+0 thru base+3).&lt;br /&gt;
&lt;br /&gt;
== BLASTER Environment Variable ==&lt;br /&gt;
&lt;br /&gt;
Perhaps the most recommended &amp;quot;detection&amp;quot; method. Reading this variable avoids blindfold I/O port scanning and possible device conflicts. The user is responsible for its proper setting.&lt;br /&gt;
&lt;br /&gt;
The variable has this format:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=Aaddr Iirq Ddma Ttype&lt;br /&gt;
&lt;br /&gt;
* A: Base I/O address given in hex. For most Sound Blasters the default is 220.&lt;br /&gt;
* I: IRQ Number (decimal). Default 7.&lt;br /&gt;
* D: DMA Number (decimal). Default 1.&lt;br /&gt;
* T: Card Type (decimal):&lt;br /&gt;
** 1 - Sound Blaster 1.5&lt;br /&gt;
** 2 - Sound Blaster Pro I&lt;br /&gt;
** 3 - Sound Blaster 2.0&lt;br /&gt;
** 4 - Sound Blaster Pro II&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=A220 I7 D1 T4&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The PC Games Programmers Encyclopedia&#039;&#039;, Mark Feldman and many others on Usenet and Internet, ftp://teeri.oulu.fi/pub/msdos/programming/gpe&lt;br /&gt;
: ... you can find (almost) everything you need there&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Sound Blaster - The Official Book&#039;&#039;, Richard Heimlich, David M. Golden, Ivan Luk, Peter M. Ridge, Osborne/McGraw Hill, ISBN 0-07-881907-5&lt;br /&gt;
: ... this is a number-one in my book-wishlist. If anyone wanted to get rid of the book, I wouldn&#039;t scorn it ... :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The SoundBlaster Developer Kit&#039;&#039;, Creative Labs Inc, Creative Technology PTE LTD&lt;br /&gt;
: ... I wonder if you can find something comprehensible in that.&lt;/div&gt;</summary>
		<author><name>Kermes</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4321</id>
		<title>OPL chip</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4321"/>
		<updated>2012-08-03T18:37:47Z</updated>

		<summary type="html">&lt;p&gt;Kermes: /* 08: CSW / NOTE-SEL */ OPL3 does not implement Composite Sine Wave (CSW) mode.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Programmer&#039;s Guide to Yamaha YMF 262/OPL3 FM Music Synthesizer =&lt;br /&gt;
Version 1.00  Nov-24-1994&lt;br /&gt;
&lt;br /&gt;
Written by Vladimir Arnost, QA-Software&lt;br /&gt;
Internet:  xarnos00@dcse.fee.vutbr.cz&lt;br /&gt;
&lt;br /&gt;
This manual can be distributed freely if not modified.&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer ===&lt;br /&gt;
&lt;br /&gt;
I assume no responsibility for any damages arising out of use or inability to use this text. No warranty is provided about correctness of any information in this file. You are on your own.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The chip I am going to describe is getting more and more common, but programming information is still scarce, so I have decided to fill in this gap. All information contained in this file is a result of my experience in Adlib programming, research (read: reverse engineering) and finally of my effort to write down everything necessary to understand and use this piece of hardware. No official sources (i.e. development kits, books about this topic, etc.) were available to me except:&lt;br /&gt;
&lt;br /&gt;
: Adlib Programming Guide - by Tero Töttö, and&lt;br /&gt;
: The PC Games Programmers Encyclopedia V1.0&lt;br /&gt;
&lt;br /&gt;
The information below is a combination of known features of Adlib (alias Yamaha YM 3812/OPL2) and my own uncountable experiments and failures, which brought out a lot of important details you have to know about the chip.&lt;br /&gt;
&lt;br /&gt;
As far as I know, there are four major sound cards based on OPL3 chip:&lt;br /&gt;
&lt;br /&gt;
* Sound Blaster Pro II (not Sound Blaster Pro I)&lt;br /&gt;
* Sound Blaster 16&lt;br /&gt;
* Adlib Gold&lt;br /&gt;
* Pro Audio Spectrum Plus/16&lt;br /&gt;
&lt;br /&gt;
I currently have a Sound Blaster Pro II-compatible card only, so all the programming info I provide will be based on this card. (The other cards are quite similar, however. They are just wired at different I/O-port addresses.)&lt;br /&gt;
&lt;br /&gt;
Note: I assume some knowledge of FM music programming (mainly Adlib FM synthesizer) in this manual. If you are new to this topic I recommend you try Adlib first before going higher. Anyway, OPL3 is a direct descendant of OPL2 (what a surprise), so most features of OPL2 are also present on OPL3.&lt;br /&gt;
&lt;br /&gt;
== Description of the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
My card&#039;s user manual says: &amp;quot;[this card contains] ... a stereo music FM synthesizer with 20 channels consisting of four (4) operators each ... &amp;quot; I thought: &amp;quot;Wow -- that&#039;s together eighty operators. This must be a GOOD sound-card.&amp;quot; I was wrong. Just another advertising lie.&lt;br /&gt;
&lt;br /&gt;
So let&#039;s clear some facts. First, OPL3 has only thirty-six (36) operators which can be combined in several ways:&lt;br /&gt;
&lt;br /&gt;
* 18 FM channels (36 operators), or&lt;br /&gt;
* 15 FM channels (30 ops) and 5 percussion instruments (6 ops), giving us 20 channels altogether, or&lt;br /&gt;
* up to 6 four-operator FM channels (max 24 ops), the rest again being divided into two-operator FM channels and drums.&lt;br /&gt;
&lt;br /&gt;
From the table above you can see that not all channels can be used in four-operator (4-OP) mode -- only a part of the synthesizer is really capable of making 4-OP sounds -- the rest uses traditional two-operator (2-OP) mode.&lt;br /&gt;
&lt;br /&gt;
Second, the manual states this card is capable of &amp;quot;stereo&amp;quot; music. Yes, the quotes are necessary, because the stereo capabilities are very limited. You are given ability to control output going to left or right channel by turning it on and off. That&#039;s all. So the sound can flow from very left side, center and very right side. No sound panning, no special stereo effects. :-(&lt;br /&gt;
&lt;br /&gt;
Well, flaming apart, back to the main topic.&lt;br /&gt;
&lt;br /&gt;
The OPL3 chip is capable of making sounds in several ways:&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Additive Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output of both operators is simply added. It is the simplest way to make any sound, and it works on both OPL2 and OPL3. The diagram should make it clear.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐&lt;br /&gt;
	│            │&lt;br /&gt;
	│ Operator 1 ├────────┐&lt;br /&gt;
	│            │        │&lt;br /&gt;
	└────────────┘        │&lt;br /&gt;
			      ├────────&amp;gt; Output&lt;br /&gt;
	┌────────────┐        │&lt;br /&gt;
	│            │        │&lt;br /&gt;
	│ Operator 2 ├────────┘&lt;br /&gt;
	│            │&lt;br /&gt;
	└────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Frequency Modulation (FM) Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output from the first operator (Modulator) is sent to the input of the second one (Carrier) and is used to modulate (alter) frequency of the second operator. Only the second operator produces sound. Most of interesting sounds are made this way. This also works on OPL2. Hope the picture helps.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐         ┌────────────┐&lt;br /&gt;
	│            │         │            │&lt;br /&gt;
	│ Operator 1 ├────────&amp;gt;│ Operator 2 ├────────&amp;gt; Output&lt;br /&gt;
	│(Modulator) │         │ (Carrier)  │&lt;br /&gt;
	└────────────┘         └────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Four-operator &amp;quot;Mess&amp;quot; Modulation Synthesis ===&lt;br /&gt;
&lt;br /&gt;
All of OPL3&#039;s 4-OP configurations are combinations of the above two modes of synthesis. OPL3 combines these two modes in four ways. I have no words to describe these four ways. Only the pictures can show their principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   a) FM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   b) AM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├───────────────────────────────────┐&lt;br /&gt;
	│       │                                   │&lt;br /&gt;
	└───────┘                                   │&lt;br /&gt;
						    │&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┴─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   c) FM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────┐&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     ├─────&amp;gt; Output&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┘&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	└───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   d) AM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├────────────────────┐&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	└───────┘                    │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────┼─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐                    │&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	│ Op. 4 ├────────────────────┘&lt;br /&gt;
	│       │&lt;br /&gt;
	└───────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Nice, aren&#039;t they?&lt;br /&gt;
&lt;br /&gt;
The only way I think this can be written is a math formula. Symbol + (plus) means additive synthesis, and * (asterisk) means frequency modulation (Op1 * Op2 means operator 1 modulates operator 2, not vice versa). Here they are:&lt;br /&gt;
&lt;br /&gt;
# FM-FM Mode:	 (Op1 * Op2 * Op3 * Op4) ────&amp;gt; Output&lt;br /&gt;
# AM-FM Mode:	  Op1 + (Op2 * Op3 * Op4) ───&amp;gt; Output&lt;br /&gt;
# FM-AM Mode:	 (Op1 * Op2) + (Op3 * Op4) ──&amp;gt; Output&lt;br /&gt;
# AM-AM Mode:	  Op1 + (Op2 * Op3) + Op4 ───&amp;gt; Output&lt;br /&gt;
&lt;br /&gt;
=== Percussion Mode ===&lt;br /&gt;
&lt;br /&gt;
In this mode 6 operators are used to produce five different percussion instruments:&lt;br /&gt;
&lt;br /&gt;
* Bass Drum (2 operators)&lt;br /&gt;
* Snare Drum (1 operator)&lt;br /&gt;
* Tom-Tom (1 operator)&lt;br /&gt;
* Cymbal (1 operator)&lt;br /&gt;
* Hi-Hat (1 operator)&lt;br /&gt;
&lt;br /&gt;
Because these instruments occupy only three melodic channels, only Bass Drum, Snare Drum and Tom-Tom frequencies can be set. Cymbal and Hi-Hat frequencies are fixed.  {{TODO|It seems it&#039;s actually the cymbal and snare frequencies that are fixed, try to confirm this -- [[User:Malvineous|Malvineous]] 13:34, 3 June 2012 (GMT)}}&lt;br /&gt;
&lt;br /&gt;
This mode is identical with that of OPL2. For more details see ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
== Programming the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
OPL3 may be found at the following addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| Sound Blaster Pro II || 220h or 240h (selectable), also 388h&lt;br /&gt;
|-&lt;br /&gt;
| Adlib Gold || 388h&lt;br /&gt;
|-&lt;br /&gt;
| Pro Audio Spectrum Plus/16 || ? (if you have a PAS you should know it)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The base address of the synthesizer will be called &amp;quot;base&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The chip occupies four I/O addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| base+0 || Primary index register (write), Status register (read)&lt;br /&gt;
|-&lt;br /&gt;
| base+1 || Primary data register (write-only)&lt;br /&gt;
|-&lt;br /&gt;
| base+2 || Secondary index register (write)&lt;br /&gt;
|-&lt;br /&gt;
| base+3 || Secondary data register (write-only)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The index registers are used to select internal registers and data registers are used to write to them. Status register returns the state of two timers built in the chip.&lt;br /&gt;
&lt;br /&gt;
OPL3 contains two sets of registers. The Primary set maps to channels 0-8 (operators 0-17) and the secondary maps to channels 9-17 (operators 18-35). The reason for this is simple: all these registers wouldn&#039;t fit into single register set.&lt;br /&gt;
&lt;br /&gt;
Unlike Adlib (OPL2), OPL3 doesn&#039;t need delay between register writes. With OPL2 you had to wait 3.3 µs after index register write and another 23 µs after data register write. On the contrary OPL3 doesn&#039;t need (almost) any delay after index register write and only 0.28 µs after data register write. This means you can neglect the delays and slightly speed up your music driver. But using reasonable delays will certainly do no harm.&lt;br /&gt;
&lt;br /&gt;
The data registers can&#039;t be read (they are write-only) on both OPL2 and OPL3.&lt;br /&gt;
&lt;br /&gt;
== Register Map ==&lt;br /&gt;
&lt;br /&gt;
The registers are grouped in the same manner as in the OPL2 chip. Programs using both OPL2 and OPL3 chips may use the same code provided that their direct I/O interface is well written. The only thing you have to change is operator-to-register mapping, which must accomodate the fact that registers are spread between two register sets.&lt;br /&gt;
&lt;br /&gt;
(The register map is nearly the same so I dared to copy it from ADLIB.DOC.)&lt;br /&gt;
&lt;br /&gt;
=== Status Register (base+0) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
!    D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQFlag || T1Flag || T2Flag ||        ||        ||        ||        ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Data Registers (base+1, base+3) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! REG   !!   D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| 01    ||colspan=2|        ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|WSEnable||colspan=5| Test Register&lt;br /&gt;
|-&lt;br /&gt;
| 02    ||colspan=8| Timer 1 Count (80 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 03    ||colspan=8| Timer 2 Count (320 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 04*   ||IRQReset|| T1Mask || T2Mask ||colspan=3|                  ||T2 Start||T1 Start&lt;br /&gt;
|-&lt;br /&gt;
| 04**  ||colspan=2|        ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP B-E||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP A-D||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 9-C||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 2-5||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 1-4||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 0-3&lt;br /&gt;
|-&lt;br /&gt;
| 05**  ||colspan=7|                                                           ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;| OPL3&lt;br /&gt;
|-&lt;br /&gt;
| 08    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|  CSW   ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|NOTE-SEL||colspan=6|&lt;br /&gt;
|-&lt;br /&gt;
| 20-35 ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Tremolo ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Vibrato ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Sustain ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|  KSR   ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Frequency Multiplication Factor&lt;br /&gt;
|-&lt;br /&gt;
| 40-55 ||colspan=2 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Key Scale Level ||colspan=6 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 60-75 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Attack Rate ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 80-95 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Sustain Level ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A0-A8 ||colspan=8 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Frequency Number  (Lower 8 bits)&lt;br /&gt;
|-&lt;br /&gt;
| B0-B8 ||colspan=2|        ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| KEY-ON ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Block Number ||colspan=2 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| F-Num (hi bits)&lt;br /&gt;
|-&lt;br /&gt;
| BD    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Trem Dep||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Vibr Dep||style=&amp;quot;background-color: #FFCCDD;&amp;quot;|PercMode||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| BD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| SD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| TT On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| CY On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| HH On&lt;br /&gt;
|-&lt;br /&gt;
| C0-C8 ||colspan=2|        ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Right  ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Left   ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;|FeedBack Modulation Factor||style=&amp;quot;background-color: #FFE0CC;&amp;quot;|SynthTyp&lt;br /&gt;
|-&lt;br /&gt;
| E0-F5 ||colspan=5|                                      ||colspan=3 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|style=&amp;quot;background-color: #CCFFCC;&amp;quot;| Chip-wide setting&lt;br /&gt;
|style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Per operator&lt;br /&gt;
|style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Per channel&lt;br /&gt;
|style=&amp;quot;background-color: #FFCCDD;&amp;quot;| Rhythm-mode only&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt; This applies only to port base+1&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;**&amp;lt;/nowiki&amp;gt; This applies only to port base+3&lt;br /&gt;
&lt;br /&gt;
For register bases A0, B0 and C0 there is one register per output channel. The primary register set holds the first nine channels (0-8) and the secondary holds last nine channels (9-17). For bases 20, 40, 60, 80 and E0 there are two registers per channel. Each register maps to one operator. Unfortunately the operator&#039;s register numbers are not continuous. The following table shows which operator maps to which register set and offset (in hex).&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Op. !! Set/Offset !! Op. !! Set/Offset&lt;br /&gt;
|-&lt;br /&gt;
| 0  || 0/00 || 18 || 1/00&lt;br /&gt;
|-&lt;br /&gt;
| 1  || 0/01 || 19 || 1/01&lt;br /&gt;
|-&lt;br /&gt;
| 2  || 0/02 || 20 || 1/02&lt;br /&gt;
|-&lt;br /&gt;
| 3  || 0/03 || 21 || 1/03&lt;br /&gt;
|-&lt;br /&gt;
| 4  || 0/04 || 22 || 1/04&lt;br /&gt;
|-&lt;br /&gt;
| 5  || 0/05 || 23 || 1/05&lt;br /&gt;
|-&lt;br /&gt;
| 6  || 0/08 || 24 || 1/08&lt;br /&gt;
|-&lt;br /&gt;
| 7  || 0/09 || 25 || 1/09&lt;br /&gt;
|-&lt;br /&gt;
| 8  || 0/0A || 26 || 1/0A&lt;br /&gt;
|-&lt;br /&gt;
| 9  || 0/0B || 27 || 1/0B&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 0/0C || 28 || 1/0C&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 0/0D || 29 || 1/0D&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 0/10 || 30 || 1/10&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 0/11 || 31 || 1/11&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 0/12 || 32 || 1/12&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 0/13 || 33 || 1/13&lt;br /&gt;
|-&lt;br /&gt;
| 16 || 0/14 || 34 || 1/14&lt;br /&gt;
|-&lt;br /&gt;
| 17 || 0/15 || 35 || 1/15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following tables summarize which operators form a channel in various modes:&lt;br /&gt;
&lt;br /&gt;
1. Two-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel    !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 13 || 14 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 || 16 || 17 || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
2. Two-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 ||colspan=4| - || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
3. Four-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 13 || 14 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 || 16 || 17 || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=3| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=3| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Channels 3, 4, 5 and 12, 13, 14 can&#039;t be used separately because their operators became part of channels 0, 1, 2 and 9, 10, 11 respectively. For instance a four-operator channel 1 consists of two two-operator channels number 1 and 4. (The second 2-OP channel number is always the first 2-OP channel number plus three.)&lt;br /&gt;
&lt;br /&gt;
OPL3 allows you to enable/disable 4-OP mode separately for any of channels 0, 1, 2, 9, 10 and 11 (see register 104h in the reference below). This means for instance when you switch only channel 2 into 4-OP mode, channels number 0, 1, 3, 4, 6, 7, 8, 9, etc. will be still independent 2-OP channels.&lt;br /&gt;
&lt;br /&gt;
Channels 6, 7, 8 and 15, 16, 17 are always two-operator ones. They can&#039;t be grouped to form four-operator channels.&lt;br /&gt;
&lt;br /&gt;
4. Four-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 ||colspan=4| - || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=5| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=5| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
Two-operator channel #14 consists of operators 26 and 29 which occupy these registers (all are in the secondary register set):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| 12A || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 12D || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 14A || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 14D || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 16A || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 16D || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18A || Operator 1 ||Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18D || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 1A5 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| 1B5 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| 1C5 ||            || FeedBack/Synthesis Type&lt;br /&gt;
|-&lt;br /&gt;
| 1EA || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| 1ED || Operator 2 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Four-operator channel #1 consists of operators 1, 4, 7 and 10. All registers except register 104h are in the primary set:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 104 || bit 1 = 1  || Enable Four-Operator Synthesis in channel #1&lt;br /&gt;
|-&lt;br /&gt;
| 21 || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 24 || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 29 || Operator 3 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 2C || Operator 4 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 41 || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 44 || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 49 || Operator 3 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 4C || Operator 4 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 61 || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 64 || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 69 || Operator 3 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 6C || Operator 4 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 81 || Operator 1 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 84 || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 89 || Operator 3 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 8C || Operator 4 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A1 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| A4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| B1 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| B4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| C1 ||            || FeedBack/Synthesis Type (part 1)&lt;br /&gt;
|-&lt;br /&gt;
| C4 ||            || Synthesis Type (part 2)&lt;br /&gt;
|-&lt;br /&gt;
| E1 || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E4 || Operator 2 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E9 || Operator 3 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| EC || Operator 4 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
NOTE: If a register number is greater than 100h, then it belongs into the secondary register set. (I use this numbering to emphasize the fact that the particular register MUST be written to the secondary set.) See the example code below for details.&lt;br /&gt;
&lt;br /&gt;
== OPL3 Register Reference ==&lt;br /&gt;
&lt;br /&gt;
Because the registers of OPL3 are almost the same as of OPL2, I have copied their descriptions from file ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
=== Status Register ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQ || T1 || T2 ||colspan=5| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ Flag. Set whenever any timer has elapsed.&lt;br /&gt;
* bit 6: Timer 1 Flag. Set every time the preset time in Timer 1 has elapsed.&lt;br /&gt;
* bit 5: Timer 2 Flag. Set every time the preset time in Timer 2 has elapsed.&lt;br /&gt;
&lt;br /&gt;
Timer interrupts are not wired to any IRQ (why??). The timers can be used to detect the OPL2/OPL3 chip (see Appendix B).&lt;br /&gt;
&lt;br /&gt;
=== Data Registers ===&lt;br /&gt;
&lt;br /&gt;
==== 01: Test Register / Waveform Select Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| WSE&lt;br /&gt;
|colspan=5| Test Register&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: Waveform Select Enable. If clear, all channels will use normal sine wave. If set, register E0-F5 (Waveform Select) contents will be used.&lt;br /&gt;
* bits 0-4: Test Register. Must be reset to zero before any operation.&lt;br /&gt;
&lt;br /&gt;
==== 02: Timer 1 Count ====&lt;br /&gt;
&lt;br /&gt;
Upward 8 bit counter with a resolution of 80 µsec. If an overflow occurs, the status register bit is set, and the preset value is loaded into the timer again.&lt;br /&gt;
&lt;br /&gt;
==== 03: Timer 2 Count ====&lt;br /&gt;
&lt;br /&gt;
Same as Timer 1, but with a resolution of 320 µsec.&lt;br /&gt;
&lt;br /&gt;
==== 004 (port: base+1): IRQ-Reset / Mask / Start ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Rst&lt;br /&gt;
| T1M&lt;br /&gt;
| T2M&lt;br /&gt;
|colspan=3| -&lt;br /&gt;
| T2S&lt;br /&gt;
| T1S&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ-Reset. Resets timer and IRQ flags in status register. All other bits are ignored when this bit is set.&lt;br /&gt;
* bit 6: Timer 1 Mask. If 1, status register is not affected in overflow.&lt;br /&gt;
* bit 5: Timer 2 Mask. Same as above.&lt;br /&gt;
* bit 1: Timer 2 Start. Timer on/off.&lt;br /&gt;
* bit 0: Timer 1 Start. Same as above.&lt;br /&gt;
&lt;br /&gt;
==== 104 (port: base+3): Four-Operator Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| ChB&lt;br /&gt;
| ChA&lt;br /&gt;
| Ch9&lt;br /&gt;
| Ch2&lt;br /&gt;
| Ch1&lt;br /&gt;
| Ch0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: Enable four-operator synthesis for channel pair 11 - 14 (decimal).&lt;br /&gt;
* bit 4: Same as above for channel pair 10 - 13.&lt;br /&gt;
* bit 3: Same as above for channel pair 9 - 12.&lt;br /&gt;
* bit 2: Same as above for channel pair 2 - 5.&lt;br /&gt;
* bit 1: Same as above for channel pair 1 - 4.&lt;br /&gt;
* bit 0: Same as above for channel pair 0 - 3.&lt;br /&gt;
&lt;br /&gt;
If reset to zero, OPL3 can produce 18 two-operator sounds at a time. If nonzero, OPL3 produces four-operator sound in appropriate channel pair.&lt;br /&gt;
&lt;br /&gt;
==== 105 (port: base+3): OPL3 Mode Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=7| -&lt;br /&gt;
| OPL3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 0: OPL3 Mode Enable. When set, OPL3 extensions (36 operators, 4-OP synthesis, 8 waveforms, stereo output) can be used. When reset, the chip behaves as an ordinary OPL2. This bit is zero by default for compatibility with OPL2.&lt;br /&gt;
&lt;br /&gt;
==== 08: CSW / NOTE-SEL ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| (CSW)&lt;br /&gt;
| N-S&lt;br /&gt;
|colspan=6| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: Composite sine wave mode on/off. All KEY-ON bits must be clear in order to use this mode. The card is unable to create any other sound when in CSW mode. (Unfortunately, I have no info how to use this mode :-&amp;lt; ). The CSW mode is not implemented on an OPL3 and this bit is ignored.&lt;br /&gt;
* bit 6: NOTE-SEL. Controls the split point of the keyboard. When 0, the keyboard split is the second bit from the bit 8 of the F-Number. When 1, the MSb of the F-Number is used. (???)&lt;br /&gt;
&lt;br /&gt;
==== 20-35: Tremolo / Vibrato / Sustain / KSR / Frequency Multiplication Factor ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Sus&lt;br /&gt;
| KSR&lt;br /&gt;
|colspan=4| Multiplication&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude vibrato) on/off.&lt;br /&gt;
* bit 6:    Frequency vibrato on/off.&lt;br /&gt;
* bit 5:    Sound Sustaining. When 1, operator&#039;s output level will be held at its sustain level until a KEY-OFF is done.&lt;br /&gt;
* bit 4:    Envelope scaling (KSR) on/off. When 1, higher notes are shorter than lower notes.&lt;br /&gt;
* bits 0-3: Frequency Multiplication Factor (MULTI). Operator&#039;s frequency is set to (see registers A0, B0) F-Number * Factor.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! MULTI !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0.5&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 2&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 3&lt;br /&gt;
|-&lt;br /&gt;
| 4 || 4&lt;br /&gt;
|-&lt;br /&gt;
| 5 || 5&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 6&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 7&lt;br /&gt;
|-&lt;br /&gt;
| 8 || 8&lt;br /&gt;
|-&lt;br /&gt;
| 9 || 9&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 40-55: Key Scale Level / Output Level ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| KSL&lt;br /&gt;
|colspan=6| Output level&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 6-7: Key Scale Level. Attenuates output level towards higher pitch:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! KSL !! Attenuation&lt;br /&gt;
|-&lt;br /&gt;
| 0 || -&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 3.0 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 1.5 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 6.0 dB/oct&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The attenuation level is based on the 3-bit octave (block number) value and top four bits of the FNUM value, so each octave is subdivided into 16 parts.&lt;br /&gt;
&lt;br /&gt;
* bits 0-5: Output Level. Attenuates the operator output level. 0 is the loudest, 3F is the softest. In additive synthesis, varying the output level of any operator varies the volume of its corresponding channel. In FM synthesis, varying the output level of the carrier varies the volume of the channel. Varying the output of the modulator will change the frequency spectrum produced by the carrier. The following table summarizes which operators&#039; output levels should be updated when trying to change channel output level.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Mode !! Op 1 !! Op 2 !! Op 3 !! Op 4&lt;br /&gt;
|-&lt;br /&gt;
| AM    || Y || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM    || - || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM-FM || - || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-FM || Y || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| FM-AM || - || Y || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-AM || Y || - || Y   || Y&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 60-75: Attack Rate / Decay Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Attack rate&lt;br /&gt;
|colspan=4| Decay rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Attack Rate. Determines the rising time for the sound. The higher the value, the faster the attack.&lt;br /&gt;
* bits 0-3: Decay Rate. Determines the diminishing time for the sound. The higher the value, the shorter the decay.&lt;br /&gt;
&lt;br /&gt;
==== 80-95: Sustain Level / Release Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Sustain level&lt;br /&gt;
|colspan=4| Release rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Sustain Level. Determines the point at which the sound ceases to decay and chages to a sound having a constant level. The sustain level is expressed as a fraction of the maximum level. 0 is the softest and F is the loudest sustain level. Note that the Sustain-bit in the register 20-35 must be set for this to have an effect.&lt;br /&gt;
* bits 0-3: Release Rate. Determines the rate at which the sound disappears after KEY-OFF. The higher the value, the shorter the release.&lt;br /&gt;
&lt;br /&gt;
==== A0-A8: Frequency Number ====&lt;br /&gt;
&lt;br /&gt;
Determines the pitch of the note. Highest bits of F-Number are stored in the register below.&lt;br /&gt;
&lt;br /&gt;
==== B0-B8: Key On / Block Number / F-Number(hi bits) ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| KEY&lt;br /&gt;
|colspan=3| Block num.&lt;br /&gt;
|colspan=2| Freq&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: KEY-ON. When 1, channel output is enabled.&lt;br /&gt;
* bits 2-4: Block Number. Roughly determines the octave.&lt;br /&gt;
* bits 0-1: Frequency Number. 2 highest bits of the above register.  The following formula is used to determine F-Number and Block:&lt;br /&gt;
: F-Number = Music Frequency * 2^(20-Block) / 49716 Hz&lt;br /&gt;
&lt;br /&gt;
NOTE: In four-operator mode only the register value of Operators 1 and 2 is used, value of Operators 3 and 4 in this register is ignored. In other words: one channel uses only one frequency, block and KEY-ON value at a time, regardless whether it is a two- or four-operator channel.&lt;br /&gt;
&lt;br /&gt;
==== BD: Tremolo Depth / Vibrato Depth / Percussion Mode / BD/SD/TT/CY/HH On ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Per&lt;br /&gt;
| BD&lt;br /&gt;
| SD&lt;br /&gt;
| TT&lt;br /&gt;
| CY&lt;br /&gt;
| HH&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude Vibrato) Depth. 0 = 1.0dB, 1 = 4.8dB.&lt;br /&gt;
* bit 6:    Frequency Vibrato Depth. 0 = 7 cents, 1 = 14 cents. A &amp;quot;cent&amp;quot; is 1/100 of a semi-tone.&lt;br /&gt;
* bit 5:    Percussion Mode. 0 = Melodic Mode, 1 = Percussion Mode.&lt;br /&gt;
* bit 4:    BD On. KEY-ON of the Bass Drum channel.&lt;br /&gt;
* bit 3:    SD On. KEY-ON of the Snare Drum channel.&lt;br /&gt;
* bit 2:    TT On. KEY-ON of the Tom-Tom channel.&lt;br /&gt;
* bit 1:    CY On. KEY-ON of the Cymbal channel.&lt;br /&gt;
* bit 0:    HH On. KEY-ON of the Hi-Hat channel.&lt;br /&gt;
&lt;br /&gt;
NOTE: KEY-ON bits of channels 6, 7 and 8 must be clear and their F-Nums, Attack/Decay/Release rates, etc. must be set properly to use percussion mode.&lt;br /&gt;
&lt;br /&gt;
==== C0-C8: FeedBack Modulation Factor / Synthesis Type ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2|&lt;br /&gt;
| R&lt;br /&gt;
| L&lt;br /&gt;
|colspan=3| Feedback&lt;br /&gt;
| Syn&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5:    Right Speaker Enable. When set, channel output goes to right speaker.&lt;br /&gt;
* bit 4:    Left Speaker Enable. When set, channel output goes to left speaker. At least one of these bits must be set to hear the channel.&lt;br /&gt;
** These two bits can be used to realize sound &amp;quot;panning&amp;quot;, but this method offers only three pan positions (left/center/right).&lt;br /&gt;
** These bits apply only to operators producing sound (Carriers). Modulators are not affected by their setting.&lt;br /&gt;
* bits 1-3: FeedBack Modulation Factor. If 0, no feedback is present. If 1-7, operator 1 will send a portion of its output back into itself.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! FeedBack !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;amp;pi;/16&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;amp;pi;/8&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;amp;pi;/4&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;amp;pi;/2&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 2&amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 4&amp;amp;pi;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
When in four-operator mode, the FeedBack value is used only by Operator 1, value of Operators 2, 3 and 4 is ignored.&lt;br /&gt;
&lt;br /&gt;
* bit 0: Synthesis Type. 1 = Additive synthesis, 0 = Frequency Modulation.  In four-operator mode, there are two bits controlling the synthesis type. Both are the bit 0 of register C0, one of Operators 1 and 2 and the second of Operators 3 and 4.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Op 1&amp;amp;2 !! Op 3&amp;amp;4 !! Type&lt;br /&gt;
|-&lt;br /&gt;
| 0 || NONE || FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || NONE || AM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || FM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || AM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || FM-AM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || AM-AM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== E0-F5: Waveform Select ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=5| -&lt;br /&gt;
|colspan=3| Waveform&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 0-2: WaveForm Select (WS): &amp;lt;gallery widths=261px perrow=4&amp;gt;&lt;br /&gt;
Image:OPL_Wave0.png|Waveform 0: Sine&lt;br /&gt;
Image:OPL_Wave1.png|Waveform 1: Half-sine&lt;br /&gt;
Image:OPL_Wave2.png|Waveform 2: Abs-sine&lt;br /&gt;
Image:OPL_Wave3.png|Waveform 3: Pulse-sine&lt;br /&gt;
Image:OPL_Wave4.png|Waveform 4: Sine - even periods only&lt;br /&gt;
Image:OPL_Wave5.png|Waveform 5: Abs-sine - even periods only&lt;br /&gt;
Image:OPL_Wave6.png|Waveform 6: Square&lt;br /&gt;
Image:OPL_Wave7.png|Waveform 7: Derived square&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* NOTE: Bit 5 of register 01 must be set to use waveforms other than sine. Waveforms 4-7 are available only on OPL3. See files WAVEn.GIF for real waveforms, where n is a number between 0 and 7.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
These examples show a few working routines used in my MUS Player. They are written in Borland C++ 3.1 but should be easy to translate to any other language.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
// I prefer using these Assembler-like types&lt;br /&gt;
typedef unsigned int  WORD;&lt;br /&gt;
typedef unsigned char BYTE;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * FM Synthesizer base port. SB Pro II - 0x220, Adlib 0x388&lt;br /&gt;
 */&lt;br /&gt;
WORD FMport = 0x220;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Enables OPL3 extensions.&lt;br /&gt;
 */&lt;br /&gt;
WORD OPL3 = 1;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Direct write to any Adlib/SB Pro II FM synthetiser register.&lt;br /&gt;
 *   reg - register number (range 0x001-0x0F5 and 0x101-0x1F5). When high byte&lt;br /&gt;
 *         of reg is zero, data go to port FMport, otherwise to FMport+2&lt;br /&gt;
 *   data - register value to be written&lt;br /&gt;
 */&lt;br /&gt;
BYTE FMwriteReg(WORD reg, BYTE data)&lt;br /&gt;
{&lt;br /&gt;
    asm {&lt;br /&gt;
	mov	dx,FMport&lt;br /&gt;
	mov	ax,reg&lt;br /&gt;
	or	ah,ah		// high byte is nonzero -- write to port base+2&lt;br /&gt;
	jz	out1&lt;br /&gt;
	inc	dx&lt;br /&gt;
	inc	dx&lt;br /&gt;
    }&lt;br /&gt;
out1: asm {&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	mov	cx,6&lt;br /&gt;
    }&lt;br /&gt;
loop1:asm {			// delay between writes&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop1&lt;br /&gt;
&lt;br /&gt;
	inc	dx&lt;br /&gt;
	mov	al,data&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	dec	dx&lt;br /&gt;
	mov	cx,36&lt;br /&gt;
    }&lt;br /&gt;
loop2:asm {			// delay after data write&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop2&lt;br /&gt;
    }&lt;br /&gt;
    return _AL;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to an operator pair. To be used for register bases of 0x20, 0x40,&lt;br /&gt;
 * 0x60, 0x80 and 0xE0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteChannel(BYTE regbase, BYTE channel, BYTE data1, BYTE data2)&lt;br /&gt;
{&lt;br /&gt;
    static BYTE adlib_op[] = {0, 1, 2, 8, 9, 10, 16, 17, 18};&lt;br /&gt;
    static BYTE sbpro_op[] = { 0,  1,  2,   6,  7,  8,  12, 13, 14,&lt;br /&gt;
			      18, 19, 20,  24, 25, 26,  30, 31, 32};&lt;br /&gt;
    static WORD rg[] = {0x000,0x001,0x002,0x003,0x004,0x005,&lt;br /&gt;
			0x008,0x009,0x00A,0x00B,0x00C,0x00D,&lt;br /&gt;
			0x010,0x011,0x012,0x013,0x014,0x015,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,&lt;br /&gt;
			0x108,0x109,0x10A,0x10B,0x10C,0x10D,&lt;br /&gt;
			0x110,0x111,0x112,0x113,0x114,0x115};&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
    {&lt;br /&gt;
	register WORD reg = sbpro_op[channel];&lt;br /&gt;
	FMwriteReg(rg[reg]+regbase, data1);&lt;br /&gt;
	FMwriteReg(rg[reg+3]+regbase, data2);&lt;br /&gt;
    } else {&lt;br /&gt;
	register WORD reg = regbase+adlib_op[channel];&lt;br /&gt;
	FMwriteReg(reg, data1);&lt;br /&gt;
	FMwriteReg(reg+3, data2);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to channel a single value. To be used for register bases of&lt;br /&gt;
 * 0xA0, 0xB0 and 0xC0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteValue(BYTE regbase, BYTE channel, BYTE value)&lt;br /&gt;
{&lt;br /&gt;
    static WORD ch[] = {0x000,0x001,0x002,0x003,0x004,0x005,0x006,0x007,0x008,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,0x106,0x107,0x108};&lt;br /&gt;
    register WORD chan;&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
	chan = ch[channel];&lt;br /&gt;
    else&lt;br /&gt;
	chan = channel;&lt;br /&gt;
    FMwriteReg(regbase + chan, value);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Detection Methods ==&lt;br /&gt;
&lt;br /&gt;
An official method of Adlib (OPL2) detection is:&lt;br /&gt;
&lt;br /&gt;
# Reset Timer 1 and Timer 2: write 60h to register 4.&lt;br /&gt;
# Reset the IRQ: write 80h to register 4.&lt;br /&gt;
#* NOTE: Steps 1 and 2 can&#039;t be combined together.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Set Timer 1 to FFh: write FFh to register 2.&lt;br /&gt;
# Unmask and start Timer 1: write 21h to register 4.&lt;br /&gt;
# Wait in a delay loop for at least 80 µsec.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Reset Timer 1, Timer 2 and IRQ as in steps 1 and 2.&lt;br /&gt;
# Test the results of the two reads: the first should be 0, the second should be C0h. If either is incorrect, then the OPL2 is not present.&lt;br /&gt;
&lt;br /&gt;
* NOTE1: You should AND the result bytes with E0h because the unused bits are undefined.&lt;br /&gt;
* NOTE2: This testing method doesn&#039;t work in some SoundBlaster compatible cards.&lt;br /&gt;
&lt;br /&gt;
=== OPL3 Detection ===&lt;br /&gt;
--------------&lt;br /&gt;
&lt;br /&gt;
# Detect OPL2. If present, continue.&lt;br /&gt;
# Read status register: read port base+0.&lt;br /&gt;
# AND the result with 06h.&lt;br /&gt;
# If the result is zero, you have OPL3, otherwise OPL2.&lt;br /&gt;
&lt;br /&gt;
* NOTE: This is NOT an official method. I have dug it out of a sound driver. I haven&#039;t tested it, because I haven&#039;t an OPL2 card (Adlib, SB Pro I). Nevertheless it &amp;quot;detects&amp;quot; my SB Pro II properly. ;-)&lt;br /&gt;
&lt;br /&gt;
Another possible detection method for distinguishing between SB Pro I and SB Pro II would be to try to detect OPL2 at I/O port base+0 and then at port base+2. The first test should succeed and the second should fail if OPL3 is present. (Remember: SB Pro I contains twin OPL2 chips at addresses base+0 and base+2, while SB Pro II contains one OPL3 chip at I/O address base+0 thru base+3).&lt;br /&gt;
&lt;br /&gt;
== BLASTER Environment Variable ==&lt;br /&gt;
&lt;br /&gt;
Perhaps the most recommended &amp;quot;detection&amp;quot; method. Reading this variable avoids blindfold I/O port scanning and possible device conflicts. The user is responsible for its proper setting.&lt;br /&gt;
&lt;br /&gt;
The variable has this format:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=Aaddr Iirq Ddma Ttype&lt;br /&gt;
&lt;br /&gt;
* A: Base I/O address given in hex. For most Sound Blasters the default is 220.&lt;br /&gt;
* I: IRQ Number (decimal). Default 7.&lt;br /&gt;
* D: DMA Number (decimal). Default 1.&lt;br /&gt;
* T: Card Type (decimal):&lt;br /&gt;
** 1 - Sound Blaster 1.5&lt;br /&gt;
** 2 - Sound Blaster Pro I&lt;br /&gt;
** 3 - Sound Blaster 2.0&lt;br /&gt;
** 4 - Sound Blaster Pro II&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=A220 I7 D1 T4&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The PC Games Programmers Encyclopedia&#039;&#039;, Mark Feldman and many others on Usenet and Internet, ftp://teeri.oulu.fi/pub/msdos/programming/gpe&lt;br /&gt;
: ... you can find (almost) everything you need there&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Sound Blaster - The Official Book&#039;&#039;, Richard Heimlich, David M. Golden, Ivan Luk, Peter M. Ridge, Osborne/McGraw Hill, ISBN 0-07-881907-5&lt;br /&gt;
: ... this is a number-one in my book-wishlist. If anyone wanted to get rid of the book, I wouldn&#039;t scorn it ... :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The SoundBlaster Developer Kit&#039;&#039;, Creative Labs Inc, Creative Technology PTE LTD&lt;br /&gt;
: ... I wonder if you can find something comprehensible in that.&lt;/div&gt;</summary>
		<author><name>Kermes</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4320</id>
		<title>OPL chip</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=OPL_chip&amp;diff=4320"/>
		<updated>2012-08-03T18:04:51Z</updated>

		<summary type="html">&lt;p&gt;Kermes: /* 40-55: Key Scale Level / Output Level */ Correction to which KSL values select which attenuation.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Programmer&#039;s Guide to Yamaha YMF 262/OPL3 FM Music Synthesizer =&lt;br /&gt;
Version 1.00  Nov-24-1994&lt;br /&gt;
&lt;br /&gt;
Written by Vladimir Arnost, QA-Software&lt;br /&gt;
Internet:  xarnos00@dcse.fee.vutbr.cz&lt;br /&gt;
&lt;br /&gt;
This manual can be distributed freely if not modified.&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer ===&lt;br /&gt;
&lt;br /&gt;
I assume no responsibility for any damages arising out of use or inability to use this text. No warranty is provided about correctness of any information in this file. You are on your own.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The chip I am going to describe is getting more and more common, but programming information is still scarce, so I have decided to fill in this gap. All information contained in this file is a result of my experience in Adlib programming, research (read: reverse engineering) and finally of my effort to write down everything necessary to understand and use this piece of hardware. No official sources (i.e. development kits, books about this topic, etc.) were available to me except:&lt;br /&gt;
&lt;br /&gt;
: Adlib Programming Guide - by Tero Töttö, and&lt;br /&gt;
: The PC Games Programmers Encyclopedia V1.0&lt;br /&gt;
&lt;br /&gt;
The information below is a combination of known features of Adlib (alias Yamaha YM 3812/OPL2) and my own uncountable experiments and failures, which brought out a lot of important details you have to know about the chip.&lt;br /&gt;
&lt;br /&gt;
As far as I know, there are four major sound cards based on OPL3 chip:&lt;br /&gt;
&lt;br /&gt;
* Sound Blaster Pro II (not Sound Blaster Pro I)&lt;br /&gt;
* Sound Blaster 16&lt;br /&gt;
* Adlib Gold&lt;br /&gt;
* Pro Audio Spectrum Plus/16&lt;br /&gt;
&lt;br /&gt;
I currently have a Sound Blaster Pro II-compatible card only, so all the programming info I provide will be based on this card. (The other cards are quite similar, however. They are just wired at different I/O-port addresses.)&lt;br /&gt;
&lt;br /&gt;
Note: I assume some knowledge of FM music programming (mainly Adlib FM synthesizer) in this manual. If you are new to this topic I recommend you try Adlib first before going higher. Anyway, OPL3 is a direct descendant of OPL2 (what a surprise), so most features of OPL2 are also present on OPL3.&lt;br /&gt;
&lt;br /&gt;
== Description of the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
My card&#039;s user manual says: &amp;quot;[this card contains] ... a stereo music FM synthesizer with 20 channels consisting of four (4) operators each ... &amp;quot; I thought: &amp;quot;Wow -- that&#039;s together eighty operators. This must be a GOOD sound-card.&amp;quot; I was wrong. Just another advertising lie.&lt;br /&gt;
&lt;br /&gt;
So let&#039;s clear some facts. First, OPL3 has only thirty-six (36) operators which can be combined in several ways:&lt;br /&gt;
&lt;br /&gt;
* 18 FM channels (36 operators), or&lt;br /&gt;
* 15 FM channels (30 ops) and 5 percussion instruments (6 ops), giving us 20 channels altogether, or&lt;br /&gt;
* up to 6 four-operator FM channels (max 24 ops), the rest again being divided into two-operator FM channels and drums.&lt;br /&gt;
&lt;br /&gt;
From the table above you can see that not all channels can be used in four-operator (4-OP) mode -- only a part of the synthesizer is really capable of making 4-OP sounds -- the rest uses traditional two-operator (2-OP) mode.&lt;br /&gt;
&lt;br /&gt;
Second, the manual states this card is capable of &amp;quot;stereo&amp;quot; music. Yes, the quotes are necessary, because the stereo capabilities are very limited. You are given ability to control output going to left or right channel by turning it on and off. That&#039;s all. So the sound can flow from very left side, center and very right side. No sound panning, no special stereo effects. :-(&lt;br /&gt;
&lt;br /&gt;
Well, flaming apart, back to the main topic.&lt;br /&gt;
&lt;br /&gt;
The OPL3 chip is capable of making sounds in several ways:&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Additive Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output of both operators is simply added. It is the simplest way to make any sound, and it works on both OPL2 and OPL3. The diagram should make it clear.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐&lt;br /&gt;
	│            │&lt;br /&gt;
	│ Operator 1 ├────────┐&lt;br /&gt;
	│            │        │&lt;br /&gt;
	└────────────┘        │&lt;br /&gt;
			      ├────────&amp;gt; Output&lt;br /&gt;
	┌────────────┐        │&lt;br /&gt;
	│            │        │&lt;br /&gt;
	│ Operator 2 ├────────┘&lt;br /&gt;
	│            │&lt;br /&gt;
	└────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Two-operator Frequency Modulation (FM) Synthesis ===&lt;br /&gt;
&lt;br /&gt;
Output from the first operator (Modulator) is sent to the input of the second one (Carrier) and is used to modulate (alter) frequency of the second operator. Only the second operator produces sound. Most of interesting sounds are made this way. This also works on OPL2. Hope the picture helps.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	┌────────────┐         ┌────────────┐&lt;br /&gt;
	│            │         │            │&lt;br /&gt;
	│ Operator 1 ├────────&amp;gt;│ Operator 2 ├────────&amp;gt; Output&lt;br /&gt;
	│(Modulator) │         │ (Carrier)  │&lt;br /&gt;
	└────────────┘         └────────────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Four-operator &amp;quot;Mess&amp;quot; Modulation Synthesis ===&lt;br /&gt;
&lt;br /&gt;
All of OPL3&#039;s 4-OP configurations are combinations of the above two modes of synthesis. OPL3 combines these two modes in four ways. I have no words to describe these four ways. Only the pictures can show their principle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   a) FM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   b) AM-FM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├───────────────────────────────────┐&lt;br /&gt;
	│       │                                   │&lt;br /&gt;
	└───────┘                                   │&lt;br /&gt;
						    │&lt;br /&gt;
	┌───────┐      ┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┴─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │      │       │&lt;br /&gt;
	└───────┘      └───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   c) FM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐      ┌───────┐&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	│ Op. 1 ├─────&amp;gt;│ Op. 2 ├─────┐&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     ├─────&amp;gt; Output&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 3 ├─────&amp;gt;│ Op. 4 ├─────┘&lt;br /&gt;
	│       │      │       │&lt;br /&gt;
	└───────┘      └───────┘&lt;br /&gt;
&lt;br /&gt;
   d) AM-AM Mode&lt;br /&gt;
&lt;br /&gt;
	┌───────┐&lt;br /&gt;
	│       │&lt;br /&gt;
	│ Op. 1 ├────────────────────┐&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	└───────┘                    │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐      ┌───────┐     │&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	│ Op. 2 ├─────&amp;gt;│ Op. 3 ├─────┼─────&amp;gt; Output&lt;br /&gt;
	│       │      │       │     │&lt;br /&gt;
	└───────┘      └───────┘     │&lt;br /&gt;
				     │&lt;br /&gt;
	┌───────┐                    │&lt;br /&gt;
	│       │                    │&lt;br /&gt;
	│ Op. 4 ├────────────────────┘&lt;br /&gt;
	│       │&lt;br /&gt;
	└───────┘&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Nice, aren&#039;t they?&lt;br /&gt;
&lt;br /&gt;
The only way I think this can be written is a math formula. Symbol + (plus) means additive synthesis, and * (asterisk) means frequency modulation (Op1 * Op2 means operator 1 modulates operator 2, not vice versa). Here they are:&lt;br /&gt;
&lt;br /&gt;
# FM-FM Mode:	 (Op1 * Op2 * Op3 * Op4) ────&amp;gt; Output&lt;br /&gt;
# AM-FM Mode:	  Op1 + (Op2 * Op3 * Op4) ───&amp;gt; Output&lt;br /&gt;
# FM-AM Mode:	 (Op1 * Op2) + (Op3 * Op4) ──&amp;gt; Output&lt;br /&gt;
# AM-AM Mode:	  Op1 + (Op2 * Op3) + Op4 ───&amp;gt; Output&lt;br /&gt;
&lt;br /&gt;
=== Percussion Mode ===&lt;br /&gt;
&lt;br /&gt;
In this mode 6 operators are used to produce five different percussion instruments:&lt;br /&gt;
&lt;br /&gt;
* Bass Drum (2 operators)&lt;br /&gt;
* Snare Drum (1 operator)&lt;br /&gt;
* Tom-Tom (1 operator)&lt;br /&gt;
* Cymbal (1 operator)&lt;br /&gt;
* Hi-Hat (1 operator)&lt;br /&gt;
&lt;br /&gt;
Because these instruments occupy only three melodic channels, only Bass Drum, Snare Drum and Tom-Tom frequencies can be set. Cymbal and Hi-Hat frequencies are fixed.  {{TODO|It seems it&#039;s actually the cymbal and snare frequencies that are fixed, try to confirm this -- [[User:Malvineous|Malvineous]] 13:34, 3 June 2012 (GMT)}}&lt;br /&gt;
&lt;br /&gt;
This mode is identical with that of OPL2. For more details see ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
== Programming the Synthesizer ==&lt;br /&gt;
&lt;br /&gt;
OPL3 may be found at the following addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| Sound Blaster Pro II || 220h or 240h (selectable), also 388h&lt;br /&gt;
|-&lt;br /&gt;
| Adlib Gold || 388h&lt;br /&gt;
|-&lt;br /&gt;
| Pro Audio Spectrum Plus/16 || ? (if you have a PAS you should know it)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The base address of the synthesizer will be called &amp;quot;base&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The chip occupies four I/O addresses:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| base+0 || Primary index register (write), Status register (read)&lt;br /&gt;
|-&lt;br /&gt;
| base+1 || Primary data register (write-only)&lt;br /&gt;
|-&lt;br /&gt;
| base+2 || Secondary index register (write)&lt;br /&gt;
|-&lt;br /&gt;
| base+3 || Secondary data register (write-only)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The index registers are used to select internal registers and data registers are used to write to them. Status register returns the state of two timers built in the chip.&lt;br /&gt;
&lt;br /&gt;
OPL3 contains two sets of registers. The Primary set maps to channels 0-8 (operators 0-17) and the secondary maps to channels 9-17 (operators 18-35). The reason for this is simple: all these registers wouldn&#039;t fit into single register set.&lt;br /&gt;
&lt;br /&gt;
Unlike Adlib (OPL2), OPL3 doesn&#039;t need delay between register writes. With OPL2 you had to wait 3.3 µs after index register write and another 23 µs after data register write. On the contrary OPL3 doesn&#039;t need (almost) any delay after index register write and only 0.28 µs after data register write. This means you can neglect the delays and slightly speed up your music driver. But using reasonable delays will certainly do no harm.&lt;br /&gt;
&lt;br /&gt;
The data registers can&#039;t be read (they are write-only) on both OPL2 and OPL3.&lt;br /&gt;
&lt;br /&gt;
== Register Map ==&lt;br /&gt;
&lt;br /&gt;
The registers are grouped in the same manner as in the OPL2 chip. Programs using both OPL2 and OPL3 chips may use the same code provided that their direct I/O interface is well written. The only thing you have to change is operator-to-register mapping, which must accomodate the fact that registers are spread between two register sets.&lt;br /&gt;
&lt;br /&gt;
(The register map is nearly the same so I dared to copy it from ADLIB.DOC.)&lt;br /&gt;
&lt;br /&gt;
=== Status Register (base+0) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
!    D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQFlag || T1Flag || T2Flag ||        ||        ||        ||        ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Data Registers (base+1, base+3) ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! REG   !!   D7   !!   D6   !!   D5   !!   D4   !!   D3   !!   D2   !!   D1   !!   D0&lt;br /&gt;
|-&lt;br /&gt;
| 01    ||colspan=2|        ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|WSEnable||colspan=5| Test Register&lt;br /&gt;
|-&lt;br /&gt;
| 02    ||colspan=8| Timer 1 Count (80 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 03    ||colspan=8| Timer 2 Count (320 µsec resolution)&lt;br /&gt;
|-&lt;br /&gt;
| 04*   ||IRQReset|| T1Mask || T2Mask ||colspan=3|                  ||T2 Start||T1 Start&lt;br /&gt;
|-&lt;br /&gt;
| 04**  ||colspan=2|        ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP B-E||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP A-D||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 9-C||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 2-5||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 1-4||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|4-OP 0-3&lt;br /&gt;
|-&lt;br /&gt;
| 05**  ||colspan=7|                                                           ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;| OPL3&lt;br /&gt;
|-&lt;br /&gt;
| 08    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|  CSW   ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|NOTE-SEL||colspan=6|&lt;br /&gt;
|-&lt;br /&gt;
| 20-35 ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Tremolo ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Vibrato ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|Sustain ||style=&amp;quot;background-color: #CCCCFF;&amp;quot;|  KSR   ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Frequency Multiplication Factor&lt;br /&gt;
|-&lt;br /&gt;
| 40-55 ||colspan=2 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Key Scale Level ||colspan=6 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 60-75 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Attack Rate ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 80-95 ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Sustain Level ||colspan=4 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A0-A8 ||colspan=8 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Frequency Number  (Lower 8 bits)&lt;br /&gt;
|-&lt;br /&gt;
| B0-B8 ||colspan=2|        ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| KEY-ON ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Block Number ||colspan=2 style=&amp;quot;background-color: #FFE0CC;&amp;quot;| F-Num (hi bits)&lt;br /&gt;
|-&lt;br /&gt;
| BD    ||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Trem Dep||style=&amp;quot;background-color: #CCFFCC;&amp;quot;|Vibr Dep||style=&amp;quot;background-color: #FFCCDD;&amp;quot;|PercMode||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| BD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| SD On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| TT On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| CY On  ||style=&amp;quot;background-color: #FFCCDD;&amp;quot;| HH On&lt;br /&gt;
|-&lt;br /&gt;
| C0-C8 ||colspan=2|        ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Right  ||style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Left   ||colspan=3 style=&amp;quot;background-color: #FFE0CC;&amp;quot;|FeedBack Modulation Factor||style=&amp;quot;background-color: #FFE0CC;&amp;quot;|SynthTyp&lt;br /&gt;
|-&lt;br /&gt;
| E0-F5 ||colspan=5|                                      ||colspan=3 style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|style=&amp;quot;background-color: #CCFFCC;&amp;quot;| Chip-wide setting&lt;br /&gt;
|style=&amp;quot;background-color: #CCCCFF;&amp;quot;| Per operator&lt;br /&gt;
|style=&amp;quot;background-color: #FFE0CC;&amp;quot;| Per channel&lt;br /&gt;
|style=&amp;quot;background-color: #FFCCDD;&amp;quot;| Rhythm-mode only&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt; This applies only to port base+1&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;**&amp;lt;/nowiki&amp;gt; This applies only to port base+3&lt;br /&gt;
&lt;br /&gt;
For register bases A0, B0 and C0 there is one register per output channel. The primary register set holds the first nine channels (0-8) and the secondary holds last nine channels (9-17). For bases 20, 40, 60, 80 and E0 there are two registers per channel. Each register maps to one operator. Unfortunately the operator&#039;s register numbers are not continuous. The following table shows which operator maps to which register set and offset (in hex).&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Op. !! Set/Offset !! Op. !! Set/Offset&lt;br /&gt;
|-&lt;br /&gt;
| 0  || 0/00 || 18 || 1/00&lt;br /&gt;
|-&lt;br /&gt;
| 1  || 0/01 || 19 || 1/01&lt;br /&gt;
|-&lt;br /&gt;
| 2  || 0/02 || 20 || 1/02&lt;br /&gt;
|-&lt;br /&gt;
| 3  || 0/03 || 21 || 1/03&lt;br /&gt;
|-&lt;br /&gt;
| 4  || 0/04 || 22 || 1/04&lt;br /&gt;
|-&lt;br /&gt;
| 5  || 0/05 || 23 || 1/05&lt;br /&gt;
|-&lt;br /&gt;
| 6  || 0/08 || 24 || 1/08&lt;br /&gt;
|-&lt;br /&gt;
| 7  || 0/09 || 25 || 1/09&lt;br /&gt;
|-&lt;br /&gt;
| 8  || 0/0A || 26 || 1/0A&lt;br /&gt;
|-&lt;br /&gt;
| 9  || 0/0B || 27 || 1/0B&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 0/0C || 28 || 1/0C&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 0/0D || 29 || 1/0D&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 0/10 || 30 || 1/10&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 0/11 || 31 || 1/11&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 0/12 || 32 || 1/12&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 0/13 || 33 || 1/13&lt;br /&gt;
|-&lt;br /&gt;
| 16 || 0/14 || 34 || 1/14&lt;br /&gt;
|-&lt;br /&gt;
| 17 || 0/15 || 35 || 1/15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following tables summarize which operators form a channel in various modes:&lt;br /&gt;
&lt;br /&gt;
1. Two-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel    !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 13 || 14 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 || 16 || 17 || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
2. Two-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 3 !! 4 !! 5 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 6 || 7  || 8  || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 24 || 25 || 26 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 9 || 10 || 11 || 15 ||colspan=4| - || 21 || 22 || 23 || 27 || 28 || 29 || 33 || 34 || 35&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
3. Four-operator Melodic Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! 6 !! 7 !! 8 !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 13 || 14 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 || 16 || 17 || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=3| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=3| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Channels 3, 4, 5 and 12, 13, 14 can&#039;t be used separately because their operators became part of channels 0, 1, 2 and 9, 10, 11 respectively. For instance a four-operator channel 1 consists of two two-operator channels number 1 and 4. (The second 2-OP channel number is always the first 2-OP channel number plus three.)&lt;br /&gt;
&lt;br /&gt;
OPL3 allows you to enable/disable 4-OP mode separately for any of channels 0, 1, 2, 9, 10 and 11 (see register 104h in the reference below). This means for instance when you switch only channel 2 into 4-OP mode, channels number 0, 1, 3, 4, 6, 7, 8, 9, etc. will be still independent 2-OP channels.&lt;br /&gt;
&lt;br /&gt;
Channels 6, 7, 8 and 15, 16, 17 are always two-operator ones. They can&#039;t be grouped to form four-operator channels.&lt;br /&gt;
&lt;br /&gt;
4. Four-operator Melodic and Percussion Mode&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred&amp;quot;&lt;br /&gt;
! Channel !! 0 !! 1 !! 2 !! BD !! SD !! TT !! CY !! HH !! 9 !! 10 !! 11 !! 15 !! 16 !! 17&lt;br /&gt;
|-&lt;br /&gt;
| Operator 1 || 0 || 1 || 2 || 12 || 16 || 14 || 17 || 13 || 18 || 19 || 20 || 30 || 31 || 32&lt;br /&gt;
|-&lt;br /&gt;
| Operator 2 || 3 || 4 || 5 || 15 ||colspan=4| - || 21 || 22 || 23 || 33 || 34 || 35&lt;br /&gt;
|-&lt;br /&gt;
| Operator 3 || 6 || 7 || 8 ||colspan=5| - || 24 || 25 || 26 ||colspan=3| -&lt;br /&gt;
|-&lt;br /&gt;
| Operator 4 || 9 || 10 || 11 ||colspan=5| - || 27 || 28 || 29 ||colspan=3| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
Two-operator channel #14 consists of operators 26 and 29 which occupy these registers (all are in the secondary register set):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| 12A || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 12D || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 14A || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 14D || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 16A || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 16D || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18A || Operator 1 ||Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 18D || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 1A5 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| 1B5 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| 1C5 ||            || FeedBack/Synthesis Type&lt;br /&gt;
|-&lt;br /&gt;
| 1EA || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| 1ED || Operator 2 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Four-operator channel #1 consists of operators 1, 4, 7 and 10. All registers except register 104h are in the primary set:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 104 || bit 1 = 1  || Enable Four-Operator Synthesis in channel #1&lt;br /&gt;
|-&lt;br /&gt;
| 21 || Operator 1 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 24 || Operator 2 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 29 || Operator 3 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 2C || Operator 4 || Tremolo/Vibrato/Sustain/KSR/Multiplication&lt;br /&gt;
|-&lt;br /&gt;
| 41 || Operator 1 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 44 || Operator 2 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 49 || Operator 3 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 4C || Operator 4 || Key Scale Level/Output Level&lt;br /&gt;
|-&lt;br /&gt;
| 61 || Operator 1 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 64 || Operator 2 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 69 || Operator 3 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 6C || Operator 4 || Attack Rate/Decay Rate&lt;br /&gt;
|-&lt;br /&gt;
| 81 || Operator 1 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 84 || Operator 2 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 89 || Operator 3 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| 8C || Operator 4 || Sustain Level/Release Rate&lt;br /&gt;
|-&lt;br /&gt;
| A1 ||            || Frequency Number (low)&lt;br /&gt;
|-&lt;br /&gt;
| A4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| B1 ||            || Key On/Block Number/Frequency Number (high)&lt;br /&gt;
|-&lt;br /&gt;
| B4 ||            || Unused&lt;br /&gt;
|-&lt;br /&gt;
| C1 ||            || FeedBack/Synthesis Type (part 1)&lt;br /&gt;
|-&lt;br /&gt;
| C4 ||            || Synthesis Type (part 2)&lt;br /&gt;
|-&lt;br /&gt;
| E1 || Operator 1 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E4 || Operator 2 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| E9 || Operator 3 || Waveform Select&lt;br /&gt;
|-&lt;br /&gt;
| EC || Operator 4 || Waveform Select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
NOTE: If a register number is greater than 100h, then it belongs into the secondary register set. (I use this numbering to emphasize the fact that the particular register MUST be written to the secondary set.) See the example code below for details.&lt;br /&gt;
&lt;br /&gt;
== OPL3 Register Reference ==&lt;br /&gt;
&lt;br /&gt;
Because the registers of OPL3 are almost the same as of OPL2, I have copied their descriptions from file ADLIB.DOC.&lt;br /&gt;
&lt;br /&gt;
=== Status Register ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| IRQ || T1 || T2 ||colspan=5| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ Flag. Set whenever any timer has elapsed.&lt;br /&gt;
* bit 6: Timer 1 Flag. Set every time the preset time in Timer 1 has elapsed.&lt;br /&gt;
* bit 5: Timer 2 Flag. Set every time the preset time in Timer 2 has elapsed.&lt;br /&gt;
&lt;br /&gt;
Timer interrupts are not wired to any IRQ (why??). The timers can be used to detect the OPL2/OPL3 chip (see Appendix B).&lt;br /&gt;
&lt;br /&gt;
=== Data Registers ===&lt;br /&gt;
&lt;br /&gt;
==== 01: Test Register / Waveform Select Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| WSE&lt;br /&gt;
|colspan=5| Test Register&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: Waveform Select Enable. If clear, all channels will use normal sine wave. If set, register E0-F5 (Waveform Select) contents will be used.&lt;br /&gt;
* bits 0-4: Test Register. Must be reset to zero before any operation.&lt;br /&gt;
&lt;br /&gt;
==== 02: Timer 1 Count ====&lt;br /&gt;
&lt;br /&gt;
Upward 8 bit counter with a resolution of 80 µsec. If an overflow occurs, the status register bit is set, and the preset value is loaded into the timer again.&lt;br /&gt;
&lt;br /&gt;
==== 03: Timer 2 Count ====&lt;br /&gt;
&lt;br /&gt;
Same as Timer 1, but with a resolution of 320 µsec.&lt;br /&gt;
&lt;br /&gt;
==== 004 (port: base+1): IRQ-Reset / Mask / Start ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Rst&lt;br /&gt;
| T1M&lt;br /&gt;
| T2M&lt;br /&gt;
|colspan=3| -&lt;br /&gt;
| T2S&lt;br /&gt;
| T1S&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: IRQ-Reset. Resets timer and IRQ flags in status register. All other bits are ignored when this bit is set.&lt;br /&gt;
* bit 6: Timer 1 Mask. If 1, status register is not affected in overflow.&lt;br /&gt;
* bit 5: Timer 2 Mask. Same as above.&lt;br /&gt;
* bit 1: Timer 2 Start. Timer on/off.&lt;br /&gt;
* bit 0: Timer 1 Start. Same as above.&lt;br /&gt;
&lt;br /&gt;
==== 104 (port: base+3): Four-Operator Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| ChB&lt;br /&gt;
| ChA&lt;br /&gt;
| Ch9&lt;br /&gt;
| Ch2&lt;br /&gt;
| Ch1&lt;br /&gt;
| Ch0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: Enable four-operator synthesis for channel pair 11 - 14 (decimal).&lt;br /&gt;
* bit 4: Same as above for channel pair 10 - 13.&lt;br /&gt;
* bit 3: Same as above for channel pair 9 - 12.&lt;br /&gt;
* bit 2: Same as above for channel pair 2 - 5.&lt;br /&gt;
* bit 1: Same as above for channel pair 1 - 4.&lt;br /&gt;
* bit 0: Same as above for channel pair 0 - 3.&lt;br /&gt;
&lt;br /&gt;
If reset to zero, OPL3 can produce 18 two-operator sounds at a time. If nonzero, OPL3 produces four-operator sound in appropriate channel pair.&lt;br /&gt;
&lt;br /&gt;
==== 105 (port: base+3): OPL3 Mode Enable ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=7| -&lt;br /&gt;
| OPL3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 0: OPL3 Mode Enable. When set, OPL3 extensions (36 operators, 4-OP synthesis, 8 waveforms, stereo output) can be used. When reset, the chip behaves as an ordinary OPL2. This bit is zero by default for compatibility with OPL2.&lt;br /&gt;
&lt;br /&gt;
==== 08: CSW / NOTE-SEL ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| CSW&lt;br /&gt;
| N-S&lt;br /&gt;
|colspan=6| -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7: Composite sine wave mode on/off. All KEY-ON bits must be clear in order to use this mode. The card is unable to create any other sound when in CSW mode. (Unfortunately, I have no info how to use this mode :-&amp;lt; ).&lt;br /&gt;
* bit 6: NOTE-SEL. Controls the split point of the keyboard. When 0, the keyboard split is the second bit from the bit 8 of the F-Number. When 1, the MSb of the F-Number is used. (???)&lt;br /&gt;
&lt;br /&gt;
==== 20-35: Tremolo / Vibrato / Sustain / KSR / Frequency Multiplication Factor ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Sus&lt;br /&gt;
| KSR&lt;br /&gt;
|colspan=4| Multiplication&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude vibrato) on/off.&lt;br /&gt;
* bit 6:    Frequency vibrato on/off.&lt;br /&gt;
* bit 5:    Sound Sustaining. When 1, operator&#039;s output level will be held at its sustain level until a KEY-OFF is done.&lt;br /&gt;
* bit 4:    Envelope scaling (KSR) on/off. When 1, higher notes are shorter than lower notes.&lt;br /&gt;
* bits 0-3: Frequency Multiplication Factor (MULTI). Operator&#039;s frequency is set to (see registers A0, B0) F-Number * Factor.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! MULTI !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0.5&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 2&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 3&lt;br /&gt;
|-&lt;br /&gt;
| 4 || 4&lt;br /&gt;
|-&lt;br /&gt;
| 5 || 5&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 6&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 7&lt;br /&gt;
|-&lt;br /&gt;
| 8 || 8&lt;br /&gt;
|-&lt;br /&gt;
| 9 || 9&lt;br /&gt;
|-&lt;br /&gt;
| 10 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 11 || 10&lt;br /&gt;
|-&lt;br /&gt;
| 12 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 13 || 12&lt;br /&gt;
|-&lt;br /&gt;
| 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
| 15 || 15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 40-55: Key Scale Level / Output Level ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| KSL&lt;br /&gt;
|colspan=6| Output level&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 6-7: Key Scale Level. Attenuates output level towards higher pitch:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! KSL !! Attenuation&lt;br /&gt;
|-&lt;br /&gt;
| 0 || -&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 3.0 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 1.5 dB/oct&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 6.0 dB/oct&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The attenuation level is based on the 3-bit octave (block number) value and top four bits of the FNUM value, so each octave is subdivided into 16 parts.&lt;br /&gt;
&lt;br /&gt;
* bits 0-5: Output Level. Attenuates the operator output level. 0 is the loudest, 3F is the softest. In additive synthesis, varying the output level of any operator varies the volume of its corresponding channel. In FM synthesis, varying the output level of the carrier varies the volume of the channel. Varying the output of the modulator will change the frequency spectrum produced by the carrier. The following table summarizes which operators&#039; output levels should be updated when trying to change channel output level.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Mode !! Op 1 !! Op 2 !! Op 3 !! Op 4&lt;br /&gt;
|-&lt;br /&gt;
| AM    || Y || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM    || - || Y || N/A || N/A&lt;br /&gt;
|-&lt;br /&gt;
| FM-FM || - || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-FM || Y || - || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| FM-AM || - || Y || -   || Y&lt;br /&gt;
|-&lt;br /&gt;
| AM-AM || Y || - || Y   || Y&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== 60-75: Attack Rate / Decay Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Attack rate&lt;br /&gt;
|colspan=4| Decay rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Attack Rate. Determines the rising time for the sound. The higher the value, the faster the attack.&lt;br /&gt;
* bits 0-3: Decay Rate. Determines the diminishing time for the sound. The higher the value, the shorter the decay.&lt;br /&gt;
&lt;br /&gt;
==== 80-95: Sustain Level / Release Rate ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=4| Sustain level&lt;br /&gt;
|colspan=4| Release rate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 4-7: Sustain Level. Determines the point at which the sound ceases to decay and chages to a sound having a constant level. The sustain level is expressed as a fraction of the maximum level. 0 is the softest and F is the loudest sustain level. Note that the Sustain-bit in the register 20-35 must be set for this to have an effect.&lt;br /&gt;
* bits 0-3: Release Rate. Determines the rate at which the sound disappears after KEY-OFF. The higher the value, the shorter the release.&lt;br /&gt;
&lt;br /&gt;
==== A0-A8: Frequency Number ====&lt;br /&gt;
&lt;br /&gt;
Determines the pitch of the note. Highest bits of F-Number are stored in the register below.&lt;br /&gt;
&lt;br /&gt;
==== B0-B8: Key On / Block Number / F-Number(hi bits) ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2| -&lt;br /&gt;
| KEY&lt;br /&gt;
|colspan=3| Block num.&lt;br /&gt;
|colspan=2| Freq&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5: KEY-ON. When 1, channel output is enabled.&lt;br /&gt;
* bits 2-4: Block Number. Roughly determines the octave.&lt;br /&gt;
* bits 0-1: Frequency Number. 2 highest bits of the above register.  The following formula is used to determine F-Number and Block:&lt;br /&gt;
: F-Number = Music Frequency * 2^(20-Block) / 49716 Hz&lt;br /&gt;
&lt;br /&gt;
NOTE: In four-operator mode only the register value of Operators 1 and 2 is used, value of Operators 3 and 4 in this register is ignored. In other words: one channel uses only one frequency, block and KEY-ON value at a time, regardless whether it is a two- or four-operator channel.&lt;br /&gt;
&lt;br /&gt;
==== BD: Tremolo Depth / Vibrato Depth / Percussion Mode / BD/SD/TT/CY/HH On ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
| Tre&lt;br /&gt;
| Vib&lt;br /&gt;
| Per&lt;br /&gt;
| BD&lt;br /&gt;
| SD&lt;br /&gt;
| TT&lt;br /&gt;
| CY&lt;br /&gt;
| HH&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 7:    Tremolo (Amplitude Vibrato) Depth. 0 = 1.0dB, 1 = 4.8dB.&lt;br /&gt;
* bit 6:    Frequency Vibrato Depth. 0 = 7 cents, 1 = 14 cents. A &amp;quot;cent&amp;quot; is 1/100 of a semi-tone.&lt;br /&gt;
* bit 5:    Percussion Mode. 0 = Melodic Mode, 1 = Percussion Mode.&lt;br /&gt;
* bit 4:    BD On. KEY-ON of the Bass Drum channel.&lt;br /&gt;
* bit 3:    SD On. KEY-ON of the Snare Drum channel.&lt;br /&gt;
* bit 2:    TT On. KEY-ON of the Tom-Tom channel.&lt;br /&gt;
* bit 1:    CY On. KEY-ON of the Cymbal channel.&lt;br /&gt;
* bit 0:    HH On. KEY-ON of the Hi-Hat channel.&lt;br /&gt;
&lt;br /&gt;
NOTE: KEY-ON bits of channels 6, 7 and 8 must be clear and their F-Nums, Attack/Decay/Release rates, etc. must be set properly to use percussion mode.&lt;br /&gt;
&lt;br /&gt;
==== C0-C8: FeedBack Modulation Factor / Synthesis Type ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=2|&lt;br /&gt;
| R&lt;br /&gt;
| L&lt;br /&gt;
|colspan=3| Feedback&lt;br /&gt;
| Syn&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bit 5:    Right Speaker Enable. When set, channel output goes to right speaker.&lt;br /&gt;
* bit 4:    Left Speaker Enable. When set, channel output goes to left speaker. At least one of these bits must be set to hear the channel.&lt;br /&gt;
** These two bits can be used to realize sound &amp;quot;panning&amp;quot;, but this method offers only three pan positions (left/center/right).&lt;br /&gt;
** These bits apply only to operators producing sound (Carriers). Modulators are not affected by their setting.&lt;br /&gt;
* bits 1-3: FeedBack Modulation Factor. If 0, no feedback is present. If 1-7, operator 1 will send a portion of its output back into itself.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! FeedBack !! Factor&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0&lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;amp;pi;/16&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;amp;pi;/8&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;amp;pi;/4&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;amp;pi;/2&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 2&amp;amp;pi;&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 4&amp;amp;pi;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
When in four-operator mode, the FeedBack value is used only by Operator 1, value of Operators 2, 3 and 4 is ignored.&lt;br /&gt;
&lt;br /&gt;
* bit 0: Synthesis Type. 1 = Additive synthesis, 0 = Frequency Modulation.  In four-operator mode, there are two bits controlling the synthesis type. Both are the bit 0 of register C0, one of Operators 1 and 2 and the second of Operators 3 and 4.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! Op 1&amp;amp;2 !! Op 3&amp;amp;4 !! Type&lt;br /&gt;
|-&lt;br /&gt;
| 0 || NONE || FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || NONE || AM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 0 || FM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 0 || AM-FM&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || FM-AM&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 1 || AM-AM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== E0-F5: Waveform Select ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable centred fixed-width&amp;quot;&lt;br /&gt;
! D7 !! D6 !! D5 !! D4 !! D3 !! D2 !! D1 !! D0&lt;br /&gt;
|-&lt;br /&gt;
|colspan=5| -&lt;br /&gt;
|colspan=3| Waveform&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* bits 0-2: WaveForm Select (WS): &amp;lt;gallery widths=261px perrow=4&amp;gt;&lt;br /&gt;
Image:OPL_Wave0.png|Waveform 0: Sine&lt;br /&gt;
Image:OPL_Wave1.png|Waveform 1: Half-sine&lt;br /&gt;
Image:OPL_Wave2.png|Waveform 2: Abs-sine&lt;br /&gt;
Image:OPL_Wave3.png|Waveform 3: Pulse-sine&lt;br /&gt;
Image:OPL_Wave4.png|Waveform 4: Sine - even periods only&lt;br /&gt;
Image:OPL_Wave5.png|Waveform 5: Abs-sine - even periods only&lt;br /&gt;
Image:OPL_Wave6.png|Waveform 6: Square&lt;br /&gt;
Image:OPL_Wave7.png|Waveform 7: Derived square&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* NOTE: Bit 5 of register 01 must be set to use waveforms other than sine. Waveforms 4-7 are available only on OPL3. See files WAVEn.GIF for real waveforms, where n is a number between 0 and 7.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
These examples show a few working routines used in my MUS Player. They are written in Borland C++ 3.1 but should be easy to translate to any other language.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
// I prefer using these Assembler-like types&lt;br /&gt;
typedef unsigned int  WORD;&lt;br /&gt;
typedef unsigned char BYTE;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * FM Synthesizer base port. SB Pro II - 0x220, Adlib 0x388&lt;br /&gt;
 */&lt;br /&gt;
WORD FMport = 0x220;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Enables OPL3 extensions.&lt;br /&gt;
 */&lt;br /&gt;
WORD OPL3 = 1;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Direct write to any Adlib/SB Pro II FM synthetiser register.&lt;br /&gt;
 *   reg - register number (range 0x001-0x0F5 and 0x101-0x1F5). When high byte&lt;br /&gt;
 *         of reg is zero, data go to port FMport, otherwise to FMport+2&lt;br /&gt;
 *   data - register value to be written&lt;br /&gt;
 */&lt;br /&gt;
BYTE FMwriteReg(WORD reg, BYTE data)&lt;br /&gt;
{&lt;br /&gt;
    asm {&lt;br /&gt;
	mov	dx,FMport&lt;br /&gt;
	mov	ax,reg&lt;br /&gt;
	or	ah,ah		// high byte is nonzero -- write to port base+2&lt;br /&gt;
	jz	out1&lt;br /&gt;
	inc	dx&lt;br /&gt;
	inc	dx&lt;br /&gt;
    }&lt;br /&gt;
out1: asm {&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	mov	cx,6&lt;br /&gt;
    }&lt;br /&gt;
loop1:asm {			// delay between writes&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop1&lt;br /&gt;
&lt;br /&gt;
	inc	dx&lt;br /&gt;
	mov	al,data&lt;br /&gt;
	out	dx,al&lt;br /&gt;
	dec	dx&lt;br /&gt;
	mov	cx,36&lt;br /&gt;
    }&lt;br /&gt;
loop2:asm {			// delay after data write&lt;br /&gt;
	in	al,dx&lt;br /&gt;
	loop	loop2&lt;br /&gt;
    }&lt;br /&gt;
    return _AL;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to an operator pair. To be used for register bases of 0x20, 0x40,&lt;br /&gt;
 * 0x60, 0x80 and 0xE0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteChannel(BYTE regbase, BYTE channel, BYTE data1, BYTE data2)&lt;br /&gt;
{&lt;br /&gt;
    static BYTE adlib_op[] = {0, 1, 2, 8, 9, 10, 16, 17, 18};&lt;br /&gt;
    static BYTE sbpro_op[] = { 0,  1,  2,   6,  7,  8,  12, 13, 14,&lt;br /&gt;
			      18, 19, 20,  24, 25, 26,  30, 31, 32};&lt;br /&gt;
    static WORD rg[] = {0x000,0x001,0x002,0x003,0x004,0x005,&lt;br /&gt;
			0x008,0x009,0x00A,0x00B,0x00C,0x00D,&lt;br /&gt;
			0x010,0x011,0x012,0x013,0x014,0x015,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,&lt;br /&gt;
			0x108,0x109,0x10A,0x10B,0x10C,0x10D,&lt;br /&gt;
			0x110,0x111,0x112,0x113,0x114,0x115};&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
    {&lt;br /&gt;
	register WORD reg = sbpro_op[channel];&lt;br /&gt;
	FMwriteReg(rg[reg]+regbase, data1);&lt;br /&gt;
	FMwriteReg(rg[reg+3]+regbase, data2);&lt;br /&gt;
    } else {&lt;br /&gt;
	register WORD reg = regbase+adlib_op[channel];&lt;br /&gt;
	FMwriteReg(reg, data1);&lt;br /&gt;
	FMwriteReg(reg+3, data2);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Write to channel a single value. To be used for register bases of&lt;br /&gt;
 * 0xA0, 0xB0 and 0xC0.&lt;br /&gt;
 */&lt;br /&gt;
void FMwriteValue(BYTE regbase, BYTE channel, BYTE value)&lt;br /&gt;
{&lt;br /&gt;
    static WORD ch[] = {0x000,0x001,0x002,0x003,0x004,0x005,0x006,0x007,0x008,&lt;br /&gt;
			0x100,0x101,0x102,0x103,0x104,0x105,0x106,0x107,0x108};&lt;br /&gt;
    register WORD chan;&lt;br /&gt;
&lt;br /&gt;
    if (OPL3)&lt;br /&gt;
	chan = ch[channel];&lt;br /&gt;
    else&lt;br /&gt;
	chan = channel;&lt;br /&gt;
    FMwriteReg(regbase + chan, value);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Detection Methods ==&lt;br /&gt;
&lt;br /&gt;
An official method of Adlib (OPL2) detection is:&lt;br /&gt;
&lt;br /&gt;
# Reset Timer 1 and Timer 2: write 60h to register 4.&lt;br /&gt;
# Reset the IRQ: write 80h to register 4.&lt;br /&gt;
#* NOTE: Steps 1 and 2 can&#039;t be combined together.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Set Timer 1 to FFh: write FFh to register 2.&lt;br /&gt;
# Unmask and start Timer 1: write 21h to register 4.&lt;br /&gt;
# Wait in a delay loop for at least 80 µsec.&lt;br /&gt;
# Read status register: read port base+0 (388h). Save the result.&lt;br /&gt;
# Reset Timer 1, Timer 2 and IRQ as in steps 1 and 2.&lt;br /&gt;
# Test the results of the two reads: the first should be 0, the second should be C0h. If either is incorrect, then the OPL2 is not present.&lt;br /&gt;
&lt;br /&gt;
* NOTE1: You should AND the result bytes with E0h because the unused bits are undefined.&lt;br /&gt;
* NOTE2: This testing method doesn&#039;t work in some SoundBlaster compatible cards.&lt;br /&gt;
&lt;br /&gt;
=== OPL3 Detection ===&lt;br /&gt;
--------------&lt;br /&gt;
&lt;br /&gt;
# Detect OPL2. If present, continue.&lt;br /&gt;
# Read status register: read port base+0.&lt;br /&gt;
# AND the result with 06h.&lt;br /&gt;
# If the result is zero, you have OPL3, otherwise OPL2.&lt;br /&gt;
&lt;br /&gt;
* NOTE: This is NOT an official method. I have dug it out of a sound driver. I haven&#039;t tested it, because I haven&#039;t an OPL2 card (Adlib, SB Pro I). Nevertheless it &amp;quot;detects&amp;quot; my SB Pro II properly. ;-)&lt;br /&gt;
&lt;br /&gt;
Another possible detection method for distinguishing between SB Pro I and SB Pro II would be to try to detect OPL2 at I/O port base+0 and then at port base+2. The first test should succeed and the second should fail if OPL3 is present. (Remember: SB Pro I contains twin OPL2 chips at addresses base+0 and base+2, while SB Pro II contains one OPL3 chip at I/O address base+0 thru base+3).&lt;br /&gt;
&lt;br /&gt;
== BLASTER Environment Variable ==&lt;br /&gt;
&lt;br /&gt;
Perhaps the most recommended &amp;quot;detection&amp;quot; method. Reading this variable avoids blindfold I/O port scanning and possible device conflicts. The user is responsible for its proper setting.&lt;br /&gt;
&lt;br /&gt;
The variable has this format:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=Aaddr Iirq Ddma Ttype&lt;br /&gt;
&lt;br /&gt;
* A: Base I/O address given in hex. For most Sound Blasters the default is 220.&lt;br /&gt;
* I: IRQ Number (decimal). Default 7.&lt;br /&gt;
* D: DMA Number (decimal). Default 1.&lt;br /&gt;
* T: Card Type (decimal):&lt;br /&gt;
** 1 - Sound Blaster 1.5&lt;br /&gt;
** 2 - Sound Blaster Pro I&lt;br /&gt;
** 3 - Sound Blaster 2.0&lt;br /&gt;
** 4 - Sound Blaster Pro II&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 BLASTER=A220 I7 D1 T4&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The PC Games Programmers Encyclopedia&#039;&#039;, Mark Feldman and many others on Usenet and Internet, ftp://teeri.oulu.fi/pub/msdos/programming/gpe&lt;br /&gt;
: ... you can find (almost) everything you need there&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Sound Blaster - The Official Book&#039;&#039;, Richard Heimlich, David M. Golden, Ivan Luk, Peter M. Ridge, Osborne/McGraw Hill, ISBN 0-07-881907-5&lt;br /&gt;
: ... this is a number-one in my book-wishlist. If anyone wanted to get rid of the book, I wouldn&#039;t scorn it ... :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The SoundBlaster Developer Kit&#039;&#039;, Creative Labs Inc, Creative Technology PTE LTD&lt;br /&gt;
: ... I wonder if you can find something comprehensible in that.&lt;/div&gt;</summary>
		<author><name>Kermes</name></author>
	</entry>
</feed>