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.
This commit is contained in:
bholman committed 2026-11-18 16:00:45 -07:00
1 parent 8b8cf72d1f
commit cb40fed3b9
126 files changed
+12795 -528

No files matched your search

+78
View File
@@ -0,0 +1,78 @@
#!/usr/bin/env python3
"""Test actual prepared core SSC instantiations, without replacing chip logic."""
import argparse
import hashlib
import json
import os
from pathlib import Path
import re
import subprocess
import threading
from validation_common import ROOT,digest
from rom_inputs import ROM_IDENTITIES,verified_rom
def main():
parser=argparse.ArgumentParser(description=__doc__)
parser.add_argument('project',type=Path);parser.add_argument('output',type=Path);parser.add_argument('--suite',type=Path,required=True)
args=parser.parse_args();project=args.project.resolve();output=args.output.resolve();suite=args.suite.resolve()
if output.exists() or not output.is_relative_to((ROOT / 'build').resolve()):parser.error('Use a fresh build/ output')
output.mkdir(parents=True);core=project / 'rtl/coco3fpga.sv';text=core.read_text()
top=project / 'CoCo3.sv';top_text=top.read_text()
pll=re.search(r'\bpll\s+pll\s*\((.*?)\);',top_text,re.S)
lock=re.search(r'\.locked\(\s*(\w+)\s*\)',pll[1]) if pll else None
reset_binding=re.search(r'\.SSC_POWER_RESET\(ssc_power_reset\)',top_text)
if not lock or not reset_binding or not re.search(r'always\s*@\(posedge clk_sys or negedge '+re.escape(lock[1])+r'\)\s*if\(!'+re.escape(lock[1])+r'\) ssc_power_release <= 2\x27b00;',top_text):
raise RuntimeError('SSC power reset is not driven by the actual core PLL lock output')
if "else ssc_power_release <= {ssc_power_release[0],1'b1};" not in top_text or 'wire ssc_power_reset = !ssc_power_release[1];' not in top_text:
raise RuntimeError('SSC power reset release contract changed')
if not re.search(r'\.SSC_MODE\(status\[42\]\)',top_text):raise RuntimeError('SSC menu mode binding changed')
if not re.search(r'assign\s+DATA_IN\s*=\s*ssc_read_valid\s*\?\s*ssc_read_data\s*:',text):raise RuntimeError('SSC CPU read-priority binding changed')
declarations=text[text.index('wire ssc_palette_owner,'):text.index('wire [15:0] ssc_legacy_left,ssc_legacy_right;')+len('wire [15:0] ssc_legacy_left,ssc_legacy_right;')]
body=text[text.index('assign ssc_legacy_left ='):text.index('.debug_pc(ssc_debug_pc));')+len('.debug_pc(ssc_debug_pc));')]
routing=''
if 'bh_mpi_router mpi_router' in text:
start=text.index('wire [2:0] mpi_rom_kind,mpi_io_kind;')
end=text.index("wire [7:0] mpi_orch_right=mpi_orchestra_present?ORCH_RIGHT:8'h80;",start)
routing="wire MPI_BOOT_LOADING=0;\nwire [1:0] MPI_CTS=0,MPI_SCS=0;\n"+text[start:end+len("wire [7:0] mpi_orch_right=mpi_orchestra_present?ORCH_RIGHT:8'h80;")]
generated=output / 'actual-bindings.sv'
power_start=top_text.index('(* preserve, altera_attribute',top_text.index('// Cartridge ROM validity'))
power_end=top_text.index('wire ssc_power_reset = !ssc_power_release[1];',power_start)+len('wire ssc_power_reset = !ssc_power_release[1];')
power_block=top_text[power_start:power_end].replace('wire ssc_power_reset =','assign ssc_power_reset =')
generated.write_text('module actual_ssc_power_reset(input clk_sys,'+lock[1]+',output ssc_power_reset);\n'+power_block+'\nendmodule\n'+'''module actual_ssc_mister_system(input clk_sys,SSC_POWER_RESET,RESET_POS_N,SSC_MODE,PH_2,RW_N,
input [15:0] ADDRESS,input [7:0] DATA_OUT,input [11:0] MPI_LAYOUT,input ioctl_download,ioctl_wr,input [15:0] ioctl_index,
input [24:0] ioctl_addr,input [7:0] ioctl_data,input SOUND_EN,input [1:0] SEL,
input [7:0] ORCH_LEFT,ORCH_RIGHT,SOUND,output SSC_READY,SSC_FAULT,
output [15:0] SOUND_LEFT,SOUND_RIGHT,output READ_VALID,output [7:0] READ_DATA,output PALETTE_OWNER);
'''+routing+'\n'+declarations+'\n'+body+'''
assign READ_VALID=ssc_read_valid;assign READ_DATA=ssc_read_data;assign PALETTE_OWNER=ssc_palette_owner;
endmodule
''',encoding='utf-8',newline='\n')
folder=project / 'rtl/ssc';sources=sorted(folder.glob('*.sv'));bench=ROOT / 'tests/ssc_mister_system_tb.sv'
if routing:sources.append(project/'rtl/bh_mpi_router.sv')
paths=[Path(__file__),ROOT / 'scripts/validation_common.py',ROOT / 'scripts/rom_inputs.py',core,top,generated,bench,*sources,*folder.glob('*.vh')]
hashes={str(p):digest(p) for p in paths};roms=ROOT / 'roms/ssc'
identities={name:verified_rom(roms / name,value) for name,value in ROM_IDENTITIES.items()}
env=os.environ.copy();env['PATH']=os.pathsep.join([str(suite / 'bin'),str(suite / 'lib'),env['PATH']]);ext='.exe' if os.name=='nt' else '';binary=output / 'system.vvp'
with (output / 'compile.log').open('w') as log:
subprocess.run([str(suite / 'bin' / ('iverilog'+ext)),'-g2012','-I',str(folder),'-s','ssc_mister_system_tb','-o',str(binary),str(bench),str(generated),*map(str,sources)],env=env,stdout=log,stderr=subprocess.STDOUT,check=True)
process=subprocess.Popen([str(suite / 'bin' / ('vvp'+ext)),str(binary),'+PIC_PATH='+(roms / 'pic-7040-510.bin').as_posix(),'+SPEECH_PATH='+(roms / 'sp0256-al2.bin').as_posix()],cwd=output,env=env,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True,bufsize=1)
timer=threading.Timer(900,process.kill);timer.start();summary=None
try:
with (output / 'rtl.log').open('w') as log:
for line in process.stdout:
print(line.rstrip(),flush=True);log.write(line);log.flush()
if line.startswith('RESULT '):summary=json.loads(line[7:])
code=process.wait()
finally:
timer.cancel()
if process.poll() is None:process.kill();process.wait()
if code or not summary or not summary['passed']:raise RuntimeError('Actual core SSC bindings failed; inspect rtl.log')
if any(digest(Path(p))!=h for p,h in hashes.items()):raise RuntimeError('Actual core/test source changed during run')
for name,value in ROM_IDENTITIES.items():verified_rom(roms / name,value)
hashes.update({str(p):digest(p) for p in output.glob('*.log')})
(output / 'test-result.json').write_text(json.dumps({'passed':True,'roms':identities,'summary':summary,'sha256':hashes,
'hardware_tested':False,'scope':'Actual extracted prepared-core SSC bindings with real chip RTL; CPU/HPS stimulus, not full CoCo CPU/vendor-IP or physical run'},indent=2)+'\n',encoding='utf-8',newline='\n')
if __name__=='__main__':main()