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.
149 lines
6.8 KiB
Systemverilog
149 lines
6.8 KiB
Systemverilog
`timescale 1ns/1ps
|
|
module bh_mpi_tb;
|
|
reg clk=0;always #5 clk=~clk;
|
|
reg reset=1;
|
|
reg [63:0] requested=0;
|
|
wire [63:0] accepted,status_in;wire status_set;
|
|
bh_mpi_config cfg(clk,reset,requested,accepted,status_in,status_set);
|
|
reg [11:0] layout=0;reg [1:0] cts=0,scs=0;
|
|
wire [2:0] rk,ik;wire fd,sd,rom,serial,ssc,orch,fdp,sdp;
|
|
bh_mpi_router router(layout,cts,scs,rk,ik,fd,sd,rom,serial,ssc,orch,fdp,sdp);
|
|
reg [1:0] read_slot=0;reg [16:0] read_address=0;
|
|
reg download=0,wr=0;reg [7:0] file_index=0,data=0;
|
|
reg [24:0] address=0;wire [7:0] read_data;
|
|
wire loading,loaded;wire [3:0] valid,fault;
|
|
reg [3:0] enabled=15;
|
|
bh_mpi_rom memory(clk,reset,read_slot,read_address,read_data,
|
|
download,wr,file_index,address,data,loading,valid,fault,loaded,enabled);
|
|
integer l,c,s,n,k,j,routes=0;
|
|
reg [2:0] a,b;
|
|
reg expect_ssc,expect_orch,expect_fd,expect_sd;
|
|
reg [63:0] next_request,saved;
|
|
reg [7:0] expected_byte;
|
|
function [7:0] pattern(input integer slot,input integer location);
|
|
begin pattern=(location>>8)^(location>>14)^(slot*71)^8'h96;end
|
|
endfunction
|
|
task tick;begin @(posedge clk);#1;end endtask
|
|
task apply(input [63:0] value);
|
|
begin @(negedge clk);requested=value;repeat(8)tick;end
|
|
endtask
|
|
task change(input integer slot,input [2:0] device);
|
|
begin next_request=accepted;next_request[43+slot*3+:3]=device;apply(next_request);end
|
|
endtask
|
|
task boot;
|
|
begin @(negedge clk);reset=1;download=0;wr=0;repeat(3)tick;
|
|
@(negedge clk);reset=0;repeat(3)tick;end
|
|
endtask
|
|
task stream(input integer slot,input integer length,input integer bad_at);
|
|
begin
|
|
@(negedge clk);file_index=6+slot;download=1;wr=0;tick;
|
|
for(k=0;k<length;k=k+1)begin
|
|
@(negedge clk);wr=1;address=k+(k==bad_at?1:0);data=pattern(slot,k);tick;
|
|
end
|
|
@(negedge clk);wr=0;download=0;repeat(3)tick;
|
|
end
|
|
endtask
|
|
task verify_byte(input integer slot,input integer offset,input integer physical);
|
|
begin
|
|
@(negedge clk);read_slot=slot;read_address=offset;repeat(2)tick;
|
|
expected_byte=pattern(slot,physical);
|
|
if(read_data!==expected_byte)$fatal(1,"ROM data slot=%d off=%h expected=%h got=%h",slot,offset,expected_byte,read_data);
|
|
end
|
|
endtask
|
|
initial begin
|
|
layout=12'hfff;#1;
|
|
// Independent exhaustive layout oracle: all4096 layouts,16 separate ROM/I/O routes.
|
|
for(l=0;l<4096;l=l+1)begin
|
|
layout=l;expect_ssc=0;expect_orch=0;expect_fd=0;expect_sd=0;
|
|
for(n=0;n<4;n=n+1)begin
|
|
a=(l>>(n*3))&7;
|
|
if(a==4||a==6)expect_ssc=1;
|
|
if(a==5||a==6)expect_orch=1;
|
|
if(a==2)expect_fd=1;
|
|
if(a==3)expect_sd=1;
|
|
end
|
|
for(c=0;c<4;c=c+1)for(s=0;s<4;s=s+1)begin
|
|
cts=c;scs=s;#1;a=(l>>(c*3))&7;b=(l>>(s*3))&7;
|
|
if(rk!==a||ik!==b||fd!==(b==2)||sd!==(b==3)||
|
|
rom!==((b==1)||(b==5)||(b==6))||serial!==((b==2)||(b==3)||(b==7))||
|
|
ssc!==expect_ssc||orch!==expect_orch||fdp!==expect_fd||sdp!==expect_sd)
|
|
$fatal(1,"Routing layout=%h cts=%d scs=%d",layout,c,s);
|
|
routes=routes+1;
|
|
end
|
|
end
|
|
boot;
|
|
if(accepted[63]!==1'b1||accepted[54:43]!=={3'd2,3'd1,3'd3,3'd6})
|
|
$fatal(1,"Initial all-zero configuration did not migrate");
|
|
apply(64'd1);
|
|
repeat(10)begin tick;if(status_set)$fatal(1,"Premature initialization status request");end
|
|
apply(64'd0);
|
|
for(n=0;n<4;n=n+1)begin
|
|
next_request=64'h0000000000020148;next_request[13:12]=n;
|
|
apply(next_request);
|
|
if(!accepted[63]||accepted[13:12]!==((n+1)&3)||
|
|
accepted[54:43]!=={3'd2,3'd1,3'd3,3'd6}||
|
|
accepted[31:16]!==next_request[31:16])$fatal(1,"Legacy status migration");
|
|
saved=accepted;repeat(10)tick;
|
|
if(accepted!==saved)$fatal(1,"Migration changed while host status stable");
|
|
apply(saved);
|
|
if(accepted!==saved)$fatal(1,"Host acknowledgement was not idempotent");
|
|
end
|
|
change(0,2); // Move floppy from slot4 into slot1, dropping that slot's legacy audio.
|
|
if(accepted[45:43]!==2||accepted[54:52]!==0)$fatal(1,"Singleton controller did not move");
|
|
for(n=0;n<4;n=n+1)change(n,1);
|
|
if(accepted[54:43]!=={3'd1,3'd1,3'd1,3'd1})$fatal(1,"ROM slots are not independent");
|
|
next_request=accepted;next_request[54:43]={3'd2,3'd1,3'd3,3'd6};apply(next_request);
|
|
change(2,4); // Moving SSC out of combined audio leaves Orchestra behind.
|
|
if(accepted[45:43]!==5||accepted[51:49]!==4||!accepted[42])$fatal(1,"SSC move/ownership split");
|
|
change(1,5);
|
|
if(accepted[45:43]!==0||accepted[48:46]!==5)$fatal(1,"Orchestra singleton move");
|
|
for(n=0;n<4;n=n+1)change(n,0);
|
|
if(accepted[54:43]!==0||accepted[42])$fatal(1,"Empty layout retains phantom device");
|
|
boot;
|
|
for(n=0;n<4;n=n+1)begin
|
|
read_slot=n;repeat(2)tick;if(read_data!==8'hff)$fatal(1,"Empty socket not open bus");
|
|
stream(n,65536,-1);
|
|
end
|
|
if(valid!==4'b1111||fault!==0)$fatal(1,"Four64K ROMs not loaded");
|
|
for(n=0;n<4;n=n+1)for(j=0;j<4;j=j+1)verify_byte(n,j*16384+371,j*16384+371);
|
|
stream(0,131072,-1); // Capacity failure must not overwrite the other three ROMs.
|
|
if(valid!==4'b1110||!fault[0])$fatal(1,"Capacity failure was not isolated");
|
|
for(n=1;n<4;n=n+1)verify_byte(n,32791,32791);
|
|
stream(0,8192,-1);verify_byte(0,7371,7371);verify_byte(0,7371+65536,7371);
|
|
stream(0,32,7);
|
|
if(valid[0]||!fault[0])$fatal(1,"Nonsequential transfer accepted");
|
|
for(n=1;n<4;n=n+1)verify_byte(n,49167,49167);
|
|
boot;stream(0,131072,-1);stream(1,131072,-1);
|
|
if(valid!==4'b0011)$fatal(1,"Two128K ROMs not loaded");
|
|
for(n=0;n<2;n=n+1)for(j=0;j<8;j=j+1)verify_byte(n,j*16384+813,j*16384+813);
|
|
stream(2,1,-1);if(!fault[2]||valid[2])$fatal(1,"Full pool did not refuse load");
|
|
verify_byte(0,123879,123879);verify_byte(1,123879,123879);
|
|
enabled[1]=0;repeat(3)tick;
|
|
if(valid[1]||fault[1])$fatal(1,"Removed ROM retained occupancy/fault");
|
|
stream(2,131072,-1);verify_byte(0,123879,123879);verify_byte(2,123879,123879);
|
|
enabled[2]=0;repeat(3)tick;stream(2,16,-1);
|
|
if(valid[2]||fault[2])$fatal(1,"Inactive remembered ROM was loaded");
|
|
enabled=15;
|
|
// Removing a different socket on a failed transfer's completion edge must
|
|
// release both owners; otherwise the cleared owner's blocks leak forever.
|
|
boot;stream(0,131072,-1);
|
|
@(negedge clk);file_index=7;download=1;wr=1;address=1;data=0;tick;
|
|
@(negedge clk);download=0;wr=0;tick;
|
|
@(negedge clk);enabled[0]=0;tick;repeat(3)tick;
|
|
if(valid[0]||!fault[1])$fatal(1,"Concurrent removal/failure state");
|
|
enabled=15;stream(2,131072,-1);stream(3,131072,-1);
|
|
if(valid!==4'b1100)$fatal(1,"Concurrent removal/failure leaked pool blocks");
|
|
boot;stream(3,131073,-1);
|
|
if(valid[3]||!fault[3])$fatal(1,"Oversized ROM accepted");
|
|
stream(3,128,-1);verify_byte(3,32779,11);
|
|
// Old index1 remains an alias for the third slot, without changing other stores.
|
|
@(negedge clk);file_index=1;download=1;wr=1;address=0;data=8'h5a;tick;
|
|
@(negedge clk);download=0;wr=0;repeat(3)tick;
|
|
read_slot=2;read_address=0;repeat(2)tick;
|
|
if(!valid[2]||read_data!==8'h5a)$fatal(1,"Legacy cartridge index alias");
|
|
$display("PASS %0d routing combinations, migration/moves, four ROMs, banking, mirrors, capacity and malformed-load isolation",routes);
|
|
$finish;
|
|
end
|
|
initial begin #30000000;$fatal(1,"MPI test timeout");end
|
|
endmodule
|