Search in sources :

Example 36 with Value

use of com.cburch.logisim.data.Value 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 37 with Value

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

the class Multiplier 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 = Multiplier.computeProduct(dataWidth, a, b, c_in);
    // propagate them
    int delay = dataWidth.getWidth() * (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 38 with Value

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

the class Shifter method propagate.

@Override
public void propagate(InstanceState state) {
    // compute output
    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
    int bits = dataWidth == null ? 32 : dataWidth.getWidth();
    Value vx = state.getPortValue(IN0);
    Value vd = state.getPortValue(IN1);
    // y will by x shifted by d
    Value vy;
    if (vd.isFullyDefined() && vx.getWidth() == bits) {
        int d = vd.toIntValue();
        Object shift = state.getAttributeValue(ATTR_SHIFT);
        if (d == 0) {
            vy = vx;
        } else if (vx.isFullyDefined()) {
            int x = vx.toIntValue();
            int y;
            if (shift == SHIFT_LOGICAL_RIGHT) {
                y = x >>> d;
            } else if (shift == SHIFT_ARITHMETIC_RIGHT) {
                if (d >= bits)
                    d = bits - 1;
                y = x >> d | ((x << (32 - bits)) >> (32 - bits + d));
            } else if (shift == SHIFT_ROLL_RIGHT) {
                if (d >= bits)
                    d -= bits;
                y = (x >>> d) | (x << (bits - d));
            } else if (shift == SHIFT_ROLL_LEFT) {
                if (d >= bits)
                    d -= bits;
                y = (x << d) | (x >>> (bits - d));
            } else {
                // SHIFT_LOGICAL_LEFT
                y = x << d;
            }
            vy = Value.createKnown(dataWidth, y);
        } else {
            Value[] x = vx.getAll();
            Value[] y = new Value[bits];
            if (shift == SHIFT_LOGICAL_RIGHT) {
                if (d >= bits)
                    d = bits;
                System.arraycopy(x, d, y, 0, bits - d);
                Arrays.fill(y, bits - d, bits, Value.FALSE);
            } else if (shift == SHIFT_ARITHMETIC_RIGHT) {
                if (d >= bits)
                    d = bits;
                System.arraycopy(x, d, y, 0, x.length - d);
                Arrays.fill(y, bits - d, y.length, x[bits - 1]);
            } else if (shift == SHIFT_ROLL_RIGHT) {
                if (d >= bits)
                    d -= bits;
                System.arraycopy(x, d, y, 0, bits - d);
                System.arraycopy(x, 0, y, bits - d, d);
            } else if (shift == SHIFT_ROLL_LEFT) {
                if (d >= bits)
                    d -= bits;
                System.arraycopy(x, x.length - d, y, 0, d);
                System.arraycopy(x, 0, y, d, bits - d);
            } else {
                // SHIFT_LOGICAL_LEFT
                if (d >= bits)
                    d = bits;
                Arrays.fill(y, 0, d, Value.FALSE);
                System.arraycopy(x, 0, y, d, bits - d);
            }
            vy = Value.create(y);
        }
    } else {
        vy = Value.createError(dataWidth);
    }
    // propagate them
    int delay = dataWidth.getWidth() * (3 * Adder.PER_DELAY);
    state.setPort(OUT, vy, delay);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 39 with Value

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

the class Subtractor method propagate.

@Override
public void propagate(InstanceState state) {
    // get attributes
    BitWidth data = state.getAttributeValue(StdAttr.WIDTH);
    // compute outputs
    Value a = state.getPortValue(IN0);
    Value b = state.getPortValue(IN1);
    Value b_in = state.getPortValue(B_IN);
    if (b_in == Value.UNKNOWN || b_in == Value.NIL)
        b_in = Value.FALSE;
    Value[] outs = Adder.computeSum(data, a, b.not(), b_in.not());
    // propagate them
    int delay = (data.getWidth() + 4) * Adder.PER_DELAY;
    state.setPort(OUT, outs[0], delay);
    state.setPort(B_OUT, outs[1].not(), delay);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 40 with Value

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

the class TtyInterface method displayTableRow.

private static void displayTableRow(ArrayList<Value> prevOutputs, ArrayList<Value> curOutputs) {
    boolean shouldPrint = false;
    if (prevOutputs == null) {
        shouldPrint = true;
    } else {
        for (int i = 0; i < curOutputs.size(); i++) {
            Value a = prevOutputs.get(i);
            Value b = curOutputs.get(i);
            if (!a.equals(b)) {
                shouldPrint = true;
                break;
            }
        }
    }
    if (shouldPrint) {
        for (int i = 0; i < curOutputs.size(); i++) {
            if (i != 0)
                // OK
                System.out.print("\t");
            // OK
            System.out.print(curOutputs.get(i));
        }
        // OK
        System.out.println();
    }
}
Also used : Value(com.cburch.logisim.data.Value)

Aggregations

Value (com.cburch.logisim.data.Value)89 BitWidth (com.cburch.logisim.data.BitWidth)30 Graphics (java.awt.Graphics)15 Location (com.cburch.logisim.data.Location)9 Color (java.awt.Color)8 Bounds (com.cburch.logisim.data.Bounds)7 InstanceDataSingleton (com.cburch.logisim.instance.InstanceDataSingleton)7 AttributeSet (com.cburch.logisim.data.AttributeSet)6 InstanceState (com.cburch.logisim.instance.InstanceState)6 Direction (com.cburch.logisim.data.Direction)3 Instance (com.cburch.logisim.instance.Instance)3 Port (com.cburch.logisim.instance.Port)3 CircuitState (com.cburch.logisim.circuit.CircuitState)2 Component (com.cburch.logisim.comp.Component)2 FailException (com.cburch.logisim.data.FailException)2 TestException (com.cburch.logisim.data.TestException)2 Dimension (java.awt.Dimension)2 FontMetrics (java.awt.FontMetrics)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2