# The 8255 PPI, the AY-3-8912, the keyboard, the cassette and the printer port Source names as in start-here.md. ## The 8255 as wired (DOC: ap12 F, K; KT `8255cpc`; ACCC 29.1) Selected by A11 = 0; A9-A8 pick port A (`F4xx`), B (`F5xx`), C (`F6xx`) or control (`F7xx`). Always mode 0 on the CPC (KT: "Mode 1 ... and Mode 2 ... as far as I know, are not used by any program"). Circuitry resets the PPI at system reset (ap12 F). The parts used were NEC D8255AC-2, D8255AC-5 and Toshiba TMP8255AP-5, all NMOS (ACCC 29.1.3). The firmware's setting is control `&82`: A output, B input, C output (OBSERVED: MAME's first OUT is `F782 <- 82` at 16 µs; KT and ap12 F give the same directions). | Port | Direction | Bits | | --- | --- | --- | | A | in or out | the AY's data/address bus DA7-DA0 | | B | in | 7 cassette read; 6 Centronics BUSY; 5 /EXP (expansion port); 4 LK4 (fitted = 60 Hz: the firmware picks its CRTC table); 3-1 LK3-LK1 (the name the firmware prints: 111 Amstrad, 101 Schneider, ... KT's table); 0 CRTC VSYNC | | C | out | 7 AY BDIR; 6 AY BC1; 5 cassette write; 4 cassette motor; 3-0 keyboard row 0-15 | Port B bits 4-1 are fitted links, so they are board parameters (`links=` with a default of Amstrad, 50 Hz). Bit 0 is the CRTC's VSYNC, read live: a VSYNC wait loop is how most software synchronises (ACCC 4.2's story of the US 60-Hz table and its deadlock risk). What the board needs of the 8255 (data sheet: Intel 82C55A, pinned; the CPC's are NMOS, so the CMOS part's bus-hold pull-ups do not apply, U8): - a mode-0 control write sets the directions and **clears every output latch**, port C included (ACCC 29.1.2: "Port C bits are normally zeroed by the command register"); - the port C bit set/reset control word (KT gives an example that sets bit 7); - a read of an output port returns its latch, a read of an input port returns the pins (port A in input mode reads the AY's data bus; ACCC 29.1.3 reports that a cost-down CPC's PPI would not read back port B set to output, "to be verified"); - an input port's outputs float high (KT: "A device connected to a port of the 8255 will see &FF on the port outputs"). The Plus ASIC's copy of the 8255 is imperfect: a control write does not clear port C (ACCC 29.1.2), and KT `psg` warns that skipping the inactive state between AY functions breaks on the Plus. Those are Plus-row variants (plus-asic.md). **Reuse:** `sms-python`'s in-board `PPI8255` (mode 0; clears latches on a mode write; `port_c(floating)`) already has the CPC's semantics. The CPC is the family's third 8255 user after the SC-3000/SF-7000 and the MSX (msx-python's Phase 0 recommends extracting `i8255-python` from sms-python with history). Open decision 5. ## The AY-3-8912 (DOC: ap12 C; KT `psg`; ay8910-python) - Clock **1.00 MHz** "exactly", BC2 tied high (ap12 C). Its data bus is PPI port A; BDIR and BC1 are PPI port C bits 7 and 6: `00` inactive, `01` read, `10` write, `11` latch address (KT `psg`). Writes to port C therefore *are* the AY's bus strobes: the board calls `PSG.select()`, `.write()` or reads `.read()` when port C's bits 7-6 change, with port A's latch (or, for a read, puts the AY's output on port A's input pins). The firmware's sequence is visible in the MAME run: `F4xx <- reg`, `F6xx <- C0`, `F6xx <- 00`, `F4xx <- value`, `F6xx <- 80`, `F6xx <- 00` (OBSERVED). - ap12 C: "when writing or loading address ... the maximum duration of the write or load address command with BDIR high is 10 microseconds". The board's AY is written at the instant BDIR/BC1 go to `10` (ay8910-python's `write()` is an instant between input clocks); what a longer strobe does is outside the CPC's software contract (U9). - **AY port A is the keyboard's column input** (ap12 H; KT `keyboard`), register 14 with port A set to input. The AY-3-8912 has port A only, which `AY8912` models. - Output wiring: the three channels to the stereo socket and the mono speaker is common knowledge (A left, B both, C right) but is not in the pinned sources (U10). Sound is "good enough" territory for the family (Aubrey, 2026-11-13); the board outputs the three channel levels and a host mixes. `ay8910-python` needs nothing new: `PSG(AY8912)`, `tick()` per 1-MHz input clock (one per microsecond, four Z80 T-states), `port_a_in` wired to the keyboard matrix row the PPI selects. ## The keyboard and joysticks (DOC: ap12 H; KT `keyboard`) A 10 x 8 matrix of switches, rows 0-9 selected by PPI port C bits 3-0, read active-low on AY port A (ap12 H). Joystick 0 is row 9; joystick 1 shares row 6 with keys (KT). Rows 11-14 read FF on a real CPC (KT: "After testing on a real CPC"). The key-number table is KT's and SOFT 968 Appendix I's (not pinned yet). How the row decoder handles values 10-15 (a 74LS145 is the usual report: HYPOTHESIS, U11) and whether pressing three keys produces ghost keys (KT: "Watch out for KEYBOARD CLASH!") are to settle against a schematic. ## The cassette (DOC: ap12 F; KT `sound`, `cdtcpc`; SOFT 968 section 8) - Read data on PPI port B bit 7, write data on port C bit 5, motor on port C bit 4. The 464 has a built-in deck; 664/6128 have a socket. - The firmware's tape format (SOFT 968 section 8, The Cassette Manager; KT `sound`) is read by the firmware's own timing loops from the PB7 level; the board's job is only the level as a function of time (the same shape as zxspectrum-python's EAR). - Tape images are **CDT**, which is the TZX format with CPC conventions (KT `cdtcpc`: "the same as the TZX image format"; all timings in Spectrum T-states at 3.5 MHz; block 20 with pause 0 must not stop the tape; Spectrum-specific blocks ignored). The board converts pulse lengths from 3.5 MHz to its 4 MHz T-states. ## The printer port (DOC: ap12 G; ACCC 5.1) A write-only latch at `EFxx` (A12 = 0): bit 7 strobe, bits 6-0 data bits 7-1 to the Centronics port (7-bit printing); BUSY on port B bit 6. Cleared at reset (ap12 G). A socket: the board exposes the latch and BUSY; a printer is a host device.