mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-15 07:48:29 -04:00
added some documentation
This commit is contained in:
parent
6cfdaec7ff
commit
751708bd7a
@ -9,12 +9,22 @@ import de.neemann.digital.core.element.ElementTypeDescription;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The And gate
|
||||||
|
*
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public class And extends Function {
|
public class And extends Function {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The And description
|
||||||
|
*/
|
||||||
public static final ElementTypeDescription DESCRIPTION = new FanInDescription(And.class);
|
public static final ElementTypeDescription DESCRIPTION = new FanInDescription(And.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param attributes the attributes
|
||||||
|
*/
|
||||||
public And(ElementAttributes attributes) {
|
public And(ElementAttributes attributes) {
|
||||||
super(attributes.get(AttributeKey.Bits));
|
super(attributes.get(AttributeKey.Bits));
|
||||||
}
|
}
|
||||||
|
@ -10,46 +10,61 @@ import java.util.ArrayList;
|
|||||||
import static de.neemann.digital.core.element.PinInfo.input;
|
import static de.neemann.digital.core.element.PinInfo.input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* A fan in. Used as base class for the simple bool operations
|
||||||
|
*
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public abstract class FanIn extends Node implements Element {
|
public abstract class FanIn extends Node implements Element {
|
||||||
|
|
||||||
protected final ArrayList<ObservableValue> inputs;
|
private final ArrayList<ObservableValue> inputs;
|
||||||
protected final ObservableValue output;
|
private final ObservableValue output;
|
||||||
private final int bits;
|
private final int bits;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param bits the number of bits
|
||||||
|
*/
|
||||||
public FanIn(int bits) {
|
public FanIn(int bits) {
|
||||||
this.bits = bits;
|
this.bits = bits;
|
||||||
inputs = new ArrayList<>();
|
inputs = new ArrayList<>();
|
||||||
output = new ObservableValue("out", bits);
|
output = new ObservableValue("out", bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableValue getOutput() {
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInputs(ObservableValue... in) throws NodeException {
|
public void setInputs(ObservableValue... in) throws NodeException {
|
||||||
for (ObservableValue v : in)
|
for (ObservableValue v : in)
|
||||||
inputs.add(v.checkBits(bits, this).addObserverToValue(this));
|
inputs.add(v.checkBits(bits, this).addObserverToValue(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the outputs
|
||||||
|
*/
|
||||||
|
public ObservableValue getOutput() {
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the outputs
|
||||||
|
*/
|
||||||
|
public ArrayList<ObservableValue> getInputs() {
|
||||||
|
return inputs;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObservableValue[] getOutputs() {
|
public ObservableValue[] getOutputs() {
|
||||||
return new ObservableValue[]{output};
|
return new ObservableValue[]{output};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class FanInDescription extends ElementTypeDescription {
|
/**
|
||||||
public FanInDescription(Class<? extends Element> clazz) {
|
* The fan in description
|
||||||
|
*/
|
||||||
|
static class FanInDescription extends ElementTypeDescription {
|
||||||
|
FanInDescription(Class<? extends Element> clazz) {
|
||||||
super(clazz);
|
super(clazz);
|
||||||
addAttributes();
|
addAttributes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public FanInDescription(String name, ElementFactory elementFactory) {
|
|
||||||
super(name, elementFactory);
|
|
||||||
addAttributes();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addAttributes() {
|
private void addAttributes() {
|
||||||
addAttribute(AttributeKey.Rotate);
|
addAttribute(AttributeKey.Rotate);
|
||||||
addAttribute(AttributeKey.Bits);
|
addAttribute(AttributeKey.Bits);
|
||||||
|
@ -8,23 +8,24 @@ import java.util.ArrayList;
|
|||||||
/**
|
/**
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public abstract class Function extends FanIn {
|
abstract class Function extends FanIn {
|
||||||
|
|
||||||
private long value;
|
private long value;
|
||||||
|
|
||||||
public Function(int bits) {
|
Function(int bits) {
|
||||||
super(bits);
|
super(bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readInputs() throws NodeException {
|
public void readInputs() throws NodeException {
|
||||||
value = calculate(inputs);
|
value = calculate(getInputs());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeOutputs() throws NodeException {
|
public void writeOutputs() throws NodeException {
|
||||||
output.setValue(value);
|
getOutput().setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract int calculate(ArrayList<ObservableValue> inputs) throws NodeException;
|
protected abstract int calculate(ArrayList<ObservableValue> inputs) throws NodeException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,21 @@ import de.neemann.digital.core.element.ElementTypeDescription;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The NAnd
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public class NAnd extends Function {
|
public class NAnd extends Function {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The NAnd description
|
||||||
|
*/
|
||||||
public static final ElementTypeDescription DESCRIPTION = new FanInDescription(NAnd.class);
|
public static final ElementTypeDescription DESCRIPTION = new FanInDescription(NAnd.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param attributes the attributes
|
||||||
|
*/
|
||||||
public NAnd(ElementAttributes attributes) {
|
public NAnd(ElementAttributes attributes) {
|
||||||
super(attributes.get(AttributeKey.Bits));
|
super(attributes.get(AttributeKey.Bits));
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,21 @@ import de.neemann.digital.core.element.ElementTypeDescription;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The NOr
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public class NOr extends Function {
|
public class NOr extends Function {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The NOr description
|
||||||
|
*/
|
||||||
public static final ElementTypeDescription DESCRIPTION = new FanInDescription(NOr.class);
|
public static final ElementTypeDescription DESCRIPTION = new FanInDescription(NOr.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param attributes the attributes
|
||||||
|
*/
|
||||||
public NOr(ElementAttributes attributes) {
|
public NOr(ElementAttributes attributes) {
|
||||||
super(attributes.get(AttributeKey.Bits));
|
super(attributes.get(AttributeKey.Bits));
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,15 @@ import de.neemann.digital.core.element.ElementTypeDescription;
|
|||||||
import static de.neemann.digital.core.element.PinInfo.input;
|
import static de.neemann.digital.core.element.PinInfo.input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The Not
|
||||||
|
*
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public class Not extends Node implements Element {
|
public class Not extends Node implements Element {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Not description
|
||||||
|
*/
|
||||||
public static final ElementTypeDescription DESCRIPTION = new ElementTypeDescription(Not.class, input("in"))
|
public static final ElementTypeDescription DESCRIPTION = new ElementTypeDescription(Not.class, input("in"))
|
||||||
.addAttribute(AttributeKey.Rotate)
|
.addAttribute(AttributeKey.Rotate)
|
||||||
.addAttribute(AttributeKey.Bits);
|
.addAttribute(AttributeKey.Bits);
|
||||||
@ -24,6 +29,11 @@ public class Not extends Node implements Element {
|
|||||||
private ObservableValue input;
|
private ObservableValue input;
|
||||||
private long value;
|
private long value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param attributes the attributes
|
||||||
|
*/
|
||||||
public Not(ElementAttributes attributes) {
|
public Not(ElementAttributes attributes) {
|
||||||
bits = attributes.get(AttributeKey.Bits);
|
bits = attributes.get(AttributeKey.Bits);
|
||||||
output = new ObservableValue("out", bits);
|
output = new ObservableValue("out", bits);
|
||||||
@ -39,10 +49,6 @@ public class Not extends Node implements Element {
|
|||||||
output.setValue(~value);
|
output.setValue(~value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableValue getOutput() {
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInputs(ObservableValue... inputs) throws NodeException {
|
public void setInputs(ObservableValue... inputs) throws NodeException {
|
||||||
input = inputs[0].addObserverToValue(this).checkBits(bits, this);
|
input = inputs[0].addObserverToValue(this).checkBits(bits, this);
|
||||||
|
@ -9,12 +9,21 @@ import de.neemann.digital.core.element.ElementTypeDescription;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The Or
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public class Or extends Function {
|
public class Or extends Function {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The And description
|
||||||
|
*/
|
||||||
public static final ElementTypeDescription DESCRIPTION = new FanInDescription(Or.class);
|
public static final ElementTypeDescription DESCRIPTION = new FanInDescription(Or.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param attributes the attributes
|
||||||
|
*/
|
||||||
public Or(ElementAttributes attributes) {
|
public Or(ElementAttributes attributes) {
|
||||||
super(attributes.get(AttributeKey.Bits));
|
super(attributes.get(AttributeKey.Bits));
|
||||||
}
|
}
|
||||||
|
@ -8,15 +8,24 @@ import de.neemann.digital.core.element.ElementTypeDescription;
|
|||||||
import static de.neemann.digital.core.element.PinInfo.input;
|
import static de.neemann.digital.core.element.PinInfo.input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The XNOr
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public class XNOr extends XOr {
|
public class XNOr extends XOr {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The XNOr description
|
||||||
|
*/
|
||||||
public static final ElementTypeDescription DESCRIPTION
|
public static final ElementTypeDescription DESCRIPTION
|
||||||
= new ElementTypeDescription(XNOr.class, input("a"), input("b"))
|
= new ElementTypeDescription(XNOr.class, input("a"), input("b"))
|
||||||
.addAttribute(AttributeKey.Rotate)
|
.addAttribute(AttributeKey.Rotate)
|
||||||
.addAttribute(AttributeKey.Bits);
|
.addAttribute(AttributeKey.Bits);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param attributes the attributes
|
||||||
|
*/
|
||||||
public XNOr(ElementAttributes attributes) {
|
public XNOr(ElementAttributes attributes) {
|
||||||
super(attributes);
|
super(attributes);
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,9 @@ import static de.neemann.digital.core.element.PinInfo.input;
|
|||||||
*/
|
*/
|
||||||
public class XOr extends Node implements Element {
|
public class XOr extends Node implements Element {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The XOr description
|
||||||
|
*/
|
||||||
public static final ElementTypeDescription DESCRIPTION
|
public static final ElementTypeDescription DESCRIPTION
|
||||||
= new ElementTypeDescription(XOr.class, input("a"), input("b"))
|
= new ElementTypeDescription(XOr.class, input("a"), input("b"))
|
||||||
.addAttribute(AttributeKey.Rotate)
|
.addAttribute(AttributeKey.Rotate)
|
||||||
@ -27,6 +30,11 @@ public class XOr extends Node implements Element {
|
|||||||
protected ObservableValue b;
|
protected ObservableValue b;
|
||||||
protected long value;
|
protected long value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param attributes the attributes
|
||||||
|
*/
|
||||||
public XOr(ElementAttributes attributes) {
|
public XOr(ElementAttributes attributes) {
|
||||||
bits = attributes.get(AttributeKey.Bits);
|
bits = attributes.get(AttributeKey.Bits);
|
||||||
this.out = new ObservableValue("out", bits);
|
this.out = new ObservableValue("out", bits);
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* The simple boolean operation like and, or and not
|
||||||
|
*
|
||||||
|
* @author hneemann
|
||||||
|
*/
|
||||||
|
package de.neemann.digital.core.basic;
|
@ -47,12 +47,12 @@ public class Multiplexer extends FanIn {
|
|||||||
@Override
|
@Override
|
||||||
public void readInputs() throws NodeException {
|
public void readInputs() throws NodeException {
|
||||||
int n = (int) selector.getValue();
|
int n = (int) selector.getValue();
|
||||||
value = inputs.get(n).getValue();
|
value = getInputs().get(n).getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeOutputs() throws NodeException {
|
public void writeOutputs() throws NodeException {
|
||||||
output.setValue(value);
|
getOutput().setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -85,9 +85,9 @@ public class FlipFlopsTest extends TestCase {
|
|||||||
|
|
||||||
|
|
||||||
FanIn a3 = model.add(new And(attr));
|
FanIn a3 = model.add(new And(attr));
|
||||||
a3.setInputs(nor1.getOutput(), not.getOutput());
|
a3.setInputs(nor1.getOutput(), not.getOutputs()[0]);
|
||||||
FanIn a4 = model.add(new And(attr));
|
FanIn a4 = model.add(new And(attr));
|
||||||
a4.setInputs(nor2.getOutput(), not.getOutput());
|
a4.setInputs(nor2.getOutput(), not.getOutputs()[0]);
|
||||||
|
|
||||||
nor3.setInputs(a3.getOutput(), nor4.getOutput());
|
nor3.setInputs(a3.getOutput(), nor4.getOutput());
|
||||||
nor4.setInputs(a4.getOutput(), nor3.getOutput());
|
nor4.setInputs(a4.getOutput(), nor3.getOutput());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user