# dlcs Release 1.1.0

Digital Logic Circuit Simulator in Javascript.

Keywords
boolean, logic gates, and, or, xor, nand, xnor, nor, digital, logic, circuit, gate, gates, addition, multiplication, simulator, digitallogic, digitallogicsim, logicanalyzer
GPL-2.0
Install
``` npm install dlcs@1.1.0 ```

# DLCS

## Digital Logic Circuit Simulation library in javascript.

Simulate nodes, logic gates, and ICs.

## Install

NPM

``````npm install dlcs
``````
`var DLCS = require('dlcs'); `

Clientside

```<script src="funary.js"></script>
<script src="DLCS.js"></script>```

## Example Simple AND with OR gate:

```var DLCS = require('dlcs');

//New output node
var outputnode = new DLCS(DLCS.outputnode);

//New OR gate
var orgate = new DLCS(DLCS.orgate);

//New AND gate
var andgate = new DLCS(DLCS.andgate);

//Set inputs paths

//New input nodes
var inputnode0 = new DLCS(DLCS.inputnode);
var inputnode1 = new DLCS(DLCS.inputnode);
var inputnode2 = new DLCS(DLCS.inputnode);

//Connect to AND

//Set single values
inputnode0.setValue(1,0); //1
inputnode1.setValue(1,0); //1
inputnode2.setValue(0,0); //0

//Simulate circuit
var result = outputnode.simulate().getOutputValues(); //[1]
```

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 = require('dlcs');

var fa = new DLCS(DLCS.fa);

//Auto generate array of input and output nodes

//Set input values
innodes[0].setOutputValues([0]); //0
innodes[1].setOutputValues([1]); //1
innodes[2].setOutputValues([1]); //1

//Little endianess
var result0 = outnodes[0].simulate().getOutputValues(); //[0]
var result1 = outnodes[1].simulate().getOutputValues(); //[1]```

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 produces U0 to UN+1 output.

```//New adder with 8 inputs and 5 outputs

//Auto generate array of input and output nodes

//Set input values of one number
innodes[0].setOutputValues([0]); //0
innodes[1].setOutputValues([1]); //1
innodes[2].setOutputValues([0]); //0
innodes[3].setOutputValues([1]); //1

//Set input values of one number
innodes[4].setOutputValues([1]); //1
innodes[5].setOutputValues([1]); //1
innodes[6].setOutputValues([1]); //1
innodes[7].setOutputValues([1]); //1

//Little endianess
var result = nadder.simulate().getOutputValues(); //[1, 0, 0, 1, 1]```

## Extending DLCS for custom components

```//New function of XOR and AND
var customfunction = function (input) {
return [((input[0] ^ input[1]) & input[2])];
}

//New custom IC data
var customICdata = {"inputs":3,
"name": "custom",
"outputs":1,
"outputvalues":[-1],
"outputfunction": customfunction
};

//New custom IC data
var customIC = new DLCS(customICdata);

//Generate input nodes

innodes[0].setOutputValues([0]); //0
innodes[1].setOutputValues([1]); //1
innodes[2].setOutputValues([0]); //0

customIC.simulate();

var result = customIC.getOutputValues(); //[0]```

## dlcircuit (Main object)

```var DLCS = require('dlcs');

//The object returned from DLC or DLCSim is dlcircuit
//dlcircuit is the object that forms every gate, node, and IC
var andgate = new DLCS(DLCS.andgate);

//Each object contains an output array
//This returns the the output array
andgate.getOutputValues();

//Setting the output array
andgate.setOutputValues([1]);

//Setting individual element
andgate.setValue(1,0);

//Instantaneous simulation of object
//The values will be set and stored until some other operation happens
andgate.simulate();
```

## Related projects

Arbitrary precision binary operations library for Javascript.