First public commit.
This commit is contained in:
parent
2a48f52979
commit
4bac9d83ed
288 changed files with 18417 additions and 1076 deletions
31
lenser/coco/cartridge.py
Normal file
31
lenser/coco/cartridge.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
"""Build a TRS-80 CoCo Program Pak cartridge ROM (.ccc) holding viewer + image.
|
||||
|
||||
The CoCo autostarts the cartridge at $C000. Layout: viewer code, then the
|
||||
6144-byte PMODE 4 image, padded to an 8KB ROM ($C000-$DFFF)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from . import viewer
|
||||
|
||||
CART_BASE = 0xC000
|
||||
CART_SIZE = 0x2000 # 8 KB
|
||||
|
||||
|
||||
def build_rom(data: bytes, vdg: int = 0xF8, display: str = "forever",
|
||||
seconds: int = 0) -> bytes:
|
||||
if len(data) != viewer.SCREEN_BYTES:
|
||||
raise ValueError(f"unexpected image length {len(data)}")
|
||||
vk = dict(vdg=vdg, display=display, seconds=seconds)
|
||||
code = viewer.build(0, **vk) # pass 1: measure code length
|
||||
data_src = CART_BASE + len(code)
|
||||
code = viewer.build(data_src, **vk) # pass 2: real data address
|
||||
rom = code + bytes(data)
|
||||
if len(rom) > CART_SIZE:
|
||||
raise ValueError("viewer + image exceed the 8KB cartridge")
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue