# I/O: the two 6520 PIAs, the 6522 VIA, keyboard, cassette, user port, sound Wiring below is read from **SCH-320349 sheets 2 and 3** (the dynamic board, rev A) unless another source is named. The static board's sheet 1 is not pinned (U1): where the 2001 differs it is marked. Register-level behaviour belongs to the chip cores, not here. ## PIA1 (C7, 6520) at $E810: keyboard, cassette #1, EOI in, the retrace interrupt | Pin | Use | | --- | --- | | PA0-PA3 | keyboard row select (KEYA-KEYD) into a 74LS145 BCD-to-decimal decoder (C9), outputs 0-9 to the keyboard connector J5 | | PA4, PA5 | cassette #1 and #2 switch sense (through the cassette jumpers) | | PA6 | EOI IN (IEEE-488) | | PA7 | DIAG (J9 pin 20, the diagnostic sense line) | | PB0-PB7 | KIN0-KIN7, the keyboard's column inputs, 10K pull-ups (R18-R25) | | CA1 | cassette #1 read | | CA2 | EOI OUT (IEEE-488, through a 7417) | | CB1 | **VIDEO ON** from the master timing (sheets 6-8): the screen's interrupt source | | CB2 | cassette #1 motor (through Q4-Q6) | | IRQA, IRQB | the CPU's IRQ | The KERNAL scans the keyboard from that interrupt (UM2001: "Each time the interrupt occurs from the CRT, the keyboard is scanned"). OBSERVED in MAME's trace (mame-oracle.md): the KERNAL steps the row with a read-modify-write instruction on $E810, so the NMOS 6502's dummy write puts the old value on the port one cycle before the new one (two writes in one instruction, e.g. `F0` then `F1`). 6502-python already makes that dummy write; the PIA must see both. ## PIA2 (C6, 6520) at $E820: the IEEE-488 data bus | Pin | Use | | --- | --- | | PA0-PA7 | DI1-DI8, data in from the bus (MC3446 transceivers A7, A8) | | PB0-PB7 | DO1-DO8, data out | | CA2 | NDAC OUT (to A9) | | CB1 | SRQ IN | | CB2 | DAV OUT | | CA1 | (no connection seen on sheet 2) | | IRQA, IRQB | the CPU's IRQ | RESET also drives IFC on the bus through a 7417 (sheet 2). ## The VIA (C5, 6522) at $E840: user port, IEEE handshake, cassette #2, graphics | Pin | Use | | --- | --- | | PA0-PA7 | user port C-L (J2) | | CA1 | user port B | | CA2 | **GRAPHIC**: the character-set select to the character ROM (sheet 8). UM2001: POKE 59468 ($E84C, the PCR) with 14 selects the second (lower-case) set, 12 returns | | PB0 | NDAC IN | | PB1 | NRFD OUT | | PB2 | ATN OUT | | PB3 | cassette write (both decks) | | PB4 | cassette #2 motor | | PB5 | (to the J2 side: vertical drive / video sense on the drawing; to read again, U8) | | PB6 | NRFD IN | | PB7 | DAV IN | | CB1 | cassette #2 read | | CB2 | user port M; the speaker on CRTC boards (OBSERVED: MAME's `cbm8032` has a "Filtered DAC" speaker, `pet2001n` none) | UM2001 table 7.25 lists the same IEEE signal assignments (its OCR is scrambled; the schematic is the citation). ## Keyboard A 10 x 8 matrix: ten rows from the '145, eight columns into PIA1 port B. The graphics (N) and business (B) keyboards differ in their matrix layout and the editor ROM that decodes them (ROMNOTES: "The differences are the keyboard scan codes, and keyboard decoding"); the business keyboard of the 8032 is in zimmers `schematics/computers/pet/8032/` and archive.org `commodore-cbm-8032-keyboard-matrix` (not pinned yet). The keyboard is a host-side map from key to (row, column), one per keyboard row of `machine.py`. ## Cassette Two decks (the second on the rear connector). Deck 1: read on PIA1 CA1, motor on PIA1 CB2, sense on PIA1 PA4; deck 2: read on VIA CB1, motor on VIA PB4, sense on PIA1 PA5; write on VIA PB3 for both (SCH-320349 sheet 3). The board takes a pulse source per deck (like vic20-python's Datasette) and a `.tap` reader in a host helper. MAME's `pet_cass` list has 226 entries (census.md), none of them on this machine. ## Sound None on the 2001: programs toggle VIA CB2 into an external amplifier on the user port. The CRTC boards add a piezo/speaker on CB2 (OBSERVED, MAME device list; the 8032 schematic sheet to read, U9). The usual trick is the VIA's shift register in free-running mode (mode 4) clocking CB2 (the "CB2 sound" convention; MAME device `petucb2` "PET Userport 'CB2 Sound' Device"). The board's sound output is the CB2 pin level over time: the good-enough rule. ## The chip cores: reuse first | Chip | Existing family work | What the PET needs | Proposal | | --- | --- | --- | --- | | 6502 | **6502-python** (`sixfiveohtwo`, pin `81e0eb6`), 6502-rust | nothing for the computer (IRQ from bus callbacks, every bus cycle visible, the RMW dummy write) | pin it | | 6520 PIA x 2 | none built. williams-python and coco-python (Phase 0 tonight) propose **`m6821-python`**; atari8bit-python plans an in-board `Pia6520` | MOS82 p. 6-5: the 6520 is "pin and functionally compatible with the MC6820" and differs from the MC6821 only electrically (input current, drive) and in its dynamic enable (25 us maximum cycle time) | **a `mos6520` row of `m6821-python`**, with no register difference (DOC MOS82 6-5) (open decision 2) | | 6522 VIA | none built: vic20-python, bbcmicro-python, c64-python, oric-python and plus4-python's Phase 0s all propose a shared core (`mos6522-python`; c64-python says `via6522-python`) | ports, both timers, the shift register (CB2 sound), CA1/CA2/CB1/CB2 modes | pin `mos6522-python` (decision 3) | | 6545-1 / MC6845 | none built: bbcmicro-python and cpc-python propose **`crtc6845-python`** | the 6545-1's differences (below) as a row | a `mos6545-1` (and `sy6545-1`) row of `crtc6845-python` (decision 4) | ### What the 6545-1 adds to the 6845 (DOC: MOS82 application brief p. 6-9) "An enhanced version of the MC6845": a **status register** (a vertical-blanking bit and a light-pen-full bit), **linear or row/column** screen-memory addressing selectable, and (the same page's footnote contradicts its own table) interlace: the table says "No", the footnote "MOS MPS 6545 has interlaced mode" (C2). The R6545-1 data sheet (pinned, scan without a text layer: to OCR when the core is built) is the second reading. The PET editor ROMs program R8 (mode control) to 0 (PET_CRTC.csv, every row; a detector, not a judge), so the PET uses the 6845-compatible subset; the status register matters only to programs that read $E880.