forked from asteriskman7/dldtg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cycle_sim_prim-min.js
1 lines (1 loc) · 31.6 KB
/
cycle_sim_prim-min.js
1
"use strict";var Cycle_sim_prim_obj=function(c,f,e,d){this.blockName=c;this.ports=[];var b=cycle_sim.expandNet(f.join(","));var a=cycle_sim.expandNet(e.join(","));if(d){b.forEach(function(g){this.ports.push({name:g,direction:"IN"})},this);a.forEach(function(g){this.ports.push({name:g,direction:"OUT"})},this)}else{a.forEach(function(g){this.ports.push({name:g,direction:"OUT"})},this);b.forEach(function(g){this.ports.push({name:g,direction:"IN"})},this)}this.nets=this.ports.map(function(g,h){return{name:g.name,type:"port",portNum:h}});this.intNets=[];this.insts=[];this.primitive=true;this.init=function(g){};this.tick=function(g){}};var cycle_sim_prim={getBlocks:function(){var a={};a.NAND=new Cycle_sim_prim_obj("NAND",["A","B"],["Z"],true);a.NAND.init=function(b){b.siga=b.nets.A.signal;b.sigb=b.nets.B.signal;b.sigz=b.nets.Z.signal};a.NAND.tick=function(e){var d=cycle_sim.hw.signals[e.siga].value;var c=cycle_sim.hw.signals[e.sigb].value;var b=!(d&&c);if(e.sigz>1){cycle_sim.hw.signals[e.sigz].next=b}};a.IO_IN=new Cycle_sim_prim_obj("IO_IN",[],["Z"],true);a.IO_IN.init=function(d){var c=document.getElementById("div_design_io");var b="checkbox_design_IO_IN_"+d.name;d.IO_ID=b;c.innerHTML+='<input type="checkbox" id="'+b+'">'+d.name+"<br>";d.eIO=undefined};a.IO_IN.tick=function(b){if(b.eIO===undefined){b.eIO=document.getElementById(b.IO_ID)}cycle_sim.setSigVal(b,"Z",b.eIO.checked)};a.IO_IN8=new Cycle_sim_prim_obj("IO_IN8",[],["Z<7>","Z<6>","Z<5>","Z<4>","Z<3>","Z<2>","Z<1>","Z<0>"],true);a.IO_IN8.init=function(d){var c=document.getElementById("div_design_io");var b="checkbox_design_IO_IN8_"+d.name;d.IO_ID=b;c.innerHTML+="<div><input type='text' id='"+b+"' size='14' value='00000000'>"+d.name+"</div>";d.eIO=undefined};a.IO_IN8.tick=function(e){if(e.eIO===undefined){e.eIO=document.getElementById(e.IO_ID)}var d=e.eIO.value;var f;var c;var b;if(d.length===3){if(d[0].toUpperCase()==="X"){f=parseInt(d.substr(1,2),16)}}else{if(d.length===8){f=parseInt(d,2)}}if(f!==undefined){c=cycle_sim.intToBoolList(f,8);for(b=0;b<c.length;b++){cycle_sim.setSigVal(e,"Z<"+b+">",c[b])}e.eIO.style.backgroundColor="#FFFFFF"}else{e.eIO.style.backgroundColor="#FF0000"}};a.IO_OUT=new Cycle_sim_prim_obj("IO_OUT",["A"],[],true);a.IO_OUT.init=function(d){var c=document.getElementById("div_design_io");var b="checkbox_design_IO_OUT_"+d.name;d.IO_ID=b;d.IO_ID_CAN="canvas_design_"+b;c.innerHTML+='<div><canvas class="canvas_wave" id="canvas_design_'+b+'" width="200" height="16"></canvas><input type="checkbox" id="'+b+'" disabled="disabled">'+d.name+"</div>";d.history=[];d.eIO=undefined;d.eIOCan=undefined};a.IO_OUT.tick=function(b){if(b.eIO===undefined){b.eIO=document.getElementById(b.IO_ID);b.eIOCan=document.getElementById(b.IO_ID_CAN)}var c=cycle_sim.getSigVal(b,"A");b.eIO.checked=c;cycle_sim.updateGraph(b,c)};a.IO_OUT8=new Cycle_sim_prim_obj("IO_OUT8",["A<7>","A<6>","A<5>","A<4>","A<3>","A<2>","A<1>","A<0>"],[],true);a.IO_OUT8.init=function(d){var c=document.getElementById("div_design_io");var b="checkbox_design_IO_OUT8_"+d.name;d.IO_ID=b;c.innerHTML+='<div><input type="text" id="'+b+'" size="14" value="00000000 (0x00)">'+d.name+"</div>";d.history=[];d.eIO=undefined};a.IO_OUT8.tick=function(c){if(c.eIO===undefined){c.eIO=document.getElementById(c.IO_ID)}var e=cycle_sim.getSigVecVal(c,"A",7,0);var d=cycle_sim.leftPadNumberString(e.toString(2),8);var b=cycle_sim.leftPadNumberString(e.toString(16),2).toUpperCase();c.eIO.value=d+" (x"+b+")"};a.IO_OUT7SEG=new Cycle_sim_prim_obj("IO_OUT7SEG",["A","B","C","D","E","F","G"],[],true);a.IO_OUT7SEG.init=function(d){var c=document.getElementById("div_design_io");var b="canvas_design_IO_OUT7SEG_"+d.name;d.IO_ID=b;c.innerHTML+='<div><canvas class="canvas_7seg" id="'+b+'" width="32px" height="50px"></canvas>'+d.name+"</div>";d.eIO=undefined;d.lastState=["a","b","c","d","e","f","g"]};a.IO_OUT7SEG.tick=function(k){if(k.eIO===undefined){k.eIO=document.getElementById(k.IO_ID)}var f=32;var b=50;var h=false;var j;var c;var l=k.eIO.getContext("2d");var g=[];g.push(cycle_sim.getSigVal(k,"A"));g.push(cycle_sim.getSigVal(k,"B"));g.push(cycle_sim.getSigVal(k,"C"));g.push(cycle_sim.getSigVal(k,"D"));g.push(cycle_sim.getSigVal(k,"E"));g.push(cycle_sim.getSigVal(k,"F"));g.push(cycle_sim.getSigVal(k,"G"));for(j=0;j<g.length;j++){if(g[j]!==k.lastState[j]){h=true;k.lastState=g;break}}if(h===false){return}var e=[[[5,5],[8,2],[25,2],[27,5],[25,7],[8,7]],[[25,7],[27,5],[30,7],[30,22],[27,25],[25,22]],[[27,25],[30,27],[30,42],[27,45],[25,42],[25,27]],[[25,42],[27,45],[25,47],[8,47],[5,45],[8,42]],[[8,42],[5,45],[3,42],[3,27],[5,25],[8,27]],[[5,25],[3,22],[3,7],[5,5],[8,7],[8,22]],[[5,25],[8,22],[25,22],[27,25],[25,27],[8,27]]];l.clearRect(0,0,f,b);l.strokeStyle="#D0D0D0";l.lineWidth=1;l.fillStyle="#FF0000";var d;for(c=0;c<g.length;c++){d=e[c];l.beginPath();l.moveTo(d[0][0]-0.5,d[0][1]+0.5);for(j=1;j<d.length;j++){l.lineTo(d[j][0]-0.5,d[j][1]+0.5)}l.closePath();if(g[c]){l.fill()}else{l.strokeStyle="#D0D0D0"}l.stroke()}};a.NAND_TEST=new Cycle_sim_prim_obj("NAND_TEST",["Z"],["A","B"],false);a.NAND_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedZ=undefined};a.NAND_TEST.tick=function(d){var g;var f;var e;var c=10;var b=16;if(cycle_sim.hw.time>=d.nextTime){switch(d.state){case 0:f=cycle_sim.randomBool();e=cycle_sim.randomBool();d.expectedZ=!(f&&e);cycle_sim.setSigVal(d,"A",f);cycle_sim.setSigVal(d,"B",e);d.nextTime+=c;d.state=1;break;case 1:g=cycle_sim.getSigVal(d,"Z");if(g!==d.expectedZ){cycle_sim.testFail("NAND","NAND output was not correct.");d.failed=true;return}else{d.testCount+=1;d.nextTime+=1;d.state=0;cycle_sim.simLog("Passed "+d.testCount+" tests of "+b)}break}}if(d.testCount>=b){if(d.failed===false){cycle_sim.testPass("NAND",0)}else{cycle_sim.testFail("NAND","Test completed with previous fails.")}}};a.NOT_TEST=new Cycle_sim_prim_obj("NOT_TEST",["Z"],["A"],false);a.NOT_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedZ=undefined};a.NOT_TEST.tick=function(d){var f;var e;var c=10;var b=8;if(cycle_sim.hw.time>=d.nextTime){switch(d.state){case 0:e=cycle_sim.randomBool();d.expectedZ=!e;cycle_sim.setSigVal(d,"A",e);d.nextTime+=c;d.state=1;break;case 1:f=cycle_sim.getSigVal(d,"Z");if(f!==d.expectedZ){cycle_sim.testFail("NOT","NOT output was not correct.");d.failed=true;return}else{d.testCount+=1;d.nextTime+=1;d.state=0;cycle_sim.simLog("Passed "+d.testCount+" tests of "+b)}break}}if(d.testCount>=b){if(d.failed===false){cycle_sim.testPass("NOT",1)}else{cycle_sim.testFail("NOT","Test completed with previous fails.")}}};a.AND_TEST=new Cycle_sim_prim_obj("AND_TEST",["Z"],["A","B"],false);a.AND_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedZ=undefined};a.AND_TEST.tick=function(d){var g;var f;var e;var c=10;var b=16;if(cycle_sim.hw.time>=d.nextTime){switch(d.state){case 0:f=cycle_sim.randomBool();e=cycle_sim.randomBool();d.expectedZ=f&&e;cycle_sim.setSigVal(d,"A",f);cycle_sim.setSigVal(d,"B",e);d.nextTime+=c;d.state=1;break;case 1:g=cycle_sim.getSigVal(d,"Z");if(g!==d.expectedZ){cycle_sim.testFail("AND","AND output was not correct.");d.failed=true;return}else{d.testCount+=1;d.nextTime+=1;d.state=0;cycle_sim.simLog("Passed "+d.testCount+" tests of "+b)}break}}if(d.testCount>=b){if(d.failed===false){cycle_sim.testPass("AND",2)}else{cycle_sim.testFail("AND","Test completed with previous fails.")}}};a.NOR_TEST=new Cycle_sim_prim_obj("NOR_TEST",["Z"],["A","B"],false);a.NOR_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedZ=undefined};a.NOR_TEST.tick=function(d){var g;var f;var e;var c=10;var b=16;if(cycle_sim.hw.time>=d.nextTime){switch(d.state){case 0:f=cycle_sim.randomBool();e=cycle_sim.randomBool();d.expectedZ=!(f||e);cycle_sim.setSigVal(d,"A",f);cycle_sim.setSigVal(d,"B",e);d.nextTime+=c;d.state=1;break;case 1:g=cycle_sim.getSigVal(d,"Z");if(g!==d.expectedZ){cycle_sim.testFail("NOR","NOR output was not correct.");d.failed=true;return}else{d.testCount+=1;d.nextTime+=1;d.state=0;cycle_sim.simLog("Passed "+d.testCount+" tests of "+b)}break}}if(d.testCount>=b){if(d.failed===false){cycle_sim.testPass("NOR",4)}else{cycle_sim.testFail("NOR","Test completed with previous fails.")}}};a.OR_TEST=new Cycle_sim_prim_obj("OR_TEST",["Z"],["A","B"],false);a.OR_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedZ=undefined};a.OR_TEST.tick=function(d){var g;var f;var e;var c=10;var b=16;if(cycle_sim.hw.time>=d.nextTime){switch(d.state){case 0:f=cycle_sim.randomBool();e=cycle_sim.randomBool();d.expectedZ=(f||e);cycle_sim.setSigVal(d,"A",f);cycle_sim.setSigVal(d,"B",e);d.nextTime+=c;d.state=1;break;case 1:g=cycle_sim.getSigVal(d,"Z");if(g!==d.expectedZ){cycle_sim.testFail("OR","OR output was not correct.");d.failed=true;return}else{d.testCount+=1;d.nextTime+=1;d.state=0;cycle_sim.simLog("Passed "+d.testCount+" tests of "+b)}break}}if(d.testCount>=b){if(d.failed===false){cycle_sim.testPass("OR",3)}else{cycle_sim.testFail("OR","Test completed with previous fails.")}}};a.XOR_TEST=new Cycle_sim_prim_obj("XOR_TEST",["Z"],["A","B"],false);a.XOR_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedZ=undefined};a.XOR_TEST.tick=function(d){var g;var f;var e;var c=10;var b=16;if(cycle_sim.hw.time>=d.nextTime){switch(d.state){case 0:f=cycle_sim.randomBool();e=cycle_sim.randomBool();d.expectedZ=(f!==e);cycle_sim.setSigVal(d,"A",f);cycle_sim.setSigVal(d,"B",e);d.nextTime+=c;d.state=1;break;case 1:g=cycle_sim.getSigVal(d,"Z");if(g!==d.expectedZ){cycle_sim.testFail("XOR","XOR output was not correct, expected "+d.expectedZ+" but saw "+g);d.failed=true;return}else{d.testCount+=1;d.nextTime+=1;d.state=0;cycle_sim.simLog("Passed "+d.testCount+" tests of "+b)}break}}if(d.testCount>=b){if(d.failed===false){cycle_sim.testPass("XOR",5)}else{cycle_sim.testFail("XOR","Test completed with previous fails.")}}};a.TRUTH_TABLE1_TEST=new Cycle_sim_prim_obj("TRUTH_TABLE1_TEST",["Z"],["A","B"],false);a.TRUTH_TABLE1_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedZ=undefined;b.truthTable=[[false,false],[true,false]]};a.TRUTH_TABLE1_TEST.tick=function(d){var g;var f;var e;var c=12;var b=16;if(cycle_sim.hw.time>=d.nextTime){switch(d.state){case 0:f=cycle_sim.randomBool();e=cycle_sim.randomBool();d.expectedZ=d.truthTable[f+0][e+0];cycle_sim.setSigVal(d,"A",f);cycle_sim.setSigVal(d,"B",e);d.nextTime+=c;d.state=1;break;case 1:g=cycle_sim.getSigVal(d,"Z");if(g!==d.expectedZ){cycle_sim.testFail("TRUTH_TABLE1","TRUTH_TABLE1 output was not correct. Expected "+d.expectedZ+" but saw "+g);d.failed=true;return}else{d.testCount+=1;d.nextTime+=1;d.state=0;cycle_sim.simLog("Passed "+d.testCount+" tests of "+b)}break}}if(d.testCount>=b){if(d.failed===false){cycle_sim.testPass("TRUTH_TABLE1",6)}else{cycle_sim.testFail("TRUTH_TABLE1","Test completed with previous fails.")}}};a.TRUTH_TABLE2_TEST=new Cycle_sim_prim_obj("TRUTH_TABLE2_TEST",["Z"],["A","B","C"],false);a.TRUTH_TABLE2_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedZ=undefined;b.truthTable=[[[true,true],[false,false]],[[true,true],[false,true]]]};a.TRUTH_TABLE2_TEST.tick=function(d){var h;var g;var f;var e;var c=14;var b=32;if(cycle_sim.hw.time>=d.nextTime){switch(d.state){case 0:g=cycle_sim.randomBool();f=cycle_sim.randomBool();e=cycle_sim.randomBool();d.expectedZ=d.truthTable[g+0][f+0][e+0];cycle_sim.setSigVal(d,"A",g);cycle_sim.setSigVal(d,"B",f);cycle_sim.setSigVal(d,"C",e);d.nextTime+=c;d.state=1;break;case 1:h=cycle_sim.getSigVal(d,"Z");if(h!==d.expectedZ){cycle_sim.testFail("TRUTH_TABLE2","TRUTH_TABLE2 output was not correct. Expected "+d.expectedZ+" but saw "+h);d.failed=true;return}else{d.testCount+=1;d.nextTime+=1;d.state=0;cycle_sim.simLog("Passed "+d.testCount+" tests of "+b)}break}}if(d.testCount>=b){if(d.failed===false){cycle_sim.testPass("TRUTH_TABLE2",7)}else{cycle_sim.testFail("TRUTH_TABLE2","Test completed with previous fails.")}}};a.TRUTH_TABLE3_TEST=new Cycle_sim_prim_obj("TRUTH_TABLE3_TEST",["Z"],["A","B","C","D"],false);a.TRUTH_TABLE3_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedZ=undefined;b.truthTable=[[[[false,false],[false,false]],[[true,true],[true,false]]],[[[true,false],[true,true]],[[true,true],[true,true]]]]};a.TRUTH_TABLE3_TEST.tick=function(e){var i;var h;var g;var f;var d;var c=18;var b=64;if(cycle_sim.hw.time>=e.nextTime){switch(e.state){case 0:h=cycle_sim.randomBool();g=cycle_sim.randomBool();f=cycle_sim.randomBool();d=cycle_sim.randomBool();e.expectedZ=e.truthTable[h+0][g+0][f+0][d+0];cycle_sim.setSigVal(e,"A",h);cycle_sim.setSigVal(e,"B",g);cycle_sim.setSigVal(e,"C",f);cycle_sim.setSigVal(e,"D",d);e.nextTime+=c;e.state=1;break;case 1:i=cycle_sim.getSigVal(e,"Z");if(i!==e.expectedZ){cycle_sim.testFail("TRUTH_TABLE3","TRUTH_TABLE3 output was not correct. Expected "+e.expectedZ+" but saw "+i);e.failed=true;return}else{e.testCount+=1;e.nextTime+=1;e.state=0;cycle_sim.simLog("Passed "+e.testCount+" tests of "+b)}break}}if(e.testCount>=b){if(e.failed===false){cycle_sim.testPass("TRUTH_TABLE3",8)}else{cycle_sim.testFail("TRUTH_TABLE3","Test completed with previous fails.")}}};a.MUX21_TEST=new Cycle_sim_prim_obj("MUX21_TEST",["Z"],["I0","I1","S"],false);a.MUX21_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedZ=undefined};a.MUX21_TEST.tick=function(f){var h;var c;var g;var e;var d=12;var b=32;if(cycle_sim.hw.time>=f.nextTime){switch(f.state){case 0:c=cycle_sim.randomBool();g=cycle_sim.randomBool();e=cycle_sim.randomBool();if(e){f.expectedZ=g}else{f.expectedZ=c}cycle_sim.setSigVal(f,"I0",c);cycle_sim.setSigVal(f,"I1",g);cycle_sim.setSigVal(f,"S",e);f.nextTime+=d;f.state=1;break;case 1:h=cycle_sim.getSigVal(f,"Z");if(h!==f.expectedZ){cycle_sim.testFail("MUX21","Output was not correct. Expected "+f.expectedZ+" but saw "+h);f.failed=true;return}else{f.testCount+=1;f.nextTime+=1;f.state=0;cycle_sim.simLog("Passed "+f.testCount+" tests of "+b)}break}}if(f.testCount>=b){if(f.failed===false){cycle_sim.testPass("MUX21",9)}else{cycle_sim.testFail("MUX21","Test completed with previous fails.")}}};a.MUX41_TEST=new Cycle_sim_prim_obj("MUX41_TEST",["Z"],["I0","I1","I2","I3","S<1>","S<0>"],false);a.MUX41_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedZ=undefined};a.MUX41_TEST.tick=function(e){var i;var f;var d;var c;var b;var k;var l;var j;var g=15;var h=64;if(cycle_sim.hw.time>=e.nextTime){switch(e.state){case 0:f=cycle_sim.randomBool();d=cycle_sim.randomBool();c=cycle_sim.randomBool();b=cycle_sim.randomBool();k=cycle_sim.randomBool();l=cycle_sim.randomBool();j=((k+0)<<1)|(l+0);switch(j){case 0:e.expectedZ=f;break;case 1:e.expectedZ=d;break;case 2:e.expectedZ=c;break;case 3:e.expectedZ=b;break}cycle_sim.setSigVal(e,"I0",f);cycle_sim.setSigVal(e,"I1",d);cycle_sim.setSigVal(e,"I2",c);cycle_sim.setSigVal(e,"I3",b);cycle_sim.setSigVal(e,"S<1>",k);cycle_sim.setSigVal(e,"S<0>",l);e.nextTime+=g;e.state=1;break;case 1:i=cycle_sim.getSigVal(e,"Z");if(i!==e.expectedZ){cycle_sim.testFail("MUX41","Output was not correct. Expected "+e.expectedZ+" but saw "+i);e.failed=true;return}else{e.testCount+=1;e.nextTime+=1;e.state=0;cycle_sim.simLog("Passed "+e.testCount+" tests of "+h)}break}}if(e.testCount>=h){if(e.failed===false){cycle_sim.testPass("MUX41",10)}else{cycle_sim.testFail("MUX41","Test completed with previous fails.")}}};a.MUX81X8_TEST=new Cycle_sim_prim_obj("MUX81X8_TEST",["Z<7>","Z<6>","Z<5>","Z<4>","Z<3>","Z<2>","Z<1>","Z<0>"],["I0<7>","I0<6>","I0<5>","I0<4>","I0<3>","I0<2>","I0<1>","I0<0>","I1<7>","I1<6>","I1<5>","I1<4>","I1<3>","I1<2>","I1<1>","I1<0>","I2<7>","I2<6>","I2<5>","I2<4>","I2<3>","I2<2>","I2<1>","I2<0>","I3<7>","I3<6>","I3<5>","I3<4>","I3<3>","I3<2>","I3<1>","I3<0>","I4<7>","I4<6>","I4<5>","I4<4>","I4<3>","I4<2>","I4<1>","I4<0>","I5<7>","I5<6>","I5<5>","I5<4>","I5<3>","I5<2>","I5<1>","I5<0>","I6<7>","I6<6>","I6<5>","I6<4>","I6<3>","I6<2>","I6<1>","I6<0>","I7<7>","I7<6>","I7<5>","I7<4>","I7<3>","I7<2>","I7<1>","I7<0>","S<2>","S<1>","S<0>"],false);a.MUX81X8_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedZ=undefined};a.MUX81X8_TEST.tick=function(j){var n;var k;var i;var h;var g;var f;var e;var c;var b;var d;var l=20;var m=128;if(cycle_sim.hw.time>=j.nextTime){switch(j.state){case 0:k=cycle_sim.randomInt(0,255);i=cycle_sim.randomInt(0,255);h=cycle_sim.randomInt(0,255);g=cycle_sim.randomInt(0,255);f=cycle_sim.randomInt(0,255);e=cycle_sim.randomInt(0,255);c=cycle_sim.randomInt(0,255);b=cycle_sim.randomInt(0,255);d=cycle_sim.randomInt(0,7);switch(d){case 0:j.expectedZ=k;break;case 1:j.expectedZ=i;break;case 2:j.expectedZ=h;break;case 3:j.expectedZ=g;break;case 4:j.expectedZ=f;break;case 5:j.expectedZ=e;break;case 6:j.expectedZ=c;break;case 7:j.expectedZ=b;break}cycle_sim.setSigVecVal(j,"I0",7,0,k);cycle_sim.setSigVecVal(j,"I1",7,0,i);cycle_sim.setSigVecVal(j,"I2",7,0,h);cycle_sim.setSigVecVal(j,"I3",7,0,g);cycle_sim.setSigVecVal(j,"I4",7,0,f);cycle_sim.setSigVecVal(j,"I5",7,0,e);cycle_sim.setSigVecVal(j,"I6",7,0,c);cycle_sim.setSigVecVal(j,"I7",7,0,b);cycle_sim.setSigVecVal(j,"S",2,0,d);j.nextTime+=l;j.state=1;break;case 1:n=cycle_sim.getSigVecVal(j,"Z",7,0);if(n!==j.expectedZ){cycle_sim.testFail("MUX81X8","Output was not correct. Expected "+j.expectedZ+" but saw "+n);j.failed=true;return}else{j.testCount+=1;j.nextTime+=1;j.state=0;cycle_sim.simLog("Passed "+j.testCount+" tests of "+m)}break}}if(j.testCount>=m){if(j.failed===false){cycle_sim.testPass("MUX81X8",11)}else{cycle_sim.testFail("MUX81X8","Test completed with previous fails.")}}};a.DEMUX12_TEST=new Cycle_sim_prim_obj("DEMUX12_TEST",["Z0","Z1"],["A","S"],false);a.DEMUX12_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedZ0=undefined;b.expectedZ1=undefined};a.DEMUX12_TEST.tick=function(g){var f;var e;var h;var d;var c=12;var b=32;if(cycle_sim.hw.time>=g.nextTime){switch(g.state){case 0:h=cycle_sim.randomBool();d=cycle_sim.randomBool();if(d){g.expectedZ0=false;g.expectedZ1=h}else{g.expectedZ0=h;g.expectedZ1=false}cycle_sim.setSigVal(g,"A",h);cycle_sim.setSigVal(g,"S",d);g.nextTime+=c;g.state=1;break;case 1:f=cycle_sim.getSigVal(g,"Z0");e=cycle_sim.getSigVal(g,"Z1");if((f!==g.expectedZ0)||(e!==g.expectedZ1)){cycle_sim.testFail("DEMUX12","Output was not correct. Expected Z0="+g.expectedZ0+", Z1="+g.expectedZ1+" but saw "+f+","+e);g.failed=true;return}else{g.testCount+=1;g.nextTime+=1;g.state=0;cycle_sim.simLog("Passed "+g.testCount+" tests of "+b)}break}}if(g.testCount>=b){if(g.failed===false){cycle_sim.testPass("DEMUX12",12)}else{cycle_sim.testFail("DEMUX12","Test completed with previous fails.")}}};a.DEMUX14_TEST=new Cycle_sim_prim_obj("DEMUX14_TEST",["Z0","Z1","Z2","Z3"],["A","S<1>","S<0>"],false);a.DEMUX14_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedZ0=undefined;b.expectedZ1=undefined;b.expectedZ2=undefined;b.expectedZ3=undefined};a.DEMUX14_TEST.tick=function(f){var h;var g;var e;var d;var b;var c;var i=14;var j=32;if(cycle_sim.hw.time>=f.nextTime){switch(f.state){case 0:b=cycle_sim.randomBool();c=cycle_sim.randomInt(0,3);f.expectedZ0=false;f.expectedZ1=false;f.expectedZ2=false;f.expectedZ3=false;switch(c){case 0:f.expectedZ0=b;break;case 1:f.expectedZ1=b;break;case 2:f.expectedZ2=b;break;case 3:f.expectedZ3=b;break}cycle_sim.setSigVal(f,"A",b);cycle_sim.setSigVecVal(f,"S",1,0,c);f.nextTime+=i;f.state=1;break;case 1:h=cycle_sim.getSigVal(f,"Z0");g=cycle_sim.getSigVal(f,"Z1");e=cycle_sim.getSigVal(f,"Z2");d=cycle_sim.getSigVal(f,"Z3");if((h!==f.expectedZ0)||(g!==f.expectedZ1)||(e!==f.expectedZ2)||(d!==f.expectedZ3)){cycle_sim.testFail("DEMUX14","Output was not correct. Expected Z0="+f.expectedZ0+", Z1="+f.expectedZ1+", Z2="+f.expectedZ2+", Z3="+f.expectedZ3+" but saw "+h+","+g+","+e+","+d);f.failed=true;return}else{f.testCount+=1;f.nextTime+=1;f.state=0;cycle_sim.simLog("Passed "+f.testCount+" tests of "+j)}break}}if(f.testCount>=j){if(f.failed===false){cycle_sim.testPass("DEMUX14",13)}else{cycle_sim.testFail("DEMUX14","Test completed with previous fails.")}}};a.DEMUX18X8_TEST=new Cycle_sim_prim_obj("DEMUX18X8_TEST",["Z0<7>","Z0<6>","Z0<5>","Z0<4>","Z0<3>","Z0<2>","Z0<1>","Z0<0>","Z1<7>","Z1<6>","Z1<5>","Z1<4>","Z1<3>","Z1<2>","Z1<1>","Z1<0>","Z2<7>","Z2<6>","Z2<5>","Z2<4>","Z2<3>","Z2<2>","Z2<1>","Z2<0>","Z3<7>","Z3<6>","Z3<5>","Z3<4>","Z3<3>","Z3<2>","Z3<1>","Z3<0>","Z4<7>","Z4<6>","Z4<5>","Z4<4>","Z4<3>","Z4<2>","Z4<1>","Z4<0>","Z5<7>","Z5<6>","Z5<5>","Z5<4>","Z5<3>","Z5<2>","Z5<1>","Z5<0>","Z6<7>","Z6<6>","Z6<5>","Z6<4>","Z6<3>","Z6<2>","Z6<1>","Z6<0>","Z7<7>","Z7<6>","Z7<5>","Z7<4>","Z7<3>","Z7<2>","Z7<1>","Z7<0>"],["A<7>","A<6>","A<5>","A<4>","A<3>","A<2>","A<1>","A<0>","S<2>","S<1>","S<0>"],false);a.DEMUX18X8_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedZ0=undefined;b.expectedZ1=undefined;b.expectedZ2=undefined;b.expectedZ3=undefined;b.expectedZ4=undefined;b.expectedZ5=undefined;b.expectedZ6=undefined;b.expectedZ7=undefined};a.DEMUX18X8_TEST.tick=function(j){var l;var k;var i;var h;var g;var f;var e;var c;var b;var d;var m=20;var n=128;if(cycle_sim.hw.time>=j.nextTime){switch(j.state){case 0:b=cycle_sim.randomInt(0,255);d=cycle_sim.randomInt(0,7);j.expectedZ0=0;j.expectedZ1=0;j.expectedZ2=0;j.expectedZ3=0;j.expectedZ4=0;j.expectedZ5=0;j.expectedZ6=0;j.expectedZ7=0;switch(d){case 0:j.expectedZ0=b;break;case 1:j.expectedZ1=b;break;case 2:j.expectedZ2=b;break;case 3:j.expectedZ3=b;break;case 4:j.expectedZ4=b;break;case 5:j.expectedZ5=b;break;case 6:j.expectedZ6=b;break;case 7:j.expectedZ7=b;break}cycle_sim.setSigVecVal(j,"A",7,0,b);cycle_sim.setSigVecVal(j,"S",2,0,d);j.nextTime+=m;j.state=1;break;case 1:l=cycle_sim.getSigVecVal(j,"Z0",7,0);k=cycle_sim.getSigVecVal(j,"Z1",7,0);i=cycle_sim.getSigVecVal(j,"Z2",7,0);h=cycle_sim.getSigVecVal(j,"Z3",7,0);g=cycle_sim.getSigVecVal(j,"Z4",7,0);f=cycle_sim.getSigVecVal(j,"Z5",7,0);e=cycle_sim.getSigVecVal(j,"Z6",7,0);c=cycle_sim.getSigVecVal(j,"Z7",7,0);if((l!==j.expectedZ0)||(k!==j.expectedZ1)||(i!==j.expectedZ2)||(h!==j.expectedZ3)||(g!==j.expectedZ4)||(f!==j.expectedZ5)||(e!==j.expectedZ6)||(c!==j.expectedZ7)){cycle_sim.testFail("DEMUX18X8","Output was not correct. Expected Z0="+cycle_sim.leftPadNumberString(j.expectedZ0.toString(2),8)+", Z1="+cycle_sim.leftPadNumberString(j.expectedZ1.toString(2),8)+", Z2="+cycle_sim.leftPadNumberString(j.expectedZ2.toString(2),8)+", Z3="+cycle_sim.leftPadNumberString(j.expectedZ3.toString(2),8)+", Z4="+cycle_sim.leftPadNumberString(j.expectedZ4.toString(2),8)+", Z5="+cycle_sim.leftPadNumberString(j.expectedZ5.toString(2),8)+", Z6="+cycle_sim.leftPadNumberString(j.expectedZ6.toString(2),8)+", Z7="+cycle_sim.leftPadNumberString(j.expectedZ7.toString(2),8)+" but saw Z0="+cycle_sim.leftPadNumberString(l.toString(2),8)+", Z1="+cycle_sim.leftPadNumberString(k.toString(2),8)+", Z2="+cycle_sim.leftPadNumberString(i.toString(2),8)+", Z3="+cycle_sim.leftPadNumberString(h.toString(2),8)+", Z4="+cycle_sim.leftPadNumberString(g.toString(2),8)+", Z5="+cycle_sim.leftPadNumberString(f.toString(2),8)+", Z6="+cycle_sim.leftPadNumberString(e.toString(2),8)+", Z7="+cycle_sim.leftPadNumberString(c.toString(2),8));j.failed=true;return}else{j.testCount+=1;j.nextTime+=1;j.state=0;cycle_sim.simLog("Passed "+j.testCount+" tests of "+n)}break}}if(j.testCount>=n){if(j.failed===false){cycle_sim.testPass("DEMUX18X8",14)}else{cycle_sim.testFail("DEMUX18X8","Test completed with previous fails.")}}};a.SRLAT_TEST=new Cycle_sim_prim_obj("SRLAT_TEST",["QT","QC"],["S","R"],false);a.SRLAT_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedQT=undefined;b.expectedQC=undefined};a.SRLAT_TEST.tick=function(h){var g;var d;var e;var f;var c=12;var b=32;if(cycle_sim.hw.time>=h.nextTime){switch(h.state){case 0:e=cycle_sim.randomBool();f=cycle_sim.randomBool();if(e&&f){e=cycle_sim.randomBool();f=!e}if(!(e||f)&&(h.testCount===0)){e=true;f=false}if(e){h.expectedQT=true;h.expectedQC=false}if(f){h.expectedQT=false;h.expectedQC=true}cycle_sim.setSigVal(h,"S",e);cycle_sim.setSigVal(h,"R",f);h.nextTime+=c;h.state=1;break;case 1:g=cycle_sim.getSigVal(h,"QT");d=cycle_sim.getSigVal(h,"QC");if((g!==h.expectedQT)||(d!==h.expectedQC)){cycle_sim.testFail("SRLAT","Output was not correct. Expected QT="+h.expectedQT+", QC="+h.expectedQC+" but saw "+g+","+d);h.failed=true;return}else{h.testCount+=1;h.nextTime+=1;h.state=0;cycle_sim.simLog("Passed "+h.testCount+" tests of "+b)}break}}if(h.testCount>=b){if(h.failed===false){cycle_sim.testPass("SRLAT",15)}else{cycle_sim.testFail("SRLAT","Test completed with previous fails.")}}};a.DFF_TEST=new Cycle_sim_prim_obj("DFF_TEST",["QT","QC"],["D","E"],false);a.DFF_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedQT=undefined;b.expectedQC=undefined;b.lastE=undefined;b.lastD=undefined};a.DFF_TEST.tick=function(h){var g;var d;var f;var e;var c=8;var b=64;if(cycle_sim.hw.time>=h.nextTime){switch(h.state){case 0:f=cycle_sim.randomBool();cycle_sim.setSigVal(h,"D",f);h.lastD=f;if(cycle_sim.hw.time===0){e=false;cycle_sim.setSigVal(h,"E",e);h.lastE=false}h.nextTime+=c;h.state=1;break;case 1:e=cycle_sim.randomBool();if(e&&!h.lastE){h.expectedQT=h.lastD;h.expectedQC=!h.lastD}h.lastE=e;cycle_sim.setSigVal(h,"E",e);h.nextTime+=c;h.state=2;break;case 2:g=cycle_sim.getSigVal(h,"QT");d=cycle_sim.getSigVal(h,"QC");if(h.expectedQT!==undefined){if((g!==h.expectedQT)||(d!==h.expectedQC)){cycle_sim.testFail("DFF","Output was not correct. Expected QT="+h.expectedQT+", QC="+h.expectedQC+" but saw "+g+","+d);h.failed=true;return}else{h.testCount+=1;h.nextTime+=1;h.state=0;cycle_sim.simLog("Passed "+h.testCount+" tests of "+b)}}else{h.nextTime+=1;h.state=0}break}}if(h.testCount>=b){if(h.failed===false){cycle_sim.testPass("DFF",17)}else{cycle_sim.testFail("DFF","Test completed with previous fails.")}}};a.TFF_TEST=new Cycle_sim_prim_obj("TFF_TEST",["QT","QC"],["T","R","E"],false);a.TFF_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedQT=undefined;b.expectedQC=undefined;b.lastE=undefined;b.lastD=undefined;b.lastT=undefined;b.lastR=undefined;b.initComplete=false};a.TFF_TEST.tick=function(i){var h;var e;var d;var f;var g;var c=12;var b=64;if(cycle_sim.hw.time>=i.nextTime){switch(i.state){case 0:d=cycle_sim.randomBool();f=cycle_sim.randomBool();if(cycle_sim.hw.time===0){g=false;cycle_sim.setSigVal(i,"E",g);i.lastE=false;d=false;f=true}i.lastR=f;i.lastT=d;cycle_sim.setSigVal(i,"T",d);cycle_sim.setSigVal(i,"R",f);i.nextTime+=c;i.state=1;break;case 1:if(i.initComplete){g=cycle_sim.randomBool()}else{g=true;i.initComplete=true}if(g&&!i.lastE){if(i.lastR){i.lastD=false}else{if(i.lastT){i.lastD=!i.lastD}}i.expectedQT=i.lastD;i.expectedQC=!i.lastD}i.lastE=g;cycle_sim.setSigVal(i,"E",g);i.nextTime+=c;i.state=2;break;case 2:h=cycle_sim.getSigVal(i,"QT");e=cycle_sim.getSigVal(i,"QC");if(i.expectedQT!==undefined){if((h!==i.expectedQT)||(e!==i.expectedQC)){cycle_sim.testFail("TFF","Output was not correct. Expected QT="+i.expectedQT+", QC="+i.expectedQC+" but saw "+h+","+e);i.failed=true;return}else{i.testCount+=1;i.nextTime+=1;i.state=0;cycle_sim.simLog("Passed "+i.testCount+" tests of "+b)}}else{i.lastD=h;i.nextTime+=1;i.state=0}break}}if(i.testCount>=b){if(i.failed===false){cycle_sim.testPass("TFF",18)}else{cycle_sim.testFail("TFF","Test completed with previous fails.")}}};a.BIN_TO_7SEG_TEST=new Cycle_sim_prim_obj("BIN_TO_7SEG_TEST",["A","B","C","D","E","F","G"],["BIN<3>","BIN<2>","BIN<1>","BIN<0>"],false);a.BIN_TO_7SEG_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expected=undefined;b.lastBIN=undefined};a.BIN_TO_7SEG_TEST.tick=function(g){var j;var c;var e;var h;var f;var d=20;var b=64;if(cycle_sim.hw.time>=g.nextTime){switch(g.state){case 0:if(g.testCount<=15){j=g.testCount}else{j=cycle_sim.randomInt(0,15)}g.lastBIN=j;g.expected=[[true,true,true,true,true,true,false],[false,true,true,false,false,false,false],[true,true,false,true,true,false,true],[true,true,true,true,false,false,true],[false,true,true,false,false,true,true],[true,false,true,true,false,true,true],[true,false,true,true,true,true,true],[true,true,true,false,false,false,false],[true,true,true,true,true,true,true],[true,true,true,true,false,true,true],[true,true,true,false,true,true,true],[false,false,true,true,true,true,true],[true,false,false,true,true,true,false],[false,true,true,true,true,false,true],[true,false,false,true,true,true,true],[true,false,false,false,true,true,true]][j];cycle_sim.setSigVecVal(g,"BIN",3,0,j);g.nextTime+=d;g.state=1;break;case 1:c=[];c.push(cycle_sim.getSigVal(g,"A"));c.push(cycle_sim.getSigVal(g,"B"));c.push(cycle_sim.getSigVal(g,"C"));c.push(cycle_sim.getSigVal(g,"D"));c.push(cycle_sim.getSigVal(g,"E"));c.push(cycle_sim.getSigVal(g,"F"));c.push(cycle_sim.getSigVal(g,"G"));e=true;for(f=0;f<c.length;f++){if(c[f]!==g.expected[f]){e=false;break}}if(!e){h="Output was not correct. Expected A-G=["+g.expected.toString()+"] but found A-G=["+c.toString()+"]";cycle_sim.testFail("BIN_TO_7SEG",h);g.failed=true;return}else{g.testCount+=1;g.nextTime+=1;g.state=0;cycle_sim.simLog("Passed "+g.testCount+" tests of "+b)}break}}if(g.testCount>=b){if(g.failed===false){cycle_sim.testPass("BIN_TO_7SEG",19)}else{cycle_sim.testFail("BIN_TO_7SEG","Test completed with previous fails.")}}};a.ADDX8_TEST=new Cycle_sim_prim_obj("ADDx8_TEST",["S<7:0>","COUT"],["A<7:0>","B<7:0>","CIN"],false);a.ADDX8_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedS=undefined;b.expectedCOUT=undefined;b.lastA=undefined;b.lastB=undefined;b.lastCIN=undefined};a.ADDX8_TEST.tick=function(e){var b;var k;var h;var d;var j;var f;var c;var g=30;var i=128;if(cycle_sim.hw.time>=e.nextTime){switch(e.state){case 0:b=cycle_sim.randomInt(0,255);k=cycle_sim.randomInt(0,255);h=cycle_sim.randomInt(0,1);f=b+k+h;e.lastA=b;e.lastB=k;e.lastCIN=h===1;e.expectedS=f&255;e.expectedCOUT=((f>>8)&1)===1;cycle_sim.setSigVecVal(e,"A",7,0,b);cycle_sim.setSigVecVal(e,"B",7,0,k);cycle_sim.setSigVal(e,"CIN",h===1);e.nextTime+=g;e.state=1;break;case 1:d=cycle_sim.getSigVecVal(e,"S",7,0);j=cycle_sim.getSigVal(e,"COUT");if(!((d===e.expectedS)&&(j===e.expectedCOUT))){c="Output was not correct. Expected "+cycle_sim.leftPadNumberString(e.lastA.toString(2),8)+" + "+cycle_sim.leftPadNumberString(e.lastB.toString(2),8)+" + "+(e.lastCIN+0)+" = "+(e.expectedCOUT+0)+","+cycle_sim.leftPadNumberString(e.expectedS.toString(2),8)+" but found "+(j+0)+","+cycle_sim.leftPadNumberString(d.toString(2),8);cycle_sim.testFail("ADDx8",c);e.failed=true;return}else{e.testCount+=1;e.nextTime+=1;e.state=0;cycle_sim.simLog("Passed "+e.testCount+" tests of "+i)}break}}if(e.testCount>=i){if(e.failed===false){cycle_sim.testPass("ADDX8",20)}else{cycle_sim.testFail("ADDX8","Test completed with previous fails.")}}};a.ALUX8_TEST=new Cycle_sim_prim_obj("ALUx8_TEST",["Z<7:0>"],["A<7:0>","B<7:0>","OP<1:0>"],false);a.ALUX8_TEST.init=function(b){b.testCount=0;b.nextTime=0;b.state=0;b.failed=false;b.expectedZ=undefined;b.lastA=undefined;b.lastB=undefined;b.lastOP=undefined};a.ALUX8_TEST.tick=function(e){var b;var j;var k;var i;var d;var c;var g=40;var h=512;var f=["ADD","AND","OR","NOT"];if(cycle_sim.hw.time>=e.nextTime){switch(e.state){case 0:b=cycle_sim.randomInt(0,255);j=cycle_sim.randomInt(0,255);k=cycle_sim.randomInt(0,3);switch(k){case 0:d=b+j;break;case 1:d=b&j;break;case 2:d=b|j;break;case 3:d=~b;break}d=d&255;e.lastA=b;e.lastB=j;e.lastOP=k;e.expectedZ=d;cycle_sim.setSigVecVal(e,"A",7,0,b);cycle_sim.setSigVecVal(e,"B",7,0,j);cycle_sim.setSigVecVal(e,"OP",1,0,k);e.nextTime+=g;e.state=1;break;case 1:i=cycle_sim.getSigVecVal(e,"Z",7,0);if(!(i===e.expectedZ)){c="Output was not correct. Expected "+f[e.lastOP]+"("+cycle_sim.leftPadNumberString(e.lastA.toString(2),8)+" , "+cycle_sim.leftPadNumberString(e.lastB.toString(2),8)+") = "+cycle_sim.leftPadNumberString(e.expectedZ.toString(2),8)+" but found "+cycle_sim.leftPadNumberString(i.toString(2),8);cycle_sim.testFail("ALUX8",c);e.failed=true;return}else{e.testCount+=1;e.nextTime+=1;e.state=0;cycle_sim.simLog("Passed "+e.testCount+" tests of "+h)}break}}if(e.testCount>=h){if(e.failed===false){cycle_sim.testPass("ALUX8",21)}else{cycle_sim.testFail("ALUX8","Test completed with previous fails.")}}};return a}};