// 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 of the //! reference); 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. //! //! Rust-forced differences (a7800-python `machine.py` at d6b220d): the frozen //! dataclasses are `Copy` structs with `&'static str` names, built as `const`s; the //! dictionaries `BIOSES`, `BIOS_PLACES` and `MACHINES` are arrays with lookup functions; //! the properties `maria_hz`, `frame_clocks` and `vblank_start` are methods; the //! `bios` tuple is a static slice. use a2600::machine as m2600; pub const LINE_CLOCKS: u32 = 454; // MARIA clocks a line, both standards (DOC: [SG] App. 3/4; [HF] "scoped") /// A BIOS image the board accepts, by hash; bring your own (docs/mame-oracle.md). /// Names, sizes and hashes identify dumps: not hardware values. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct Bios { pub name: &'static str, pub size: usize, pub sha1: &'static str, pub sha256: &'static 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. pub checks_signature: bool, } pub const BIOS_NTSC: Bios = Bios { name: "NTSC 4K (7800.u7, C300558-001)", size: 0x1000, sha1: "d9d134bb6b36907c615a594cc7688f7bfcef5b43", sha256: "7d94551defcd8e7b045a34255654d6d169a683f63062d51dee3eedabf2042db0", checks_signature: true, }; pub const BIOS_NTSC_16K: Bios = Bios { name: "NTSC 16K 'prototype' (c300558-001a.u7, U21)", size: 0x4000, sha1: "14584b1eafe9721804782d4b1ac3a4a7313e455f", sha256: "9a968a7d6ca762721d70e2bac2b23e9dff5b88d5c29aad80dfa6b72457e831d1", checks_signature: true, }; pub const BIOS_PAL: Bios = Bios { name: "PAL 16K with Asteroids (c300558-001b.u7)", size: 0x4000, sha1: "5a140136a16d1d83e4ff32a19409ca376a8df874", sha256: "63e1884e27c89d47e968e2c31dd268e17b415be590865739d5b366c76c123c48", checks_signature: false, }; pub const BIOSES: [Bios; 3] = [BIOS_NTSC, BIOS_NTSC_16K, BIOS_PAL]; /// `BIOSES[sha256]`. pub fn bios_by_sha256(sha256: &str) -> Option { BIOSES.iter().copied().find(|b| b.sha256 == sha256) } // Where the images are: (zip below $MAME_ROMPATH, member), read in place, never copied // (romsets.rs). Not hardware values. pub const BIOS_PLACES: [(&str, (&str, &str)); 3] = [ (BIOS_NTSC.sha256, ("a7800.zip", "7800.u7")), (BIOS_NTSC_16K.sha256, ("a7800.zip", "c300558-001a.u7")), (BIOS_PAL.sha256, ("a7800p.zip", "c300558-001b.u7")), ]; /// `BIOS_PLACES.get(sha256)`. pub fn bios_place(sha256: &str) -> Option<(&'static str, &'static str)> { BIOS_PLACES.iter().find(|(s, _)| *s == sha256).map(|(_, p)| *p) } /// 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). #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct PowerOn { pub a: u8, pub x: u8, pub y: u8, pub s: u8, pub p: u8, pub line: u32, pub clock: u32, pub ram_fill: u8, pub riot_ram_fill: u8, pub riot_timer_value: u8, pub riot_timer_divider: i64, pub riot_timer_first_decrement: i64, pub tia_hclock: u32, } pub const POWER_ON: PowerOn = PowerOn { a: 0, x: 0x80, y: 0, s: 0, p: 0x26, line: 250, clock: 444, ram_fill: 0x00, riot_ram_fill: 0x00, riot_timer_value: 0xFF, riot_timer_divider: 1024, riot_timer_first_decrement: 1023, tia_hclock: 224, }; impl Default for PowerOn { fn default() -> Self { POWER_ON } } /// 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). #[derive(Clone, Copy, Debug, PartialEq)] pub struct Machine { pub name: &'static str, pub crystal_hz: f64, pub lines: u32, pub vblank_end: u32, pub dma_lines: u32, pub bios: &'static [Bios], pub mode_2600: m2600::Machine, pub certified: bool, // not a hardware value pub power_on: 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!). pub switches: u8, } impl Machine { pub fn maria_hz(&self) -> f64 { self.crystal_hz / 2.0 } pub fn frame_clocks(&self) -> u64 { (self.lines * LINE_CLOCKS) as u64 } pub fn vblank_start(&self) -> u32 { self.vblank_end + self.dma_lines } } // Rows: values as the Machine docstring cites them (DOC). pub const NTSC: Machine = Machine { name: "Atari 7800 (NTSC)", crystal_hz: 4.0 * 315e6 / 88.0, lines: 263, vblank_end: 16, dma_lines: 242, bios: &[BIOS_NTSC, BIOS_NTSC_16K], mode_2600: m2600::NTSC_7800, certified: false, power_on: POWER_ON, switches: 0x3F, }; pub const PAL: Machine = Machine { name: "Atari 7800 (PAL)", crystal_hz: 14_187_576.0, lines: 313, vblank_end: 16, dma_lines: 292, bios: &[BIOS_PAL], mode_2600: m2600::PAL_7800, certified: false, power_on: POWER_ON, switches: 0x3F, }; pub const MACHINES: [Machine; 2] = [NTSC, PAL]; /// `MACHINES[name]`. pub fn machine(name: &str) -> Option { MACHINES.iter().copied().find(|m| m.name == name) }