# SPDX-License-Identifier: MIT # Uses bll_loader.enc, the BLL kit's uloader/bll.enc (42Bastian Schick, Apache-2.0): notice in NOTICE. """A BLL program (``BS93``) as a cart: the BLL kit's own recipe. A BLL ``.o`` file is not a cart. On hardware it reached RAM over ComLynx from the BLL uploader, or it was put on a cart behind the kit's cart loader. That second way is documented in the kit (new_bll ``e2dded9``, ``uloader/readme.md``: "bll.enc: Encrypted header for files with BLL header. Concatenate with a BLL file to build a ROM image"; ``uloader/Makefile``: ``cat bll.enc file.o``, then ``$FF`` to 256 KiB, ``make_lnx -b0 256K``), so a BLL image is booted that way here: the real boot ROM decrypts the kit's loader, which reads the 10-byte header behind it, copies the program to its load address and jumps there (``uloader/bll_loader.s``: four 256-byte pages per block, so 1024-byte blocks). Nothing about the hand-over state is invented: it is what the boot ROM and the kit's loader leave. DOC (the BLL kit, Apache-2.0, permitted: emulator-lineage docs/sources.md). The 256 KiB variant is enough: a BLL program is at most 64 KiB. """ from __future__ import annotations from importlib.resources import files CART_SIZE = 256 * 1024 # uloader/Makefile: make_lnx -b0 256K BLOCK = 1024 # uloader/bll_loader.s: "4 pages per block" of 256 bytes FILL = 0xFF # uloader/Makefile: allff.lyx ("better for flashing") def loader() -> bytes: """The kit's encrypted micro loader plus its BLL second stage (246 bytes).""" return (files("lynx_python.cart") / "bll_loader.enc").read_bytes() def as_cart(program: bytes) -> tuple[bytes, int]: """(cart image, bank-0 block size) for a whole BLL file, header included.""" image = loader() + bytes(program) if len(image) > CART_SIZE: raise ValueError(f"a BLL program of {len(program)} bytes does not fit a 256 KiB cart") return image + bytes([FILL]) * (CART_SIZE - len(image)), BLOCK