/* SPDX-License-Identifier: MIT */ /* A probe around YM2608-LLE's YM2610 (reference/src/YM2608-LLE, GPL-2.0, pinned at * 7a2aca7; its README credits John McMaster for decapping the YM2610). A CLOSED * BOX: this file sets the model's input pins, calls its clock function and reads * its output pins, using only the names this probe already used when it came * over from the first repository (docs/restart.md). The model's .c files are * compiled, never opened; no internal state is read. Built by * validation/build_referees.sh into the ignored reference/build-referees/. * * Only the plain YM2610 is driven: the YM2610B bonding input is held at 0 and * cannot be set (Aubrey's decision of 2026-11-12; docs/decisions.md, decision 6). * * lle2610_probe run every measurement * lle2610_probe [args] one of: clock fm ssg busy timers flagctl * pages adpcma adpcmb lfo * lle2610_probe lfo [windows] AM depth per 32 samples * lle2610_probe adpcma [samples] [atl] [acl] constant ROM byte * lle2610_probe adpcmb [samples] [deltaN] constant ROM byte * * Every number it prints is tagged OBSERVED (YM2608-LLE 7a2aca7) where the * specification uses it. The run of 2026-11-19 is in * validation/results/lle2610_probe-2026-11-19.txt; docs/validation.md reads it. * * One "clock" below is one period of the input clock (phi M): the model is * called once with the pin low and once with it high. The serial output is read * from the pins: a bit is taken at each rising edge of phi S, and the bits are * counted from the first phi S rise after SH1 rises (docs/clocking-and-output.md). */ #include #include #include #include "fmopna_2610.h" static fmopna_2610_t chip; static unsigned long long now; static void clock1(void) { FMOPNA_2610_Clock(&chip, 0); FMOPNA_2610_Clock(&chip, 1); now++; } static void run(long clocks) { while (clocks-- > 0) clock1(); } /* A bus write held for `hold` clocks, then released for `after`. */ static void bus_write_held(int port, int data, int hold, int after) { chip.input.a0 = port & 1; chip.input.a1 = (port >> 1) & 1; chip.input.data = data; chip.input.cs = 0; chip.input.wr = 0; run(hold); chip.input.cs = 1; chip.input.wr = 1; run(after); } static void bus_write(int port, int data, int after) { bus_write_held(port, data, 16, after); } static void reg(int part, int address, int data) { bus_write(part * 2, address, 40); bus_write(part * 2 + 1, data, 200); } static int bus_read(int port) { chip.input.a0 = port & 1; chip.input.a1 = (port >> 1) & 1; chip.input.cs = 0; chip.input.rd = 0; FMOPNA_2610_Clock(&chip, chip.input.clk); /* settle the combinational path */ int value = chip.o_data & 255; chip.input.cs = 1; chip.input.rd = 1; FMOPNA_2610_Clock(&chip, chip.input.clk); return value; } static void power_on(void) { memset(&chip, 0, sizeof chip); now = 0; chip.input.cs = chip.input.wr = chip.input.rd = 1; chip.input.test = 1; chip.input.ym2610b = 0; /* the plain YM2610, always */ chip.input.rad = 0x80; chip.input.pad = 0x80; chip.input.ic = 0; /* /IC asserted */ run(4096); chip.input.ic = 1; run(4096); } /* Wait for the next SH1 rise, then decode `n` samples. Bits are taken at each * phi S rise after the clock on which SH1 rose (bit 0 is the first of them). * A word is 16 bits, LSB first, offset binary ($8000 = 0): the L word is bits * 15..30 of a sample, the R word bits 39..54 (it runs into the next sample). */ static unsigned char stream[48 * 8200 + 64]; static void capture(int n, int *left, int *right) { int last_sh1 = chip.o_sh1, last_s, s, i; long k = 0, need = 48L * n + 55; do { last_sh1 = chip.o_sh1; clock1(); } while (!(chip.o_sh1 && !last_sh1)); last_s = chip.o_s; while (k < need) { clock1(); if (chip.o_s && !last_s) stream[k++] = chip.o_opo & 1; last_s = chip.o_s; } for (s = 0; s < n; s++) { unsigned lw = 0, rw = 0; for (i = 0; i < 16; i++) { lw |= (unsigned)stream[48L * s + 15 + i] << i; rw |= (unsigned)stream[48L * s + 39 + i] << i; } if (left) left[s] = (int)lw - 32768; if (right) right[s] = (int)rw - 32768; } } /* ---- 1. clocks and the serial frame ------------------------------------- */ static void m_clock(void) { int i, last, edges = 0; unsigned long long t0 = 0; char s[4][160]; power_on(); last = chip.o_sh1; for (i = 0; i < 2000 && edges < 3; i++) { clock1(); if (chip.o_sh1 && !last) { if (edges) printf("clock: SH1 period %llu clocks\n", now - t0); t0 = now; edges++; } last = chip.o_sh1; } for (i = 0; i < 144; i++) { s[0][i] = chip.o_s ? '1' : '0'; s[1][i] = chip.o_sh1 ? '1' : '0'; s[2][i] = chip.o_sh2 ? '1' : '0'; s[3][i] = chip.o_opo ? '1' : '0'; clock1(); } printf("clock: one sample from an SH1 rise, one column per clock (silence)\n"); for (i = 0; i < 4; i++) { s[i][144] = 0; printf(" %s %s\n", (const char *[]){"phiS", "SH1 ", "SH2 ", "OPO "}[i], s[i]); } } /* ---- 2. FM: which columns key on, full scale, level steps ---------------- */ static void fm_voice(int part, int column, int pan, int tl) { int i; for (i = 0; i < 4; i++) { reg(part, 0x30 + column + i * 4, 0x01); reg(part, 0x40 + column + i * 4, i == 3 ? tl : 0x7f); reg(part, 0x50 + column + i * 4, 0x1f); reg(part, 0x60 + column + i * 4, 0x00); reg(part, 0x70 + column + i * 4, 0x00); reg(part, 0x80 + column + i * 4, 0x0f); } reg(part, 0xb0 + column, 0x07); /* algorithm 7, no feedback */ reg(part, 0xb4 + column, pan); reg(part, 0xa4 + column, 0x22); /* block 4 */ reg(part, 0xa0 + column, 0x69); reg(0, 0x28, 0xf0 | (part << 2) | column); } static void peak(int n, int *lo_l, int *hi_l, int *lo_r, int *hi_r) { static int l[4096], r[4096]; int i; capture(n, l, r); *lo_l = *hi_l = l[0]; *lo_r = *hi_r = r[0]; for (i = 0; i < n; i++) { if (l[i] < *lo_l) *lo_l = l[i]; if (l[i] > *hi_l) *hi_l = l[i]; if (r[i] < *lo_r) *lo_r = r[i]; if (r[i] > *hi_r) *hi_r = r[i]; } } static void m_fm(void) { int part, column, a, b, c, d, tl; for (part = 0; part < 2; part++) for (column = 0; column < 3; column++) { power_on(); fm_voice(part, column, 0xc0, 0); run(144 * 40); peak(1200, &a, &b, &c, &d); printf("fm: part %s column %d keyed on: L %d..%d, R %d..%d\n", part ? "II" : "I", column, a, b, c, d); } power_on(); fm_voice(0, 1, 0x80, 0); run(144 * 40); { int l[48], i, low = 0; capture(48, l, NULL); printf("fm: one carrier, TL 0, L words:"); for (i = 0; i < 48; i++) { printf(" %d", l[i]); low |= l[i] & 3; } printf("\nfm: low two bits ever set: %s\n", low ? "yes" : "no"); } peak(1200, &a, &b, &c, &d); printf("fm: pan $80 (L only): L %d..%d, R %d..%d\n", a, b, c, d); for (tl = 0; tl <= 16; tl += 8) { power_on(); fm_voice(0, 1, 0xc0, tl); run(144 * 40); peak(1200, &a, &b, &c, &d); printf("fm: one carrier, TL %d: L peak %d..%d\n", tl, a, b); } } /* Which key-on bit of $28 (D4..D7) keys the operator at register offset +0, +4, * +8, +C? Algorithm 7 (all carriers), only one operator at TL 0. */ static void m_slots(void) { int offs, bit, i, a, b, c, d; for (offs = 0; offs < 16; offs += 4) { printf("fm: operator at offset +%X sounds with key-on bit:", offs); for (bit = 4; bit < 8; bit++) { power_on(); for (i = 0; i < 16; i += 4) { reg(0, 0x31 + i, 0x01); reg(0, 0x41 + i, i == offs ? 0x00 : 0x7f); reg(0, 0x51 + i, 0x1f); reg(0, 0x81 + i, 0x0f); } reg(0, 0xb1, 0x07); reg(0, 0xb5, 0xc0); reg(0, 0xa5, 0x22); reg(0, 0xa1, 0x69); reg(0, 0x28, (1 << bit) | 1); run(144 * 40); peak(300, &a, &b, &c, &d); if (b > 0) printf(" D%d", bit); } printf("\n"); } } /* Channel 2 (part I, column 2) in the special mode ($27 D7-D6 = mode): which * F-number register pair does each operator follow? F-numbers $100 ($A2/$A6), * $200 ($A8/$AC), $300 ($A9/$AD), $400 ($AA/$AE), block 4; the pitch is read * by counting sign changes over 2048 samples. */ static void m_multifreq(int mode) { static int l[2048]; int offs, i, n; printf("fm: $27 = $%02X, channel 2: sign changes per 2048 samples by operator:", mode); for (offs = 0; offs < 16; offs += 4) { power_on(); for (i = 0; i < 16; i += 4) { reg(0, 0x32 + i, 0x01); reg(0, 0x42 + i, i == offs ? 0x00 : 0x7f); reg(0, 0x52 + i, 0x1f); reg(0, 0x82 + i, 0x0f); } reg(0, 0xb2, 0x07); reg(0, 0xb6, 0xc0); reg(0, 0x27, mode); reg(0, 0xa6, 0x21); reg(0, 0xa2, 0x00); reg(0, 0xac, 0x22); reg(0, 0xa8, 0x00); reg(0, 0xad, 0x23); reg(0, 0xa9, 0x00); reg(0, 0xae, 0x24); reg(0, 0xaa, 0x00); reg(0, 0x28, 0xf2); run(144 * 40); capture(2048, l, NULL); for (n = 0, i = 1; i < 2048; i++) if ((l[i] < 0) != (l[i - 1] < 0)) n++; printf(" +%X:%d", offs, n); } printf("\n"); } /* ---- 3. SSG --------------------------------------------------------------- */ static double analog_after(long clocks) { run(clocks); return chip.o_analog; } static void m_ssg(void) { int i, edges, code, period; unsigned long long t0; float before; for (period = 0; period <= 10; period += (period < 2 ? 1 : 8)) { power_on(); reg(0, 0x00, period); reg(0, 0x01, 0); reg(0, 0x07, 0x3e); reg(0, 0x08, 0x0f); run(20000); before = chip.o_analog; edges = 0; t0 = 0; for (i = 0; i < 200000 && edges < 3; i++) { clock1(); if (chip.o_analog > before) { if (edges == 2) printf("ssg: tone period register %d: %llu clocks a cycle\n", period, now - t0); t0 = now; edges++; } before = chip.o_analog; } } /* fixed levels: tone and noise off (the mixer then holds the channel high) */ printf("ssg: fixed level 0..15, channel A alone (pin value):"); for (code = 0; code < 16; code++) { power_on(); reg(0, 0x07, 0x3f); reg(0, 0x08, code); printf(" %.5f", analog_after(2000)); } printf("\n"); power_on(); reg(0, 0x07, 0x3f); reg(0, 0x08, 0x0f); reg(0, 0x09, 0x0f); reg(0, 0x0a, 0x0f); printf("ssg: A, B and C at level 15: %.5f\n", analog_after(2000)); power_on(); reg(0, 0x07, 0x3f); printf("ssg: all levels 0: %.5f\n", analog_after(2000)); /* the 32 envelope codes: shape $0D (attack, hold), envelope period 64. * Record each distinct pin value in the order it appears, and the clocks * between changes. */ power_on(); reg(0, 0x07, 0x3f); reg(0, 0x0b, 64); reg(0, 0x0c, 0); reg(0, 0x08, 0x10); reg(0, 0x0d, 0x0d); { float v[64]; unsigned long long when[64]; int n = 0; float last = chip.o_analog; v[n] = last; when[n++] = now; for (i = 0; i < 200000 && n < 64; i++) { clock1(); if (chip.o_analog != last) { last = chip.o_analog; v[n] = last; when[n++] = now; } } printf("ssg: envelope ramp (shape $0D, period 64): %d distinct steps\n", n); for (i = 0; i < n; i++) printf(" step %2d value %.5f after %llu clocks\n", i, v[i], i ? when[i] - when[i - 1] : 0ULL); } } /* ---- 4. BUSY ---------------------------------------------------------------- */ static void busy_after(const char *what, int part, int address) { unsigned long long t_end; int i, set_at_end; power_on(); bus_write(part * 2, address, 40); bus_write_held(part * 2 + 1, 0x00, 16, 0); t_end = now; set_at_end = bus_read(0) >> 7; for (i = 0; i < 4000 && (bus_read(0) & 0x80); i++) clock1(); printf("busy: data write to %s ($%02X, part %s): busy %s at the end of a 16-clock write, " "clear %llu clocks after it\n", what, address, part ? "II" : "I", set_at_end ? "set" : "clear", now - t_end); } static void m_busy(void) { unsigned long long t_end; int i, hold; busy_after("FM", 0, 0x30); busy_after("FM", 0, 0xa1); busy_after("FM", 1, 0x31); busy_after("FM common", 0, 0x22); busy_after("SSG", 0, 0x00); busy_after("ADPCM-B", 0, 0x12); busy_after("ADPCM-A", 1, 0x10); power_on(); bus_write_held(0, 0x30, 16, 0); t_end = now; for (i = 0; i < 4000 && (bus_read(0) & 0x80); i++) clock1(); printf("busy: address write alone: clear %llu clocks after it\n", now - t_end); for (hold = 2; hold <= 64; hold = hold < 16 ? hold + 2 : hold * 4) { unsigned long long t_fall, t_rise = 0; power_on(); bus_write(0, 0x30, 40); t_fall = now; bus_write_held(1, 0x00, hold, 0); for (i = 0; i < 64 && !(bus_read(0) & 0x80); i++) clock1(); t_rise = now; for (i = 0; i < 4000 && (bus_read(0) & 0x80); i++) clock1(); printf("busy: FM data write held %d clocks: BUSY seen from %llu to %llu clocks after /WR falls\n", hold, t_rise - t_fall, now - t_fall); } /* does a short write land? SSG register 0 is readable */ for (hold = 1; hold <= 16; hold++) { power_on(); bus_write(0, 0x00, 40); bus_write_held(1, 0x5a, hold, 200); bus_write(0, 0x00, 40); if (hold == 1 || bus_read(1) != 0x5a) printf("busy: SSG data write held %d clocks: register 0 reads %02X\n", hold, bus_read(1)); } } /* BUSY against the write's phase inside the 144-clock sample, and whether a * write made while BUSY is set lands. */ static void m_busy_phase(void) { int off, i, gap, lo = 99999, hi = 0, first_ok = -1; unsigned long long t_fall; for (off = 0; off < 144; off++) { power_on(); run(off); bus_write(0, 0x30, 40); t_fall = now; bus_write_held(1, 0x00, 32, 0); for (i = 0; i < 4000 && (bus_read(0) & 0x80); i++) clock1(); if ((int)(now - t_fall) < lo) lo = (int)(now - t_fall); if ((int)(now - t_fall) > hi) hi = (int)(now - t_fall); } printf("busy: over 144 write phases (32-clock writes): BUSY drops %d..%d clocks after /WR falls\n", lo, hi); /* a second data write (to SSG register 2, after an address write) `gap` * clocks after the first ends: does it land? */ for (gap = 0; gap <= 260; gap += 4) { power_on(); bus_write(0, 0x00, 40); bus_write_held(1, 0x11, 16, 0); run(gap); bus_write(0, 0x02, 16); bus_write_held(1, 0x22, 16, 300); bus_write(0, 0x02, 40); if (bus_read(1) == 0x22) { first_ok = gap; break; } } printf("busy: data, address, data: the second data write lands when the address write starts " ">= %d clocks after the first data write ends\n", first_ok); for (gap = 0; gap <= 260; gap += 4) { power_on(); bus_write(0, 0x00, 40); bus_write_held(1, 0x11, 16, gap); bus_write_held(1, 0x22, 16, 300); if (bus_read(1) == 0x22) break; } printf("busy: data, data (same address): the second lands from a gap of %d clocks\n", gap); } /* ---- 5. timers ---------------------------------------------------------------- */ static void m_timers(void) { int ta, tb, i, edges, last, flag; unsigned long long t0; static const int tas[] = {1023, 1020, 1000}; static const int tbs[] = {255, 254, 250}; for (int k = 0; k < 3; k++) { ta = tas[k]; power_on(); reg(0, 0x24, ta >> 2); reg(0, 0x25, ta & 3); reg(0, 0x27, 0x05); edges = 0; last = 0; t0 = 0; for (i = 0; i < 200000 && edges < 4; i++) { clock1(); flag = bus_read(0) & 1; if (flag && !last) { if (edges) printf("timers: A = %d: %llu clocks between flag rises (/IRQ pulled: %d)\n", ta, now - t0, chip.o_irq_pull); t0 = now; edges++; /* reset the flag with one data write (the address stays $27) */ bus_write(1, 0x15, 0); { /* the reset lands a few clocks later: wait for the flag to drop */ int w = 0; while (w < 1000 && (bus_read(0) & 1)) { clock1(); w++; } if (edges == 1) printf("timers: flag reset write: flag low %d clocks after /WR rises\n", w); } flag = 0; } last = flag; } } for (int k = 0; k < 3; k++) { tb = tbs[k]; power_on(); reg(0, 0x26, tb); reg(0, 0x27, 0x0a); edges = 0; last = 0; t0 = 0; for (i = 0; i < 200000 && edges < 4; i++) { clock1(); flag = (bus_read(0) >> 1) & 1; if (flag && !last) { if (edges) printf("timers: B = %d: %llu clocks between flag rises\n", tb, now - t0); t0 = now; edges++; bus_write(1, 0x2a, 0); { /* the reset lands a few clocks later: wait for the flag to drop */ int w = 0; while (w < 1000 && (bus_read(0) & 2)) { clock1(); w++; } if (edges == 1) printf("timers: flag reset write: flag low %d clocks after /WR rises\n", w); } flag = 0; } last = flag; } } /* /IRQ: timer A flag with its enable bit (D2) clear: does the flag rise? */ power_on(); reg(0, 0x24, 0xff); reg(0, 0x25, 0x03); reg(0, 0x27, 0x01); run(5000); printf("timers: A running, enable (D2) clear: status 0 %02X, /IRQ pulled %d\n", bus_read(0), chip.o_irq_pull); } /* ---- 6. flag control ($1C) ---------------------------------------------------- */ static void adpcma_block(int channel) { reg(1, 0x01, 0x3f); reg(1, 0x08 + channel, 0xdf); reg(1, 0x10 + channel, 0x00); reg(1, 0x18 + channel, 0x00); reg(1, 0x20 + channel, 0x00); reg(1, 0x28 + channel, 0x00); reg(1, 0x00, 1 << channel); } static int wait_status1(int mask, long limit) { long i; for (i = 0; i < limit && !(bus_read(2) & mask); i++) clock1(); return i < limit; } static void m_flagctl(void) { int part; unsigned long long t0; for (part = 0; part < 2; part++) { power_on(); adpcma_block(0); t0 = now; wait_status1(1, 400000); printf("flagctl: ADPCM-A channel 1 end flag after %llu clocks, status 1 %02X;", now - t0, bus_read(2)); reg(part, 0x1c, 0x3f); run(2000); printf(" $1C=$3F to part %s -> status 1 %02X\n", part ? "II" : "I", bus_read(2)); } /* mask or reset? at the part that took it */ power_on(); adpcma_block(0); wait_status1(1, 400000); reg(1, 0x1c, 0x00); run(2000); printf("flagctl: after the flag, $1C=$00 (part II): status 1 %02X\n", bus_read(2)); reg(1, 0x1c, 0x01); run(2000); printf("flagctl: then $1C=$01: status 1 %02X\n", bus_read(2)); reg(1, 0x1c, 0x00); run(2000); printf("flagctl: then $1C=$00: status 1 %02X\n", bus_read(2)); /* a masked channel's end: does the flag rise once unmasked afterwards? */ power_on(); reg(1, 0x1c, 0x01); adpcma_block(0); run(260000); printf("flagctl: channel 1 ended while masked: status 1 %02X;", bus_read(2)); reg(1, 0x1c, 0x00); run(2000); printf(" unmasked: %02X\n", bus_read(2)); /* key on again without clearing the flag: does the channel play? */ power_on(); adpcma_block(0); wait_status1(1, 400000); reg(1, 0x00, 0x01); { int l[600], i, moving = 0; capture(600, l, NULL); for (i = 1; i < 600; i++) if (l[i] != l[0]) moving = 1; printf("flagctl: key on again with the end flag still set: output %s\n", moving ? "moves (the channel plays)" : "flat (the channel is silent)"); } /* ADPCM-B's end flag (status 1 bit 7) and $1C bit 7, at each part */ for (part = 0; part < 2; part++) { power_on(); reg(0, 0x11, 0xc0); reg(0, 0x12, 0x00); reg(0, 0x13, 0x00); reg(0, 0x14, 0x00); reg(0, 0x15, 0x00); reg(0, 0x19, 0xff); reg(0, 0x1a, 0xff); reg(0, 0x1b, 0xff); reg(0, 0x10, 0x80); t0 = now; wait_status1(0x80, 400000); printf("flagctl: ADPCM-B (start 0, end 0, delta-N 65535) end flag after %llu clocks, status 1 %02X;", now - t0, bus_read(2)); reg(part, 0x1c, 0x80); run(2000); printf(" $1C=$80 to part %s -> status 1 %02X\n", part ? "II" : "I", bus_read(2)); } /* status 0 and the timer flags are not touched by $1C */ power_on(); printf("flagctl: status 0 / 1 after power-on: %02X / %02X\n", bus_read(0), bus_read(2)); } /* ---- 7. ADPCM-A with a constant ROM byte ---------------------------------------- */ static void m_adpcma(int byte, int samples, int atl, int acl, int pan) { static int l[8192], r[8192]; unsigned long long t0; int i, last, edges; power_on(); chip.input.rad = byte; last = chip.o_rmpx; edges = 0; t0 = 0; for (i = 0; i < 4000 && edges < 3; i++) { clock1(); if (chip.o_rmpx && !last) { if (edges == 2) printf("adpcma: RMPX rises every %llu clocks\n", now - t0); t0 = now; edges++; } last = chip.o_rmpx; } reg(1, 0x01, atl); if (pan >= 0) reg(1, 0x08, pan | acl); reg(1, 0x10, 0x00); reg(1, 0x18, 0x00); reg(1, 0x20, 0x00); reg(1, 0x28, 0x00); reg(1, 0x00, 0x01); if (samples > 8192) samples = 8192; capture(samples, l, r); printf("adpcma: byte %02X ATL %02X ACL %02X pan %s: L words, one per FM sample:\n", byte, atl, acl, pan < 0 ? "(not written)" : (pan == 0xc0 ? "C0" : "other")); for (i = 0; i < samples; i++) printf("%d%c", l[i], (i % 24 == 23) ? '\n' : ' '); printf("\n"); } /* ADPCM-A end address: how many 256-byte blocks play between a start and an * end in different 1 MiB pages (the manual asks for equal top nibbles) */ static void m_adpcma_pages(void) { static const int pairs[][2] = {{0x0000, 0x0000}, {0x0000, 0x0001}, {0x00ff, 0x0100}, {0x1000, 0x0000}, {0x0ffe, 0x1fff}}; unsigned long long t0; for (unsigned k = 0; k < sizeof pairs / sizeof pairs[0]; k++) { int st = pairs[k][0], en = pairs[k][1]; power_on(); reg(1, 0x01, 0x3f); reg(1, 0x08, 0xdf); reg(1, 0x10, st & 255); reg(1, 0x18, st >> 8); reg(1, 0x20, en & 255); reg(1, 0x28, en >> 8); reg(1, 0x00, 0x01); t0 = now; if (wait_status1(1, 432L * 512 * 8)) printf("adpcma: start $%04X end $%04X: end flag after %.2f blocks of 512 nibbles\n", st, en, (double)(now - t0) / (432.0 * 512)); else printf("adpcma: start $%04X end $%04X: no end flag within 8 blocks\n", st, en); } } /* LFO: carrier with AM (AMS 3), LFO rate `rate`; print the largest |word| in * each window of 32 samples (the carrier repeats about every 32 samples) */ static void m_lfo(int rate, int windows) { static int l[32]; int w, i, m; power_on(); reg(0, 0x22, 0x08 | rate); for (i = 0; i < 4; i++) { reg(0, 0x31 + i * 4, 0x01); reg(0, 0x41 + i * 4, i == 3 ? 0x00 : 0x7f); reg(0, 0x51 + i * 4, 0x1f); reg(0, 0x61 + i * 4, i == 3 ? 0x80 : 0x00); reg(0, 0x81 + i * 4, 0x0f); } reg(0, 0xb1, 0x07); reg(0, 0xb5, 0xc0 | 0x30); reg(0, 0xa5, 0x3f); /* block 7, F-number $7FF */ reg(0, 0xa1, 0xff); reg(0, 0x28, 0xf1); run(144 * 64); printf("lfo: rate %d, max |L| per 32 samples:", rate); for (w = 0; w < windows; w++) { capture(32, l, NULL); for (m = 0, i = 0; i < 32; i++) if (abs(l[i]) > m) m = abs(l[i]); printf(" %d", m); } printf("\n"); } /* ---- 8. ADPCM-B with a constant ROM byte ---------------------------------------- */ static void m_adpcmb(int byte, int samples, int delta) { static int l[8192]; int i; power_on(); chip.input.pad = byte; reg(0, 0x11, 0xc0); reg(0, 0x12, 0x00); reg(0, 0x13, 0x00); reg(0, 0x14, 0x00); reg(0, 0x15, 0x00); reg(0, 0x19, delta & 255); reg(0, 0x1a, delta >> 8); reg(0, 0x1b, 0xff); reg(0, 0x10, 0x80); if (samples > 8192) samples = 8192; capture(samples, l, NULL); printf("adpcmb: byte %02X delta-N %d: L words, one per FM sample:\n", byte, delta); for (i = 0; i < samples; i++) printf("%d%c", l[i], (i % 24 == 23) ? '\n' : ' '); printf("\n"); printf("adpcmb: status 1 %02X\n", bus_read(2)); } int main(int argc, char **argv) { const char *what = argc > 1 ? argv[1] : "all"; int all = !strcmp(what, "all"); if (all || !strcmp(what, "clock")) m_clock(); if (all || !strcmp(what, "fm")) { m_fm(); m_slots(); m_multifreq(0x00); m_multifreq(0x40); m_multifreq(0x80); } if (all || !strcmp(what, "ssg")) m_ssg(); if (all || !strcmp(what, "busy")) { m_busy(); m_busy_phase(); } if (all || !strcmp(what, "timers")) m_timers(); if (all || !strcmp(what, "flagctl")) m_flagctl(); if (!strcmp(what, "adpcma")) m_adpcma(argc > 2 ? (int)strtol(argv[2], NULL, 16) : 0x00, argc > 3 ? atoi(argv[3]) : 96, argc > 4 ? (int)strtol(argv[4], NULL, 16) : 0x3f, argc > 5 ? (int)strtol(argv[5], NULL, 16) : 0x1f, argc > 6 ? (int)strtol(argv[6], NULL, 16) : 0xc0); else if (all) m_adpcma(0x00, 48, 0x3f, 0x1f, 0xc0); if (all || !strcmp(what, "pages")) m_adpcma_pages(); if (!strcmp(what, "lfo")) m_lfo(argc > 2 ? atoi(argv[2]) : 7, argc > 3 ? atoi(argv[3]) : 200); if (!strcmp(what, "adpcmb")) m_adpcmb(argc > 2 ? (int)strtol(argv[2], NULL, 16) : 0x00, argc > 3 ? atoi(argv[3]) : 96, argc > 4 ? atoi(argv[4]) : 65535); else if (all) m_adpcmb(0x00, 48, 65535); return 0; }