# Timing: microcycles, bus phases, and the cycle count of every instruction Source tags as in [start-here.md](start-here.md). A cell marked *inferred* is a count from a source with the order of phases filled in by us; nothing measured stands behind the order. ## The microcycle - The CPU is driven by a two-phase non-overlapping clock (φ1, φ2). **One microcycle is two clock periods, four time slots TS1-TS4** (S1 p.17-18 Fig. 2-3; "1 MICROCYCLE = 2 CLOCK CYCLES", DS76 to DS82 and G82 p.45). Each microcycle is one microcode state and has **one bus control code**. - Limits: CP1600A 5 MHz (400 ns), CP1600 3.3 MHz (600 ns), CP1610 2 MHz (1 µs). The dynamic logic also has a floor: a wait state must end within 40 µs (S1 p.12, p.21). The Intellivision runs its CP1610 from 3.579545 MHz / 2, so 894,886 microcycles a second; that rate is what MAME calls the CPU's clock. - BC1, BC2, BDIR change within 70 ns of φ1 in TS1 (S1 p.39) and hold for the microcycle (the diagrams draw each code from TS1's hatched transition to the next TS1). An address or write data is valid on the bus from late TS1/TS2; read data is sampled around the φ1 that ends the DTB cycle (S1 p.18, p.41). - BUSRQ, INTR and INTRM are synchronised **every TS1** (S1 p.24, p.25). BDRDY is sampled in the TS1 after a BAR or ADAR cycle (S1 p.39). EBCI is sampled in TS1 of a BEXT's fifth microcycle (S1 p.32). The core's unit of time is the microcycle. Nothing below the microcycle needs modelling for the board: the time slots matter only as the answer to "is a line that changed during cycle *n* seen at the end of cycle *n* or *n + 1*" (U9). ## The eight bus phases | BDIR | BC1 | BC2 | Phase | Meaning | Who drives D0-D15 | | --- | --- | --- | --- | --- | --- | | 0 | 0 | 0 | **NACT** | no action | nobody | | 0 | 1 | 0 | **ADAR** | addressed data to address register: the word at the latched address becomes the new latched address | the addressed device | | 0 | 0 | 1 | **IAB** | interrupt address to bus: a device supplies the new PC (interrupt or reset) | external logic | | 0 | 1 | 1 | **DTB** | data to bus: read from the latched address | the addressed device | | 1 | 0 | 0 | **BAR** | bus to address register: latch this address | CPU | | 1 | 1 | 0 | **DW** | data write, first cycle | CPU | | 1 | 0 | 1 | **DWS** | data write strobe, second cycle (same data) | CPU | | 1 | 1 | 1 | **INTAK** | interrupt acknowledge; the bus carries the stack pointer, to be latched as an address | CPU | Pin levels from S1 p.10-11 (the table's own column order there is BC1, BC2, BDIR) and checked against the waveforms on S1 p.27-35: IAB is BC2 alone, ADAR is BC1 alone, DW raises BC1 and DWS raises BC2. **Mind the column order when comparing sources**: the wiki's Bus Phases table and the HDL cores order the code BDIR, **BC2**, BC1, in which ADAR is `001`, IAB `010`, DW `101`, DWS `110`. The two agree; a reader who assumes BDIR, BC1, BC2 for the wiki's table swaps four phases. BDIR = 1 exactly when the CPU drives the bus. The AY-3-891x sound chips use the same three lines by design. ## Building blocks | Block | Phases | Cycles | Source | | --- | --- | --- | --- | | fetch | BAR(PC) NACT DTB NACT | 4 | S1 p.28 | | read through a register, or immediate | BAR(EA) NACT DTB NACT | 4 | S1 p.29 | | direct read | BAR(PC) NACT ADAR NACT DTB NACT | 6 | S1 p.30 | | write | BAR(EA) NACT DW DWS NACT | 5 | S1 p.31 | | direct write | BAR(PC) NACT ADAR NACT DW DWS NACT | 7 | wiki Bus Phases; the count is S1 p.55 | | double-byte read | BAR(EA) NACT DTB BAR(EA') NACT DTB | 6 | wiki Bus Phases (no NACT after either DTB); S1 p.23 gives the execute part as "BAR, NACT, and then DTB" | | internal execute | NACT NACT | 2 | S1 p.23 "Register-Register: 2, NACT" | | two-position shift | NACT NACT NACT NACT | 4 | S1 p.23 "Shift: 2 or 4 NACT" | | branch tail, taken | BAR(PC+1) NACT DTB NACT NACT | 5 | G82 Fig. 12a | | branch tail, not taken | BAR(PC+1) NACT NACT | 3 | G82 Fig. 12a: **no DTB**, the displacement is never read | | interrupt | INTAK(R6) NACT DW(PC) DWS(PC) NACT IAB NACT NACT NACT | 9 | S1 p.35 = G82 Fig. 15 | | reset | NACT IAB NACT NACT NACT, then the first BAR | 5 | S1 p.27, O81 p.2-13 (C1) | During ADAR the CPU does not use the word on the bus: the *devices* latch it as the next address, and the CPU never learns the direct address. A direct instruction therefore issues only one BAR after its fetch, carrying the address *of the address word* (PC + 1), never the operand's address. ## Every instruction "Docs" is S1 p.53-58 and G82 p.45 where they agree. The votes column lists only disagreement. | Instruction | Phases | Docs | Votes against | | --- | --- | --- | --- | | HLT | fetch | 4 | wiki "infinity"; see C8 | | SDBD EIS DIS TCI CLRC | fetch | 4 | | | SETC | fetch | 4 | **MAME 6** (measured in our trace, C3) | | INCR DECR COMR NEGR ADCR | fetch + 2 NACT | 6 | jzIntv 7 when the register is R6 or R7 (C4) | | GSWD NOP SIN RSWD | fetch + 2 NACT | 6 | | | shift or SWAP, one position | fetch + 2 NACT | 6 | | | shift or SWAP, two positions | fetch + 4 NACT | 8 | **MAME 6 for `SARC r,2`** (C3) | | MOVR (TSTR) | fetch + 2 NACT | 6 | | | MOVR to R6 or R7 (JR) | fetch + 3 NACT (*inferred*) | 7 | S1 p.53 footnote, DS80 "6/7"; DS76/77 print 6 only | | ADDR SUBR CMPR ANDR XORR (CLRR) | fetch + 2 NACT | 6 | jzIntv 7 when the destination is R6 or R7 (C4) | | J JE JD JSR JSRE JSRD | fetch, fetch, fetch | 12 | **jzIntv 13, FreeIntv 13; HW26 13** (its fit, one more NACT at the end; C5). Bliss 12 | | B, branch taken, BEXT taken | fetch + BAR NACT DTB NACT NACT | 9 | | | NOPP, branch not taken | fetch + BAR NACT NACT | 7 | | | MVO (direct) | fetch + direct write | 11 | | | MVO@, PSHR, MVOI | fetch + write | 9 | | | MVI ADD SUB CMP AND XOR, direct | fetch + direct read | 10 | jzIntv +1 for R6/R7 destination (C4) | | ... indirect R1-R5 | fetch + read | 8 | jzIntv +1 for R6/R7 destination (C4) | | ... immediate | fetch + read at PC+1 | 8 | jzIntv +1 for R6/R7 destination (C4) | | ... stack (PULR) | fetch + 3 cycles + read (*order inferred*, U6) | 11 | jzIntv 12; HW26 12 for `PULR R7` (C4, C5) | | ... after SDBD, R1-R5 or immediate | fetch + double-byte read | 10 | HW26 11 for `SDBD; MVI@ R4,R7` (C5) | | ... after SDBD, R6 | not supported | - | wiki 10; MAME 13; HW26 behaviour only (C9) | | ... after SDBD, direct | not supported | - | HW26: 10 (*model's count*); jzIntv 13 (C10) | | interrupt entry | above | 9 (figure) | wiki 7 and 10; **jzIntv 12** (2 idle cycles first); MAME 9; HW26 9 or 11 (C2) | S1's wait-state rule (p.43): each memory access can add W cycles when BDRDY is low; the counts above are for W = 0. Interruptibility is in [interrupts-and-bus.md](interrupts-and-bus.md). ### Where the pins pulse | Pin | When | Source | | --- | --- | --- | | TCI (out, high pulse, 300 ns typical) | S1's TCI diagram draws it in the microcycle after the BAR of the **next** fetch (the pulse follows the TCI instruction's four cycles) | S1 p.33 (U7) | | PCIT (out, low pulse) | in SIN's two execute NACT cycles | S1 p.34 | | EBCA0-3 (out) | valid from the DTB of a BEXT, t_DE ≤ 150 ns, "stable as long as address is stable" | S1 p.32 | | EBCI (in) | sampled in TS1 of BEXT's fifth cycle (the BAR for the displacement) | S1 p.32 | | BUSAK (out) | low from the first NACT after the granting instruction; high again after two NACTs that follow BUSRQ's release | S1 p.36, O81 | | HALT (out) | high while stopped | S1 p.13 | ## What the manuals' cycle counts were checked against here - The 1975 instruction table (S1 p.53-58) was read from the OCR text and, where the OCR was damaged, the page images. G82's summary (PDF p.47) was read from the page image. - The block sequences were read from the timing diagrams as images (S1 p.27-37 at 70 dpi, G82 PDF p.26 and p.30), not from the OCR. - A 180-frame MAME 0.285 trace of Astrosmash (343,189 instructions, 177 interrupts; [mame-oracle.md](mame-oracle.md)) gave these cycle deltas per mnemonic: every one equals the Docs column **except SETC (6) and `SARC r,2` (6)**; MAME's interrupt is +9; MAME's merged SDBD steps cost 14 (4 + 10). MAME 0.285's CPU has no BUSRQ, so nothing about bus requests can be read from it. - The core's rung 0 turns this table into data and checks it against two independent transcriptions ([validation.md](validation.md)).