// 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 (`cart/bll.py`). //! //! 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. //! //! Differences forced by Rust: the loader is compiled in (`include_bytes!`) rather than //! read as package data; Python's `ValueError` is an `Err(String)`. pub const CART_SIZE: usize = 256 * 1024; // uloader/Makefile: make_lnx -b0 256K pub const BLOCK: usize = 1024; // uloader/bll_loader.s: "4 pages per block" of 256 bytes pub const FILL: u8 = 0xFF; // uloader/Makefile: allff.lyx ("better for flashing") /// The kit's encrypted micro loader plus its BLL second stage (246 bytes). pub fn loader() -> &'static [u8] { include_bytes!("bll_loader.enc") } /// (cart image, bank-0 block size) for a whole BLL file, header included. pub fn as_cart(program: &[u8]) -> Result<(Vec, usize), String> { let mut image = loader().to_vec(); image.extend_from_slice(program); if image.len() > CART_SIZE { return Err(format!( "a BLL program of {} bytes does not fit a 256 KiB cart", program.len() )); } image.resize(CART_SIZE, FILL); Ok((image, BLOCK)) }