"""A finished frame: colour indices, already resolved through the planes.""" from __future__ import annotations from dataclasses import dataclass @dataclass(frozen=True) class Frame: """One frame as the chip drew it. ``pixels`` is 192 rows of 256 colour indices (0-15). Each index is already resolved through TI's plane order [TI 2.4]: a sprite colour, else the pattern colour, else the backdrop (R7 bits 3-0). Index 0 therefore appears only where every plane is transparent and the backdrop is 0 (black, or external video if the board mixes it). Text mode's 240 pixels sit 6 pixels in [TI table 3-3], backdrop either side. A line drawn while BLANK = 0 is backdrop from edge to edge [TI 2.1.5]. ``border`` is the backdrop index per line, one entry per line of the frame (262 or 313), line 0 the first active line, sampled as each line began. ``number`` counts frames from power-on (the first is 0). """ pixels: tuple[bytes, ...] border: tuple[int, ...] number: int def row(self, y: int) -> bytes: return self.pixels[y] def flat(self) -> bytes: """The 192 x 256 indices as one bytes object, row after row.""" return b"".join(self.pixels)