DLCS
Digital Logic Circuit Simulation library in javascript.

Simulate nodes, logic gates, and ICs.
Install
npm install dlcs
var DLCS = ;
Clientside
Example Simple AND with OR gate:
var DLCS = ; //New output nodevar outputnode = DLCSoutputnode; //New OR gatevar orgate = DLCSorgate; //New AND gatevar andgate = DLCSandgate; //Set inputs pathsoutputnode; //New input nodesvar inputnode0 = DLCSinputnode;var inputnode1 = DLCSinputnode;var inputnode2 = DLCSinputnode; //Connect to ANDandgate;andgate;orgate; //Set single valuesinputnode0; //1inputnode1; //1inputnode2; //0 //Simulate circuitvar result = outputnode; //[1]
Example Full adder IC
Full adder takes in inputs A , B, and CIN(Carry in). S(Sum) is addition of inputs. COUT(Carry out) is the overflow of the addition of inputs.
A | B | CIN | COUT | S |
---|---|---|---|---|
0 | 0 | 0 | 0 | 0 |
0 | 0 | 1 | 0 | 1 |
0 | 1 | 0 | 0 | 1 |
0 | 1 | 1 | 1 | 0 |
1 | 0 | 0 | 0 | 1 |
1 | 0 | 1 | 1 | 0 |
1 | 1 | 0 | 1 | 0 |
1 | 1 | 1 | 1 | 1 |
var DLCS = ; //New Full addervar fa = DLCSfa; //Auto generate array of input and output nodesvar innodes = fa;var outnodes = fa; //Set input valuesinnodes0; //0innodes1; //1innodes2; //1 //Little endianessvar result0 = outnodes0; //[0]var result1 = outnodes1; //[1]
N-bit adder
I0(least significant) to IN(most significant) is the first binary number.
IN+1(least significant) to I2N(most significant) is the second binary number.
N-bit adder takes both and adds them.
N-bit adder produces U0 to UN+1 output.
//New adder with 8 inputs and 5 outputsvar nadder = DLCSnadder085; //Auto generate array of input and output nodesvar innodes = nadder; //Set input values of one numberinnodes0; //0innodes1; //1innodes2; //0innodes3; //1 //Set input values of one numberinnodes4; //1innodes5; //1innodes6; //1innodes7; //1 //Little endianessvar result = nadder; //[1, 0, 0, 1, 1]
Extending DLCS for custom components
//New function of XOR and ANDvar { return input0 ^ input1 & input2;} //New custom IC datavar customICdata = "inputs":3 "name": "custom" "outputs":1 "outputvalues":-1 "outputfunction": customfunction; //New custom IC datavar customIC = customICdata; //Generate input nodesvar innodes = customIC; innodes0; //0innodes1; //1innodes2; //0 customIC; var result = customIC; //[0]
dlcircuit (Main object)
var DLCS = ; //The object returned from DLC or DLCSim is dlcircuit//dlcircuit is the object that forms every gate, node, and ICvar andgate = DLCSandgate; //Each object contains an output array//This returns the the output arrayandgate; //Setting the output arrayandgate; //Setting individual elementandgate; //Instantaneous simulation of object//The values will be set and stored until some other operation happensandgate;
Related projects
Arbitrary precision binary operations library for Javascript.