Skip to content
RetrogamingDeep Dive Published Updated 8 min readViews unavailable

Master System YM2413 FM Unit: Detection, Port Control, and Voice Modes

Explain the Mark III and Japanese Master System YM2413 path, from F2 control and hardware detection to OPLL instruments and rhythm-mode testing.

The Sega Mark III and Japanese Master System could use Yamaha’s YM2413 FM Operator Type-LL chip, either through a Mark III FM Sound Unit or as built-in hardware in the Japanese Master System. Many export models lack the chip. This makes FM sound a hardware-presence and control problem as much as a synthesis problem: a game must detect the device, select the correct output route, initialize its registers, and generate notes with a chip whose instrument set differs from a fully programmable FM synthesizer.

The YM2413 is an OPLL-style two-operator FM generator with an internal instrument ROM. Nine channels can play melody instruments in ordinary mode. Rhythm mode repurposes the upper channels to provide five percussion voices while retaining six melodic voices. The chip’s fixed preset patches make it inexpensive to program, but those patches are part of the sound signature and must not be replaced with an arbitrary General MIDI bank.

The Sega audio path and port F2

On Sega’s Mark III with the FM unit and on Japanese Master System configurations, the FM chip is accessed through the system’s I/O architecture. The audio control port at F2 is used to detect and enable the YM2413 on systems that contain it. It also participates in controlling the relationship between FM output and the SN76489 PSG. Behavior differs between the add-on unit and the integrated Japanese system, so a single global “FM enabled” Boolean is too crude.

The F2 interface is also a compatibility boundary. On systems without FM hardware, reads may be undefined; software should not assume a portable constant signature. Some systems allow PSG and FM output to be controlled or mixed differently from the standalone unit, where enabling one source can disable the other. An emulator should model a selected console region and expansion configuration, not infer all hardware from a game title.

Games that support FM typically probe for availability, configure the control port, then write address/data pairs to the YM2413. A correct emulator trace should include the port operation, selected register, write timestamp, FM hardware presence, PSG mute state, and audio route. If a game emits correct FM register writes but the output is silent, the failure may be in detection or routing rather than synthesis.

OPLL register and voice behavior

The YM2413’s instrument register selects one of the fixed patch definitions or the user-programmable instrument. The selected patch determines operator multiplier, envelope, waveform, feedback, and modulation-related parameters. A channel’s frequency and key-on fields establish pitch and note lifetime, while volume and sustain bits affect level behavior. These are chip registers with quantized values and envelope state, not a host oscillator API.

The custom instrument slot is important for software that wants timbres outside the preset set. Store its operator parameters exactly and define when a write affects sounding notes. Some register writes alter a running voice’s envelope or timbre; do not assume every patch is latched only at key-on unless supported by the chip reference. The Yamaha application manual should be treated as the register-level source, with emulator code serving as an implementation cross-check.

Rhythm mode changes channel allocation. It is not simply an extra sample player layered over nine unchanged FM voices. The chip’s rhythm bits enable percussion behavior that uses specific operator resources and leaves fewer melodic channels. A driver that fails to clear rhythm mode during transition can leave a melody voice silent or repurposed. Test changes into and out of rhythm mode while notes are held.

Frequency, envelopes, and output mixing

An OPLL voice is created by phase accumulation and envelope evolution in its operators. The operator frequencies derive from programmed pitch and multiplier settings, while attack, decay, sustain, and release control amplitude across time. A good emulator preserves these internal phases between output samples. Restarting operator phase on every host callback introduces discontinuities and changes the sound at different host rates.

The output is not a raw sequence of game samples. The YM2413 produces its own mixed audio signal, while the PSG may produce another. The console’s output circuit and model-specific control determine whether sources are combined, muted, or selected. Keep chip generation separate from console routing and any analog or output filtering. This architecture lets a test isolate wrong patch data from wrong system configuration.

