# The PSG and the general-purpose ports ## Chip and clock "GI AY-3-8910 Compatible. Clock 1.7897725 MHz (1/2 CPU clock)" [TDB p. 42, 1.3.6]. MAME 0.285 gives 142 of its MSX rows a `YM2149 SSG` and 122 an `AY-3-8910A PSG` (census.md). The S3527 and S1985 engines incorporate an SSG "equivalent of YAMAHA YM-2149" [S3527 p. 1]. I/O ports: A0h address latch, A1h data write, A2h data read [TH2 appendix 6]. [ay8910-python](../../ay8910-python) has the AY-3-8910 and YM2149 as variant rows, the two 8-bit ports as callables the board supplies (`port_a_in`, `port_b_out`), and on a YM2149 the clock divider pin (`clock_divider = 2`). Nothing new is needed. The board picks the row per machine (AY-3-8910 for the first MSX1 row if it carries one, YM2149 for engine machines) and ties the YM2149's divider pin as the engine does (U8: the engines' SEL pin level is not stated in the pages read; MSX software expects 1.79 MHz either way). The PSG output is mixed with the key-click bit (PPI port C bit 7), the cassette input monitor on some machines, and cartridge SOUNDIN (pin 49, [TDB p. 32]) by the board. ## Port A (input) and port B (output): the joystick connectors From [TDB p. 44, 1.7.12 "PSG Bit Assignments"]: | Port, bit | Direction | Use | | --- | --- | --- | | A0-A3 | in | up, down, left, right of the selected joystick port (J3 or J4, pins 1-4) | | A4-A5 | in | trigger A, trigger B (pins 6, 7) | | A6 | in | keyboard layout select: JIS = H, syllable layout = L (Japanese version only) | | A7 | in | CSAR: cassette read data | | B0-B1 | out | J3 pins 6, 7 as outputs (set H to use them as inputs; open-collector buffer) | | B2-B3 | out | J4 pins 6, 7 likewise | | B4 | out | J3 pin 8 | | B5 | out | J4 pin 8 | | B6 | out | port A input select: L = J3 (joystick 1), H = J4 (joystick 2) | | B7 | out | KLAMP: kana lamp (L = on), Japanese version only | So the board's `port_a_in` reads the connector chosen by the last `port_b_out` bit 6, ORs in the cassette bit (A7) and the layout strap (A6), and the joystick devices (two-button pads, paddles, mice, the Konami Hyper Shot) see pins 6-8 as outputs driven from port B, which is how mice and paddles are clocked. Controller devices are sockets (the controller list MAME carries: joystick, mouse, Hyper Shot, Vaus, Magic Key, SG adapter, XE-1AP, Towns pads; census.md lists its `ctrl` devices). ## Sound path questions (later, by the good-enough rule) The mix levels between PSG, key click, SCC and FM differ per machine and cartridge; no document read gives them (U9). Sound is allowed to be less exact than pictures (Aubrey's rule); the board states its mix as FITTED and moves on.