use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Joystick method propagate.
@Override
public void propagate(InstanceState state) {
BitWidth bits = state.getAttributeValue(ATTR_WIDTH);
int dx;
int dy;
State s = (State) state.getData();
if (s == null) {
dx = 0;
dy = 0;
} else {
dx = s.xPos;
dy = s.yPos;
}
int steps = (1 << bits.getWidth()) - 1;
dx = (dx + 14) * steps / 29 + 1;
dy = (dy + 14) * steps / 29 + 1;
if (bits.getWidth() > 4) {
if (dx >= steps / 2)
dx++;
if (dy >= steps / 2)
dy++;
}
state.setPort(0, Value.createKnown(bits, dx), 1);
state.setPort(1, Value.createKnown(bits, dy), 1);
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Adder method propagate.
@Override
public void propagate(InstanceState state) {
// get attributes
BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
// compute outputs
Value a = state.getPortValue(IN0);
Value b = state.getPortValue(IN1);
Value c_in = state.getPortValue(C_IN);
Value[] outs = Adder.computeSum(dataWidth, a, b, c_in);
// propagate them
int delay = (dataWidth.getWidth() + 2) * PER_DELAY;
state.setPort(OUT, outs[0], delay);
state.setPort(C_OUT, outs[1], delay);
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class NotGate method getHDLName.
@Override
public String getHDLName(AttributeSet attrs) {
StringBuffer CompleteName = new StringBuffer();
CompleteName.append(CorrectLabel.getCorrectLabel(this.getName()).toUpperCase());
BitWidth width = attrs.getValue(StdAttr.WIDTH);
if (width.getWidth() > 1)
CompleteName.append("_BUS");
return CompleteName.toString();
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class BitAdder method configurePorts.
private void configurePorts(Instance instance) {
BitWidth inWidth = instance.getAttributeValue(StdAttr.WIDTH);
int inputs = instance.getAttributeValue(NUM_INPUTS).intValue();
int outWidth = computeOutputBits(inWidth.getWidth(), inputs);
int y;
int dy = 10;
switch(inputs) {
case 1:
y = 0;
break;
case 2:
y = -10;
dy = 20;
break;
case 3:
y = -10;
break;
default:
y = ((inputs - 1) / 2) * -10;
}
Port[] ps = new Port[inputs + 1];
ps[0] = new Port(0, 0, Port.OUTPUT, BitWidth.create(outWidth));
ps[0].setToolTip(Strings.getter("bitAdderOutputManyTip"));
for (int i = 0; i < inputs; i++) {
ps[i + 1] = new Port(-40, y + i * dy, Port.INPUT, inWidth);
ps[i + 1].setToolTip(Strings.getter("bitAdderInputTip"));
}
instance.setPorts(ps);
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class BitFinder method configurePorts.
private void configurePorts(Instance instance) {
BitWidth inWidth = instance.getAttributeValue(StdAttr.WIDTH);
int outWidth = computeOutputBits(inWidth.getWidth() - 1);
Port[] ps = new Port[3];
ps[0] = new Port(-20, 20, Port.OUTPUT, BitWidth.ONE);
ps[1] = new Port(0, 0, Port.OUTPUT, BitWidth.create(outWidth));
ps[2] = new Port(-40, 0, Port.INPUT, inWidth);
Object type = instance.getAttributeValue(TYPE);
if (type == HIGH_ZERO) {
ps[0].setToolTip(Strings.getter("bitFinderPresentTip", "0"));
ps[1].setToolTip(Strings.getter("bitFinderIndexHighTip", "0"));
} else if (type == LOW_ZERO) {
ps[0].setToolTip(Strings.getter("bitFinderPresentTip", "0"));
ps[1].setToolTip(Strings.getter("bitFinderIndexLowTip", "0"));
} else if (type == HIGH_ONE) {
ps[0].setToolTip(Strings.getter("bitFinderPresentTip", "1"));
ps[1].setToolTip(Strings.getter("bitFinderIndexHighTip", "1"));
} else {
ps[0].setToolTip(Strings.getter("bitFinderPresentTip", "1"));
ps[1].setToolTip(Strings.getter("bitFinderIndexLowTip", "1"));
}
ps[2].setToolTip(Strings.getter("bitFinderInputTip"));
instance.setPorts(ps);
}
Aggregations