Files
bholman cb40fed3b9 Introduce Coco 3 Plus for MiSTer
Add original-firmware Sound & Speech, four configurable Multi-Pak sockets,
bounded per-slot ROM allocation and a nine-page menu organized around devices
and media. Repair inherited clock/reset/CPU-memory/video paths and add explicit
conditional external-I/O timing contracts. Preserve native Main startup-file
ordering, saved layouts, stock-core separation and the coco3plus media profile.

Provide native Windows tool downloads, pinned ToolShed ROM assembly, fresh
Quartus builds, functional and fitted timing checks, reviewed release packaging
and passwordless SSH installation with backups. Retain original component
notices, document contribution copyright and keep SSC ROM inputs outside Git.

Validation: Quartus17.0.2 Build602 seed5, zero errors; 15 functional jobs,
368 both-corner timing scopes and eight tooling-integrity checks pass.
The renamed build reaches Disk BASIC, PRINT1+1 returns2 and SSC loads ready.
Physical cold power cycling and conditional board-delay assumptions remain
separate. Full original upstream histories are preserved before this single
consolidated implementation commit.
2026-11-18 16:00:45 -07:00

46 lines
3.1 KiB
Python

#!/usr/bin/env python3
"""Assemble ToolShed CoCo firmware with native LWASM; no make, WSL or binary inputs."""
import argparse, hashlib, json, shutil, subprocess
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest()
def main():
p=argparse.ArgumentParser(description=__doc__)
p.add_argument('--source',type=Path,default=ROOT/'.deps/cocoroms')
p.add_argument('--lwasm',type=Path)
p.add_argument('--output',type=Path,default=ROOT/'build/roms')
a=p.parse_args();meta=json.loads((ROOT/'tools/cocoroms.json').read_text())
if a.output.exists():raise RuntimeError('Use a fresh output directory')
for name,h in meta['upstreamFileSHA256'].items():
if sha(a.source/name)!=h:raise RuntimeError('Assembly source mismatch: '+name)
if a.lwasm is None:
found=list((ROOT/'.tools/lwtools').rglob('lwasm.exe'))
if len(found)!=1:raise RuntimeError('Run bootstrap.py or supply --lwasm')
a.lwasm=found[0]
a.lwasm=a.lwasm.resolve();a.output.mkdir(parents=True)
work=a.output/'work';shutil.copytree(a.source,work)
if any(p.suffix.lower() in ('.bin','.rom') for p in work.rglob('*')):raise RuntimeError('Unexpected binary firmware input')
commands=[]
def run(args,stdout=None):
commands.append(args)
result=subprocess.run([str(a.lwasm),*args],cwd=work,capture_output=True,check=True)
if stdout:(work/stdout).write_bytes(result.stdout)
with (a.output/'build.log').open('ab') as log:log.write(result.stderr)
run(['--raw','-o','bas13.rom','equates.asm','bas.asm'])
run(['--symbol-dump','--no-output','equates.asm','bas.asm'],'cb_equates.asm')
run(['--raw','-o','extbas11.rom','cb_equates.asm','extbas.asm'])
run(['--symbol-dump','--no-output','equates.asm','bas.asm','extbas.asm'],'ecb_equates.asm')
run(['--raw','--pragma=noindex0tonone','-o','disk11.rom','ecb_equates.asm','disk.asm'])
run(['--raw','-o','coco3.rom','equates.asm','coco3.asm'])
outputs={}
for name,expected in meta['romOutputs'].items():
actual={'bytes':(work/name).stat().st_size,'sha256':sha(work/name)}
if actual!=expected:raise RuntimeError('Assembled ROM mismatch: '+name)
shutil.copyfile(work/name,a.output/name);outputs[name]=actual
for source,target in [('coco3.rom','boot0.rom'),('disk11.rom','boot1.rom')]:shutil.copyfile(a.output/source,a.output/target)
notice='Rebuilt from ToolShed cocoroms assembly at '+meta['sourceRevision']+'.\nOriginal Tandy/Microsoft/Microware notices remain applicable.\nNo preassembled firmware input. SSC chip ROMs are separate external inputs.\n'
(a.output/'ROM_SOURCE_NOTICE.txt').write_text(notice)
(a.output/'manifest.json').write_text(json.dumps(dict(source_url=meta['sourceURL'],source_revision=meta['sourceRevision'],source_sha256=meta['upstreamFileSHA256'],assembler_sha256=sha(a.lwasm),assembler_version=subprocess.check_output([str(a.lwasm),'--version']).decode().strip(),commands=commands,roms=outputs,preassembled_inputs=False),indent=2)+'\n')
print('PASS: all four reconstructed ROM hashes; boot0/boot1 staged')
if __name__=='__main__':main()