# The two CIAs (6526, 6526A, 8521) Each CIA has two 8-bit ports with direction registers, two 16-bit interval timers (A and B; one-shot or continuous; counting phi2 or CNT edges, and B can count A's underflows), a time-of-day clock in BCD with an alarm, fed with 50 or 60 Hz, an 8-bit serial shift register clocked by timer A or CNT, and an interrupt control register (DOC: PRG appendix M pp. 419-435; CIADS). Sixteen registers, mirrored through the 256-byte page. ## Wiring in the C64 | | CIA 1 ($DC00) | CIA 2 ($DD00) | | --- | --- | --- | | interrupt output | CPU IRQ (shared with the VIC) | CPU NMI (shared with RESTORE and the cartridge port) | | port A | keyboard columns (output); PRG's "joystick A" (bits 0-4); paddle select (bits 6-7) | bit 0-1 VIC bank (inverted), 2 RS-232 TXD, 3 IEC ATN out, 4 IEC CLK out, 5 IEC DATA out, 6 IEC CLK in, 7 IEC DATA in | | port B | keyboard rows (input); PRG's "joystick 1" (bits 0-4); bit 4 also the VIC's light-pen input | user port; RS-232 handshake lines | | FLAG | cassette read | user port FLAG2 (RS-232 receive) | | TOD | 50/60 Hz from the mains (CRA bit 7 selects) | same | | SP/CNT | user port | user port | Sources: PRG memory map ($DC00, $DD00 entries, pp. 330-331); PRG appendix M; VIC 3.11 for the light pen on PB4. The interrupt sharing (IRQ with the VIC and the cartridge port; NMI with RESTORE and the cartridge port) and the FLAG inputs are as commonly described and to be confirmed on SM's schematic in M1 (not checked in this Phase 0). The keyboard matrix, joysticks and paddles are host inputs presented through these ports; the matrix is resistive, so two keys on one line interact ("ghosting"): its electrical rule is U7. ## Corners the board needs - **Old and new CIA**: the 6526 and the 6526A/8521 (C64C) are known in the scene to differ in when a timer interrupt is visible (one cycle), in the ICR read, and in the TOD; the VICE test list carries both expectations (`CIA/irqdelay`, `dd0dtest`, `cia-timer` with "old"/"new" variants). A row setting `cia_model = "6526" | "8521"`. HYPOTHESIS until the tests' readmes are read and the hardware-verified ones named. - **Timer start/stop and load latency** (writes take effect a cycle or two later), timer B counting timer A underflows, one-shot reload, "force load" while running: `CIA/timerbasics`, `reload0`, `CIA-AcountsB`, Lorenz 2.15's CIA parts (tier 3: the suite was written to pass on a real C64). - **The serial shift register** (used by fast loaders over the user port, burst mode on the C128): `CIA/shiftregister` (hardware notes found by keyword). - **TOD** latching on read of hours, stopping on write of hours, the alarm, the 50/60 Hz divider: `CIA/tod` (hardware notes found by keyword). - **Port reads return pins, not latches**, where outputs fight inputs (keyboard plus joystick); PB6/PB7 timer outputs (`CIA/pb6pb7`); `ciaports`, `mirrors`. ## The chip rule | Family board | Uses a 6526? | | --- | --- | | c64-python | two | | the 1541 | no (two 6522 VIAs) | | a future c128-python, 1571, 1581 (8520), Amiga (8520) | yes; none exists in the family | So the CIA **stays in the board** (`c64_python/cia.py`, pin-shaped, no C64 names inside). Open decision 4 covers it with the SID.