# SPDX-License-Identifier: MIT """The other schemes licensed cartridges used: E0, 3F, FE, E7, CV, UA, F0 and 32IN1. Main source: Kevin Horton, *Mostly Inclusive Atari 2600 Mapper / Selected Hardware Document* v1.00 (2012; ``reference/docs/kevtris-atari-2600-mappers.txt``, cited "Horton"), whose author built most of these schemes in his own FPGA console. Where Horton leaves a detail open, MAME 0.285's BSD-3-Clause cartridge devices (``src/devices/bus/vcs/rom.cpp``, copyright Fabio Priuli; notice in NOTICE) are cited as "MAME rom.cpp": an emulator's source, a lower tier than a document. Details neither settles are HYPOTHESIS, with the experiment that would settle them. Power-on banks are arbitrary on hardware (HYPOTHESIS: no document states them); the defaults are MAME's, for the lockstep. """ from __future__ import annotations from .connector import Cartridge class E0(Cartridge): """Parker Brothers 8K: four 1K slices (DOC Horton). $1000/$1400/$1800 each show any 1K slice of the 8K, chosen by an access to $1FE0-$1FE7, $1FE8-$1FEF and $1FF0-$1FF7 respectively; $1C00-$1FFF is fixed to the last slice. Power-on slices 4, 5, 6 (MAME rom.cpp:424-429). """ name = "E0" def __init__(self, image: bytes, *, start_slices: tuple[int, int, int] = (4, 5, 6)) -> None: if len(image) != 0x2000: raise ValueError(f"E0 needs 8192 bytes, not {len(image)}") self.rom = bytes(image) self.slices = [*start_slices, 7] def access(self, address: int, value: int, t: int, write: bool = False) -> int | None: if not address & 0x1000: return None if 0x1FE0 <= address <= 0x1FF7: self.slices[(address >> 3) & 3] = address & 7 return self.rom[(self.slices[(address >> 10) & 3] << 10) | (address & 0x3FF)] class Tigervision3F(Cartridge): """Tigervision 3F: 2K pages, the last fixed at $1800 (DOC Horton). A write to $0000-$003F latches the page for $1000-$17FF from the data bus (Horton: "selectable by writing to any location between 0000 and 003F"; the TIA sees the same write, which is why games use $3F, a register the TIA lacks). Only writes count: HYPOTHESIS for the mechanism, since the slot has no R/W line (Horton names a 74LS173 latch without its wiring); a game reading a TIA register at $00-$3F would show whether reads latch too. The latch holds as many bits as the image has pages (MAME rom.cpp:401-405 masks the same way). Power-on: the last page (MAME rom.cpp:384-387). """ name = "3F" def __init__(self, image: bytes, *, start_page: int | None = None) -> None: if len(image) % 0x800 or len(image) < 0x1000: raise ValueError(f"3F needs a whole number of 2K pages, not {len(image)} bytes") self.rom = bytes(image) self.mask = len(image) // 0x800 - 1 self.last = self.mask << 11 self.page = (self.mask if start_page is None else start_page) << 11 def access(self, address: int, value: int, t: int, write: bool = False) -> int | None: if address & 0x1000: if address & 0x800: return self.rom[self.last | (address & 0x7FF)] return self.rom[self.page | (address & 0x7FF)] if write and address < 0x40: self.page = (value & self.mask) << 11 return None class ActivisionFE(Cartridge): """Activision FE: two 4K banks chosen through the stack (DOC Horton). Horton: JSR and RTS both end with the byte that holds the new PC's high byte (the JSR's high address fetch; the RTS's PCH pull from $01FF), right after a stack access at $01FE (the JSR's PCL push, the RTS's PCL pull), and the chip "latch[es] D5. This is the NEW bank". The programs are assembled at $Fxxx in one bank and $Dxxx in the other, so D5 = 1 ($Fxxx) selects bank 0, the image's first 4K, and D5 = 0 ($Dxxx) bank 1 (DOC: the dumps' own reset vectors and JSR targets; MAME rom.cpp:284-290 has the same). The trigger is modelled as an access to $01FE, read or write, arming a latch of the next cycle's data bus (MAME rom.cpp:258-302 likewise). HYPOTHESIS: Horton describes the chip as also watching for the $20/$60 opcodes; whether a bare $01FE access arms it (as the reset sequence's stack reads do when S powers up at 0, and MAME's model skips that first one) is untested. A probe cartridge that touches $01FE with no JSR/RTS would settle it on a console. Power-on: bank 0 (MAME rom.cpp:250-256). """ name = "FE" snoops_reads = True def __init__(self, image: bytes, *, start_bank: int = 0) -> None: if len(image) != 0x2000: raise ValueError(f"FE needs 8192 bytes, not {len(image)}") self.rom = bytes(image) self.bank = start_bank << 12 self.armed = False # an access to $01FE was the previous cycle self.latch = False # this cycle's byte is the new bank def access(self, address: int, value: int, t: int, write: bool = False) -> int | None: self.latch = self.armed self.armed = address == 0x01FE if write and self.latch: self.snoop(value) if address & 0x1000: return self.rom[self.bank | (address & 0xFFF)] return None def snoop(self, value: int) -> None: if self.latch: self.bank = 0 if value & 0x20 else 0x1000 self.latch = False class MNetworkE7(Cartridge): """M-Network E7 ("Big Game"): 2K ROM pages, 2K of RAM (DOC Horton). - $1000-$17FF: ROM page 0-6 chosen by an access to $1FE0-$1FE6; an access to $1FE7 puts 1K of RAM there instead, written at $1000-$13FF, read at $1400-$17FF. - $1800-$19FF: the other 1K of RAM, 256 bytes at a time, written at $1800-$18FF and read at $1900-$19FF, the block chosen by $1FE8-$1FEB. - $1A00-$1FFF: the last 1.5K of the ROM. (Horton's 1997 ``sizes.txt`` put the block select at $1FF8-$1FFB; his 2012 document and MAME rom.cpp:513 put it at $1FE8-$1FEB, and the dumps' own code touches $1FE8-$1FEB: the 2012 text is used.) A 12K image (BurgerTime's proper dump) holds ROM pages 0-1 and 4-7 of the 16K map, with pages 2-3 mirroring 0-1: DOC, from comparing the 12K and 16K dumps of BurgerTime page by page (the 16K dump's pages 2-3 equal its 0-1). An 8K image (Bump 'n' Jump's USA dump, which Stella's ``-rominfo`` calls E7) has four pages; HYPOTHESIS: the ROM's address lines repeat it, so page n is page n mod 4 and the fixed area is the image's last 1.5K. A 16K dump of the same cartridge, or the board, would settle it. Power-on: ROM page 0, RAM block 0 (MAME rom.cpp:489-493). """ name = "E7" def __init__(self, image: bytes, *, start_page: int = 0, ram_fill: int = 0x00) -> None: pages = [image[i : i + 0x800] for i in range(0, len(image), 0x800)] if len(image) == 0x3000: image = b"".join(pages[:2] + pages[:2] + pages[2:]) elif len(image) == 0x2000: image = b"".join(pages * 2) if len(image) != 0x4000: raise ValueError(f"E7 needs 16384, 12288 or 8192 bytes, not {len(image)}") self.rom = bytes(image) self.ram = bytearray([ram_fill]) * 0x800 # $000-$3FF low 1K, $400-$7FF the blocks self.page = start_page # 7 = RAM self.block = 0 def access(self, address: int, value: int, t: int, write: bool = False) -> int | None: if not address & 0x1000: return None if 0x1FE0 <= address <= 0x1FEB: if address <= 0x1FE7: self.page = address & 7 else: self.block = address & 3 offset = address & 0xFFF if offset < 0x800: if self.page == 7: if offset < 0x400: self.ram[offset] = value return None return self.ram[offset - 0x400] return self.rom[(self.page << 11) | offset] if offset < 0xA00: index = 0x400 | (self.block << 8) | (offset & 0xFF) if offset < 0x900: self.ram[index] = value return None return self.ram[index] return self.rom[0x3800 | (offset & 0x7FF)] class CommaVid(Cartridge): """CommaVid CV: 2K of ROM at $1800-$1FFF, 1K of RAM read at $1000-$13FF and written at $1400-$17FF (DOC Horton; MAME rom.cpp:587-593 agrees).""" name = "CV" def __init__(self, image: bytes, *, ram_fill: int = 0x00) -> None: if len(image) == 0x1000: # a 4K dump with the ROM in its upper half image = image[0x800:] if len(image) != 0x800: raise ValueError(f"CV needs 2048 bytes, not {len(image)}") self.rom = bytes(image) self.ram = bytearray([ram_fill]) * 0x400 def access(self, address: int, value: int, t: int, write: bool = False) -> int | None: if not address & 0x1000: return None offset = address & 0xFFF if offset >= 0x800: return self.rom[offset & 0x7FF] if offset < 0x400: return self.ram[offset] self.ram[offset & 0x3FF] = value return None class UA(Cartridge): """UA Ltd 8K: two 4K banks, an access to $0220 selecting the first and $0240 the second (DOC Horton). HYPOTHESIS on the decode: Horton names the two addresses only. The model decodes A12 = 0, A9 = 1, A7 = 0 (the RIOT's I/O half and the TIA never use that combination for these programs) and takes the bank from A6, as MAME does over $0200-$027F (rom.cpp:555-568); a game touching another mirror would tell the two apart. Power-on: bank 0 (MAME rom.cpp:550-553). """ name = "UA" def __init__(self, image: bytes, *, start_bank: int = 0) -> None: if len(image) != 0x2000: raise ValueError(f"UA needs 8192 bytes, not {len(image)}") self.rom = bytes(image) self.bank = start_bank << 12 def access(self, address: int, value: int, t: int, write: bool = False) -> int | None: if address & 0x1000: return self.rom[self.bank | (address & 0xFFF)] if address & 0x1380 == 0x0200 and address & 0x60: self.bank = (address & 0x40) << 6 return None class MegaboyF0(Cartridge): """Dynacom Megaboy F0: sixteen 4K banks; each access to $1FF0 steps to the next (DOC Horton: "accessing 1FF0 causes the bank number to increment"). MAME (rom.cpp:617-637) also returns the bank number at $1FEC; Horton says the program finds its bank from a ROM byte there ("Each bank is numbered by means of one of the ROM locations"), so the ROM is returned (DOC Horton over MAME). Power-on: bank 0 (MAME rom.cpp:612-615). """ name = "F0" def __init__(self, image: bytes, *, start_bank: int = 0) -> None: if len(image) != 0x10000: raise ValueError(f"F0 needs 65536 bytes, not {len(image)}") self.rom = bytes(image) self.bank = start_bank def access(self, address: int, value: int, t: int, write: bool = False) -> int | None: if not address & 0x1000: return None if address == 0x1FF0: self.bank = (self.bank + 1) & 15 return self.rom[(self.bank << 12) | (address & 0xFFF)] class ThirtyTwoInOne(Cartridge): """32 in 1: thirty-two 2K games, one per power cycle (DOC MAME rom.cpp:798-832: "the 2K banks change at each reset", the next game on every reset of the console; Horton does not cover it). HYPOTHESIS: the cartridge counts the console's power-ups; the first game at the first. Each 2K game appears twice in the 4K window, like a plain 2K cartridge.""" name = "32IN1" def __init__(self, image: bytes, *, game: int = 0) -> None: if len(image) != 0x10000: raise ValueError(f"32IN1 needs 65536 bytes, not {len(image)}") self.rom = bytes(image) self.game = game def reset(self) -> None: self.game = (self.game + 1) & 31 def access(self, address: int, value: int, t: int, write: bool = False) -> int | None: if address & 0x1000: return self.rom[(self.game << 11) | (address & 0x7FF)] return None