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:
1 parent
8b8cf72d1f
commit
cb40fed3b9
126 files changed
+12795
-528
No files matched your search
@@ -0,0 +1,179 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Exercise the pinned original MiSTer FC parser with BH records and mocked I/O.
|
||||
|
||||
This verifies host parser/record/index behavior, not the installed ARM binary,
|
||||
FPGA configuration, analog timing or physical startup. No Main source is edited.
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
from validation_common import ROOT, digest, cpp_environment
|
||||
from coco3_bh_profile import NAME, ROM_SLOTS, startup_records
|
||||
|
||||
|
||||
def block(text, anchor):
|
||||
start = text.index(anchor)
|
||||
opening = text.index('{', start)
|
||||
depth = 1
|
||||
end = opening + 1
|
||||
while depth:
|
||||
depth += (text[end] == '{') - (text[end] == '}')
|
||||
end += 1
|
||||
return text[start:end]
|
||||
|
||||
|
||||
def main():
|
||||
p = argparse.ArgumentParser(description=__doc__)
|
||||
p.add_argument('project', type=Path)
|
||||
p.add_argument('reference', type=Path)
|
||||
p.add_argument('output', type=Path)
|
||||
a = p.parse_args()
|
||||
out = a.output.resolve()
|
||||
if out.exists() or not out.is_relative_to(ROOT / 'build'):
|
||||
p.error('Use a fresh build directory')
|
||||
out.mkdir(parents=True)
|
||||
source = a.reference / 'user_io.cpp'
|
||||
provenance = json.loads((a.reference / 'provenance.json').read_text())
|
||||
if digest(source) != provenance['files']['user_io.cpp']['sha256']:
|
||||
raise RuntimeError('Pinned Main parser changed')
|
||||
original = source.read_text()
|
||||
# Main's real initialization order matters to slot-ROM eligibility: FC
|
||||
# parsing precedes saved status restoration while bit0 remains asserted.
|
||||
init_reset = original.index('user_io_status_set("[0]", 1);', original.index('void user_io_init('))
|
||||
parse_call = original.index('parse_config();', init_reset)
|
||||
saved_config = original.index('int config_found = FileLoadConfig(name, cur_status', parse_call)
|
||||
release_reset = original.index('user_io_status_set("[0]", 0);', saved_config)
|
||||
assert init_reset < parse_call < saved_config < release_reset
|
||||
file_tx = block(original, 'int user_io_file_tx(const char* name,')
|
||||
acknowledgement = block(original, 'static void check_status_change()')
|
||||
assert 'check_status_change();' in file_tx
|
||||
assert 'user_io_status_set("[0]", 0);' in acknowledgement
|
||||
parser = block(original, "if (p[0] == 'F')")
|
||||
substring = block(original, 'int substrcpy(')
|
||||
extension = block(original, 'unsigned char user_io_ext_idx(')
|
||||
top = a.project / 'CoCo3.sv'
|
||||
if 'bh_mpi_config mpi_configuration' in top.read_text():
|
||||
assert '.MPI_BOOT_LOADING(status[0])' in top.read_text(), 'Retain FC files until saved layout arrives'
|
||||
conf = top.read_text().split('localparam CONF_STR = {', 1)[1].split('};', 1)[0]
|
||||
lines = re.findall(r'"([^"\n]*)"', conf)
|
||||
if not lines[0].startswith('Coco 3 Plus;'):
|
||||
raise RuntimeError('Fitted source does not have the independent identity')
|
||||
picks = [next(x[:-1] for x in lines if x.startswith(f'H4FC{n},')) for n in ROM_SLOTS]
|
||||
cases = [
|
||||
('default', NAME, picks, [4, 5]),
|
||||
('hidden-independent', NAME, ['H4D0' + x[2:] for x in picks], [4, 5]),
|
||||
('legacy-manual', NAME, [x.replace('FC', 'F', 1) for x in picks], []),
|
||||
('stock-isolated', 'COCO3', picks, []),
|
||||
('missing-voice', NAME, picks, [4]),
|
||||
('rom-extension', NAME, picks, [68, 69]),
|
||||
]
|
||||
slot_picks = [next(x[:-1] for x in lines if re.match(r'H[89AB]P1FC'+str(n)+',', x))
|
||||
for n in range(6, 10)] if any('P1FC6,' in x for x in lines) else []
|
||||
if slot_picks:
|
||||
cases.append(('slot-autoload', NAME, slot_picks, [6, 7, 8, 9]))
|
||||
records = startup_records()
|
||||
if slot_picks:
|
||||
for n in range(6, 10):
|
||||
value = f'/media/fat/games/coco3plus/slot{n-5}.ccc'.encode()
|
||||
records[f'config/{NAME}.f{n}'] = value.ljust(1024, b'\0')
|
||||
for path, data in records.items():
|
||||
target = out / path
|
||||
target.parent.mkdir(exist_ok=True)
|
||||
target.write_bytes(data)
|
||||
harness = r'''
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#ifdef _MSC_VER
|
||||
#define strcasecmp _stricmp
|
||||
#else
|
||||
#include <strings.h>
|
||||
#endif
|
||||
#include <string>
|
||||
#include <vector>
|
||||
static const char *identity, *scenario;
|
||||
static int boot0_loaded=0;
|
||||
static std::vector<int> sent;
|
||||
const char *user_io_get_core_name(){return identity;}
|
||||
bool is_cpc(){return false;}
|
||||
void StoreIdx_F(int,const char*){}
|
||||
int FileLoadConfig(const char *name,void *buffer,int size){
|
||||
std::string path="config/";path+=name;
|
||||
if(!strcmp(scenario,"missing-voice") && path.find(".f5")!=std::string::npos)return 0;
|
||||
FILE *f=fopen(path.c_str(),"rb");if(!f)return 0;
|
||||
int n=fread(buffer,1,size,f);fclose(f);
|
||||
if(!strcmp(scenario,"rom-extension")) {
|
||||
char *s=(char*)buffer;char *e=strrchr(s,'.');assert(e);strcpy(e,".rom");
|
||||
}
|
||||
assert(((char*)buffer)[size-1]==0);return n;
|
||||
}
|
||||
void user_io_file_tx(const char *name,int index,int,int,int,uint32_t address){
|
||||
assert(!strncmp(name,"/media/fat/games/coco3plus/",strlen("/media/fat/games/coco3plus/")));
|
||||
assert(address==0);sent.push_back(index);
|
||||
printf("TX %d %s\n",index,name);
|
||||
}
|
||||
'''
|
||||
generated = harness + '\n' + substring + '\n' + extension + '\nvoid load(char *p){\nchar str[1024]={},ext[256]={};\n'
|
||||
generated += 'while((p[0]==\'H\'||p[0]==\'D\'||p[0]==\'h\'||p[0]==\'d\')&&strlen(p)>=2)p+=2;\n'
|
||||
# Exact page-prefix skip from pinned user_io.cpp's config initialization.
|
||||
page_skip = re.search(r"if \(p\[0\] == 'P'\) p \+= 2;", original)
|
||||
if not page_skip:
|
||||
raise RuntimeError('Pinned Main page-prefix contract changed')
|
||||
generated += page_skip[0] + '\n'
|
||||
# Exercise the exact original Main name reader with the display identity and
|
||||
# native MGL override, including embedded spaces and its real 32-byte fields.
|
||||
name_reader = block(original, 'void user_io_read_core_name()')
|
||||
name_fixture = r'''namespace identity_contract {
|
||||
static char core_name[32]={},orig_name[32]={},ovr_name[32]={};
|
||||
static int is_no_type=0;
|
||||
char *user_io_get_confstr(int){static char n[]="Coco 3 Plus";return n;}
|
||||
'''+name_reader+r'''
|
||||
void run(){
|
||||
user_io_read_core_name();
|
||||
assert(!strcmp(core_name,"Coco 3 Plus") && !strcmp(orig_name,"Coco 3 Plus"));
|
||||
strcpy(ovr_name,"coco3plus");user_io_read_core_name();
|
||||
assert(!strcmp(core_name,"coco3plus") && !strcmp(orig_name,"Coco 3 Plus"));
|
||||
}
|
||||
}
|
||||
'''
|
||||
generated += parser + '\n}\n'+name_fixture+'\nint main(int argc,char **argv){assert(argc==3);identity_contract::run();identity=argv[1];scenario=argv[2];\n'
|
||||
for tag, identity, options, expected in cases:
|
||||
generated += f'if(!strcmp(scenario,{json.dumps(tag)})){{\n'
|
||||
for item in options:
|
||||
generated += f'{{char p[]={json.dumps(item)};load(p);}}\n'
|
||||
generated += 'assert(boot0_loaded==0);assert((sent==std::vector<int>{' + ','.join(map(str, expected)) + '}));}\n'
|
||||
generated += 'puts("PASS native Main FC startup parser");}\n'
|
||||
cpp = out / 'main-fc-probe.cpp'
|
||||
cpp.write_text(generated)
|
||||
compiler, env = cpp_environment(out)
|
||||
ext = '.exe' if os.name == 'nt' else ''
|
||||
exe = out / ('probe' + ext)
|
||||
with (out / 'compile.log').open('w') as log:
|
||||
command = ([compiler, '/nologo', '/std:c++17', '/EHsc', '/O2', '/D_CRT_SECURE_NO_WARNINGS', '/Fe:' + str(exe)]
|
||||
if os.name == 'nt' else [compiler, '-std=c++17', '-O2', '-o', str(exe)])
|
||||
subprocess.run([*command, str(cpp)], cwd=out,
|
||||
env=env, stdout=log, stderr=subprocess.STDOUT, check=True)
|
||||
results = []
|
||||
for tag, identity, _, expected in cases:
|
||||
result = subprocess.run([str(exe), identity, tag], cwd=out, env=env, capture_output=True, text=True)
|
||||
(out / (tag + '.log')).write_text(result.stdout + result.stderr)
|
||||
if result.returncode or 'PASS native Main FC startup parser' not in result.stdout:
|
||||
raise RuntimeError('Startup parser probe failed: ' + tag)
|
||||
results.append({'case': tag, 'indices': expected, 'log_sha256': digest(out / (tag + '.log'))})
|
||||
data = {'passed': True, 'hardware_tested': False, 'main_reference': provenance,
|
||||
'top_sha256': digest(top), 'records': {k: {'bytes': len(v), 'path': v.split(b'\0')[0].decode()} for k, v in records.items()},
|
||||
'cases': results, 'script_sha256': digest(Path(__file__)),
|
||||
'scope': 'Original native Main FC/extension parser; mocked file I/O and transport; installed binary startup remains a hardware check'}
|
||||
(out / 'result.json').write_text(json.dumps(data, indent=2) + '\n')
|
||||
print(f'PASS {len(cases)} original-Main startup cases, including applicable page-scoped slot ROM records')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in new issue
Block a user