# Reading the gate-level diagrams ([GLD]), milestone 2's first task `reference/docs/TIA-Maria_Gate-Level_Logic_Diagrams.pdf`, 50 sheets, April 1984: the **TIA-MARIA hybrid** ("STEPHANIE" is the TIA half), not the 1702B as built (validation.md caveat). Tier 2 (schematic). Rendered with `pdftoppm -r 150` for the index and `-r 300` for every PLA quoted below; each fact here was read off the page image, not OCR. Bit patterns are given as the PLA rows' transistor positions read them: a dot on the complement column means "bit = 1", on the true column "bit = 0" (calibrated on rows whose value [MiS] `video_sync.sv` also states; every row read agreed with it). ## Sheet index (PDF page = sheet position) | Pages | Title block | | --- | --- | | 1-15 | TIA_MARIA_STEPHANIE: horizontal and ball counter, HMOVE, playfield, colour/luminance, P0/M0/P1/M1 position and graphics, address decode / collision register, collision register, audio channels 0 and 1, audio summer | | 16 | MARIA_SYNC 1/2: horizontal sync timing (counter H0-H8, decode PLA) | | 17 | MARIA_SYNC 2/2: vertical sync timing and RSYNC (counter VQ0-VQ8, decode PLA, VBLANK, HALT, LRSEL, DLI, INTF; PAV, PCK0, DBEN) | | 18 | MARIA_CONTROL 1/2: RCPLA and RCDEC logic (register decode) | | 19 | MARIA_CONTROL 2/2: control register and RLOG | | 20-26 | DMA, sheets 1-7 (the state-machine PLA [MiS] DMA.sv transcribes) | | 27-31 | MARIA_VIDEO: colour RAM decode, colour RAM core, colour RAM decode logic | | 32-39, 41-44 | MARIA_LINBUF: line buffer output decoder, RAM core, R/W address counters, PCWPLA and RAM input logic, JOG (shift up one line), row select, sub-blocks, RAM cell | | 40 | MARIA block wiring | | 45-48 | TIA~MARIA: address I/O buffers, MARIA & STEPHANIE blocks, colour delay line & luminance, data bus I/O interface | | 49-50 | TIA~MARIA top-level 5/6 and 6/6: PB2/PB4 logic (port B), trigger and pot inputs; the MEN pad (the hybrid takes the two-button lines into the chip) | ## Findings | Question | Sheet and signal | Reading | Standing | | --- | --- | --- | --- | | C7: DMA lines per frame | 17, PLA rows VRESET, VBLANKR, VBLANKS | VRESET = 262 (so 263 lines), VBLANKR = 16, VBLANKS = 258, VSYNCS = 0, VSYNCR = 3 | **242 NTSC DMA lines** on the drawing, as [MT84] 2.2 and MAME say; [SG]'s diagram (243) is the odd one. The board's NTSC row now says 242 (PAL: 292, by the same rule, unread for PAL) | | U4: when MSTAT changes | 16, PLA row HRESET (= 452) feeding VINC; 17, VINC clocks VQ, decoded rows set/reset the VBLANK latch | the horizontal count runs 0-453 with HSYNC at 0, HBLANK 440-68, border 413-93 (rows HBLANKS, HBLANKR, HBORDERS, HBORDERR read off the PLA); the vertical count steps at HRESET, 12 MARIA clocks after HBLANK's leading edge | **Answered to the clock, schematic-read**: with the board's clock 0 at HBLANK's leading edge (H = 440), VBLANK (MSTAT D7) changes at clock 12 of the line on which the vertical count becomes 16 or 258. The one-clock latch delay [MiS] notes for HRESET is not resolved | | Line RAM swap / DMA abort | 16, row HLRC = 412 | LRC at H = 412 = board clock 426 | the 426-clock cap MAME and A7800 use is this decode | | C6: read mode 1 | 32 (LINE BUFFER OUTPUT DECODER), inputs RM1, RM0, H0, CRAMF, EBORDER | NORMAL is RM1 inverted and latched, alone; RM0 reaches only the two gates that also take RM1 (the 320 A/C and B/D odd/even selects) | **Answered**: read mode 1 decodes as read mode 0 (160A/B). Matches [MiS] line_ram.sv `2'b0x` | | U14: register $38 | 18 (RCDEC), 10 product terms over PRWF, A4-A0, PAR23 | every term needs A1 = A0 = 0; the writes decoded are A4-A2 = 000 ($20), 001 ($24 WSYNC), 011 ($2C), 100 ($30), 101 ($34), 111 ($3C), plus one generic write and two reads (000 and 010, MSTAT) | **Answered on the drawing**: no term decodes a write to $38; "store zero here" has no effect on this design | | U2: CPU divider across DMA | not located: sheets 16-18, 32, 49 read; 17 takes PCK0 and PCK2 as inputs (PAV = processor address valid from them) and does not make them | [MiS] maria.sv (tier 4): "The timing schematic has no reset input to the processor-clock generator" | **Open.** The board keeps the divider's phase (whole periods during HALT), which agrees with [MiS]'s reading; the generating sheet is to be found (likely 40 or 46) | | U3: shape of the slow cycle | as U2 | [MiS]: each half-period is 2 or 3 MARIA clocks, the first half chosen by the current address, the second by a latch | **Open** at sub-cycle level; only the +2 total is modelled | | U8 (DM = 0/1), U12 | 20-26 | not read gate by gate in this session | open | | C23: DLI from the entry read on the last DMA line | 17 (INTF, RSYNC PLA, latches LA/LB/LC), 16 (BLK), DMA 2/6/7 (DLI, INTENBL = DMAS42, HALTRST = DMAS43-47, no VBLANK input) | VBLANK gates neither the DLI latch's set, its clock, nor INTF; the last DMA line's DMA starts 12 clocks before VBLANK rises and runs its DLL fetch | **Answered (session 6, below)**: raised; and the flag, cleared only by a line DMA's start, raises a second NMI after the next VBE fetch. One printed gate (N1, grid 144,66) conflicts with the machine's function and is read as its complement | ## C23: the DLI latch and INTF, sheet 17 (session 6) Rendered at 600 dpi (`pdftoppm -r 600 -f 17`), read crop by crop at native resolution; sheets 16 (BLK), 21, 25, 26 (DMA 2, 6, 7) and 40 (block wiring) at 200-500 dpi for the inputs. Grid references are the sheet's own border scale (x left to right, y bottom to top). Clocks: PH2-gated inputs are sampled in PH2, PH1-gated ones in PH1 (the half-diamond pass gates). Every NOR latch below is two cross-coupled NORs. **Inputs to the interrupt logic** (sheet 17, left edge and top right): - `START` (generated at grid 164,138): NOR of `~BLK` and `BLK` one clock earlier = a one-clock pulse on BLK's rising edge. `BLK` (sheet 16, grid 190,120) is the latched OR of the HBLANK latch and `VB`, so START pulses at HBLANK's onset (H = 440, the board's clock 0) on every line that begins outside vertical blank, and never inside it. - `EOVB` (grid 164,130): the same circuit on the VBLANK pin = a pulse on VBLANK's falling edge. - `HALTRST` (from DMA sheet 7, grid ~190,32): the OR of the DMA state terms DMAS43-DMAS47 (the end-of-DMA states). - `DLI` (from DMA sheet 2, grid 20,24): `NOR(~INTENBL, ~b7)` = INTENBL and the DLL flags byte's bit 7, held in its own latch from the DLL fetch. `INTENBL` (DMA sheet 7, its row, grid ~183,72) has one product term, **DMAS42**: DLI is a pulse during one DMA state, not a level. - The DMA state PLA (sheet 6 = PDF page 25) takes RSS0, RSS1, W0, OFF0, IND, LONGHDR, DM0, DM1, CWIDTH and its state PLA0-PLA4: **no vertical-blank input**. RSS0/RSS1 come from sheet 17's RSYNC NORs (grid 120-135, 10-20), built from the latches below and LRCF; VB is not among their inputs. - `VB` and `VS` are **outputs** of sheet 17 (the VBLANK and VSYNC NOR latches at grid 99,57 and 99,62, set and reset by the PLA rows VBLANKS = 258, VBLANKR = 16). VB goes to sheet 16 (BLK) and nowhere else on sheet 17. **The three request latches** (grid 136, 44 / 33 / 22; inputs PH2-gated): LA: QA = 1 after EOVB, 0 after HALTRST (the VBE fetch request) LB: QB = 1 after START, 0 after HALTRST (the line DMA request) LC: F = 1 after DLI, 0 after CLR (the DLI flag) CLR = NOR(QTB, ~c2d) = (START latch set) AND c2d (NOR at 137,13) `QTB` is LB's other output; `c2d` is PLA term c2 passed through inverter-PH2-inverter-PH1-inverter (grid 158-178, 33) and a PH2 gate (grid 155,33): c2 about one and a half clocks late. `N1 = NOR(QA, QB)` (grid 144,66) feeds the PLA's input 2 directly and the HALT pad through a PH1 gate and a push-pull buffer (grid 160-165, 66). **The RSYNC PLA** (grid 185-210, 47-74): 7 product columns over five PH1-sampled inputs, each given true (upper row) and complement (lower row): P = PCKEDGE, A2 = N1, A3 = F, and the fed-back state S4, S5. Read with the convention calibrated on the VQ PLA (a dot on a row pulls the column low): c1 = P & S4 & S5 -> INTF latch, assert (PH2 gate, grid 172,30) c2 = P & A2 & ~S4 & ~S5 c3 = A2 & S4 & ~S5 c4 = ~P & A3 & S4 & ~S5 c5 = P & ~A2 & A3 & S4 & ~S5 c6 = ~P & S4 & S5 c7 = P & ~S4 & ~S5 -> INTF latch, release (PH2 gate, grid 172,27) S4' = c2|c3|c4|c5|c6 S5' = c5|c6 (NOR5 and NOR2 at grid 190,40, each through PH2 and an inverter) **INTF** (grid 156,17): `Q = NOR(Qbar, c7, MENBLF)`, `Qbar = NOR(Q, c1)`, INTF = Q through the inverting push-pull buffer (c1 makes INTF low, the 6502's NMI level). c1 pulls INTF one way, c7 (and MENBLF, outside 7800 mode) the other: a pulse one processor clock (one PCKEDGE) wide. **Reading the machine.** With A2 = "MARIA holds the bus" the machine is the one [1702B] p. 14 describes: idle (S=00) it releases INTF at every processor edge; at the first edge of a DMA it goes to 10 (c2), stays while the DMA lasts (c3), and when the DMA ends goes to 11 if the DLI flag is set (c5, c4 waits for the edge) or back to 00 if not; from 11 the next edge asserts INTF (c1). The flag is cleared about 1.5 clocks after a START-begun DMA's first edge (c2d with LB set), before that DMA can fetch a DLL entry; an EOVB-begun DMA (the VBE fetch) does not clear it. **One conflict in the print**: N1 is drawn as a NOR of the two request latches, which makes A2 = 0 during DMA; taken literally, the machine would assert INTF two edges after a DMA *starts*, while the CPU is halted, and the flag would never be cleared (CLR needs c2d while LB is set, and c2 would then occur only after LB is reset). Every other part of the sheet (the HALT pad, CLR, [1702B] p. 14's "one cycle after HALT is released", and every emulator's ordinary DLI timing) needs the complement, so the board takes A2 = DMA active and notes the gate at grid 144,66 as the one place where the drawing and the function disagree. **What it gives on the last DMA line (C23).** VBLANK gates **neither the set, nor the latch's clock, nor INTF**: VB is not an input of LC, of the RSYNC PLA, of INTF, nor of the DMA PLA. Timing on the last DMA line (the line on which the vertical count becomes 258): START pulses at H = 440 (the board's clock 0) because BLK rises with HBLANK while VB is still low; VBLANK sets only at HRESET, H = 452 (clock 12, sheets 16-17: VINC, then the VBLANKS row). LB is therefore set and that line's DMA runs to its end as on any line; VBLANK rises 12 clocks into it, before its zone-end DLL fetch, and nothing looks at it. The fetch's DMAS42 pulses DLI if the entry has bit 7, LC sets, HALTRST ends the DMA, and INTF follows one processor edge after the release: **the DLI is raised**, as on the board and ProSystem NTSC; MAME 0.285, A7800 5.2 and ProSystem PAL are wrong here (tier 2 over tier 5). Because only a START-begun DMA clears LC, the flag is still set when the next frame's VBE fetch ends (no START occurs during vertical blank), so the drawing raises a **second NMI after that VBE fetch** (line 16, clock about 20). The board now does both (`maria.py`); `scripts/dli_probe.py` phase 2 expects 32 in 16 frames. ProSystem NTSC's one per frame is kept as the detector setting `dli-clear-on-nmi`, MAME's none as `c23-mame`. Sheets 20-26 (the DMA PLA) were not re-read cell by cell here: [MiS] states that every cell of both planes was read off them, and the board's DMA engine is written from [SG]'s list formats and measured costs with [MiS] as the readable cross-check, as the brief's judges say. ## C23: an independent second reading of sheet 17 (session 7) Made before reading the section above. Source: the page's embedded scan itself (`pdfimages -png -f 17`: one 3376 x 2256 greyscale image at 200 ppi, the highest resolution the PDF holds; a 600-dpi render only resamples it), read in crops of 220-750 native pixels at 2-4x with a pixel grid, and traced wire by wire from the pads. Pad direction: a pentagon pointing into the drawing is an input (HALTRST, DLI, HELRRQ, PCKEDGE, BLK, MENI), out of it an output (VB, VS, VBLANK, HALT, RESET, LRSEL, INTF). - **Latches** (cross-coupled NOR pairs, both inputs through PH2 pass gates): LA set by the inner loop wire that is `EOVB` at the top of the sheet, LB set by the middle loop wire, `START`; both reset by HALTRST. LC set by `DLI`, reset by `CLR`. The NOR fed by the set input gives the latch's complement; its partner gives Q (QA, QB, F). - **CLR** (left-pointing NOR at native 1940,1945): inputs LB's complement output and the end of a chain from PLA column 2: inverter, PH2 gate, inverter, gate, inverter, gate. Three inversions, so `CLR = NOR(~QB, ~c2d) = QB & c2d`. CLR reaches LC's reset directly (taken off before the PH1 gate that sends the same node to the RSS logic). - **The gate at grid (144,66)**, native (2050,1215): a clean print, an OR body with the output bubble: **NOR**, inputs QA (from LA's Q, native x 2022) and QB (LB's Q, x 2048). Its output goes (a) straight to the PLA's second input row, (b) through a PH1 pass gate into a two-inverter push-pull buffer (the inverter whose output drives the ⊥ terminal of the other is this sheet's superbuffer, inverting) whose output runs up the sheet (x 2282) to the **HALT** pad. So HALT = NOT N1, sampled in PH1. - **PLA** (5 inputs, each PH1-sampled, inverted onto the lower line and re-inverted onto the upper; 7 precharged columns, a transistor on a line pulls its column low). Inputs: PCKEDGE (P), N1, F, and the fed-back state S4 = OR(c2..c6), S5 = OR(c5, c6) (a NOR5 and a NOR2 under the plane, each through PH2 and an inverter). Read cell by cell: c1 = P S4 S5, c2 = P N1 ~S4 ~S5, c3 = N1 S4 ~S5, c4 = ~P F S4 ~S5, c5 = P ~N1 F S4 ~S5, c6 = ~P S4 S5, c7 = P ~S4 ~S5. - **INTF**: a NOR latch, `R = NOR(L, c7, MENBLF)`, `L = NOR(c1, R)` (c1 and c7 through PH2 gates; the third input of R is the MENBLF pad's net), and INTF = NOT R through a push-pull buffer: c1 drives INTF low, c7 or MENBLF high. **The same equations as the section above, gate for gate**, except that this reading writes CLR's second input as the chain's raw output (`~c2d`), which the section above folds into `c2d`; the result is identical. **Is the complement reading of N1 forced?** Yes, on three independent counts. (1) Literal N1 = "no request latched": c2 then fires at an edge while MARIA is idle, the machine sits in 10 while idle (c3), and when a DMA starts with F set it goes to 11 and asserts INTF one edge later, while the CPU is halted, a whole line after the flag was set; with F clear it drops to 00 until the DMA ends. (2) CLR needs c2d while LB is set; with literal N1, c2 occurs only while LB is reset, so the flag would never clear and every DMA start would raise an NMI. (3) HALT = NOT N1 would be high during DMA, the wrong polarity for SALLY's active-low HALT pin (the pad is driven straight from the buffer). With N1 = OR(QA, QB) all three become the documented machine ([1702B] p. 14: the DLI one processor cycle after HALT's release). The drawing therefore has one printing error; it could equally sit in the PLA's N1 row (true and complement lines exchanged) instead of the gate's bubble, but the PLA's function is the same either way, and only the gate's bubble also fixes the HALT polarity, so the gate is the likelier place. **Does the second NMI depend on it?** The second NMI needs two things: the flag survives the VBE fetch, and the machine fires INTF at the end of any DMA while the flag is set. The first rests only on CLR (QB & c2d: the VBE fetch sets LA, not LB), which reads cleanly and does not involve the gate. The second is the complement reading's c3/c5 path, which is the only coherent reading of the PLA (above). So the consequence follows from the one coherent reading; it does not rest on a choice between two coherent ones.