Search in sources :

Example 61 with BitWidth

use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.

the class Buffer method repair.

// 
// static methods - shared with other classes
// 
static Value repair(InstanceState state, Value v) {
    AttributeSet opts = state.getProject().getOptions().getAttributeSet();
    Object onUndefined = opts.getValue(Options.ATTR_GATE_UNDEFINED);
    boolean errorIfUndefined = onUndefined.equals(Options.GATE_UNDEFINED_ERROR);
    Value repaired;
    if (errorIfUndefined) {
        int vw = v.getWidth();
        BitWidth w = state.getAttributeValue(StdAttr.WIDTH);
        int ww = w.getWidth();
        if (vw == ww && v.isFullyDefined())
            return v;
        Value[] vs = new Value[w.getWidth()];
        for (int i = 0; i < vs.length; i++) {
            Value ini = i < vw ? v.get(i) : Value.ERROR;
            vs[i] = ini.isFullyDefined() ? ini : Value.ERROR;
        }
        repaired = Value.create(vs);
    } else {
        repaired = v;
    }
    Object outType = state.getAttributeValue(GateAttributes.ATTR_OUTPUT);
    return AbstractGate.pullOutput(repaired, outType);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) AttributeSet(com.cburch.logisim.data.AttributeSet) Value(com.cburch.logisim.data.Value)

Example 62 with BitWidth

use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.

the class Comparator method propagate.

@Override
public void propagate(InstanceState state) {
    // get attributes
    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
    // compute outputs
    Value gt = Value.FALSE;
    Value eq = Value.TRUE;
    Value lt = Value.FALSE;
    Value a = state.getPortValue(IN0);
    Value b = state.getPortValue(IN1);
    Value[] ax = a.getAll();
    Value[] bx = b.getAll();
    int maxlen = Math.max(ax.length, bx.length);
    for (int pos = maxlen - 1; pos >= 0; pos--) {
        Value ab = pos < ax.length ? ax[pos] : Value.ERROR;
        Value bb = pos < bx.length ? bx[pos] : Value.ERROR;
        if (pos == ax.length - 1 && ab != bb) {
            Object mode = state.getAttributeValue(MODE_ATTRIBUTE);
            if (mode != UNSIGNED_OPTION) {
                Value t = ab;
                ab = bb;
                bb = t;
            }
        }
        if (ab == Value.ERROR || bb == Value.ERROR) {
            gt = Value.ERROR;
            eq = Value.ERROR;
            lt = Value.ERROR;
            break;
        } else if (ab == Value.UNKNOWN || bb == Value.UNKNOWN) {
            gt = Value.UNKNOWN;
            eq = Value.UNKNOWN;
            lt = Value.UNKNOWN;
            break;
        } else if (ab != bb) {
            eq = Value.FALSE;
            if (ab == Value.TRUE)
                gt = Value.TRUE;
            else
                lt = Value.TRUE;
            break;
        }
    }
    // propagate them
    int delay = (dataWidth.getWidth() + 2) * Adder.PER_DELAY;
    state.setPort(GT, gt, delay);
    state.setPort(EQ, eq, delay);
    state.setPort(LT, lt, delay);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 63 with BitWidth

use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.

the class Divider 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 upper = state.getPortValue(UPPER);
    Value[] outs = Divider.computeResult(dataWidth, a, b, upper);
    // propagate them
    int delay = dataWidth.getWidth() * (dataWidth.getWidth() + 2) * PER_DELAY;
    state.setPort(OUT, outs[0], delay);
    state.setPort(REM, outs[1], delay);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 64 with BitWidth

use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.

the class Negator method propagate.

@Override
public void propagate(InstanceState state) {
    // get attributes
    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
    // compute outputs
    Value in = state.getPortValue(IN);
    Value out;
    if (in.isFullyDefined()) {
        out = Value.createKnown(in.getBitWidth(), -in.toIntValue());
    } else {
        Value[] bits = in.getAll();
        Value fill = Value.FALSE;
        int pos = 0;
        while (pos < bits.length) {
            if (bits[pos] == Value.FALSE) {
                bits[pos] = fill;
            } else if (bits[pos] == Value.TRUE) {
                if (fill != Value.FALSE)
                    bits[pos] = fill;
                pos++;
                break;
            } else if (bits[pos] == Value.ERROR) {
                fill = Value.ERROR;
            } else {
                if (fill == Value.FALSE)
                    fill = bits[pos];
                else
                    bits[pos] = fill;
            }
            pos++;
        }
        while (pos < bits.length) {
            if (bits[pos] == Value.TRUE) {
                bits[pos] = Value.FALSE;
            } else if (bits[pos] == Value.FALSE) {
                bits[pos] = Value.TRUE;
            }
            pos++;
        }
        out = Value.create(bits);
    }
    // propagate them
    int delay = (dataWidth.getWidth() + 2) * Adder.PER_DELAY;
    state.setPort(OUT, out, delay);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 65 with BitWidth

use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.

the class Shifter method configurePorts.

private void configurePorts(Instance instance) {
    BitWidth dataWid = instance.getAttributeValue(StdAttr.WIDTH);
    int data = dataWid == null ? 32 : dataWid.getWidth();
    int shift = 1;
    while ((1 << shift) < data) shift++;
    Port[] ps = new Port[3];
    ps[IN0] = new Port(-40, -10, Port.INPUT, data);
    ps[IN1] = new Port(-40, 10, Port.INPUT, shift);
    ps[OUT] = new Port(0, 0, Port.OUTPUT, data);
    ps[IN0].setToolTip(Strings.getter("shifterInputTip"));
    ps[IN1].setToolTip(Strings.getter("shifterDistanceTip"));
    ps[OUT].setToolTip(Strings.getter("shifterOutputTip"));
    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