# Port FE: the keyboard, the border and the beeper; the AY ## Keyboard (DOC: FAQ48) Any even port reads the keyboard; the high address byte selects half-rows, a 0 bit in it selecting the row, a 0 in bits 0-4 of the result meaning a key is down. Several rows selected at once AND their results. | Port | Bits 0..4 | | --- | --- | | FEFE | SHIFT, Z, X, C, V | | FDFE | A, S, D, F, G | | FBFE | Q, W, E, R, T | | F7FE | 1, 2, 3, 4, 5 | | EFFE | 0, 9, 8, 7, 6 | | DFFE | P, O, I, U, Y | | BFFE | ENTER, L, K, J, H | | 7FFE | SPACE, SYM SHIFT, M, N, B | The matrix has no diodes: with three keys down at the corners of a rectangle the fourth reads as pressed (FAQ48's example: CAPS, B and V give SPACE, so "Break into Program"). The board models the matrix as a set of closed switches and computes ghosting from it, not from a table. Bits 5 and 7 read 1. A joystick on a port that also decodes FE (Kempston on 1F, Sinclair on the keyboard rows) is a socket, later. The 128K's keypad (on the AUX/keypad connector, driven through the AY's port A) and the +2/+2A's Sinclair joystick sockets (wired to keyboard rows, with the pins "wired differently to the standard used by other manufacturers", FAQ128) are later sockets. ## Border, MIC and speaker (DOC: FAQ48) OUT to FE: bits 0-2 border colour, bit 3 MIC (active low), bit 4 EAR and speaker. The border changes in 4-T (8-pixel) steps; an OUT ending at T 14,339-14,342 (48K) changes the border exactly at the first screen byte's position, and port FE's own contention shifts when the OUT ends (ula-and-contention.md). **Bit 6 on read depends on the last OUT** (FAQ48 table, MEASURED by the FAQ's contributors on Issue 2 and Issue 3 boards): | Bits 4,3 written | Issue 2 reads | Issue 3 reads | pin 28 V (Iss 2 / Iss 3) | | --- | --- | --- | --- | | 1 1 | 1 | 1 | 3.79 / 3.70 | | 1 0 | 1 | 1 | 3.66 / 3.56 | | 0 1 | 1 | 0 | 0.73 / 0.66 | | 0 0 | 0 | 0 | 0.39 / 0.34 | with the 0.70 V threshold and the delayed fall described in tape.md. The +2A/+3 read bit 6 as 0 with no signal, independent of the OUT (FAQ128). The beeper is the level of bit 4 (and, more weakly, bit 3) on pin 28: the board outputs the pin's level as a sample stream, sampled per T-state edge; the analogue path (speaker, filtering) is an output-stage choice for hosts, recorded, not specified as hardware (Aubrey's rule: sound good enough). ## The AY-3-8912 (DOC: FAQ128, +3 manual part 30; core: ay8910-python) 128K, +2, +2A, +3: register select by OUT to FFFD, read back by IN from FFFD, data write by OUT to BFFD; clock 1.7734 MHz (half the CPU clock; +3 manual "1.7734MHz (to 0.01%)"). The 8912 has one I/O port (A), which on these machines carries the RS-232/MIDI lines and the 128K's keypad (+3 manual: "this device also controls the RS232/MIDI and AUX ports"). ay8910-python (local `76cace3`, PUBLIC) has the `AY8912` variant (ports: A only), counts input clocks (`tick()`), and its contract already names "1,773,400 Hz on a Spectrum 128". The board feeds it one input clock every two CPU T-states and brings it up to time before each write or read. Nothing in the core needs changing for the Spectrum; port A's pins are wired by the board to the RS-232/MIDI/keypad socket (cpu-core.md). The +3 manual's register list has a slip: R7 bit 3 is printed as "Channel C noise" twice (bits 5 and 3); bit 3 is channel A noise by the data sheet's layout (C12, a typo). The +2A/+3 audio output stage distorts the AY (the +2B/+3B fix it; Wiki): an analogue property, not modelled.