# The two ACIAs and the intelligent keyboard ## MC6850 ACIA x 2 (DOC: MC6850; HWSPEC 4.2, 5.1, 9, 10; SVC "Musical Instrument Communication") | ACIA | Address | Clock | Divide | Rate | Peer | | --- | --- | --- | --- | --- | --- | | keyboard | FFFC00 control/status, FFFC02 data | 500 kHz from GLUE | 64 | 7812.5 bit/s | the IKBD's HD6301 SCI | | MIDI | FFFC04, FFFC06 | 500 kHz | 16 | 31.25 kbit/s | MIDI IN, OUT (THRU optional) | The MC6850 (data sheet): a control register (counter divide 1/16/64 or master reset; word select: 7 or 8 bits, parity, stop bits; transmit control with RTS and transmit-interrupt enable, or a break; receive-interrupt enable), a status register (RDRF, TDRE, DCD, CTS, framing error, overrun, parity error, IRQ), one transmit and one receive data register. Both ACIAs' IRQ outputs are wired together into the MFP's GPIP 4 (HWSPEC 10: the IRQ status bits tell keyboard from MIDI). Bus: the ACIAs are 6800-family peripherals, so their accesses are VPA/E-clock cycles (HWSPEC 9 groups them as "MC68xx" registers; [bus-and-memory.md](bus-and-memory.md), U5). Modelling: bit level at the 500 kHz clock divided by the counter (a bit every 128 µs on the keyboard link, 32 µs on MIDI), so a byte's arrival time, overrun and the transmit-empty timing are exact. The serial line between the keyboard ACIA and the HD6301 is the channel between two domains ([domains-and-speed.md](domains-and-speed.md)). **Chip rule**: the MC6850 is also the BBC Micro's serial and cassette ACIA (`../bbcmicro-python`, Phase 0, which proposes `mc6850-python` "on a second family user"). The ST is that second user: propose extracting **`mc6850-python`** when the second board is built (open decision 5). ## The IKBD: an HD6301V1 with Atari's firmware (DOC: HWSPEC 5.1; IKBD; IKBDINT; U07) - **The MCU**: a Hitachi **HD6301V1** running at 1 MHz (HWSPEC 5.1): an MC6801-compatible core with Hitachi's additions (the HD6301 family's bit-manipulation instructions, XGDX, SLP, the address and op-code traps), 4 KB of mask ROM, 128 bytes of RAM, 29 I/O lines in ports 1-4, a 16-bit timer and an SCI (U07, "HD6301V1/HD6303R User's Manual" 1.1). MAME 0.285: `HD6301V1 @ 4.00 MHz` input (OBSERVED, `-listdevices st`), and the traced E clock ran 999,367 cycles in one emulated second (OBSERVED), consistent with E = input / 4. - **The firmware** is Atari's: one 4,096-byte image, SHA-1 `1102f20d38f333234041c13687d82528b7cde2e1` (MAME `st_kbd.zip:keyboard.u1`, shared by all 30 ST-family sets: [census.md](census.md)). Bring your own; never fetched or kept. The traced reset vector is F000 (OBSERVED), the start of the 4 KB ROM. - **Wiring** (to read from SCH520/SCH1040 and IKBDINT, milestone 4): the key matrix on the ports, mouse XA/XB/YA/YB and joystick switches through the matrix, the two fire/mouse buttons on MCU pins (HWSPEC 5.1 pin tables), the SCI's TX/RX to the keyboard ACIA. - **The protocol** (IKBD, revised 1985-02-26): make/break scan codes (break = make + 80h), relative, absolute or keycode mouse modes, joystick event, interrogation, monitoring and keycode modes, a time-of-day clock with one-second resolution, status inquiries; RESET is 80h 01h (the only two-byte command), after which the IKBD answers F0h within 300 ms (the version byte: "the first release ... is version 0xF0"); a break of at least 200 ms on the line also resets it (IKBD 8, 9.1). - **MEMORY LOAD (20h), MEMORY READ (21h) and CONTROLLER EXECUTE (22h)** let the host load code into the MCU's RAM and run it (IKBD 9.24-9.26). Programs that do this (copy protections, demos with their own keyboard handlers) cannot run on a functional model of the protocol: **the IKBD must be the real HD6301 running the real ROM** for those, which decides the model (below). ## Modelling (proposed) - **The IKBD as its own domain**: an HD6301V1 core (m6800-python's MC6801 superset plus a Hitachi variant: [cpu-cores.md](cpu-cores.md)) running the player's ROM by SHA-1, with its on-chip ports, timer and SCI, and the keyboard matrix, mouse quadrature and joystick switches as inputs. It meets the main domain only on the serial line (7812.5 bit/s: a byte every 1.28 ms) and the reset line, so it is the board's cheapest thread split. - **A functional IKBD** (the documented protocol in Python, no ROM) only as a convenience socket for hosts without the firmware, named as a concession downstream; never the specification's default. - MIDI and RS-232: sockets with test-only fakes; a MIDI byte stream in and out is enough for a test program.