# Start here: the Atari 7800 ProSystem as a board The machine in one page, as the build needs it. Timing has its own document ([timing.md](timing.md)); cartridges and file formats theirs ([cartridge.md](cartridge.md)). Sources and their tiers are in [validation.md](validation.md); the short names ([SG], [1702B], [MT84], [HF], [MiS]) are defined at the top of timing.md. ## What is on the board | Part | What | Where it lives in the family | | --- | --- | --- | | SALLY, Atari C014806 "6502C" | NMOS 6502 with one more pin, HALT | `6502-python` (`MOS6502`); HALT is board logic around the bus callbacks | | MARIA, GCC1702B (NTSC) / GCC1712 (PAL) | display-list video, DMA, the clock divider, the address decoder, WSYNC, the DLI | **this repository** (one machine uses it) | | TIA | sound and input ports in 7800 mode; the whole picture in 2600 mode | `a2600-python` (pinned; see handoff-brief.md "Open decisions") | | 6532 RIOT | joystick directions, console switches, two-button control, timer; its RAM is the 2600's RAM | `a2600-python` | | 2 x 6116 | 4 KiB RAM, $1800-$27FF with shadows | this repository | | BIOS ROM | 4 KiB (NTSC) or 16 KiB (PAL, with Asteroids built in) | bring your own, found by hash | | INPTCTRL latch | four bits of glue that choose 7800 or 2600 mode and lock | this repository | | Cartridge port | 32 pins: the 2600's 24 plus A13-A15, R/W, Φ2, HALT, audio in, IRQ | this repository (`cartridge/`); POKEY from `pokey-python` | | Expansion port (early consoles) | bus signals; the XM and the High Score Cartridge sit in the cart slot instead | not modelled as a port | ## Two machines in one case At power-on the BIOS runs with MARIA and the 4 KiB RAM switched off. It checks the cartridge and writes INPTCTRL ($01, any address $00-$1F until locked): | Bit | Name | 1 | 0 | | --- | --- | --- | --- | | D0 | lock | no further write changes the latch until power-off | | | D1 | MARIA enable | MARIA and the 6116 RAM on | off | | D2 | EXT | cartridge mapped | BIOS mapped | | D3 | TIA-EN | video output from the TIA; two-button joystick mode disabled | video from MARIA | ([SG] "INPTCTRL register".) The latch shares its addresses with the TIA, so until it is locked a TIA write is also an INPTCTRL write. HALT is blocked from reaching the CPU until the latch has been written twice ([SG]). The BIOS's decision, in outline ([SG]; the commented disassemblies `reference/8bitdev-wiki/ntsc-bios.txt` and `pal-bios.txt`; the 1984 listing `reference/docs/7800_ntsc_bios_source_code.pdf`): 1. Copy itself to RAM, map the cartridge, and look at $FFF8-$FFFF: the region byte and the start address of the signed area. 2. Hash the cartridge from that address to $FF7F (excluding the signature) and compare with the 120-byte signature at $FF80-$FFF7 under Atari's public key (NTSC BIOS only; **the PAL BIOS does not check the signature**, it checks the region byte: confirm in milestone 1, C8). 3. Valid: lock into 7800 mode and jump through the cartridge's reset vector. Not valid: lock into 2600 mode (MARIA off, TIA video on) and jump through the vector as a 2600 would. The board therefore has two bus decoders selected by the latch ([MT84] Figure 2 gives both as tables), and the 2600 half is `a2600-python`'s board running on the same TIA, RIOT and CPU objects. Without a BIOS the board can start a cartridge directly (as ProSystem and A7800 do): INPTCTRL preset to $07 for a 7800 cartridge. That path is labelled "BIOS skipped": the RAM contents, the TIA and RIOT state, the position on the frame at the first cartridge instruction and the CPU registers all differ from a real start, and a few titles depend on them (Pole Position II, Klax: the wiki's "Common emulator development issues"). `7800OpenBIOS` (CC0 source, `reference/src/7800OpenBIOS`) is a free BIOS replacement that could be assembled and shipped; see Open decisions. ## Memory map, 7800 mode [SG] Appendix 1 and [MT84] Figure 2 (which is the decoder as a truth table). | Range | Device | Speed | | --- | --- | --- | | $0000-$001F | TIA (and INPTCTRL until locked); also at $0100, $0200, $0300 | slow | | $0020-$003F | MARIA registers; also at $0120, $0220, $0320 | fast | | $0040-$00FF | RAM: shadow of $2040-$20FF | fast | | $0140-$01FF | RAM: shadow of $2140-$21FF (the stack) | fast | | $0280-$02FF | RIOT ports and timer; also $0380-$03FF | slow | | $0400-$047F | free for cartridge hardware: POKEY at $440 and $450, YM2151 at $460-$461, XM control at $470, Covox at $430 | fast | | $0480-$04FF | RIOT RAM ("don't use"); also $0580-$05FF | slow | | $0500-$057F, $0600-$17FF | free for cartridge hardware (High Score Cartridge RAM at $1000-$17FF; POKEY at $0800 on some carts) | fast | | $1800-$27FF | RAM, two 6116 | fast | | $2800-$2FFF | shadow of $2000-$27FF | fast | | $3000-$3FFF | cartridge (High Score Cartridge ROM) | fast | | $4000-$FFFF | cartridge; the BIOS replaces the top while EXT = 0 | fast | The MARIA row carries a footnote in [MT84]: MARIA's own select "does not have 'pav' in its equation when HALT- is asserted", so the decoder keeps working on MARIA's own DMA addresses. What MARIA reads when a display list points into $00-$3F or at a slow device is unknown (U12); MAME returns 0 for DMA reads below $20. **The data bus floats.** TIA reads drive two bits; the rest is what the bus last held: "TIA undriven bits not representing the value of the last opcode byte" breaks M.I.A., and Choplifter needs a floating TIA range (wiki, "Common emulator development issues"). As in `a2600-python`, the board keeps the last byte on the data bus and returns it for undriven bits and unmapped addresses. MARIA's DMA reads also move the bus (U13: whether a program can see that). ## MARIA registers Write-only except MSTAT ([SG] Appendix 2; [1702B] p. 11). | Addr | Name | | | --- | --- | --- | | $20 | BACKGRND | background colour | | $21-$23, $25-$27, $29-$2B, $2D-$2F, $31-$33, $35-$37, $39-$3B, $3D-$3F | PnC1-PnC3 | 8 palettes of 3 colours; a colour is 4 bits hue, 4 bits luminance | | $24 | WSYNC | strobe: RDY low until the line ends | | $28 | MSTAT | read: D7 = vertical blank | | $2C, $30 | DPPH, DPPL | display-list-list pointer, read by MARIA once per frame | | $34 | CHARBASE | high byte for indirect (character) graphics | | $38 | OFFSET | "store zero here" (the future-expansion register; U14) | | $3C | CTRL | D7 colour kill, D6-D5 DMA mode (2 = on, 3 = off, 0/1 = test modes that take the bus without HALT), D4 CWIDTH, D3 border control, D2 Kangaroo (transparency off), D1-D0 read mode | Graphics modes are a pair: the **write mode** bit of the last 5-byte header seen on the line (2 or 4 line-RAM cells per graphics byte) and CTRL's **read mode** (how line-RAM cells become pixels and palette indices): 160A, 160B, 320A, 320B, 320C, 320D ([SG] "DMA modes" and CTRL; [1702B] p. 16-17 gives the cell-to-colour-address table). Read mode 1 is undefined in the guide (C6). Two modes need care beyond the table: **Kangaroo** makes colour 0 of a palette opaque (as the background colour in 160 modes), and in the 320 modes pixel pairs share palette bits, which is where 320B/320D colours come from. **Colour kill** removes the colour burst; Tower Toppler relies on composite artifacts of alternating 320-mode pixels, which is a frontend effect, not a board one. ## The display list list, zones and headers [SG] "Display list list" and "Display list"; [1702B] p. 13-14. - **DLL entry** (3 bytes, read once per zone): D7 DLI, D6 Holey-16, D5 Holey-8, D4 zero, D3-D0 OFFSET (zone height - 1); then the display list's address, high byte then low. - **4-byte header**: address low; palette (D7-D5) and width (D4-D0, two's complement, 0 not allowed); address high; horizontal position. - **5-byte header** (the second byte has D6 = 1 and width bits zero): address low; write mode D7, indirect D5; address high; palette and width (0 means 32); horizontal position. - **End of list**: a header whose second byte has zero in bits 6 and 4-0, that is `(byte & $5F) == 0` (C5; Ninja Golf and Crossbow end their lists with non-zero bytes, per the wiki). - OFFSET is added to the graphics address's high byte and decremented each line: each line of an object lives on a different page. - **Holey DMA**: with Holey-16 (or -8) set, a graphics address with A12 (or A11) set, at $8000 or above, reads as zeros and the object is dropped. RealSports Baseball's title screen is the known hard case (kevtris's logic capture, AtariAge 215357, first read as a silicon bug). - **Line RAM**: 160 cells of 5 bits (2 colour, 3 palette), two of them: one being written by DMA, one being displayed ([MT84] Figure 1). A cell written twice keeps the last non-transparent write. The horizontal position is 8 bits for 160 cells; where positions 160-255 land is read off [MiS] `line_ram.sv` and the detectors in milestone 2. The line RAM is cleared to background each line ([SG]); what an object that DMA never finished leaves there is whatever was written before the abort. - A display list "can't cross more than one page" and display lists, list lists and character maps "must be in fast (RAM) memory": MARIA reads them in 2 clocks ([1702B] p. 14; [SG]). Slow memory there returns bus garbage on a console; what garbage is unknown (U12). ## TIA and RIOT in 7800 mode - **Sound**: the TIA's two channels, unchanged. Cartridge sound (POKEY, YM2151, Covox, BupChip) arrives on the cartridge's audio pin and is summed with the TIA's at the modulator; the mix ratio is not documented (U15). - **Fire buttons**: a ProLine stick has two buttons. In two-button mode they read on INPT0/INPT1 (left port, right and left button) and INPT2/INPT3 (right port), **1 = pressed**. In one-button mode either button reads on INPT4/INPT5, 0 = pressed, as a 2600 stick. The mode is chosen by RIOT port B: bits 2 (left port) and 4 (right port) set as outputs and driven low enable two-button mode (wiki "Hardware interfacing guide"). One on One and Worm! rely on the RIOT's power-on state for this (wiki "Common emulator development issues"). - **Console**: SWCHB D0 reset, D1 select, D3 pause, D6/D7 difficulty. - **Other controllers**: light gun (XG-1: the trigger on a joystick direction line, the light sensor on INPT4/5, position by timing the pulse against the beam), paddles, trackball, driving, keypad, ST/Amiga mouse, SNES2Atari (a serial protocol over the port, wiki "SNES2Atari"), Mega7800, AtariVox and SaveKey (`a2600-python` has the SaveKey's EEPROM). ## Output - **Picture**: per line, 454 values at MARIA-clock resolution (colour byte or blank) with sync and blank levels; a `television` stage cuts frames and crops. A colour byte is hue (D7-D4) and luminance (D3-D0); the 256 RGB values are frontend data with their origin named. The 7800's colours shift as the console warms up (wiki "Atari 7800 Color Documentation", which gives cool, warm and hot palettes); the board emits colour bytes only. - **Sound**: the TIA's samples as `a2600-python` produces them, and each cartridge sound chip's samples at its own rate, as separate streams; mixing and resampling are the frontend's. ## Module shape (a suggestion) ``` src/a7800_python/ machine.py NTSC / PAL rows: crystal, lines, BIOS hashes, power-on parameters maria.py registers, the DMA engine, line RAM, pixel output, WSYNC, DLI board.py the MARIA-clock timeline, both decoders, INPTCTRL, HALT and RDY around the bus callbacks, the data bus latch system.py SALLY (MOS6502) + board + cartridge + controllers; BIOS or direct start mode2600.py hands the same CPU, TIA and RIOT to a2600_python's board controllers.py ProLine, light gun, and adapters over a2600_python's controllers cartridge/ formats.py the one loader: .a78, .bin, archives, 2600 dumps description.py CartDescription (see cartridge.md) table.py payload-hash table connector.py the 32-pin protocol linear.py supergame.py activision.py absolute.py souper.py banksets.py devices.py POKEY sockets, YM2151 socket, Covox, HSC, XM television.py frames from lines state.py trace.py debugger.py __main__.py ``` `maria.py` must import nothing from the board (a test enforces it), so that a recorded bus trace can drive it alone.