"""The parts this core models, as data. Sources are cited as in ``docs/chip.md``: **[TI]** the TMS9918A/TMS9928A/TMS9929A data manual (Nov 1982, tier 2, section numbers its own); **[PG]** TI's Programmer's Guide SPPU004 (tier 2); **[Young]** Sean Young's ``tms9918a.txt`` (tier 3). C and U numbers are the contradictions and unknowns of ``docs/handoff-brief.md``; ``docs/claims.md`` says which values are provisional. No logic in the chip asks which part it is running: it reads these fields. A host may build its own row (for example a TMS9118) with ``dataclasses.replace``. """ from __future__ import annotations from dataclasses import dataclass #: TI table 2-3, the 9918A's columns: (luminance, chrominance amplitude) for colours 0-15. #: ``None`` where TI prints a dash. Transparent (0) has luminance 0.00. LEVELS_9918A: tuple[tuple[float, float | None], ...] = ( (0.00, None), (0.00, None), (0.53, 0.53), (0.67, 0.40), (0.40, 0.60), (0.53, 0.53), (0.47, 0.47), (0.67, 0.60), (0.53, 0.60), (0.67, 0.60), (0.73, 0.47), (0.80, 0.33), (0.46, 0.47), (0.53, 0.40), (0.80, None), (1.00, None), ) # fmt: skip #: TI table 2-3, the 9928A/9929A columns: (Y, R-Y, B-Y) for colours 0-15; ``None`` for #: transparent, where TI prints dashes. 0.47 is zero colour difference. Dark blue's R-Y #: is printed ".4" (one digit) on the page; it is kept as printed. LEVELS_9928A: tuple[tuple[float, float, float] | None, ...] = ( None, (0.00, 0.47, 0.47), (0.53, 0.07, 0.20), (0.67, 0.17, 0.27), (0.40, 0.4, 1.00), (0.53, 0.43, 0.93), (0.47, 0.83, 0.30), (0.73, 0.00, 0.70), (0.53, 0.93, 0.27), (0.67, 0.93, 0.27), (0.73, 0.57, 0.07), (0.80, 0.57, 0.17), (0.47, 0.13, 0.23), (0.53, 0.73, 0.67), (0.80, 0.47, 0.47), (1.00, 0.47, 0.47), ) # fmt: skip @dataclass(frozen=True) class VerticalLayout: """Lines per frame region, top to bottom from the first active line [TI table 3-3].""" active: int bottom_border: int bottom_blanking: int sync: int top_blanking: int top_border: int @property def lines(self) -> int: return ( self.active + self.bottom_border + self.bottom_blanking + self.sync + self.top_blanking + self.top_border ) # fmt: skip #: [TI table 3-3], the only column TI prints: 192 + 24 + 3 + 3 + 13 + 27 = 262. NTSC_LAYOUT = VerticalLayout(192, 24, 3, 3, 13, 27) #: The TMS9929A's 313 lines. TI prints no PAL column (U7). PROVISIONAL, tier 5: the top #: (13 blanking + 51 border) is MAME 0.285's ``VERT_DISPLAY_START_PAL = 13 + 51``; the #: bottom 51 + 3 + 3 is this core's choice, mirroring the NTSC column's 3 + 3. PAL_LAYOUT = VerticalLayout(192, 24, 3, 3, 13, 27) @dataclass(frozen=True) class VDPVariant: """What differs between the parts. Configuration: nothing here changes at run time.""" #: A label for messages and reports. Nothing compares against it. name: str #: The vertical layout. 262 lines on the 9918A and 9928A, 313 on the 9929A [TI 3.6.2; #: its "TMS9918A/9929A ... 262" is a misprint for 9928A, C8]. layout: VerticalLayout #: Whether R0 bit 1 (M3, Graphics II) exists. True on every "A" part; the plain #: TMS9918 lacks Graphics II (MAME ``m_reva``; the 1980 draft's three modes; U6). graphics2: bool = True #: Whether R1 bit 7 (4K/16K) does anything. True on the 99x8A; the TMS91x8 treat #: it as "Don't Care" and assume 16K [PG 5.1.2 note]. has_4k_select: bool = True #: Whether R3's Graphics II colour mask also masks the pattern index (C3). True on #: the 99x8: TI's 1982 memo ("due to a logic error, the color table cannot be #: reduced ... without adverse effects to the pattern addressing", tier 2) and MAME #: (tier 5). MAME has it False on the 91x8. colour_mask_masks_patterns: bool = True #: "composite" (9918A) or "colour-difference" (9928A/9929A). Information only: #: the core outputs colour indices [TI 2.4, 3.6]. output: str = "composite" #: TI table 2-3's column for this part. Information only. levels: tuple = LEVELS_9918A #: What pin 38 carries: "cpuclk" (XTAL/3) or "r-y" [TI 3.7]. Information only. pin38: str = "cpuclk" #: Master clocks from a CPU access to the first memory cycle that may serve it: TI's #: "approximately 2 microseconds" of VDP delay [TI 2.1.5, table 2-2] (U13). #: PROVISIONAL, fitted (tier 3): 16 master clocks (1.49 us) is the value at which #: the 1978 schedule best reproduces VATT's landing fractions on real MSX1 machines #: (docs/results.md, rung 4); TI's 2 us (21.5) and Vermaelen's guess of 11 pixel #: clocks (22) fit worse (12 of 16 periods outside the hardware spread at 22). access_delay: int = 16 @property def lines(self) -> int: return self.layout.lines TMS9918A = VDPVariant(name="TMS9918A", layout=NTSC_LAYOUT) TMS9928A = VDPVariant( name="TMS9928A", layout=NTSC_LAYOUT, output="colour-difference", levels=LEVELS_9928A, pin38="r-y", ) # fmt: skip TMS9929A = VDPVariant( name="TMS9929A", layout=PAL_LAYOUT, output="colour-difference", levels=LEVELS_9928A, pin38="r-y", ) # fmt: skip #: Rows by name. VARIANTS: dict[str, VDPVariant] = {v.name: v for v in (TMS9918A, TMS9928A, TMS9929A)}