Programmer's Guide to Yamaha YMF 262/OPL3 FM Music Synthesizer

Colophon

This is a Gemini rendition (by Retrograde.dk) of the Programmer's Guide to Yamaha YMF 262/OPL3 FM Music Synthesizer by Vladimir Arnost of QA-Software.

Said guide remains an important source of information on programming the historical OPL3 FM chips, but unfortunately it disappeared from the web around May 2024. Luckily, the Wayback Machine had a saved snapshot, which served as the foundation for this version. The colophon of the original web version states:

Gemini version 1.0, Last updated: 2025-10-07

Last good Wayback Machine version

Disclaimer

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.

Table of Contents

Introduction

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:

Adlib Programming Guide - by Tero Totto, and

The PC Games Programmers Encyclopedia V1.0

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.

As far as I know, there are four major sound cards based on OPL3 chip:

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.)

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.

Description of the Synthesizer

Some basic facts

My card's user manual says: "[this card contains] ... a stereo music FM synthesizer with 20 channels consisting of four (4) operators each ... ". I thought: "Wow -- that's together eighty operators. This must be a GOOD sound-card." I was wrong. Just another advertising lie.

So let's clear some facts. First, OPL3 has only thirty-six (36) operators which can be combined in several ways:

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.

Second, the manual states this card is capable of "stereo" 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's all. So the sound can flow from very left side, center and very right side. No sound panning, no special stereo effects. :-(

Well, flaming apart, back to the main topic.

Synthesis modes

The OPL3 chip is capable of making sounds in several ways:

Two-operator Additive Synthesis

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.

Two-operator Frequency Modulation (FM) Synthesis

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.

Four-operator "Mess" Modulation Synthesis

All of OPL3'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.

Nice, aren't they?

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:

Note 1: Actually, modes FM-AM and AM-AM are redundant, because they can be replaced by any pair of 2-OP channels operating at the same frequency. In FM-AM mode, the operator assignment would be straightforward: (Op1, Op2) and (Op3, Op4), both running in FM mode. In the case of AM-AM Mode, a small rearrangement of operators would be necessary: (Op1, Op4) in AM mode and (Op2, Op3) in FM mode.

Note 2: This document uses AM as a shorthand form of Additive Synthesis. Actually this is not any kind of modulation, just a simple addition of two signals. The AM shorthand was chosen as an "obvious" opposite of FM (as seen on your radio receiver). Please note that the OPL2/3 chips are unable to automatically perform any kind Amplitude Modulation other than tremolo effect.

Percussion Mode

In this mode 6 operators are used to produce five different percussion instruments:

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.

This mode is identical with that of OPL2. For more details see ADLIB.DOC.

Programming the Synthesizer

OPL3 Base Port Assignment

OPL3 may be found at the following addresses:

ESS 688, etc.

The base address of the synthesizer will be called "base".

OPL3 I/O Ports

The chip occupies four I/O addresses:

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. 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't fit into single register set.

Unlike Adlib (OPL2), OPL3 doesn't need delay between register writes. With OPL2 you had to wait 3.3 us after index register write and another 23 us after data register write. On the contrary OPL3 doesn't need (almost) any delay after index register write and only 0.28 us after data register write. This means you can neglect the delays and considerably speed up your music driver. But using reasonable delays will certainly do no harm.

The data registers can't be read (they are write-only) on both OPL2 and OPL3.

Register Map

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.

(The register map is nearly the same so I dared to copy it from ADLIB.DOC.)

Status Register (base+0)

Empty fields are considered reserved and should not be used or relied upon their value.

Data Registers (base+1, base+3)

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's register numbers are not continuous. The following table shows which operator maps to which register set and offset (in hex).

The following tables summarize which operators form a channel in various modes:

Two-operator Melodic Mode

Two-operator Melodic and Percussion Mode

Four-operator Melodic Mode

Channels 3, 4, 5 and 12, 13, 14 can'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.)

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.

Channels 6, 7, 8 and 15, 16, 17 are always two-operator ones. They can't be grouped to form four-operator channels.

Four-operator Melodic and Percussion Mode

Examples

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 Appendix A.

OPL3 Register Reference

Status Register

Timer interrupts are not wired to any IRQ (why??). The timers can be used to detect the OPL2/OPL3 chip (see Appendix B).

Data Registers

01: Test Register / Waveform Select Enable

02: Timer 1 Count

Upward 8 bit counter with a resolution of 80 usec. If an overflow occurs, the status register bit is set, and the preset value is loaded into the timer again.

03: Timer 2 Count

Same as Timer 1, but with a resolution of 320 usec.

004 (port: base+1): IRQ-Reset / Mask / Start

104 (port: base+3): Four-Operator Enable

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.

105 (port: base+3): OPL3 Mode Enable

08: CSW / NOTE-SEL

20-35: Tremolo / Vibrato / Sustain / KSR / Frequency Multiplication Factor

40-55: Key Scale Level / Output Level

The following table summarizes which operators' output levels should be updated when trying to change channel output level.

60-75: Attack Rate / Decay Rate

80-95: Sustain Level / Release Rate

A0-A8: Frequency Number

Determines the pitch of the note. Highest bits of F-Number are stored in the register below.

B0-B8: Key On / Block Number / F-Number(hi bits)

The following formula is used to determine F-Number and Block:

F-Number = Music Frequency * 2^(20-Block) / 49716 Hz

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.

BD: Tremolo Depth / Vibrato Depth / Percussion Mode / BD/SD/TT/CY/HH On

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.

C0-C8: FeedBack Modulation Factor / Synthesis Type

These two bits can be used to realize sound "panning", but this method offers only three pan positions (left/center/right). These bits apply only to operators producing sound (Carriers). Modulators are not affected by their setting.

When in four-operator mode, the FeedBack value is used only by Operator 1, value of Operators 2, 3 and 4 is ignored.

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.

E0-F5: Waveform Select

WaveForm 0: Sine

WaveForm 1: Half-Sine

WaveForm 2: Abs-Sine

WaveForm 3: Pulse-Sine

WaveForm 4: Sine (even periods only)

WaveForm 5: Abs-Sine (even periods only)

WaveForm 6: Square

WaveForm 7: Derived Square

Note: Bit 5 of register 01 must be set to use waveforms other than sine. Waveforms 4-7 are available only on OPL3.

Appendixes

Appendix A - Examples

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.

Appendix B - Detection Methods

OPL2 Detection

An official method of Adlib (OPL2) detection is:

Notes:

OPL3 Detection

Note: This is NOT an official method. I have dug it out of a sound driver. I haven't tested it, because I haven't an OPL2 card (Adlib, SB Pro I). Nevertheless it "detects" my SB Pro II properly. ;-)

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).

The BLASTER Environment Variable

Perhaps the most recommended "detection" method. Reading this variable avoids blindfold I/O port scanning and possible device conflicts. The user is responsible for its proper setting.

The variable has this format:

BLASTER=Aaddr Iirq Ddma8 Hdma16 Pmidi Eemu Ttype

Examples:

References

... you can find (almost) everything you need there

... this is a number-one in my book-wishlist. If anyone wanted to get rid of the book, I wouldn't scorn it ... :-)

... I wonder if you can find something comprehensible in that.