First public commit.

This commit is contained in:
The Dust Council 2026-07-03 19:35:35 -07:00
parent 2a48f52979
commit 4bac9d83ed
288 changed files with 18417 additions and 1076 deletions

29
lenser/coco3/cartridge.py Normal file
View file

@ -0,0 +1,29 @@
"""Build a CoCo 3 Program Pak cartridge ROM (.ccc): GIME viewer + 15360-byte image.
The CoCo 3 autostarts the cartridge at $C000. Layout: viewer code, then the
linear GIME image, padded to a 16KB ROM."""
from __future__ import annotations
from . import viewer
CART_BASE = 0xC000
CART_SIZE = 0x4000 # 16 KB
def build_rom(data: bytes, cres: int, inks, border: int) -> bytes:
if len(data) != viewer.IMG_LEN:
raise ValueError(f"unexpected image length {len(data)}")
kw = dict(cres=cres, inks=inks, border=border)
code = viewer.build(0, **kw) # pass 1: measure code length
data_src = CART_BASE + len(code)
code = viewer.build(data_src, **kw) # pass 2: real data address
rom = code + bytes(data)
if len(rom) > 0x3F00: # keep clear of the $FF00 I/O page
raise ValueError("viewer + image exceed the cartridge ROM window")
return rom + bytes(CART_SIZE - len(rom))
def write_ccc(rom: bytes, path: str) -> str:
with open(path, "wb") as f:
f.write(rom)
return path