This is some very technical info I found during my experiments with real chip. I hope someone will find it interesting. YM2151 TIMING DIAGRAM +-------------------------------------------------------------------------------------------------------------------------------|--------- Cycle no. | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |10 |11 |12 |13 |14 |15 |16 |17 |18 |19 |20 |21 |22 |23 |24 |25 |26 |27 |28 |29 |30 |31 | 0 | 1 | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---|---+---+- | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _| _ _ D/A clock |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_ | | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---|---+---+- | _______________________________ | SH1 signal |_______________________________| |_______________________________________________________________|_________ | | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---|---+---+- | _______________________________| SH2 signal |_______________________________________________________________________________________________| |_________ | | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---|---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---|---+---+- | | | SO | x | x | x | D0| D1| D2| D3| D4| D5| D6| D7| D8| D9| S0| S1| S2| x | x | x | D0| D1| D2| D3| D4| D5| D6| D7| D8| D9| S0| S1| S2| x | x | (D/A data) | | | | R I G H T C H A N N E L | L E F T C H A N N E L | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---|---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---|---+---+- READ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | INTERNAL CH| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 0 | 1 | DATA OP| C2| C2| C2| C2| C2| C2| C2| C2| M1| M1| M1| M1| M1| M1| M1| M1| M2| M2| M2| M2| M2| M2| M2| M2| C1| C1| C1| C1| C1| C1| C1| C1| C2| C2| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | operator #| 24| 25| 26| 27| 28| 29| 30| 31| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| +---------------------------------------------------------------|---------------------------------------------------------------|--------- Note: ----- The SO (D/A data) is sequentially output to the YM3012 (stereo) or YM3014 (mono). Formula to calculate sample from SO data is: N = S2(2^2) + S1(2^1) + S0 where S2 = S1 = S0 = 0 - not allowed SAMPLE = (-1+D9 + D8(2^-1) + D7(2^-2) + D6(2^-3) + ... + D0(2^-9) + 2^-10) * 2^-N Anyway, important is that SO data is delayed by one sample compared to READ INTERNAL DATA. This is logical since chip has to sum all channels' outputs before it will send SO data (this is what the ACC (accumulator) does). YM2151 Test register (0x01): +----------+-----+------+-----+-----+------+------+------+-------+ | bit no. | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | +----------+-----+------+-----+-----+------+------+------+-------+ | hex val. | 80 | 40 | 20 | 10 | 08 | 04 | 02 | 01 | +----------+-----+------+-----+-----+------+------+------+-------+ | |LS/MS| RIen | HEG | NEG | HPGL | ILFO | HLFO | u_clk | +----------+-----+------+-----+-----+------+------+------+-------+ bit 6 - RIen (Read Internal data Enable) When set to 1, chip's internal data can be read via status register. Simply set this bit and read data that will come out sequentially via the 8-bit bus. Format of this data and the timing will be described later (diagram is above). bit 7 - LS/MS (Least Significant or Most Significant 8 bits of internal data) When 0 - chip's internal data read via status register is lower 8 bits (LSB), When 1 - chip's internal data is upper 8 bits (MSB) (plus something I haven't figured out). In other words: in order to read 8 LSB bits set this bit to 0, in order to read 8 MSB bits set this bit to 1. bit 5 - HEG (Halt Envelope Generator) When 1 - Envelope Generator gets halted. This means that *Phase* Generator data can be read out when: HEG bit is set to 1 (EG gets halted), and data coming out via the status register will be pure sinus wave at the _CURRENT_ EG output. This means you need to know _EXACTLY_ when to set this bit. Simple workaround is to do the following: - TL (Total Level) of the operator to minimum dB value (0x00) - it is max volume, - AR (Attack Rate) of the operator to maximum speed (shortest time) (0x1f), - D1L (Decay Level) of the operator to max (93 dB) (0xf0), - D1R (Decay Rate) of the operator to zero (infinite time) speed (0x00), - set KEYON of that operator, - wait a while (long enough so Attack phase of the EG can be done), - set HEG bit in the test register to 1, and its done, since EG will be halted generating 0 (zero) dB level for that operator (exactly speaking EG will stay in D1R phase) and, since 0 dB from EG means no change on the sinus data stored inside of the chip's internal ROM, you can read this ROM data. Careful reader will notice that it may not be needed to use HEG bit to read the data (bacause EG will be at 0dB anyway), but using this bit, one can make samples of pure PHASE generator innerworking - that is how I obtained phaseinc_rom[]. bit 4 - NEG (Negate output data) When 1 - output data sign will be simply inverted. Worth noticing is that when this bit is 1 - also chip output data will be negated, causing bad sound coming out of the speakers since the YM3012 (the D/A converter) does not expect the negated data !!! bit 3 - HPGL (Halt Phase Generator AND LFO amplitude modulation) When 1 - Phase Generator is halted. Also amplitude modulation (from LFO to Envelope Generator) is halted. You can use this bit to analyse Envelope Generator work. As it was in the case of HEG bit you need to know _EXACTLY_ when to set this bit. Unfortunately, there is no _simple_ way. You will need to synchronise on the chip output signals to know when to set it. bit 2 - ILFO (Internal LFO related) When 1 - LFO output (depends on selected waveform) LFO outputs some internal signals...what are they ? I did not test if this bit alters Phase Modulation in any way. Also alters timer A somehow. At least it sounds like a restart. bit 1 - HLFO (Halt LFO) When 1 - LFO gets HALTED (at maximum amplitude in case of AM). On the 1 to 0 transition LFO will be RESET to startup of the waveform (phase of the LFO _only_). bit 0 - u_clk (unknown, but probably internal clock related) When 1 - Envelope Generator times are much shorter (faster envelopes). I do not know if it alters Attacks parts of the envelope. I'm sure it alters Decays times. Also timers are much (twice ?) faster than normally. Perhaps this bit is disabling some internal clock divider. FWIW, frequencies of the operators are NOT altered by setting this bit. Jarek Burczynski s0246@poczta.onet.pl bujar@mame.net static UINT16 phaseinc_rom[768]={ 1299,1300,1301,1302,1303,1304,1305,1306,1308,1309,1310,1311,1313,1314,1315,1316, 1318,1319,1320,1321,1322,1323,1324,1325,1327,1328,1329,1330,1332,1333,1334,1335, 1337,1338,1339,1340,1341,1342,1343,1344,1346,1347,1348,1349,1351,1352,1353,1354, 1356,1357,1358,1359,1361,1362,1363,1364,1366,1367,1368,1369,1371,1372,1373,1374, 1376,1377,1378,1379,1381,1382,1383,1384,1386,1387,1388,1389,1391,1392,1393,1394, 1396,1397,1398,1399,1401,1402,1403,1404,1406,1407,1408,1409,1411,1412,1413,1414, 1416,1417,1418,1419,1421,1422,1423,1424,1426,1427,1429,1430,1431,1432,1434,1435, 1437,1438,1439,1440,1442,1443,1444,1445,1447,1448,1449,1450,1452,1453,1454,1455, 1458,1459,1460,1461,1463,1464,1465,1466,1468,1469,1471,1472,1473,1474,1476,1477, 1479,1480,1481,1482,1484,1485,1486,1487,1489,1490,1492,1493,1494,1495,1497,1498, 1501,1502,1503,1504,1506,1507,1509,1510,1512,1513,1514,1515,1517,1518,1520,1521, 1523,1524,1525,1526,1528,1529,1531,1532,1534,1535,1536,1537,1539,1540,1542,1543, 1545,1546,1547,1548,1550,1551,1553,1554,1556,1557,1558,1559,1561,1562,1564,1565, 1567,1568,1569,1570,1572,1573,1575,1576,1578,1579,1580,1581,1583,1584,1586,1587, 1590,1591,1592,1593,1595,1596,1598,1599,1601,1602,1604,1605,1607,1608,1609,1610, 1613,1614,1615,1616,1618,1619,1621,1622,1624,1625,1627,1628,1630,1631,1632,1633, 1637,1638,1639,1640,1642,1643,1645,1646,1648,1649,1651,1652,1654,1655,1656,1657, 1660,1661,1663,1664,1666,1667,1669,1670,1672,1673,1675,1676,1678,1679,1681,1682, 1685,1686,1688,1689,1691,1692,1694,1695,1697,1698,1700,1701,1703,1704,1706,1707, 1709,1710,1712,1713,1715,1716,1718,1719,1721,1722,1724,1725,1727,1728,1730,1731, 1734,1735,1737,1738,1740,1741,1743,1744,1746,1748,1749,1751,1752,1754,1755,1757, 1759,1760,1762,1763,1765,1766,1768,1769,1771,1773,1774,1776,1777,1779,1780,1782, 1785,1786,1788,1789,1791,1793,1794,1796,1798,1799,1801,1802,1804,1806,1807,1809, 1811,1812,1814,1815,1817,1819,1820,1822,1824,1825,1827,1828,1830,1832,1833,1835, 1837,1838,1840,1841,1843,1845,1846,1848,1850,1851,1853,1854,1856,1858,1859,1861, 1864,1865,1867,1868,1870,1872,1873,1875,1877,1879,1880,1882,1884,1885,1887,1888, 1891,1892,1894,1895,1897,1899,1900,1902,1904,1906,1907,1909,1911,1912,1914,1915, 1918,1919,1921,1923,1925,1926,1928,1930,1932,1933,1935,1937,1939,1940,1942,1944, 1946,1947,1949,1951,1953,1954,1956,1958,1960,1961,1963,1965,1967,1968,1970,1972, 1975,1976,1978,1980,1982,1983,1985,1987,1989,1990,1992,1994,1996,1997,1999,2001, 2003,2004,2006,2008,2010,2011,2013,2015,2017,2019,2021,2022,2024,2026,2028,2029, 2032,2033,2035,2037,2039,2041,2043,2044,2047,2048,2050,2052,2054,2056,2058,2059, 2062,2063,2065,2067,2069,2071,2073,2074,2077,2078,2080,2082,2084,2086,2088,2089, 2092,2093,2095,2097,2099,2101,2103,2104,2107,2108,2110,2112,2114,2116,2118,2119, 2122,2123,2125,2127,2129,2131,2133,2134,2137,2139,2141,2142,2145,2146,2148,2150, 2153,2154,2156,2158,2160,2162,2164,2165,2168,2170,2172,2173,2176,2177,2179,2181, 2185,2186,2188,2190,2192,2194,2196,2197,2200,2202,2204,2205,2208,2209,2211,2213, 2216,2218,2220,2222,2223,2226,2227,2230,2232,2234,2236,2238,2239,2242,2243,2246, 2249,2251,2253,2255,2256,2259,2260,2263,2265,2267,2269,2271,2272,2275,2276,2279, 2281,2283,2285,2287,2288,2291,2292,2295,2297,2299,2301,2303,2304,2307,2308,2311, 2315,2317,2319,2321,2322,2325,2326,2329,2331,2333,2335,2337,2338,2341,2342,2345, 2348,2350,2352,2354,2355,2358,2359,2362,2364,2366,2368,2370,2371,2374,2375,2378, 2382,2384,2386,2388,2389,2392,2393,2396,2398,2400,2402,2404,2407,2410,2411,2414, 2417,2419,2421,2423,2424,2427,2428,2431,2433,2435,2437,2439,2442,2445,2446,2449, 2452,2454,2456,2458,2459,2462,2463,2466,2468,2470,2472,2474,2477,2480,2481,2484, 2488,2490,2492,2494,2495,2498,2499,2502,2504,2506,2508,2510,2513,2516,2517,2520, 2524,2526,2528,2530,2531,2534,2535,2538,2540,2542,2544,2546,2549,2552,2553,2556, 2561,2563,2565,2567,2568,2571,2572,2575,2577,2579,2581,2583,2586,2589,2590,2593 };