# Start here: the Atari 5200 as a board Source keys used across these documents: | Key | Source (path under `reference/`) | Tier | | --- | --- | --- | | [FSM] | CX5200 Field Service Manual rev 3, June 1983 (`docs/CX5200-Field-Service-Manual-rev3-1983-06.pdf`) | 2 | | [HM] | Atari 400/800 Hardware Manual CO16555, Oct 1980 (`docs/Atari-400-800-Hardware-Manual-CO16555-1980-10.pdf`) | 2 | | [DS-A], [DS-G], [DS-P] | ANTIC C012296, GTIA C014805, POKEY C012294 data sheets (`docs/*-datasheet.pdf`) | 2 | | [IJOR] | ANTIC rev. E reconstructed schematics from the die, J. Cwik (`die/AnticReSchemLayout.zip`) | 1 | | [AHRM] | Altirra Hardware Reference Manual, 2026-01-02 edition (`docs/Altirra-Hardware-Reference-Manual-2026-01-02.pdf`); section and page given | 3 | | [BUCH] | Buchholz, "Transporting Atari Computer Programs to the Atari 5200", ANALOG 15 (`docs/buchholz-*.html`, text copy `danb/52analog.txt`) | 3 | | [DANB] | Dan Boris's 5200 pages and BIOS disassembly (`danb/`) | 3 | | [FAQ] | Atari 5200 FAQ v3.3 (`docs/atari-5200-faq.html`) | 3 | | [A800] | Atari800 at `98cc2dc`: its documentation file `DOC/cart.txt` only; the program is a closed box (built as libatari800 and run, never read) | 5 | | [MAME] | MAME 0.285: the installed binary, run as a closed box; its BSD-3 and CC0 files (`src/mame`) | 5 | | measured | run or computed here on 2026-11-11; the script is named | - | ## The machine in one page The 5200 is an Atari 400 with the keyboard, PIA, SIO port and OS removed, a 2K monitor ROM, 16K of RAM, a 32K cartridge window that never overlays RAM, and analog controllers read through POKEY. It cannot run 400/800 software: GTIA and POKEY sit at different addresses and there is no OS ([AHRM] 13.1-13.2 p. 410; [BUCH]). | Part | What | Notes | | --- | --- | --- | | CPU | 6502C "SALLY", C014806 ([FSM] parts lists, both boards) | NMOS 6502 core plus a HALT input; **not** a 65C02. `sixfiveohtwo.MOS6502`. See [sally-halt.md](sally-halt.md) | | ANTIC | C012296 (NTSC) | display list, playfield and P/M DMA by HALT, WSYNC by RDY, NMIs (VBI, DLI), VCOUNT, light pen (unused), RAM refresh | | GTIA | C014805 | players/missiles, colour, priority, collisions, 4 trigger inputs, 4 CONSOL lines used as **outputs** | | POKEY | C012294 | sound, 8 pot inputs (4 sticks x 2 axes), keypad scan, timers, IRQs; serial port present on the expansion connector, unused | | RAM | 16K dynamic, $0000-$3FFF | refreshed by ANTIC | | BIOS | 2K at $F800-$FFFF, two revisions | character set $F800-$FBFF, code $FC00-$FFFF | | No PIA | | controllers go through POKEY and GTIA | There was no PAL 5200. The 2-port board has room for PAL parts and the revision A BIOS tests GTIA's PAL register ([FAQ] 4.8, quoting ANALOG; confirmed in the ROM bytes, [undocumented-behavior.md](undocumented-behavior.md) C1). The board has one television standard; ANTIC and GTIA still take PAL fields as data so that the chips can be reused by a computer board. ## Machines as data Two rows, differing in a handful of fields: | Field | `a5200` (4-port, 1982) | `a5200_2port` (1983) | | --- | --- | --- | | BIOS | CO19156, SHA-1 `6ad7a1e8c9fad486fbec9498cb48bf5bc3adc530` | CO19156A, SHA-1 `1d2a3f00109d75d2d79fecb565775eb95b7d04d5` (the usual pairing; either ROM runs on either board) | | Controller ports | 4 | 2 | | POT4-POT7 | ports 3 and 4 | tied to ground on later boards ([FAQ] 4.10 item 2) | | TRIG2, TRIG3 | ports 3 and 4 | unused; TRIG3 was wired to TRIG1 until a factory modification lifted GTIA pin 11 ([FAQ] 4.10 item 1) | | CONSOL bit 1 | selects ports 3/4 for the keypad | no effect | | Cartridge connector | | three pins redefined for the 2600 adapter: phi2 out, video in, audio in ([FAQ] 4.8). Not modelled | | Crystal | 3.579575 MHz ([FSM] parts list, Y1) | same | Fields every row carries: crystal, CPU divider, lines per frame (262), the power-on parameters (CPU registers, RAM fill, chip register state, the phase between POKEY's dividers and ANTIC's line), each with its source or marked "unknown: default". ## Clocks - Crystal 3.579575 MHz ([FSM] parts lists; note this is not the broadcast 3.579545 MHz). The machine cycle is half of it: 1.7897875 MHz. [AHRM] 4.2 gives 1.789773 MHz from a 14.31818 MHz master as on the computers; MAME uses 1,789,790 Hz (C2). The board counts cycles; the frequency only matters to the audio resampler and the frame rate shown to the user. - One scan line is 114 machine cycles = 228 colour clocks; a frame is 262 lines = 29,868 cycles, 59.92 Hz ([AHRM] 4.2 Table 6). MAME's frame marks are 29,866-29,871 CPU cycles apart on Pac-Man (measured, `tests/detectors/mame-pacman-2026-11-11.txt`): the same number, sampled at instruction boundaries. - POKEY is clocked by the same phi2 ([FSM] Figure 1-6, pin 7). Its 64 kHz and 15.7 kHz dividers (28 and 114 cycles) are its own and are **not** locked to ANTIC's line: the phase is whatever POKEY's initialisation left ([AHRM] 5.4, 5.9). ## Memory map ([AHRM] 13.2, 13.4 p. 410-413; [BUCH]; [FSM] decoder sheet; mirrors confirmed by Acid5200's `*_addrmirror` tests. Phase 0 also read the mirrors from Atari800's and MAME's GPL sources; those are no longer cited, provenance.md wave 2.) | Range | What | | --- | --- | | $0000-$3FFF | RAM. The BIOS uses $00-$18 and $200-$21B for shadows and vectors | | $4000-$BFFF | cartridge (32K window; see [cartridge.md](cartridge.md)) | | $C000-$CFFF | GTIA, 32 registers repeated through the page(s) | | $D000-$D3FF | nothing (U5: what a read returns) | | $D400-$D4FF | ANTIC, 16 registers repeated | | $D500-$E7FF | nothing | | $E800-$EFFF | POKEY, 16 registers repeated | | $F000-$F7FF | selected as ROM; contents uncertain (C8). Default: the BIOS again | | $F800-$FFFF | BIOS: character set $F800-$FBFF, monitor $FC00-$FFFF. Vectors (measured: `a2 fc 23 fd 00 fc` at $FFFA): NMI $FCA2, RESET $FD23, IRQ $FC00 | There is no bank switching in the console. Reads of unmapped space: U5. ## The BIOS 2K, no entry-point table; cartridges that call into it by address break on the other revision (K-Razy Shoot-Out, Mountain King, Pitfall!: measured in milestone 6, validation.md; mechanism [AHRM] F.2). What it does, from the bytes and [DANB] `5200BIOS.txt` (4-port revision): 1. Reset at $FD23: SEI, CLD, stack, then reads $BFFD. **If $BFFD is $FF it jumps through ($BFFE) at once** (diagnostic cartridges, and every third-party cartridge that did not want the Atari logo: 50 of the 181 local dumps of 4K-32K, measured by `count_carts.py`). 2. Otherwise it clears the chip registers and RAM vectors, sets up a display list, copies the cartridge's 20-character title from $BFE8-$BFFB and the two "year" characters at $BFFC/$BFFD to the screen, shows the rainbow Atari logo for about four seconds, then jumps through ($BFFE). Measured: MAME enters Pac-Man's code at cycle 7,706,528 (frame 258, 4.3 s); Atari800 between frames 240 and 300. 3. Interrupt handlers: NMI and IRQ dispatch through RAM vectors at $200-$21B ([BUCH] lists them), with deferred/immediate VBI, DLI, keyboard, break key and POKEY timer vectors, and shadow registers updated in the VBI. Revision A inserts 22 bytes at $FD32 (a PAL test, C1); everything after moves by 22 bytes and nothing else changes (measured: byte-wise diff, 8 relocated operands, the filler ending in the text "RJZ 1982" at $FFE4 dropped to make room). The board treats the BIOS as bring-your-own data found by SHA-1 (the No-Intro `[BIOS] Atari 5200 (USA)` is the 4-port ROM; MAME's `a5200.zip` holds both). Altirra's and Atari800's replacement 5200 kernels exist (Atari800 embeds `altirra_5200_os`); using one is an open decision, not a default. ## Controllers ([AHRM] 13.3 p. 411-412; [BUCH]; [FSM] Figure 1-6 and controller schematic.) Per port: an analog stick (two pots), two fire buttons each side (lower = trigger, upper = "softfire"), a 12-key pad, Start, Pause, Reset. - **Stick**: port n drives POT(2n) horizontally and POT(2n+1) vertically. Left/up read low, right/down high; range about 1-228, centre near 114 and **not self-centring**; a working stick spans at least 160 counts ([AHRM] 13.3, citing Atari's PAM package p. 25, which is not pinned here). CONSOL bit 2 must be 1 to power the pots; with it 0 every POT reads the maximum, 228. - **Lower button**: GTIA TRIG(n), 0 when pressed. - **Keypad and Start/Pause/Reset**: on POKEY's keyboard scan, for the one port selected by CONSOL bits 0-1. Codes in KBCODE bits 1-4 ([AHRM] 13.3 table). POKEY's K0 and K5 are not connected ([FSM] Figure 1-6 marks pins 23 and 18 "Not Connected"), so every key is seen twice per 64-step scan, and debounce (SKCTL bit 0) must be off for a key to register at all. - **Upper button**: POKEY's KR2 for the selected port ("Softfire" in [FSM] Figure 1-6): reads as SHIFT/CONTROL in KBCODE and raises the BREAK interrupt (IRQST bit 7). - **Trak-Ball (CX53)**: plugs into a controller port and presents itself as a stick: a motion board turns ball speed into pot positions ([DANB] `52trakball.shtml`, schematic `52TB_PCB1_schem.pdf`); CONSOL bit 2 doubles as its calibration/detect line ([AHRM] 13.3, citing the PAM package p. 21). Games that support it read it as a velocity. Model: U11. What POKEY must provide for all this is an interface request to `pokey-python`: [handoff-brief.md](handoff-brief.md), "Interface to sibling cores". ## The chips, at the level the board composes them ANTIC and GTIA are documented for the build in [timing.md](timing.md) (cycle-level behaviour) and by [AHRM] chapters 4 and 6, which the build session must read in full; this repository does not restate the register tables. The division of labour: - **ANTIC** owns time: the horizontal and vertical counters, which cycles are DMA, HALT, RDY, NMI. It reads memory through the board's bus (so it sees cartridge ROM, RAM, and the floating bus) and sends GTIA three playfield lines (AN0-AN2) per colour clock plus the P/M data bytes it fetched (GTIA latches them from the data bus on the DMA cycles). - **GTIA** owns the picture: it turns AN0-AN2 into playfield colours, shifts out players and missiles, applies priority, detects collisions, and outputs one colour value (hue/luma) per colour clock, two luma values per colour clock in the high-resolution modes. - **POKEY** is a sibling core (`pokey-python`); the board feeds it the cycle clock and the pot, keypad and KR2 inputs and takes its IRQ line and audio. ## Output Per frame: 262 lines of 228 colour clocks (456 half-clocks where a high-resolution mode is on) of GTIA colour-register values (hue in the high nibble, luma in bits 1-3), not RGB. Palettes belong to the frontend, each labelled with its origin; NTSC artifact colours are a frontend option. Audio: whatever form `pokey-python` settles on, taken per frame and resampled in the frontend; GTIA's CONSOL bit 3 "speaker" is mixed in ([BUCH]). ## Suggested module shape ``` src/a5200_python/ machine.py machine rows (4-port, 2-port), power-on parameters board.py the bus, the one timeline, HALT/RDY in the callbacks antic.py ANTIC behind a pin-shaped interface (no board imports) gtia.py GTIA behind a pin-shaped interface (no board imports) controllers.py stick, keypad, trak-ball -> pot/trigger/key matrix inputs cartridge/ loader front door, the cart description, mappings, table state.py, debug.py, trace.py, __main__.py tests/ import-boundary tests for antic.py and gtia.py ``` `antic.py` and `gtia.py` take and return only pins and bytes (address out, data in, HALT, RDY, NMI, AN0-2; colour out, triggers in, CONSOL lines) so that they can be lifted out with their history when an 8-bit computer board starts (open decision 2).