# SPDX-License-Identifier: MIT """The cartridge connector, as signals: the only thing a scheme knows of the console. docs/cartridge.md "The connector is 24 pins and has no R/W line" has the reasons. A scheme module imports this module and nothing else of the board (``tests/test_cartridge_boundary.py`` enforces it). - **Every CPU cycle**, whatever its address, reaches :meth:`Cartridge.access`: the slot carries A0-A12 always, and schemes watch TIA writes (3F) and stack accesses (FE) as well as their own window. - **No R/W.** ``value`` is the byte on the data bus as the cartridge would see it before driving: the CPU's byte on a write cycle, the floating bus on a read cycle. A scheme decides by address alone, as the hardware must; a Super Chip's write window stores ``value`` either way, which is how a read of the write window corrupts RAM on a console. - ``write`` says whether the CPU drives this cycle. The slot has no such pin, so a scheme may use it only where its documentation says the cartridge reacts to writes alone and the mechanism is not known (3F: Horton, "writing to any location between 0000 and 003F"); each such use is tagged HYPOTHESIS for the mechanism. ``tests/test_cartridge.py`` lists the schemes allowed to read it. - **The return value** is the byte the cartridge drives, or ``None`` if it leaves the bus alone. The board uses it on read cycles only; on a write cycle the CPU drives the bus. - **Snooping.** A scheme that latches a byte someone else drives (FE takes the bank from D5 of the byte after a $01FE access, and on an RTS that byte comes from RIOT RAM) sets ``snoops_reads``; the board then calls :meth:`snoop` with the byte that settled on the bus at the end of every read cycle. - ``t`` is the CPU cycle count at the access (the board's one timeline), for schemes with their own clock (the DPC's music oscillator). """ from __future__ import annotations class Cartridge: """No cartridge: nothing driven, nothing remembered.""" name = "none" snoops_reads = False def access(self, address: int, value: int, t: int, write: bool = False) -> int | None: """One CPU cycle; ``address`` is A0-A12.""" return None def snoop(self, value: int) -> None: """The byte on the data bus at the end of the read cycle just accessed.""" def reset(self) -> None: """The console's power was cycled with the cartridge in (32IN1 counts these)."""