Files
CoCo3_Plus_MiSTer/scripts/test_external_pixel.py
T
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

87 lines
3.7 KiB
Python

#!/usr/bin/env python3
"""Verify the actual pixel divider's generated-clock edges and reject a defect."""
import argparse
import hashlib
import json
import os
from pathlib import Path
import re
import subprocess
ROOT = Path(__file__).resolve().parents[1]
def main():
p = argparse.ArgumentParser(description=__doc__)
p.add_argument('project', type=Path)
p.add_argument('output', type=Path)
p.add_argument('--suite', type=Path, required=True)
a = p.parse_args()
out = a.output.resolve()
if not out.is_relative_to(ROOT / 'build') or out.exists():
p.error('Use a fresh build/ directory')
out.mkdir(parents=True)
source = a.project / 'rtl/Mister_Video.v'
sdc = a.project / 'external-io.sdc'
text = source.read_text()
divider = re.search(r'always @ \(posedge MASTER_CLK\)\s*begin\s*reg\s*\[1:0\]\s*div;.*?\nend', text, re.S)
assert divider is not None
assert '-edges {3 7 11}' in sdc.read_text()
block = divider[0].replace('begin', 'begin : divider', 1)
env = os.environ.copy()
env['PATH'] = os.pathsep.join([str(a.suite / 'bin'), str(a.suite / 'lib'), env['PATH']])
ext = '.exe' if os.name == 'nt' else ''
bench = '''`timescale 1ns/1ps
module tb;
reg clk=0; always #5 clk=~clk;
wire pix; generator dut(clk,pix);
integer cycles=0, rises=0, last_rise=0, last_fall=0;
reg previous=0;
always @(posedge clk) cycles=cycles+1;
// Observe the registered final value after all nonblocking assignments settle.
// The original RTL assigns default low then conditionally high in one process.
always @(negedge clk) begin
if(pix && !previous) begin
if(rises==0 && cycles!=2) $fatal(1,"Pixel first edge %0d",cycles);
if(rises>0 && cycles-last_rise!=4) $fatal(1,"Pixel period %0d",cycles-last_rise);
if(rises>0 && cycles-last_fall!=2) $fatal(1,"Pixel low width");
last_rise=cycles;rises=rises+1;
end
if(!pix && previous && rises>0) begin
if(cycles-last_rise!=2) $fatal(1,"Pixel high width");
last_fall=cycles;
end
previous=pix;
end
initial begin
dut.divider.div=0;
repeat(4096) @(negedge clk);
if(rises!=1024) $fatal(1,"Pixel count");
$display("PASS pixel edges {3 7 11}: 1024 periods, divide four, duty half");
$finish;
end
endmodule
'''
(out / 'tb.sv').write_text(bench)
cmd = [str(a.suite / 'bin' / ('iverilog' + ext)), '-g2012', '-s', 'tb', '-o', str(out / 'run.vvp'), str(out / 'tb.sv'), str(out / 'generator.sv')]
for negative in (False, True):
tag = 'negative' if negative else 'positive'
logic = block.replace("(div == 2'd2)", "(div == 2'd3)") if negative else block
(out / 'generator.sv').write_text('module generator(input MASTER_CLK,output reg PIX_CLK);\n' + logic + '\nendmodule\n')
with (out / f'{tag}-compile.log').open('w') as log:
subprocess.run(cmd, env=env, stdout=log, stderr=subprocess.STDOUT, check=True)
with (out / f'{tag}.log').open('w') as log:
r = subprocess.run([str(a.suite / 'bin' / ('vvp' + ext)), str(out / 'run.vvp')], env=env, stdout=log, stderr=subprocess.STDOUT, timeout=30)
output = (out / f'{tag}.log').read_text()
print(output, end='')
if (not negative and (r.returncode or 'PASS pixel edges' not in output)) or (negative and (not r.returncode or 'Pixel' not in output)):
raise RuntimeError('Unexpected divider result: ' + tag)
(out / 'result.json').write_text(json.dumps({'passed': True, 'wrong_duty_mutant_rejected': True,
'generated_edges': [3, 7, 11], 'periods': 1024,
'scope': 'extracted actual divider; FPGA zero power-up counter assumption; not pixel rendering',
'source_sha256': {str(path.relative_to(a.project)): hashlib.sha256(path.read_bytes()).hexdigest() for path in (source, sdc)}}, indent=2) + '\n')
if __name__ == '__main__':
main()