# The two 6522 VIAs, the addressable latch and the keyboard Citations as in [start-here.md](start-here.md); VIA = Rockwell's R6522 data sheet, revision 9 (pinned TIFF scans; OCR in `reference/text/ocr/R6522_*.txt`). ## The parts Two 6522s on the Model B: the **system VIA** (IC3 at &FE40-&FE5F) and the **user VIA** (IC69 at &FE60-&FE7F) (DOC: SM85-1 parts list item 152 "6522, IC3, 69"; AUG 17). Both are clocked by 1MHzE and accessed in stretched cycles ([timing.md](timing.md)). The Master's parts list offers "6522 VIA NMOS 1MHZ" for IC6, IC8 and a CMOS 6522 as an option (DOC: MSM parts list item 126), so **some machines may carry a CMOS 65C22**, which differs from the NMOS part in documented ways (the WDC W65C22 data sheet is pinned by vectrex-python): a row field, U10. ## System VIA wiring (DOC: AUG 23.1-23.2) | Line | Use | | --- | --- | | PA0-PA7 | the **slow data bus** to the keyboard, the SN76489 and the speech chip | | CA1 | 6845 vertical sync (the 50 Hz interrupt) | | CA2 | keyboard: a key is down (interrupt) | | PB0-PB2 | address of the addressable latch IC32 (74LS259) | | PB3 | the data bit for the latch | | PB4, PB5 | joystick fire buttons (inputs, 1 = up) | | PB6, PB7 | speech processor ready and interrupt (inputs) | | CB1 | uPD7002 end of conversion | | CB2 | light pen strobe | | T1 | the MOS's 100 Hz clock | | T2 | speech timing | | SR | unused | **Addressable latch IC32** (DOC: AUG 23.2): B0 sound write enable (active low), B1 speech read, B2 speech write, B3 keyboard write enable (active low: autoscan off), B4-B5 the screen wrap size C0/C1 ([crtc6845.md](crtc6845.md)), B6 caps lock LED, B7 shift lock LED. "Each time the system VIA is written to, any changes on Port B which should affect the addressable latch are strobed into it by a flip-flop (IC31) which is triggered from the 1 MHz clock signal" (DOC: SM 3.6): the latch updates on a 1 MHz edge after the port write. **Master** (DOC: MRM "Slow Data Control Port"): PB6/PB7 become the CMOS clock chip's address strobe and chip enable; latch addresses 1 and 2 become the clock's R/W and data strobe. A row field. ## User VIA Port B is the user port; port A drives the Centronics printer port with CA1/CA2 its handshake (DOC: AUG 24). For the board it is a 6522 with sockets on its pins: the printer and user-port devices are later sockets, unconnected at milestone 1. ## The keyboard (DOC: SM 3.7; SMBP 5.15) A 74LS163 counter clocked at 1 MHz scans the column lines through a 7445 decoder while the keyboard write enable (latch B3) is high ("free running mode"); a key down on the strobed column raises CA2. With autoscan off the CPU loads a column and row through the slow bus (PA0-PA6) and reads the key's state on PA7. Link switches on the keyboard (the start-up options read by the MOS at reset) sit in row 0 of the matrix: AUG's OSBYTE &FF entry says "bits 0 to 7 refer to the links at the front of the keyboard circuit" (DOC: AUG 8, OSBYTE &FF); where they sit in the matrix is to be read from the keyboard circuit (AUG appendix J, SM) before it is written. BREAK is wired to the reset circuit, not the matrix (DOC: SM85-1 3.1). ## The chip itself: what the specification owes All registers, both timers (one-shot, free-run, PB7 output, pulse counting on PB6), the shift register in all eight modes, CA1/CA2/CB1/CB2 in every mode, input latching, IFR/IER, and the read and write side effects (reading T1C-L clears the T1 flag; writing ORA clears CA1/CA2 flags; the handshake modes). The corners that matter on the BBC: - **Timer reload timing**: T1 counts N, N-1, ... 0, -1 (FFFF), then reloads, so a free-running period is N + 2 cycles (DOC: VIA; vectrex-python's Phase 0 cites the same "N+1.5 one-shot, N+2 free-run" from the R6522/MCS6522 data sheets). - **When the CPU's read sees the counter and when IFR sets**, relative to the stretched cycle's 1 MHz edge: judged by Tom Seddon's real-hardware outputs (`O.VIA.T11`, `O.VIA.T21`, `O.VIA.T22`, `O.VIA.AC1`-`AC7`, `O.VIA.C1`-`C5`, `O.VIA.I1`, `O.VIA.I2`, `O.VIA.PB2`, `O.VIA.PB6`, `O.VIA.PB7`, `O.VTIMERS`, `O.VPOLL`, `O.VTIMEOU`): **tier 1**, the best evidence for any 6522 in the family so far. - **Power-on vs BREAK**: the system VIA is reset only by Reset A, at power-up (DOC: SM85-1 3.1), so its registers survive BREAK. The user VIA is reset by both. ## The chip rule: this is the second family machine vectrex-python's Phase 0 (docs/via.md, decision 2) keeps its 6522 in the board as a general `VIA6522` "with no Vectrex knowledge" and moves it "to `mos6522-python` when a second machine (most likely a Commodore or Acorn) needs one". The BBC Micro is that machine, with two instances; the Apple II's Mockingboard (two 6522s) and the VIC-20 and 1541 would be later users. **Open decision 1** recommends creating `mos6522-python` now, before either board writes its own, with: - variants as data: NMOS (MOS/Rockwell/Synertek R6522) first, CMOS W65C22 later (U10); - pin callbacks for PA/PB/CA/CB and an IRQ output; a `tick()` per phi2 (1 MHz on the BBC, the 6809's E on the Vectrex); - its judges: the data sheets (tier 2), **the b2 VIA outputs from a real BBC (tier 1)**, VICE's VIA test programs' reference values (tier 3; VICE itself is GPL, run only), and MAME (tier 5). Who builds it first is a scheduling question for Aubrey (the Vectrex board's milestone 1 is "VIA alone").