removed obsolete constructor from ObservableValue.java

This commit is contained in:
hneemann 2018-03-05 17:47:09 +01:00
parent 8d4ce9bcc2
commit 694584157c
18 changed files with 69 additions and 59 deletions

View File

@ -30,40 +30,16 @@ public class ObservableValue extends Observable implements PinDescription {
private String pinNumber; private String pinNumber;
/** /**
* Creates a new instance * Creates a new instance.
* *
* @param name the name of this value * @param name the name of this value
* @param bits the number of bits * @param bits the number of bits
*/ */
public ObservableValue(String name, int bits) { public ObservableValue(String name, int bits) {
this(name, bits, 0); this.name = name;
}
/**
* Creates a new instance.
*
* @param name the name of this value
* @param bits the number of bits
* @param highZ if true this value can be a high impedance value
*/
public ObservableValue(String name, int bits, boolean highZ) {
this(name, bits, highZ ? -1 : 0);
}
/**
* Creates a new instance.
*
* @param name the name of this value
* @param bits the number of bits
* @param highZ if true this value can be a high impedance value
*/
public ObservableValue(String name, int bits, long highZ) {
super();
this.bits = bits; this.bits = bits;
mask = Bits.mask(bits); mask = Bits.mask(bits);
this.highZ = highZ & mask;
signedFlag = Bits.signedFlagMask(bits); signedFlag = Bits.signedFlagMask(bits);
this.name = name;
} }

View File

@ -52,14 +52,15 @@ public class In implements Element {
*/ */
public In(ElementAttributes attributes) { public In(ElementAttributes attributes) {
InValue value = attributes.get(Keys.INPUT_DEFAULT); InValue value = attributes.get(Keys.INPUT_DEFAULT);
boolean highZ = attributes.get(Keys.IS_HIGH_Z) || value.isHighZ();
pinNumber = attributes.get(Keys.PINNUMBER); pinNumber = attributes.get(Keys.PINNUMBER);
output = new ObservableValue("out", attributes.get(Keys.BITS), highZ).setPinDescription(DESCRIPTION).setPinNumber(pinNumber); output = new ObservableValue("out", attributes.get(Keys.BITS))
.setPinDescription(DESCRIPTION)
.setPinNumber(pinNumber);
boolean highZ = attributes.get(Keys.IS_HIGH_Z) || value.isHighZ();
if (highZ) if (highZ)
output.setToHighZ(); output.setToHighZ().setBidirectional();
else else
output.setValue(value.getValue()); output.setValue(value.getValue());
if (highZ) output.setBidirectional();
label = attributes.getCleanLabel(); label = attributes.getCleanLabel();
format = attributes.get(Keys.INT_FORMAT); format = attributes.get(Keys.INT_FORMAT);
} }

View File

@ -60,8 +60,11 @@ public class RAMDualAccess extends Node implements Element, RAMInterface {
public RAMDualAccess(ElementAttributes attr) { public RAMDualAccess(ElementAttributes attr) {
super(true); super(true);
bits = attr.get(Keys.BITS); bits = attr.get(Keys.BITS);
out1 = new ObservableValue("1D", bits, true).setPinDescription(DESCRIPTION); out1 = new ObservableValue("1D", bits)
out2 = new ObservableValue("2D", bits).setPinDescription(DESCRIPTION); .setToHighZ()
.setPinDescription(DESCRIPTION);
out2 = new ObservableValue("2D", bits)
.setPinDescription(DESCRIPTION);
addrBits = attr.get(Keys.ADDR_BITS); addrBits = attr.get(Keys.ADDR_BITS);
size = 1 << addrBits; size = 1 << addrBits;
memory = new DataField(size); memory = new DataField(size);

View File

@ -68,7 +68,9 @@ public class RAMDualPort extends Node implements Element, RAMInterface {
* @return the output value * @return the output value
*/ */
protected ObservableValue createOutput() { protected ObservableValue createOutput() {
return new ObservableValue("D", bits, true).setPinDescription(DESCRIPTION); return new ObservableValue("D", bits)
.setToHighZ()
.setPinDescription(DESCRIPTION);
} }
@Override @Override

View File

@ -66,7 +66,10 @@ public class RAMSinglePortSel extends Node implements Element, RAMInterface {
size = 1 << addrBits; size = 1 << addrBits;
memory = createDataField(attr, size); memory = createDataField(attr, size);
label = attr.getCleanLabel(); label = attr.getCleanLabel();
dataOut = new ObservableValue("D", bits, true).setPinDescription(DESCRIPTION).setBidirectional(); dataOut = new ObservableValue("D", bits)
.setToHighZ()
.setPinDescription(DESCRIPTION)
.setBidirectional();
} }
/** /**

View File

@ -61,7 +61,9 @@ public class ROM extends Node implements Element, ROMInterface {
*/ */
public ROM(ElementAttributes attr) { public ROM(ElementAttributes attr) {
dataBits = attr.get(Keys.BITS); dataBits = attr.get(Keys.BITS);
output = new ObservableValue("D", dataBits, true).setPinDescription(DESCRIPTION); output = new ObservableValue("D", dataBits)
.setToHighZ()
.setPinDescription(DESCRIPTION);
data = attr.get(Keys.DATA); data = attr.get(Keys.DATA);
addrBits = attr.get(Keys.ADDR_BITS); addrBits = attr.get(Keys.ADDR_BITS);
autoLoad = attr.get(Keys.AUTO_RELOAD_ROM); autoLoad = attr.get(Keys.AUTO_RELOAD_ROM);

View File

@ -36,8 +36,12 @@ public class Diode implements Element, NodeInterface {
* @param attr the elements attributes * @param attr the elements attributes
*/ */
public Diode(ElementAttributes attr) { public Diode(ElementAttributes attr) {
cathode = new ObservableValue("cathode", 1, true).setBidirectional(); cathode = new ObservableValue("cathode", 1)
anode = new ObservableValue("anode", 1, true).setBidirectional(); .setToHighZ()
.setBidirectional();
anode = new ObservableValue("anode", 1)
.setToHighZ()
.setBidirectional();
blown = attr.get(Keys.BLOWN); blown = attr.get(Keys.BLOWN);
} }

View File

@ -47,7 +47,10 @@ public class DiodeForward implements Element, NodeInterface {
* @param requiredResistor resistor needed at the output net * @param requiredResistor resistor needed at the output net
*/ */
protected DiodeForward(ElementAttributes attr, ElementTypeDescription description, PinDescription.PullResistor requiredResistor) { protected DiodeForward(ElementAttributes attr, ElementTypeDescription description, PinDescription.PullResistor requiredResistor) {
output = new ObservableValue("out", 1, true).setPinDescription(description).setBidirectional(); output = new ObservableValue("out", 1)
.setToHighZ()
.setPinDescription(description)
.setBidirectional();
this.requiredResistor = requiredResistor; this.requiredResistor = requiredResistor;
blown = attr.get(Keys.BLOWN); blown = attr.get(Keys.BLOWN);
if (blown) if (blown)

View File

@ -57,7 +57,8 @@ public class PullDown implements Element {
private final PullResistor res; private final PullResistor res;
PullObservableValue(int bits, PullResistor res) { PullObservableValue(int bits, PullResistor res) {
super("out", bits, true); super("out", bits);
setToHighZ();
this.res = res; this.res = res;
} }

View File

@ -73,8 +73,8 @@ public class Switch implements Element, NodeInterface {
public Switch(ElementAttributes attr, boolean closed, String out1, String out2) { public Switch(ElementAttributes attr, boolean closed, String out1, String out2) {
bits = attr.getBits(); bits = attr.getBits();
this.closed = closed; this.closed = closed;
output1 = new ObservableValue(out1, bits, true).setBidirectional().setToHighZ(); output1 = new ObservableValue(out1, bits).setBidirectional().setToHighZ();
output2 = new ObservableValue(out2, bits, true).setBidirectional().setToHighZ(); output2 = new ObservableValue(out2, bits).setBidirectional().setToHighZ();
} }
@Override @Override

View File

@ -47,13 +47,15 @@ public class BusSplitter extends Node implements Element {
public BusSplitter(ElementAttributes attr) { public BusSplitter(ElementAttributes attr) {
ObservableValues.Builder builder = new ObservableValues.Builder(); ObservableValues.Builder builder = new ObservableValues.Builder();
bits = attr.getBits(); bits = attr.getBits();
commonOut = new ObservableValue("D", bits, true) commonOut = new ObservableValue("D", bits)
.setToHighZ()
.setBidirectional() .setBidirectional()
.setPinDescription(DESCRIPTION); .setPinDescription(DESCRIPTION);
builder.add(commonOut); builder.add(commonOut);
out = new ObservableValue[bits]; out = new ObservableValue[bits];
for (int i = 0; i < bits; i++) { for (int i = 0; i < bits; i++) {
out[i] = new ObservableValue("D" + i, 1, true) out[i] = new ObservableValue("D" + i, 1)
.setToHighZ()
.setBidirectional() .setBidirectional()
.setDescription(Lang.get("elem_BusSplitter_pin_D_N", i)); .setDescription(Lang.get("elem_BusSplitter_pin_D_N", i));
builder.add(out[i]); builder.add(out[i]);

View File

@ -45,7 +45,9 @@ public class Driver extends Node implements Element {
*/ */
public Driver(ElementAttributes attributes) { public Driver(ElementAttributes attributes) {
bits = attributes.get(Keys.BITS); bits = attributes.get(Keys.BITS);
output = new ObservableValue("out", bits, true).setPinDescription(DESCRIPTION); output = new ObservableValue("out", bits)
.setToHighZ()
.setPinDescription(DESCRIPTION);
} }
@Override @Override

View File

@ -29,7 +29,9 @@ public final class CommonBusValue extends ObservableValue implements NodeInterfa
} }
CommonBusValue(int bits, BusModelStateObserver obs, PullResistor resistor, ObservableValue[] inputs, File origin) { CommonBusValue(int bits, BusModelStateObserver obs, PullResistor resistor, ObservableValue[] inputs, File origin) {
super("commonBusOut", bits, resistor.equals(PullResistor.none)); super("commonBusOut", bits);
if (resistor.equals(PullResistor.none))
setToHighZ();
this.obs = obs; this.obs = obs;
this.resistor = resistor; this.resistor = resistor;
this.inputs = inputs; this.inputs = inputs;

View File

@ -86,7 +86,8 @@ public class GraphicCard extends Node implements Element, RAMInterface {
addrBits = aBits; addrBits = aBits;
memory = new DataField(size); memory = new DataField(size);
dataOut = new ObservableValue("D", bits, true) dataOut = new ObservableValue("D", bits)
.setToHighZ()
.setPinDescription(DESCRIPTION) .setPinDescription(DESCRIPTION)
.setBidirectional(); .setBidirectional();
} }

View File

@ -45,7 +45,9 @@ public class Keyboard extends Node implements Element {
* @param attributes the attributes * @param attributes the attributes
*/ */
public Keyboard(ElementAttributes attributes) { public Keyboard(ElementAttributes attributes) {
data = new ObservableValue("D", 16, true).setPinDescription(DESCRIPTION); data = new ObservableValue("D", 16)
.setToHighZ()
.setPinDescription(DESCRIPTION);
label = attributes.getCleanLabel(); label = attributes.getCleanLabel();
} }

View File

@ -63,16 +63,18 @@ public class ObservableValueTest extends TestCase {
} }
public void testNoChange() { public void testNoChange() {
ObservableValue v = new ObservableValue("z", 4, 3).addObserverToValue(Assert::fail); ObservableValue v = new ObservableValue("z", 4)
v.set(0,3); .setToHighZ()
v.set(1,3); .addObserverToValue(Assert::fail);
v.set(2,3); v.set(0,15);
v.set(3,3); v.set(1,15);
v.set(2,15);
v.set(3,15);
} }
public void testChange() { public void testChange() {
ChangeDetector cd = new ChangeDetector(); ChangeDetector cd = new ChangeDetector();
ObservableValue v = new ObservableValue("z", 4, 3).addObserverToValue(cd); ObservableValue v = new ObservableValue("z", 4).addObserverToValue(cd);
v.set(0, 2); v.set(0, 2);
assertTrue(cd.isChanged()); assertTrue(cd.isChanged());
v.set(2, 2); v.set(2, 2);

View File

@ -18,8 +18,10 @@ import junit.framework.TestCase;
public class DataBusTest extends TestCase { public class DataBusTest extends TestCase {
public void testSimple() throws PinException, NodeException { public void testSimple() throws PinException, NodeException {
ObservableValue a = new ObservableValue("a", 4, true); ObservableValue a = new ObservableValue("a", 4)
ObservableValue b = new ObservableValue("b", 4, true); .setToHighZ();
ObservableValue b = new ObservableValue("b", 4)
.setToHighZ();
Model m = new Model(); Model m = new Model();

View File

@ -22,7 +22,8 @@ import static de.neemann.digital.core.ObservableValues.ovs;
public class SplitterHighZTest extends TestCase { public class SplitterHighZTest extends TestCase {
public void testHighZError() throws NodeException, PinException { public void testHighZError() throws NodeException, PinException {
ObservableValue a = new ObservableValue("a", 1, true); ObservableValue a = new ObservableValue("a", 1)
.setToHighZ();
ObservableValue b = new ObservableValue("b", 1); ObservableValue b = new ObservableValue("b", 1);
Splitter splitter = new Splitter(new ElementAttributes() Splitter splitter = new Splitter(new ElementAttributes()
@ -43,7 +44,8 @@ public class SplitterHighZTest extends TestCase {
} }
public void testHighZEnabled() throws NodeException, PinException { public void testHighZEnabled() throws NodeException, PinException {
ObservableValue a = new ObservableValue("a", 2, true); ObservableValue a = new ObservableValue("a", 2)
.setToHighZ();
Splitter splitter = new Splitter(new ElementAttributes() Splitter splitter = new Splitter(new ElementAttributes()
.set(Keys.INPUT_SPLIT, "2") .set(Keys.INPUT_SPLIT, "2")