Sample-rate conversion should happen after chip-time synthesis. A host callback may request a block at 44.1 or 48 kHz, but the chip’s clock and register writes define the source timeline. Use an integer or fixed-point phase accumulator for operator clocks, then a resampler with a documented filter. Log the YM2413 clock, host rate, and resampler phase in audio bug reports.

A conservative detection test

The following code is a test-plan sketch only. It intentionally does not assert one universal F2 value because absent-hardware reads and system wiring vary:

def configure_fm(io, has_fm_by_machine_config):
    if not has_fm_by_machine_config:
        return False

    before = io.read(0xF2)
    io.write(0xF2, 0x01)
    after = io.read(0xF2)
    return before != after

Real game detection may inspect particular bits or a counter behavior described in Sega-compatible development documentation. A test suite should instantiate explicit Mark III plus add-on, Japanese Master System, and export Master System cases, with expected undefined behavior documented rather than converted into a fabricated signature.

Emulator regression plan

Test all 16 instrument selections on each melodic channel, the user patch, key-on and key-off, each envelope stage, pitch extremes, volume extremes, and stereo/mono route as applicable. Validate rhythm-mode allocation and percussion voices independently. Then test the console control port with and without the FM device and under the model-specific PSG routing rules.

A useful deterministic recording begins with reset, writes a known patch, starts one note, sustains it for a fixed emulated duration, then releases it. Compare register state and chip output before any host resampling. Add a second test that changes instrument data while the note is active, and another that enables/disables the chip while the PSG is producing a steady tone.

Save states must include each channel’s phase, envelope stage and counter, key state, instrument selection, operator values, rhythm configuration, address-latch state, pending bus writes, chip clock phase, and console output selection. Restoring only visible registers can restart oscillators or envelopes at the wrong point and produce an audible discontinuity.

Acceptance criteria

A faithful Master System FM implementation distinguishes the YM2413 from the SN76489 PSG, models system and add-on availability, preserves F2 routing behavior, and emulates fixed OPLL patches, custom voice registers, rhythm allocation, key state, envelopes, and chip-time phase. It reports which machine configuration is active and does not invent defined behavior for an absent chip.

The FM Sound Unit is not merely a sound effect upgrade switch. It is a distinct piece of hardware with specific detection, control, and synthesis semantics. Treating those layers separately makes Japanese and export software differences understandable and gives emulator testing a precise target.

Driver initialization is a sequence, not a preset toggle

A robust driver first establishes that the machine configuration can expose FM, selects the output routing appropriate to that model, then initializes the chip’s address/data interface and clears stale key-on state. It should define the user instrument before assigning that instrument to a sounding channel. Finally, it starts notes and schedules later register updates against the chip clock. Keeping this sequence visible in trace logs makes a partial initialization easy to spot.

Address and data writes are separate bus transactions. The driver selects a register and then supplies its value; repeatedly writing data without changing the address can be legal for some register streams, but it still depends on the YM2413 interface timing. An emulator should preserve the address latch and write ordering, not accept a host-side batch as if every pair occurred at one instant.

The fixed instrument ROM creates a useful regression oracle. For a selected patch number, dump the effective operator values after initialization and compare them with the Yamaha manual’s patch definition or the documented chip behavior. If a game sounds wrong only on one patch, compare those values before changing envelope or filter code. This separates corrupted register addressing from an actual synthesis-model mismatch.

Avoid synthetic certainty for absent hardware

Many Master System compatibility checks were written for particular board wiring. Reading a port on an export console without FM can return undefined values, and a console variant may expose the FM unit through different integration than an external Mark III add-on. This is a case where inventing a deterministic read value for cleanliness can reduce compatibility. Use explicit machine models and document the chosen absent-device behavior as a hardware uncertainty if the original behavior is not measured.

For output comparisons, record whether the machine mixes or switches PSG/FM, the state of each chip’s mute or enable controls, and the final system route. A correct YM2413 waveform routed to a disabled output is not a synthesizer defect. Conversely, matching one game’s audio by silently enabling both chips can conceal an incorrect model and break another title that depends on the original switching behavior.

Related:

Sources:

Comments