# SPDX-License-Identifier: MIT """Assemble a console: machine row, BIOS by hash, cartridge through the front door.""" from __future__ import annotations from pathlib import Path from .bios import find_bios from .board import Board from .cartridge import Cart, load_cartridge from .controllers import Controllers from .machine import A5200, MACHINES, Machine class Console: """A 5200 with a cartridge in and controllers attached.""" def __init__( self, cart: Cart | str | Path | bytes, machine: Machine | str = A5200, *, bios: bytes | None = None, bios_path: str | Path | None = None, mapping: str | None = None, ) -> None: if isinstance(machine, str): machine = MACHINES[machine] if not isinstance(cart, Cart): cart = load_cartridge(cart, mapping=mapping) if bios is None: bios, self.bios_source = find_bios(machine.bios_sha1, bios_path) else: self.bios_source = "" self.machine = machine self.cart = cart self.board = Board(machine, bios, cart.port()) self.controllers = Controllers(self.board) @property def frames(self) -> int: return self.board.frames def run_frames(self, n: int) -> None: run = self.board.run_frame for _ in range(n): self.controllers.frame() run()