# Notes: permissively licensed OPN2 source (fork survey, 2026-11-12) Pins for everything fetched: `reference/scratch/pins-source.json` (17 entries). Nothing was ported. No GPL/LGPL source was opened. ## 1. ymfm (Aaron Giles) - Repo https://github.com/aaronsgiles/ymfm, `main` = `81aec25ccbb98f4873a255f7551ac4dadac59b4a`. - Fetched to `reference/ymfm/`: LICENSE, README.md, src/ymfm.h (566 lines), ymfm_fm.h (463), ymfm_fm.ipp (1592), ymfm_opn.h (802), ymfm_opn.cpp (2485). - Licence, checked in each file: every source file begins `// BSD 3-Clause License` / `// Copyright (c) 2021, Aaron Giles` / `// All rights reserved.` LICENSE: "BSD 3-Clause License / Copyright (c) 2021, Aaron Giles". - megadrive-python's copy (`reference/src/mame/3rdparty/ymfm/src`): ymfm_fm.ipp, ymfm_fm.h, ymfm_opn.h byte-identical to the fresh copy; ymfm_opn.cpp and ymfm.h differ (not diffed further). - Read: README whole; ymfm_fm.ipp whole; ymfm_fm.h whole; ymfm_opn.h lines 44-340 and 726-802; ymfm_opn.cpp lines 38-440 and 2188-2485 (the OPN register class and the ym2612/ym3438/ymf276 classes). NOT read: the SSG resampler, ym2203/ym2608/ymf288/ym2610 classes (opn.cpp 441-2187), ymfm.h beyond the envelope enum and the busy hooks. ### 1.1 What the README says about itself (exact) - "These cores were originally written during the summer and fall of 2020 as part of the MAME project. As such, their design started off heavily based on how MAME works." - Goals: "1. provide BSD-licensed emulation cores that are more compatible with MAME's core licensing 2. modernize and unify the code around a common implementation of shared features 3. improve accuracy where possible based on discoveries made by others" - "The goal of these cores is not 100% digital accuracy. To achieve that would require full emulation of the pipelines, which would make the code extremely difficult to comprehend. ... If you want that level of accuracy, there are several decap-based emulation cores out there." (the three links are Nuked-OPN2, Nuked-OPM, Nuked-OPLL) - "Instead, the main goals are: 1. Extremely high (audibly indistinguishable) accuracy 2. Reasonable performance 3. Clean design with readable code 4. Clear documentation of the various chips" - The README does NOT say any code was derived from Nuked or from MAME's old GPL FM cores. It says "discoveries made by others". ### 1.2 Every place the OPN2-relevant code cites a source (this is the laundering question) | file:line | exact words | behaviour | |---|---|---| | ymfm_fm.ipp:48-49 | "the values here are stored as 4.8 logarithmic values for 1/4 phase / this matches the internal format of the OPN chip, extracted from the die" | log-sine table, 256 entries | | ymfm_fm.ipp:88-89 | "10-bit mantissas with an implied leading bit / this matches the internal format of the OPN chip, extracted from the die" | exponent (power) table, 256 entries | | ymfm_fm.ipp:171-176 | "this table has been verified against Nuked's equations, but the equations are rather complicated, so we'll keep the simplicity of the table" | detune table 32x4 | | ymfm_fm.ipp:325-329 | "opn_lfo_pm_phase_adjustment ... algorithm written to match Nuked behavior" | LFO vibrato shift table 8x8 and the adjustment arithmetic | | ymfm_fm.ipp:709-712 | "glitch means that attack rates of 62/63 don't increment if changed after the initial key on ...; nukeykt confirms this happens on OPM, OPN, OPL/OPLL at least so assuming it is true for everyone" | attack-rate 62/63 freeze | | ymfm_fm.ipp:744-746 | "clock_phase ... the OPN version of the logic has been verified against the Nuked phase generator" | phase step computation | | ymfm_opn.cpp:214-215 | "this table is based on converting the frequencies in the applications manual to clock dividers, based on the assumption of a 7-bit LFO value" | LFO divider table {109,78,72,68,63,45,9,6} | | ymfm_opn.cpp:223-225 | "to match the published values this should be 0x100 - subcount; however, tests on the hardware and nuked bear out an off-by-one error exists that causes the max LFO rate to be faster than published" | LFO period is count+1... (effective periods 108,77,71,67,62,44,8,5 samples per LFO step, see 1.3) | | ymfm_opn.cpp:260-263 | "QUESTION: max sensitivity should give 11.8dB range, but this value is directly added to an x.8 attenuation value, which will only give 126/256 or ~4.9dB range -- what am I missing? The calculation below matches several other emulators, including the Nuked implemenation." | tremolo depth | | ymfm_opn.cpp:306-309 | "lowest bit is determined by a mix of next lower FNUM bits according to this equation from the YM2608 manual: (F11 & (F10 | F9 | F8)) | (!F11 & F10 & F9 & F8)" | key code low bit | | ymfm_opn.cpp:206-210 | "MegaDrive Venom plays some notes with LFO globally disabled but enabling LFO on the operators, and it expects this added attenutation" | LFO off => AM value 0x3f (game evidence) | | ymfm_fm.ipp:681-685 | "check the cymbals sound in channel 0 of shinobi's test mode sound #5" | decay->sustain same step when SL=0 (game evidence) | | ymfm_fm.ipp:1228 | "QUESTION: old cores initialize this to 0x30 -- who is right?" | reg 27 at reset | | ymfm_fm.ipp:1570-1571 | "QUESTION: should this maybe just reset the IRQ bit and not all the bits?" | (OPL path) | | ymfm_opn.cpp:379 | "clamp to 17 bits in case detune overflows / QUESTION: is this specific to the YM2612/3438?" | phase step mask 0x1ffff | | ymfm_fm.ipp:1584-1586 | "timer B gets a small negative adjustment because the *16 multiplier is free-running, so the first tick of the clock is a bit shorter" | timer B prescaler (no source named) | No comment names Nemesis, the SpritesMind thread, MAME's `fm.c`, Jarek Burczynski or Tatsuyuki Satoh in the files read. (ymfm_fm.ipp:228 credits "David Viens' analysis, used with his permission" but that is the OPM key-code table, not OPN.) No hardware tests by named people are cited for OPN2 except "nukeykt confirms" (fm.ipp:711) and the unattributed "tests on the hardware and nuked" (opn.cpp:224). **Bearing on porting**: ymfm is BSD and is its author's own structure, not a transcription of Nuked. But four OPN2 behaviours are, by its own comments, tuned or verified against Nuked-OPN2 (detune table, LFO PM algorithm, phase generator, LFO off-by-one) and one rests on a statement by Nuked's author (AR 62/63). The two ROM tables are "extracted from the die" with no credit line. So a port of ymfm inherits Nuked-checked *numbers and behaviours* through a BSD intermediary. Whether that is acceptable under restart.md is a policy question (facts verified against a model vs code copied from it); ymfm's licence itself is clean. ### 1.3 What ymfm documents about OPN2, topic by topic **Register map** (ymfm_opn.h:50-107, comment block). Global: 21 test; 22 bit3 LFO enable, bits 2-0 LFO rate; 24 timer A upper 8; 25 timer A lower 2; 26 timer B; 27 bits 7-6 "CSM/Multi- frequency mode for channel #2" (csm = value 2 exactly, opn.h:198; multi_freq = value != 0, opn.h:199), bit5 reset B, bit4 reset A, bit3 enable B, bit2 enable A, bit1 load B, bit0 load A; 28 bits 7-4 key on/off operators 4..1, bits 1-0 channel (value 3 ignored; bit 2 adds 3 on OPNA+, opn.cpp:176-185). Per operator 30-9F: DT bits 6-4, MUL 3-0; TL 6-0; KS 7-6, AR 4-0; AM enable bit 7, DR 4-0; SR 4-0; SL 7-4, RR 3-0; SSG-EG bit 3 enable, bits 2-0 mode. Per channel: A0-A2 fnum low 8; A4-A6 block bits 5-3, fnum high bits 2-0; B0 feedback 5-3, algorithm 2-0; B4 bit7 L, bit6 R, bits 5-4 AM sensitivity, bits 2-0 PM sensitivity. Channel 3 special: A8-AA / AC-AE. Register slot ->operator order: address bits 3-2 select 0,2,1,3 (operator map opn.cpp:113-133: "the order in the map is carrier 1, carrier 2, modulator 1, modulator 2"). - A4/AC high-byte writes only latch (low 6 bits); the latch is applied when the low byte A0/A8 is written (opn.cpp:145-165). One latch for A4-A6 and one for AC-AE per register bank (latchindex = 0xb8 | bit 3 of address) — i.e. ymfm models a single shared latch per group, not one per channel. - Channel-3 special frequencies: operator offsets 2, 10, 6 take multi_block_freq(1), (2), (0) (opn.cpp:287-295), i.e. A9/AD -> one operator, AA/AE -> another, A8/AC -> third; the fourth uses the channel's A2/A6. - YM2612-only: 2A DAC data, 2B bit 7 DAC enable, 2C bit 3 = "test/low DAC bit" (opn.cpp: 2291-2305): DAC value is 9 bits, `(data ^ 0x80) << 1` plus bit 3 of 2C as the LSB. - Test register 21: stored, never used (`test()` accessor at opn.h:193 has no caller). 2C other bits: not modelled. **No test-register behaviour in ymfm for OPN2.** - Data written to the wrong bank's data port is ignored (opn.cpp:2287-2289, 2336-2338: a data write to port 1 is dropped if the last address write was to port 2, and vice versa). **Clocking / sample rate**. DEFAULT_PRESCALE 6 (opn.h:122); sample_rate = clock / (prescale * operators) = clock / (6*24) = clock/144 (fm.h:373-380). EG_CLOCK_DIVIDER = 3 (opn.h:123): the envelope counter advances once per 3 samples (fm.ipp:1304-1309). **Phase generator** (opn.cpp:350-384, fm.ipp:749-759). 20-bit phase ("10.10"), top 10 bits address the sine. fnum (11 bits) is doubled to 12 bits; if PM sensitivity != 0, a vibrato adjustment computed from the top 7 bits of fnum is added and the sum masked to 12 bits; step = (fnum12 << block) >> 2; detune (signed, from table by key code) added; masked to 17 bits; multiplied by MUL (MUL 0 = x0.5: `(step * (2*mul or 1)) >> 1`). Key code = block(3):fnum bit 10 : one bit from the manual's formula on fnum bits 10..7 (opn.cpp:297-312; constant 0xfe80). - Detune table: fm.ipp:181-191, 32 key codes x 4 magnitudes; DT bit 2 = sign. Values (key code 0..31, columns DT&3 = 0,1,2,3): col0 all 0; col1 = 0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,2,3,3,3, 4,4,4,5,5,6,6,7,8,8,8,8; col2 = 1,1,1,1,2,2,2,2,2,3,3,3,4,4,4,5,5,6,6,7,8,8,9,10,11,12,13, 14,16,16,16,16; col3 = 2,2,2,2,2,3,3,3,4,4,4,5,5,6,6,7,8,8,9,10,11,12,13,14,16,17,19,20,22, 22,22,22. - LFO PM table: fm.ipp:337-347, 8 sensitivities x 8 quarter-wave steps, each entry two shift amounts applied to the 7 fnum bits (7 = contributes nothing); sensitivities 6 and 7 shift the result left by 1 and 2; result >> 2; sign from the LFO's top PM bit. - Phase is reset to 0 at key-on (fm.ipp:545-549). **LFO** (opn.cpp:196-245). Counter with an 8-bit sub-count; divider table {109, 78, 72, 68, 63, 45, 9, 6} with the off-by-one note above; 7-bit LFO value (128 steps per cycle). AM = low 6 bits, inverted in the first half (a triangle 0x3f..0..0x3f, starting at 0x3f... see code: when bit 6 is 0 the value is XORed with 0x3f). PM = 5 bits taken from value bits 6..2: 3-bit magnitude, reflected by bit 3, negated by bit 4. LFO disabled: counter held at 0, AM value forced to 0x3f "since position 0 gives an AM value of 0x3f" — hmm: this means with LFO off but AM enabled on an operator the operator gets the maximum tremolo attenuation (Venom cited). *Check this reading against other sources: ares instead yields `~0 & 0x3f` = 0x3f too when clock = 0, consistent.* AM depth: shift = [7,3,1,0] for sensitivity 0..3 applied to (am << 1) (opn.cpp:256-267), commented "[0, 1.4, 5.9, and 11.8dB]" with the unresolved QUESTION above. **Envelope generator** (fm.ipp:145-167, 674-740; opn.cpp:329-342). 10-bit attenuation, 0 = loudest, 0x3ff = silent; reset state: release, 0x3ff. Rates: AR, DR, SR are 5-bit doubled; RR is 4-bit as `rr*4 + 2`; rate scaling adds `keycode >> (KS ^ 3)`; "ignoring ksr if the raw value is 0, and clamping to 63" (fm.h effective_rate). Sustain level: 4 bits << 5, with 15 treated as 31 (i.e. 0x3e0). Counter: a global counter stepped every 3 samples; for rate r, shift = r >> 2; the envelope updates when the low (11 - shift) bits of the counter are zero; the increment is taken from an 8-step pattern selected by 3 counter bits above that. Increment table fm.ipp:147-165, 64 rates x 8 steps (values, low nibble first step): rates 0-1 all 0; 2-5 pattern 0,1,0,1,0,1,0,1; 6-7 = 0,1,1,1,0,1,1,1; then for each group of four rates 8-47: [0,1,0,1,0,1,0,1], [0,1,0,1,1,1,0,1], [0,1,1,1,0,1,1,1], [0,1,1,1,1,1,1,1]; 48: all 1; 49: 1,1,1,2,1,1,1,2; 50: 1,2,1,2,..; 51: 1,2,2,2,1,2,2,2; 52-55 the same doubled (2/4); 56-59 doubled again (4/8); 60-63 all 8. (Read the table itself for exact nibble order.) Attack: `att += (~att * inc) >> 4` (exponential approach to 0); decay/sustain/release: `att += inc`, clamp 0x3ff. With SSG-EG enabled: `att += 4*inc` only while att < 0x200. Attack rate >= 62 at key-on: attenuation jumps to 0 at once (fm.ipp:551-553); attack with rate 62/63 set later does not move (see citation table). Attack->decay when attenuation reaches 0; decay->sustain tested in the same step ("important ... in the event that the sustain level is set to 0"). Key-on while already in attack state changes nothing (fm.ipp:534-536). Key-off while already in release changes nothing. Total level is added as TL << 3 to the 10-bit attenuation together with AM, clamped to 0x3ff (fm.ipp:767-785). EG output below "quiet" threshold 0x380 is treated as silence by ymfm as an optimisation (fm.ipp EG_QUIET, compute_ volume returns 0 when attenuation > 0x380) — an ymfm shortcut, not a chip rule. **SSG-EG** (fm.ipp:531-577, 618-666, 724-726, 772-774). Modes listed at fm.ipp:625-633 (000 repeat; 001 run once hold low; 010 alternate; 011 run once hold high; 1xx the same inverted). Work happens when attenuation bit 9 is set (>= 0x200). Hold modes: inverted flag = bit2 XOR bit1; once past attack, attenuation is forced to 0x200 (if inverted) or 0x3ff. Repeat modes: toggle inversion if alternating; if in decay or sustain, restart attack (without resetting phase unless mode bit 1 is 0, in which case phase = 0); in release, attenuation forced to 0x3ff. Output when inverted: `(0x200 - att) & 0x3ff`. At key-on: inverted = enable AND mode bit 2. At key-off while inverted: attenuation snapped to `(0x200 - att) & 0x3ff` and inversion cleared. No source is cited for any of this in the code. **Operator output** (fm.ipp:46-134, 469-490, 968-1075). Log-sine table: 256 entries, 12-bit values (4.8 fixed point attenuation) for a quarter wave, mirrored; exponent table 256 entries, 11-bit mantissa incl. implied leading 1, shifted by the integer part: 13-bit magnitude, 14-bit signed operator output. Envelope attenuation (10 bits, 4.6) is shifted left 2 and added to the sine attenuation. Modulation input: other operator's 14-bit output >> 1 added to the 10-bit phase. Feedback (operator 1 only): `(prev1 + prev2) >> (10 - fb)` for fb 1..7, none for 0. Algorithms: table fm.ipp:1017-1028 with the eight connection sets written out in comments (0: 1>2>3>4; 1: (1+2)>3>4; 2: (1+(2>3))>4; 3: ((1>2)+3)>4; 4: (1>2)+(3>4); 5: 1>(2,3,4); 6: (1>2)+3+4; 7: 1+2+3+4). ymfm computes all four operators of a channel from the *current* sample (no pipeline delay between operators, MODULATOR_DELAY false for OPN). Compare ares below, which uses previous-sample values on certain paths. **Channel output, bit depth** (opn.cpp:2380-2416). YM2612/YM3438: each operator output is shifted right 5 (14 bits -> 9 bits) before summing; carriers are summed with clipping to [-257, +256] (`clipmax` 256: "OPN2 is 9-bit with intermediate clipping"). YMF276: no shift, clip +-8191, "OPN2L is 14-bit", final sum >> 1 clamped to 16 bits, "properly mixed". - **Ladder / DAC discontinuity** (opn.h:765-766): per channel, per side: `value < 0 ? value - 3 : value + 4` in 9-bit units, applied to every channel each sample, including a muted (panned-off) DAC channel which contributes `dac_discontinuity(0)` = +4. NOTE: for FM channels ymfm applies the discontinuity to the *panned* value, so a channel panned off one side contributes +4 on that side (value 0). No source cited; no comment on where +4/-3 come from. YM3438: no discontinuity ("YM3438 doesn't have the same DAC discontinuity, though its output is multiplexed like the YM2612"). - Mixing: "output is technically multiplexed rather than mixed, but that requires a better sound mixer than we usually have, so just average over the six channels; also apply a 64/65 factor to account for the discontinuity adjustment" — final = sum * 128 * 64 / (6 * 65). - DAC: when 2B bit 7 set, channel 6's FM output is replaced by the 9-bit signed DAC value, using channel 6's pan bits. **Key on/off, CSM** (fm.ipp:426-438, 515-522, 585-610, 1504-1527). Key state per operator is the OR of sources (normal, CSM); key changes written by the CPU take effect at the next `prepare()`/clock, not instantly. CSM: when timer A expires and reg 27 bits 7-6 == 2, all four operators of channel 3 get a CSM key-on for one sample (cleared after one prepare, fm.ipp:434), so with no normal key-on the operator keys on then off one sample later. CSM_TRIGGER_MASK = channel index 2 only (opn.h:126). **Timers** (fm.ipp:1473-1527, 1559-1590). Timer A period = (1024 - TA) samples; timer B = 16 * (256 - TB) samples (one sample = 144 clocks). Loading: a timer starts when its load bit goes 1 while not running; clearing the load bit stops it. On expiry: flag set only if the enable bit is set; timer reloads itself. Timer B's divide-by-16 "is free-running, so the first tick of the clock is a bit shorter": first period shortened by (samples elapsed & 15). Writes to reg 27 are routed through a "sync" callback so they order correctly with timer expiry. Flag reset bits clear the flags. No latency constants beyond that. **Status / busy** (opn.cpp:2236-2265, 2312-2313). Status: bit 0 timer A, bit 1 timer B, bit 7 busy. Busy lasts `32 * prescale` = 192 master clocks after every *data* write (address writes do not set it), and needs the host to implement the time hooks. Read: only offset 0 returns status; offsets 1, 2, 3 return 0 with an "Unexpected read" log (so ymfm does NOT model the YM3438 returning status on all four ports, nor the discrete chip's behaviour on ports 1-3). **YM2612 vs YM3438 vs YMF276**: the only differences in ymfm are in `generate()`: the discontinuity (2612 only) and 9-bit truncated multiplexed output (2612, 3438) versus 14-bit mixed output (276). Same engine otherwise. Status read behaviour is the same for all three. **Reset** (fm.ipp:1218-1238, opn.cpp:60-70). All registers 0 except B4-B6 in both banks = 0xC0 (both outputs on); status cleared; reg 27 written 0; operators: phase 0, attenuation 0x3ff, release state, keys off; feedback history 0. LFO counter is not explicitly cleared in reset() but is zeroed on the first clock while LFO is disabled. The address latch and DAC registers of the ym2612 class are NOT reset by `ym2612::reset()` (only the constructor zeroes them). ### 1.4 Where ymfm says it is guessing The four QUESTIONs listed in 1.2 (tremolo depth, reg 27 reset value, 17-bit clamp, IRQ reset), "assuming it is true for everyone" (AR 62/63), and the README's statement that pipelines are not modelled. Nothing is marked "known wrong" for OPN2. Things it simply leaves out: test registers 21 and 2C (apart from the DAC LSB), status on ports 1-3, any write-to-effect latency, operator pipeline order. ### 1.5 Size and shape; how hard to extract OPN2 - Lines that matter for OPN2: fm.ipp tables + operator/channel/engine about 1,100 of its 1,592 (the rest is OPM key-code table and OPL rhythm); opn.cpp 38-440 (about 400) + 2188-2485 (about 300); opn.h about 250; plus roughly 100 lines of ymfm.h interface. About 2,000 lines of C++ of which roughly 550 are tables. - It is a template engine `fm_engine_base` parameterised by a register class (`opn_registers_base` for OPN2), with compile-time switches (EG_HAS_SSG, EG_HAS_DEPRESS, EG_HAS_REVERB, DYNAMIC_OPS, MODULATOR_DELAY, EG_CLOCK_DIVIDER) and caching (`opdata_cache`, `prepare()`, active-channel masks, EG_QUIET shortcut). Timers and busy go through a host callback interface (`ymfm_interface`). - Extracting OPN2 into Python: straightforward mechanically (fix the template to OPNA registers, delete OPL/OPM/OPLL branches, replace the callback timers by sample counting, drop the cache). The result would be perhaps 500-700 lines of Python plus tables. It is heavily table-driven for sine/exp/EG increments/detune/LFO-PM, formula-driven elsewhere. It would be sample-level (one step per 144 clocks), not cycle-level: no operator pipeline, no write latency, no test registers, no per-port status differences; the board's API items tied to internal timing have no counterpart in it. ## 2. Exodus (Roger Sanders, "Nemesis") - Local copy `/data/emu/megadrive-python/reference/src/Exodus` (commit 08f388f77040af28d16d44fdfbddb73252953161 per megadrive-python's pinned_repos.json; not re-verified against the network). - Licence: `License.txt` at the root: "MIT License / Copyright (c) 2024 Roger Sanders". The YM2612 device files carry no per-file licence header. - Files: `Devices/YM2612/YM2612.cpp` (4,061 lines, 200 KB), `YM2612.h` (494), `YM2612.inl` (791), `IYM2612.h` (169), `IYM2612.inl` (1,086). - **`YM2612.cpp` was NOT read beyond its first 12 lines.** Lines 8-12 say: "These tables are primarily based on the work of Jarek Burczynski in his OPN envelope generator implementation for the MAME core. Some corrections have been made to the attenuation increment table following hardware tests." MAME's FM core is GPL-headed, so under the fork's instruction the file is listed as tainted-in-part and reading stopped. The statement is about the EG tables at the top of the file only; the rest is, by the header's description, built from the author's hardware tests. Whether the remainder may be read (skipping the tables) is for the parent / owner. This is the single most valuable unread permissive source: the researcher's own implementation, 4,000 lines. - `YM2612.h` lines 1-49 (header comment) read in full; declaration comment lines skimmed by grep. `YM2612.inl`, `IYM2612.*` not read (register accessors and UI interface). - Header comment, exact: "This core emulates the Yamaha YM2612(OPN2) FM synthesizer chip. Extensive hardware testing has been done on the YM2612 in order to confirm the behaviour of the real chip, and this emulation core has been built using those results." - Its own to-do list (YM2612.h:7-27) is a statement of what its author considered NOT settled: - "Test and implement the saved results within operator circuits present in the MAME core." - "Investigate new information on the embedded DAC and implement more accurate handling of the DAC stage." - CSM overflow events tracked by timeslice not cycle count: "Rounding error can introduce some 1-cycle errors in CSM timing events". - "Make the render process cycle-accurate." - "Try toggling SSG-EG mode off when the output is currently inverted in an SSG-EG pattern, and see if the output inversion is also immediately disabled." - "Research and implement full support for all the behaviour of the YM2612 test register" - "Implement support for the busy flag. We will need to perform tests on the actual waiting times the chip requires. The integrated YM2612 will also need to be tested in case its waiting times are different. ... The DAC data is the register which is most likely to be hammered, and we have no documentation on its waiting times whatsoever, as the YM2608 didn't have it." - Its reference list (YM2612.h:37-48), exact: "YM2608(OPNA) Application Manual, Yamaha"; "Genesis Sound Software Manual, Sega Enterprises, 1992, scans by antime"; "MAME Envelope Generator Implementation, Jarek Burczynski"; "YM2151 Users Manual, Yamaha"; "YM2413 Application Manual, Yamaha, scans by Ricardo Bittencourt"; "Y8950 Application Manual, Yamaha, scans by Albert Beevendorp"; "YM2203(OPN) Datasheet, Yamaha"; "YM3015 Datasheet, Yamaha LSI"; "YM3016 Datasheet, Yamaha LSI"; "YM2612 Test Register Notes, Charles MacDonald"; "YM2151 Test Register Notes, Jarek Burczynski". (So the "ym2612 test register.txt" in FMDocs.7z is very probably Charles MacDonald's note.) - From the header's declarations: operator state is "attenuation; // 10-bit" and "phaseCounter; // 20-bit" (YM2612.h:150-151); a timer-A overflow log exists "in order to implement CSM support" (YM2612.h:440-441); "Temporary storage for fnum/block register latch behaviour" (YM2612.h:402). ## 3. ares YM2612 (ISC) - Repo https://github.com/ares-emulator/ares at `0b928930af4cc59ed99e942996f0d3c815379388`. Fetched `LICENSE` and `ares/component/audio/ym2612/` (7 files, 929 lines) to `reference/ares/`. - Licence: root LICENSE, ISC text, "Copyright (c) 2004-2025 ares team, Near et al". The LICENSE's further sections cover MAME-derived ROM decryption (BSD-3), sljit and other third-party parts; none names the YM2612. The ym2612 files have no licence header; `ym2612.hpp:5-6` says "//Yamaha YM2612 (OPN2) / //Author: Talarubi". - The files cite NO sources at all (grep for nuked, mame, nemesis, gens, hardware, credit: nothing). Two comments say "(confirmed behavior)" without saying by whom or how. So its provenance is unknown; treat as tier 5, independent structure, origin of numbers unstated. - Read: ym2612.cpp, channel.cpp, timer.cpp, constants.cpp, io.cpp whole; ym2612.hpp comment lines only; serialization.cpp not read. - What it documents that ymfm does not, or does differently: - **Envelope counter**: "12-bit counter: 1..4095 - zero-value is skipped (confirmed behavior)" (ym2612.cpp:21); stepped every 3 samples. - **Operator pipelining**: "Despite not emulating per cycle, operator pipelining has been accounted for. Given the op order 0-2-1-3, newly generated output is not available for the following op." (ym2612.cpp:62-63). In its algorithm code some modulation inputs use the *previous* sample's output (`old(n)`): algorithm 0: op3 <- old(op2); 1: op3 <- old(op1) + old(op2); 2: op3 <- old(op2); 3: op4 <- old(op2) + current(op3); 5: op3 <- old(op1). (ares indices 0..3 = operators 1..4.) ymfm has no such delay. - **Operator output precision**: modulation uses the 14-bit output with the lowest bit masked (`modMask = -(1<<1)`); summing uses outputs with the low 5 bits masked; channel sum clamped to 14 bits then low 5 bits masked (i.e. 9 significant bits). Feedback = `(prior + priorBuffer) >> (9 - fb)` on masked values. - **Output floor**: `y < 0x1a00 ? ... : 0 // -78 dB floor` (ym2612.cpp:49). - **Sine/exp tables computed from formulas** (ym2612.cpp:163-178): sine[x] = round(-256 * log2(sin((2x+1) * pi / 1024))) for x in 0..255; pow2[y] = round(1024 * 2^((255 - y)/256)); negative values stored as one's complement ("~z; //not -z"). This gives a formula for the two ROMs that needs no die-extracted table (whether it reproduces ymfm's tables entry for entry was not checked here; a build session can compare the two as data). - **Ladder**: "DAC output + voltage offset (crossover distortion)" (ym2612.cpp:140-147): in 14-bit units, negative samples: `enable * (v + 32) - 128`; non-negative: `enable * v + 128`; i.e. in 9-bit units -4+1 = -3 and +4, same magnitudes as ymfm, and a channel panned off still contributes +-4 according to the sign of its (unpanned) sample. Differs from ymfm, where a muted channel always contributes +4. The YM3438 alternative is a commented- out plain sum. - **DAC**: 8-bit sample `(sample - 0x80) << 6` replaces channel 6 (no ninth bit). - **Attack-rate freeze**: "will stop updating if attack rate is increased to upper threshold during attack phase (confirmed behavior)" (channel.cpp:51). - **SSG-EG** has a different formulation from ymfm (channel.cpp:60-87, 143-149): the check runs every sample in the phase step; "SSG is meant to skip the attack phase"; inversion is `ssg.attack != ssg.invert` and not applied in release; key-on clears `ssg.invert`; key-off with inversion active sets value = 0x200 - value. "SSG results in a 4x faster envelope"; with SSG enabled the step is 0 once value >= 0x200. - **Key scale / key code**: computed arithmetically, `(octave << 2) + ((clamp(fnum, 0x300, 0x4ff) - 0x300) >> 7)` (channel.cpp:113-114) — a different expression from the YM2608 manual's bit formula; whether they agree for all fnum was not checked here. - **Detune**: a 3x8 table scaled by `>> (3 - (keyScale >> 3))` (constants.cpp:36-40), different shape from ymfm's 32x4 table; mask 0x1ffff after detune, 0xfffff after multiple. - **Vibrato**: table of 8x16 multipliers, `pm = fnum * vibratos[depth][lfo&15] >> 9`, sign from LFO bit 4 (constants.cpp:12-21); **LFO dividers** {108,77,71,67,62,44,8,5} (constants.cpp:1-10) — consistent with ymfm's off-by-one-corrected periods. LFO disabled: clock and divider reset to 0 (io.cpp:15-21). - **Tremolo** shifts {7,3,1,0}, `(lfo << 1 >> depth)`; LFO AM triangle taken from the 7-bit LFO clock. - **EG rate table** (constants.cpp:42-53): per 4-rate group a counter shift (11 down to 0) and four 8-step patterns; same information as ymfm's 64x8 table in another layout. Release rate stored as `rr << 1 | 1` then doubled (= 4*rr + 2, same as ymfm). Rate scaling `keyScale >> (3 - KS)`, only when rate > 0, clamp 63. - **Timers** (timer.cpp, 15 lines): counters count up each sample; flag set on overflow if the IRQ-enable bit is set; reload on overflow or on the enable (load) bit's rising edge; timer B has an 8-bit free-running divider (so /256? the divider is a byte that must wrap — read the type in ym2612.hpp before relying on this) and "do not reset divider on reenable"; io.cpp:39-41 "Not sure if this is the right place for it, but... handle a specific use case to reset the subticks on timer B" when period is written while disabled. - **Not modelled, by its own comments**: "d7 = busy (not emulated, requires cycle timing accuracy)" (io.cpp:2); "d7 is enable bit for CSM mode (not yet implemented)" (io.cpp:57). No test registers. Channel-3 mode is any non-zero value of reg 27 bits 7-6. - Frequency latch: A4 latches, A0 applies (io.cpp:167-180), per channel (unlike ymfm's single latch). - Power-on: pan both on, envelope release at 0x3ff, release rate 1 (channel.cpp:153-194). ## 4. Other candidates | What | Licence finding | Read? | |---|---|---| | **IKAOPN** (Raki / ika-musume), https://github.com/ika-musume/IKAOPN at `a756c02c3c7d46bd6815b7a934d2ae76009199a7` | LICENSE: "BSD 2-Clause License / Copyright (c) 2022, Raki". README (575 bytes, read whole): "A cycle-accurate, die shot based OPN series core for FPGA implementation. It was reverse engineered with only Yamaha's datasheet and the die shots from siliconpr0n. This core does not reference any existing hard/soft core." Initial goals: "YM3438/YM2612 support with DAC characteristics emulation; YM2203 support; YM2608/YM2610B support". No mention of the excluded author in README or LICENSE (grep). | LICENSE and README only. At this commit the tree holds **no HDL**: only `resources/YM3438_schematics.pdf` (14.8 MB), `YM3438_wires.svg` (18.6 MB), `YM2608_schematics.pdf` (6.4 MB), `YM2608B_wires.svg` (2.2 MB) and a picture. The schematics were NOT fetched or opened: they are a traced die schematic (tier 1 by origin, permissive, and claimed independent of Nuked), i.e. as near a blueprint as the SEGAChips netlist was for the PSG; whose die photograph it traces and that author's wishes were not checked. For the parent's open decisions. Whether another branch holds Verilog was not checked. | | ym2612.js (apollolux) | A search summary says MIT-labelled but "a JavaScript port of the ... YM2612 core found in ... Genesis Plus GX". Tainted by its own description. | not opened | | MAME `fm2612.cpp` | search result title shows `// license:GPL-2.0+` | not opened | | Nuked-OPN2, Gens core, libOPNMIDI's bundled cores, Furnace `extern/opn` | LGPL/GPL per search summary | not opened | | jt12 (jotego) | GPL-3 (per the brief) | not opened | | Nuked-MD-FPGA | GPL-2.0 per a third-party index | not opened | | jgenesis, clownmdemu, BlastEm, Genesis Plus GX, PicoDrive | GPL/AGPL/non-commercial (brief, pinned_repos.json) | not opened | Only two web searches were run; the list of small MIT/BSD cores (Rust, JS) is not exhaustive. No further permissive software OPN2 core with stated independent provenance was found. ## 5. Slips and near misses - A web search summary quoted one line of description of ym2612.js and the licence line (`// license:GPL-2.0+`) of MAME's fm2612.cpp as a result title. No code seen. - ymfm's two "extracted from the die" ROM tables and its Nuked-verified tables were read (they are in BSD files); they are flagged in 1.2 so the parent can decide how to treat numbers whose stated provenance is a die extraction or a check against Nuked. - Exodus `YM2612.cpp`: lines 1-12 read (enough to see the MAME attribution), then stopped. - An unauthenticated GitHub API call (directory listing) was made for ares and IKAOPN; no identifying data sent. - The notes' description of ymfm's increment-table nibble order and of ares's timer-B divider width are from one reading; the build session should read the cited lines before use.