# Architecture: modelling levels, domains and channels What the charter asks a specification to state (axis B, and "Domains and channels"), for the 5200 as this repository models it. Source keys: [start-here.md](start-here.md). ## Modelling level per component | Component | Where | Level | Notes | | --- | --- | --- | --- | | CPU, 6502C "SALLY" | `sixfiveohtwo.MOS6502` (6502-python core, pin 741419a) | cycle | every bus cycle, dummy accesses included; HALT as a held clock, RDY as repeated reads ([sally-halt.md](sally-halt.md)) | | ANTIC | `antic.py` | cycle, with die-derived structure | per machine cycle: DMA, refresh, WSYNC, NMI, AN codes for two colour clocks. The playfield DMA clock (a shift register), the DMA-request gate and the line buffer's LFSR address counter are modelled as the circuits [AHRM] 4.12 and [IJOR] sheets 2, 4 and 6 draw them, not as cases; nothing is modelled at gate level | | GTIA | `gtia.py` | cycle (colour clock) | two colour clocks per machine cycle, half-clock pixels in high resolution; register write delays in colour clocks; priority as [AHRM] 6.7's equations | | POKEY | `pokey_python.POKEY(C012294)` (the restarted core, pin 6ed1ffa) | cycle | ticked once per machine cycle, halted cycles included, after the cycle's bus access; sound mixed by the core's `mix()` (FITTED there, its B3.9) | | Memory, decoder, floating bus | `board.py` | cycle | one access per machine cycle; the data-bus latch updated on every cycle, DMA included | | Cartridge port and classes | `cartridge/mappings.py` | cycle | every cycle in $4000-$BFFF reaches the cartridge (bank hotspots switch on any access) | | Controllers: sticks, keypads, buttons | `controllers.py` | cycle at the chip pins | pot lines through pokey-python's `PotRC` helper (a stick at count p charges for p x 114 cycles to threshold, drained by the chip's dump transistors), keypad answered per POKEY scan code, triggers as GTIA pin levels; the pad state is set once per frame by the host | | CX53 Trak-Ball | `controllers.TrakBall` | functional | speed to pot deflection through a per-frame lag; constants are labelled hypotheses (U11) | | BIOS | the player's ROM, run by the CPU | (real firmware) | not modelled: Atari's 2K program runs as is | | Audio output | `media.AudioTap` | functional | a box filter from POKEY's mix and the CONSOL speaker bit to 44.1 kHz; a frontend stage, outside the specification's per-cycle state | | Palette, PNG | `media.py` | functional | a frontend choice, labelled; the board's output is colour-register values | | Cartridge loader, table, walk | `cartridge/__init__.py`, `walk.py` | functional | identification policy, not hardware | Profile in one line: SALLY, ANTIC, GTIA and POKEY at cycle level on one shared bus, ANTIC's DMA clock and line buffer structured after the die schematics; trak-ball, audio filter and palette functional. ## Domains **One domain.** Every chip runs from the same phi2: the crystal divided by two ([FSM] Figure 1-6; POKEY's clock is pin 7 on the same phi2), and GTIA's colour clock is exactly twice it. There is no second processor, no sound subsystem on its own clock and no drive. A Rust tier has nothing to put on another thread except pure producers (picture conversion from the finished line buffer, audio resampling from the per-cycle mix), which this specification keeps outside the per-cycle state. ## Channels Inside the one domain the chips still meet only through named lines, so the interleaving is explicit: | Channel | From → to | Kind | In the code | | --- | --- | --- | --- | | address and data bus | CPU or ANTIC → RAM, cartridge, GTIA, ANTIC, POKEY, BIOS | shared memory | `Board._read` / `_write`; ANTIC drives addresses through `begin()` and receives the byte in `end(data)` | | HALT | ANTIC → CPU (and GTIA, which latches P/M DMA bytes on halted cycles) | line | `ANTIC.begin()` returning an address; `ANTIC.halt` passed to `GTIA.cycle` | | RDY (WSYNC) | ANTIC → CPU | line | `ANTIC.wsync_at`, checked in `Board.read_byte` | | NMI | ANTIC → CPU | interrupt line | `ANTIC.nmi_fire` → `cpu.request_non_maskable_interrupt()` | | /IRQ | POKEY → CPU | interrupt line | `POKEY.irq`, handed over at the start of the next machine cycle | | AN0-AN2 | ANTIC → GTIA | port (3 lines per colour clock) | `ANTIC.an_a`, `an_b` → `GTIA.cycle` | | CONSOL lines | GTIA → controllers (port select, pot power, trak-ball calibrate) and the speaker | port | `GTIA.consol_out`, read by `Controllers.pot_level` / `key_response` and by `AudioTap` | | POT0-POT7 | controllers → POKEY | port | `POKEY.pot_level` callback, `pokey_python.rc.PotRC` | | dump transistors | POKEY → pot capacitors | line | `POKEY.on_dump` → `PotRC.dumped` | | keyboard matrix (K scan, KR1, KR2) | POKEY ↔ controllers | port | `POKEY.key_response` callback | | TRIG0-TRIG3 | controllers → GTIA | port | `GTIA.set_trigger` | | cartridge enables | decoder → cartridge | line | `Cartridge.read` / `access` for $4000-$BFFF | The controllers read `GTIA.consol_out` directly rather than through a callback; it is the CONSOL output lines' level and is read only, in the same domain, so it hides no dependency. A transcription should keep it as a read of that one field. ## The serial order of record One machine cycle, as `board.py` runs it inside the CPU's bus callbacks (docs/timing.md "One timeline"): 1. the pending POKEY /IRQ level reaches the CPU; 2. `ANTIC.begin()`: is this cycle ANTIC's (DMA or refresh)? If so the cycle is ANTIC's bus access and the CPU's access waits (steps 3-6 run for it, then step 1 again); 3. otherwise RDY: a held read is repeated (the cycle is spent, steps 4-6 run); 4. the bus access (ANTIC's, or the CPU's read or write), updating the data-bus latch; 5. `ANTIC.end(data)`, then `GTIA.cycle` for the cycle's two colour clocks; 6. `POKEY.tick()`, the NMI if ANTIC fired one, POKEY's /IRQ sampled for the next cycle, the audio tap, the finished line copied into the frame. x-rust transcribes this order unchanged; it is the order every lockstep trace is compared in.