Search in sources :

Example 41 with BitWidth

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);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) InstanceState(com.cburch.logisim.instance.InstanceState)

Example 42 with BitWidth

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);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 43 with BitWidth

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();
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Example 44 with BitWidth

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);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Port(com.cburch.logisim.instance.Port)

Example 45 with BitWidth

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);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Port(com.cburch.logisim.instance.Port)

Aggregations

BitWidth (com.cburch.logisim.data.BitWidth)106 Value (com.cburch.logisim.data.Value)30 Bounds (com.cburch.logisim.data.Bounds)21 Direction (com.cburch.logisim.data.Direction)20 Location (com.cburch.logisim.data.Location)16 Graphics (java.awt.Graphics)15 Port (com.cburch.logisim.instance.Port)12 EndData (com.cburch.logisim.comp.EndData)3 AttributeSet (com.cburch.logisim.data.AttributeSet)3 Font (java.awt.Font)3 FontMetrics (java.awt.FontMetrics)3 AttributeOption (com.cburch.logisim.data.AttributeOption)2 Graphics2D (java.awt.Graphics2D)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 WidthIncompatibilityData (com.cburch.logisim.circuit.WidthIncompatibilityData)1 Attribute (com.cburch.logisim.data.Attribute)1 Instance (com.cburch.logisim.instance.Instance)1 InstanceState (com.cburch.logisim.instance.InstanceState)1 Dimension (java.awt.Dimension)1