# SPDX-License-Identifier: MIT """Shared helpers: tiny cartridges built from hand-assembled 6502 code.""" from __future__ import annotations from a2600_python import System from a2600_python.cartridge import load def image_4k(program: bytes, *, origin: int = 0xF000) -> bytes: """A 4K image with ``program`` at its start and the reset vector pointing at it.""" rom = bytearray(0x1000) rom[: len(program)] = program rom[0xFFC:0xFFE] = bytes((origin & 0xFF, origin >> 8)) return bytes(rom) def system_running(program: bytes) -> System: """A powered-on console about to execute ``program`` (reset sequence done).""" system = System(load(image_4k(program), scheme="4K").cartridge) system.step() return system