# SPDX-License-Identifier: MIT """The consoles, as data: one board, two television standards. Every field names its source and that source's tier (docs/validation.md); where a value is a choice made to match a detector it says so. Adding a console revision is adding a row, not a code path. """ from __future__ import annotations from dataclasses import dataclass, field from a2600_python import machine as m2600 LINE_CLOCKS = 454 # MARIA clocks a line, both standards (DOC: [SG] App. 3/4; [HF] "scoped") @dataclass(frozen=True) class Bios: """A BIOS image the board accepts, by hash; bring your own (docs/mame-oracle.md). Names, sizes and hashes identify dumps: not hardware values.""" name: str size: int sha1: str sha256: str # NTSC: Atari's signature; PAL: the region byte only (C8). What the dump's own code # does, read from it: not a board value. checks_signature: bool BIOS_NTSC = Bios( "NTSC 4K (7800.u7, C300558-001)", 0x1000, "d9d134bb6b36907c615a594cc7688f7bfcef5b43", "7d94551defcd8e7b045a34255654d6d169a683f63062d51dee3eedabf2042db0", checks_signature=True, ) # fmt: skip BIOS_NTSC_16K = Bios( "NTSC 16K 'prototype' (c300558-001a.u7, U21)", 0x4000, "14584b1eafe9721804782d4b1ac3a4a7313e455f", "9a968a7d6ca762721d70e2bac2b23e9dff5b88d5c29aad80dfa6b72457e831d1", checks_signature=True, ) # fmt: skip BIOS_PAL = Bios( "PAL 16K with Asteroids (c300558-001b.u7)", 0x4000, "5a140136a16d1d83e4ff32a19409ca376a8df874", "63e1884e27c89d47e968e2c31dd268e17b415be590865739d5b366c76c123c48", checks_signature=False, ) # fmt: skip BIOSES = {b.sha256: b for b in (BIOS_NTSC, BIOS_NTSC_16K, BIOS_PAL)} # Where the images are: (zip below $MAME_ROMPATH, member), read in place, never copied # (romsets.py). Not hardware values. BIOS_PLACES = { BIOS_NTSC.sha256: ("a7800.zip", "7800.u7"), BIOS_NTSC_16K.sha256: ("a7800.zip", "c300558-001a.u7"), BIOS_PAL.sha256: ("a7800p.zip", "c300558-001b.u7"), } @dataclass(frozen=True) class PowerOn: """What the console holds when switched on. Undefined on hardware; every value is chosen to match MAME 0.285's start (OBSERVED: MAME 0.285; docs/timing.md "Power-on and reset"; docs/mame-oracle.md trap 11), so the milestone-1 lockstep starts aligned. A test that depends on one must say so. - ``a``/``x``/``y``/``s``/``p``: before the reset sequence (OBSERVED: MAME's first traced instruction shows A=0 X=$80 Y=0 P=$36 S=$1FD after it). - ``line``/``clock``: MARIA's beam at power (OBSERVED: MAME's first instruction starts at its line 251, beamx 32). 6502-python's reset sequence is 7 cycles, and at power INPTCTRL is 0, so MEN = 0 selects the 2600 decoder and every cycle is slow (DOC: [MT84] Figure 2): 42 MARIA clocks. Power is placed 42 clocks before line 251 clock 32: line 250, clock 444. - ``ram_fill``: the two 6116s (OBSERVED: MAME 0.285 zeroes its RAM). - ``riot_*``: the 6532 as a2600-python's MAME-matched rows give it (OBSERVED: the same MAME device, mos6532). - ``tia_hclock``: the TIA's colour clock in its own 228-clock line at power. Free-running beside MARIA's 227 in 7800 mode; matters only to 2600 mode. a2600-python's default (HYPOTHESIS, U11: the PAL 7800 rows of the Stella #699 tables and a2600-python's die traces would bound it). """ a: int = 0 x: int = 0x80 y: int = 0 s: int = 0 p: int = 0x26 line: int = 250 clock: int = 444 ram_fill: int = 0x00 riot_ram_fill: int = 0x00 riot_timer_value: int = 0xFF riot_timer_divider: int = 1024 riot_timer_first_decrement: int = 1023 tia_hclock: int = 224 @dataclass(frozen=True) class Machine: """One 7800 model. ``lines``: [HF] (DOC, reported console measurement: counted on consoles). ``vblank_end`` is the line on which MSTAT D7 falls and DMA begins: "raster 16" (DOC: [SG] MSTAT). ``dma_lines`` is 242 NTSC: the gate-level diagrams decode VBLANK's end at vertical count 16 and its start at 258 (DOC: [GLD] sheet 17, docs/gld-reading.md), as [MT84] 2.2 has it (and MAME 0.285, OBSERVED); [SG] App. 4's diagram draws 243 (C7). PAL 292 by [MT84] 2.2 (DOC; the PAL decode was not read). ``crystal_hz``: C10 for NTSC (DOC: [HF], [1702B]); [HF] for PAL (DOC). ``mode_2600`` is a2600-python's row for this console in 2600 mode (``HOSTED_MACHINES`` there, docs/api.md "Machines": ``NTSC_7800`` with the reference TIA, unmeasured, and ``PAL_7800`` with the #699 revision; both with ``tia_clocks_cpu`` False; their evidence is stated there). """ name: str crystal_hz: float lines: int vblank_end: int dma_lines: int bios: tuple[Bios, ...] mode_2600: m2600.Machine certified: bool = False # not a hardware value power_on: PowerOn = field(default_factory=PowerOn) # SWCHB with nothing pressed: reset D0, select D1, pause D3 released (high) # (DOC: [SG] SWCHB); difficulties D6/D7 on B (a user setting, not a hardware # value); D2/D4 are the two-button lines, inputs at power reading high (DOC: the # wiki's two-button notes, One on One and Worm!). switches: int = 0x3F @property def maria_hz(self) -> float: return self.crystal_hz / 2 @property def frame_clocks(self) -> int: return self.lines * LINE_CLOCKS @property def vblank_start(self) -> int: return self.vblank_end + self.dma_lines # Rows: values as the Machine docstring cites them (DOC). NTSC = Machine( "Atari 7800 (NTSC)", 4 * 315e6 / 88, 263, 16, 242, (BIOS_NTSC, BIOS_NTSC_16K), m2600.NTSC_7800, ) # fmt: skip PAL = Machine( "Atari 7800 (PAL)", 14_187_576.0, 313, 16, 292, (BIOS_PAL,), m2600.PAL_7800, ) # fmt: skip MACHINES = {m.name: m for m in (NTSC, PAL)}