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

42 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""Compare the exact keyboard row against upstream with the stated control delay."""
import argparse
import hashlib
import json
import os
from pathlib import Path
import subprocess
from source_snapshot import original_sources
ROOT=Path(__file__).resolve().parents[1]
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();output=args.output.resolve()
if not output.is_relative_to((ROOT/'build').resolve()) or output.exists():parser.error('Use a new build/ output')
output.mkdir(parents=True)
original=original_sources('coco3-mister')/'rtl/coco3fpga.sv';candidate=args.project/'rtl/coco3fpga.sv'
def row(text,start):return text[text.index(start):text.index('assign KEYBOARD_IN[7]')]
reference=row(original.read_text(),'assign KEYBOARD_IN[6] =')
actual=row(candidate.read_text(),'// Research: phase-match the remaining CPU keyboard control flags.')
header='input [3:0] controls,input [72:0] KEY,input [7:0] KEY_COLUMN,output y);\nwire EE_N=controls[3],MUGS=controls[2],SHIFT=controls[1],SHIFT_OVERRIDE=controls[0];\nwire [7:0] KEYBOARD_IN;wire [7:0] BUTTON_N={7\'d0,EE_N};\n'
source=output/'actual-keyboard.sv'
source.write_text('module actual_keyboard_controls(input clk_sys,'+header+actual+'\nassign y=KEYBOARD_IN[6];endmodule\nmodule reference_keyboard_controls('+header+reference+'\nassign y=KEYBOARD_IN[6];endmodule\n',encoding='utf-8')
bench=ROOT/'tests/keyboard_control_phase_tb.sv'
env=os.environ.copy();env['PATH']=os.pathsep.join([str(args.suite/'bin'),str(args.suite/'lib'),env['PATH']])
ext='.exe' if os.name=='nt' else ''
with (output/'compile.log').open('w') as log:
subprocess.run([str(args.suite/'bin'/('iverilog'+ext)),'-g2012','-s','keyboard_control_phase_tb','-o',str(output/'test.vvp'),str(bench),str(source)],env=env,stdout=log,stderr=subprocess.STDOUT,check=True)
with (output/'test.log').open('w') as log:
subprocess.run([str(args.suite/'bin'/('vvp'+ext)),str(output/'test.vvp')],env=env,stdout=log,stderr=subprocess.STDOUT,check=True)
print((output/'test.log').read_text())
(output/'test-result.json').write_text(json.dumps({'passed':True,'hardware_tested':False,'sha256':{str(p):hashlib.sha256(p.read_bytes()).hexdigest() for p in [original,candidate,bench,source,Path(__file__),output/'test.log']}},indent=2)+'\n',encoding='utf-8')
if __name__=='__main__':main()