# The PPI (8255) and the keyboard ## The chip "Intel i-8255 compatible" [TDB p. 10]; I/O ports A8h port A, A9h port B, AAh port C, ABh mode set [TH2 appendix 6]. Engines fold it in (S3527, S1985). The 82C55A data sheet [8255]: three 8-bit ports in modes 0-2; a control write with bit 7 set chooses the mode, with bit 7 clear sets or resets one bit of port C; "All of the output registers ... will be reset whenever the mode is changed"; on hardware reset all ports are inputs, held at a logic one by the CMOS part's bus-hold devices (an NMOS 8255 has none) [8255 p. 3-4]. The MSX uses mode 0: A out, B in, C out (the BIOS writes the mode word at boot). ## Pin assignments [TDB p. 43, 1.7.11] | Port | Bits | Signal | Use | | --- | --- | --- | --- | | A | 0-7 | CS0L/H ... CS3L/H | primary slot of pages 0-3 ([slots-and-memory.md](slots-and-memory.md)) | | B | 0-7 | keyboard return | the selected row's eight keys, 0 = pressed | | C | 0-3 | KB0-KB3 | keyboard row select (to a 4-to-10 decoder: rows Y0-Y10) | | C | 4 | CASON | cassette motor, L = on | | C | 5 | CASW | cassette write data | | C | 6 | CAPS | CAPS lamp, L = on | | C | 7 | SOUND | the 1-bit "key click" sound output, mixed with the PSG [TH2 5.1.3] | ## The matrix Rows Y0-Y8 hold the 72 keys, Y9-Y10 the optional numeric pad [TDB p. 13, 1.3.5]. Row 0 holds 7 6 5 4 3 2 1 0 (bit 7 to bit 0), row 1 ; [ @ ¥ ^ - 9 8, row 2 B A _ / . , ] :, row 3 J I H G F E D C, row 4 R Q P O N M L K, row 5 Z Y X W V U T S, row 6 F3 F2 F1 KANA (CODE on international machines) CAP GRAPH CTRL SHIFT, row 7 RETURN SELECT BS STOP TAB ESC F5 F4, row 8 right down up left DEL INS HOME SPACE [TDB p. 13, Japanese layout, read from the page image]. The international and European layouts move the punctuation; the TH2 gives USA, international and European matrices [TH2 5.3.1 figs. 5.16-5.17B]. **Contradiction C1:** the TH2 as transcribed (Konamiman's markdown, `43959e9`) gives row 0 as `B L / 1 S X ,` and row 2 as `G 8 0 ] W F Z M`, which matches neither the TDB's drawing nor the well-known layout; it looks like a transcription error in the markdown (the TH2 scan was not available to check). Follow the TDB; the board's matrix tables are per layout and each cites its page. Board questions: - Rows 11-15 (port C values the decoder does not decode) read FFh? (U10; HYPOTHESIS: the 74145-style decoder drives no row, so all keys read released.) - **Ghosting**: pressing three keys at the corners of a rectangle makes the fourth appear on a diode-less matrix. Whether MSX keyboards have diodes is per machine (U11); default none, a machine-row switch, since some games read several keys at once. - The scan is software, "driven by VDP interrupt" [TDB p. 13]: the board only answers port B for the row in port C's low nibble at the moment of the read. ## Chip rule The 8255 is used by one other family board already: **sms-python** has an in-board `PPI8255` (mode 0, the SC-3000 keyboard and the SF-7000's second PPI). The MSX would be its second user, which is the charter's trigger: "A chip that a second project needs becomes its own core, extracted with history and pinned by both". It is a small, well-documented chip with a manufacturer data sheet as judge, and arcade boards in the family's plans use it too. Recommendation (decision 6): extract `i8255-python` from sms-python's `io.py` with history before msx-python's milestone 1, (it already clears the output latches on a mode word and sets or resets single port C bits), add what the MSX needs beyond it (the reset state as a variant field, NMOS floating or CMOS bus-hold high, and what an input port reads with nothing driving it), and have both boards pin it. Until it exists, msx-python keeps a pin-shaped class of its own (no code copied).