# The 8255A PPI, the keyboard, the speaker and the cassette Source names as in [cpu-8088.md](cpu-8088.md). ## The 8255A-5 (ports 60h-63h) Mode 0 throughout; the BIOS writes control word `99h` "SET 8255 A,C-INPUT,B-OUTPUT" (A81 p.196 / A-6; OBSERVED `63h<-99h` at 66 us). The 5160 BIOS first writes `89h` (A as output for its POST checkpoints) and later `99h` (XT p.335-338). | Port | 5150 (A81 p.40 / 2-24, A83 p.20 / 1-12) | 5160 differences (XT p.22 / 1-10) | | --- | --- | --- | | A (60h, in) | keyboard scan code, or switch block SW1 when PB7 = 1 (PA0 IPL diskette, PA2-3 board RAM, PA4-5 display, PA6-7 drives; 0 = switch on) | also POST diagnostic output | | B (61h, out) | PB0 timer 2 gate; PB1 speaker data; PB2 read RAM-size switches (SW2) or spare key; PB3 cassette motor off; PB4 -enable RAM parity; PB5 -enable I/O CH CK; PB6 -hold keyboard clock low; PB7 -enable keyboard / +clear keyboard and read SW1 | PB2 spare; PB3 selects high or low switch nibble; no cassette | | C (62h, in) | PC0-3 SW2 (RAM size x 32K) or spare-key bit; PC4 cassette data in; PC5 timer 2 output; PC6 I/O channel check; PC7 RAM parity check | PC0-3 the switch nibble PB3 selects; PC4 spare | Data sheet rules (I83 8255A sheet, PDF p.699): reset sets "all ports ... to the input mode"; "All of the output registers, including the status flip-flops, will be reset whenever the mode is changed". The board relies on this at the BIOS's mode writes. **Reuse:** sms-python already has an in-board `PPI8255` (mode 0) for the SC-3000 and SF-7000; the MSX and CPC Phase 0s propose extracting `i8255-python`. The PC uses only mode 0 with fixed directions. See [reuse.md](reuse.md). ## The keyboard (83-key, an Intel 8048 inside) - Cable: shielded, four wires: +5 V, ground, "two bidirectional signal lines" (clock and data); DIN pins 1 clock, 2 data, 3 reset (not used by the keyboard), 4 ground, 5 +5 V (A81 p.30, p.34 / 2-14, 2-18). - Inside: "a microcomputer (Intel 8048)" scans, self-tests, debounces, buffers "up to 20 key scan codes" (A81 p.30 / 2-14; A83 and XT say 16) and runs the handshake. - System board (A81 p.31 / 2-15; A83 p.83 / 1-75): a 74LS322 shift register assembles the serial bits onto PA0-7; a flip-flop raises IRQ1 "when a complete scan code is received"; PB7 clears the register (and the interrupt); PB6 holds the clock line low. - Scan codes: make 01h-53h, break = make + 80h (A81 p.30, p.33 / 2-14, 2-17). Typematic rate and delay are not in the manuals (U5). - Reset handshake (BIOS `KBD_RESET`, A81 p.209 / A-19; OBSERVED `61h<-0Ch`, ~20 ms, `CCh`, `4Ch`): hold the clock low about 20 ms, release, wait for IRQ1; "SCAN CODE 'AA' SHOULD BE RETURNED". The POST checks for AAh (A81 p.201 / A-11). ### The keyboard's firmware: what exists | Keyboard | MCU | ROM in MAME 0.285 | | --- | --- | --- | | 5150's 83-key (1981) | 8048 | `kb_pc83` 8048.u1: **no good dump known** | | 5160's 83-key | 8048 at 5.102535 MHz (MAME's clock, OBSERVED) | `kb_pcxt83` 4584751.m1, SHA-1 `4f5b2a07...`: present | | PCjr | 80C48, infrared, biphase serial with a 440 us bit cell and a 40 kHz carrier; the start bit raises NMI and the 8088 times the bits with the PIT (JR p.123, p.129, p.62-63) | not listed | | Tandy 1000 HX | 8048 | no good dump known | | MAME's default for `ibm5150` | a Keytronic PC3270 keyboard with an Intel 8051 (OBSERVED, `-listxml`) | 14166.bin present | So the 5150's own keyboard cannot be run at the MCU level from a dump. Two honest options (open decision 4): a **serial-interface model** (scan codes and the AAh self-test with stated timing, HYPOTHESIS until measured) for every machine, and the **XT keyboard's dumped 8048 ROM** run on `mcs48-python` as the referee for the interface model's timing (the two keyboards share the interface, A83/XT pp. 1-73ff). `mcs48-python` is Phase 0 (`../mcs48-python`, `03328ff`); this is its second family user after the Videopac. ## The speaker "TIMER CLKOUT 2 AND PPI BIT 1 -> DRV -> LOW PASS FILTER -> SPEAKER", GATE 2 from PPI bit 0 (A81 p.38 / 2-22); "approximately a 1/2 watt", and the timer, the PPI bit and modulation of the timer can be used "simultaneously" (A81 p.21 / 2-5). The filter's component values are not in the prose (U6: read the schematic sheet; "sound good enough" applies). Sample players drive the speaker as 1-bit PWM through channel 2 in mode 0 or by toggling PB1, so the speaker output must be the exact logic level per PIT tick, filtered afterwards. ## The cassette (5150 only) Written by PIT channel 2's output, read on PC4, motor relay on PB3; 1,000-2,000 baud with different bit-cell times for 0 and 1 (A81 p.21, p.35 / 2-5, 2-19). Later milestone; ROM BASIC's cassette commands are the test.