"""The ColecoVision as data: two machine rows and the board's switches. A row says which video chip the console carries, how many lines it draws and which BIOS dump belongs to it. Everything the sources leave open is a named field of :class:`BoardOptions` with its default and its evidence; ``docs/claims.md`` lists them. """ from __future__ import annotations from dataclasses import dataclass, field, replace from tms9918_python import TMS9928A, TMS9929A, VDPVariant #: Crystal / 2 [Coleco Technical Manual; MAME XTAL(7'159'090) / 2; C4]. CPU_CLOCK_HZ = 3_579_545 #: The VDP runs at exactly three times the CPU clock ("third harmonic", [TM p. III-5]). MASTER_PER_CPU_CLOCK = 3 #: SHA-1 of the two Coleco OS-7 dumps (docs/cartridge.md, "BIOS dumps"). BIOS_NTSC_SHA1 = "45bedc4cbdeac66c7df59e9e599195c778d86a92" BIOS_PAL_SHA1 = "160077afb139943725c634d6539898db59f33657" #: The VDP's phase at the CPU's first clock, in master clocks after the core's own reset #: point (line 0, dot 0). U6: nothing in hand says where the dot counter is when the #: console comes out of reset. The default is MAME 0.285's: its trace starts at raster #: line 244, beam x 0, i.e. active line 204 (MAME's first active line is raster line #: 40), and MAME's line starts 27 dots before the core's dot 0 (MAME draws pixel 0 at #: beam x 37, the core at dot 10). Core line 203, dot 315 = 203 * 684 + 315 * 2. MAME_NTSC_VDP_PHASE = 203 * 684 + 315 * 2 @dataclass(frozen=True) class BoardOptions: """The board's provisional behaviours, each a switch (docs/claims.md). The defaults follow the two schematic tracings (tier 3) where they and MAME (tier 5) disagree, per the owner's decision 13. :func:`mame_options` gives MAME's choices, which the lockstep replays use. """ #: C11: does the M1 wait lengthen the NMI response and the interrupt acknowledge? #: Tracings: every M1 cycle gets it (True). MAME 0.285: fetches and HALT only. m1_wait_on_acknowledge: bool = True #: U3: an interrupt acknowledge with PC's low byte in $A0-$BF strobes the VDP's read #: (the I/O decoder has no /M1 and no /RD term on either tracing). MAME: no access. acknowledge_reads_vdp: bool = True #: C9: CPU clocks the SN76489A's READY holds the Z80 after a write. TI: "approximately #: 32 clock cycles"; MAME 0.285 measured here: 28; Clock Signal: 31. MAME's for lockstep. ready_wait: int = 28 #: U6: the VDP's phase at the CPU's first clock, master clocks after line 0, dot 0. vdp_phase: int = MAME_NTSC_VDP_PHASE #: U4: what reads of $80-$9F, $C0-$DF and ports $00-$7F (nothing driving) return. open_bus_port: int = 0xFF #: U5: what reads of $2000-$5FFF and absent cartridge selects return. open_bus_memory: int = 0xFF #: Not hardware: reproduce MAME 0.285's video clock rounding (its screen runs on a #: 5,369,317 Hz pixel clock, not 5,369,317.5, so its VDP falls one master clock behind #: the CPU every 10,738,635). Only for lockstep runs longer than about a second. mame_video_rounding: bool = False #: U6: Z80 registers at power-on, as attribute names of z80_python.Z80CPU. Empty: #: the core's zeros. MAME 0.285 starts with AF = $0040, IX = IY = $FFFF. power_on_cpu: dict = field(default_factory=dict) #: Keywords passed to tms9918_python.TMS9918 (its docs/claims.md; the core's defaults #: when empty). vdp: dict = field(default_factory=dict) def mame_options(**overrides: object) -> BoardOptions: """MAME 0.285's choice on every switch: what the lockstep replays run with. C11 off, U3 off, the VDP serving every access at once with F set at line 193 and R1 bit 7 doing nothing (tms9918-python's C10/C11 keywords set to MAME's points). """ vdp = { "windows": False, "roll_over_4k": False, "mux_4k": False, "flag_dot": (193, 10), "offscreen_collisions": False, } cpu = {"a": 0x00, "f": 0x40, "ix": 0xFFFF, "iy": 0xFFFF} options = BoardOptions( m1_wait_on_acknowledge=False, acknowledge_reads_vdp=False, vdp=vdp, power_on_cpu=cpu, mame_video_rounding=True, ) return replace(options, **overrides) @dataclass(frozen=True) class Machine: """One ColecoVision row.""" name: str vdp_variant: VDPVariant bios_sha1: str #: Frames per second, for the audio and pacing only (the timeline is in clocks). frame_rate: float @property def lines(self) -> int: return self.vdp_variant.lines @property def cpu_clocks_per_frame(self) -> int: return self.lines * 684 // MASTER_PER_CPU_CLOCK #: The reference: a TMS9928A, 262 lines, 59,736 CPU clocks a frame. NTSC = Machine("NTSC", TMS9928A, BIOS_NTSC_SHA1, CPU_CLOCK_HZ / 59_736) #: The PAL console: TMS9929A, 313 lines; its own BIOS. Crystal assumed the same (U7). PAL = Machine("PAL", TMS9929A, BIOS_PAL_SHA1, CPU_CLOCK_HZ / 71_364) MACHINES = {m.name: m for m in (NTSC, PAL)}