29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
"""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
|