Search in sources :

Example 61 with Value

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

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

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

the class NotGate method propagate.

@Override
public void propagate(InstanceState state) {
    Value in = state.getPortValue(1);
    Value out = in.not();
    out = Buffer.repair(state, out);
    state.setPort(0, out, GateAttributes.DELAY);
}
Also used : Value(com.cburch.logisim.data.Value)

Example 64 with Value

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

the class PainterDin method paint.

private static void paint(InstancePainter painter, int width, int height, boolean drawBubble, int dinType) {
    Graphics g = painter.getGraphics();
    int xMid = -width;
    int y0 = -height / 2;
    if (drawBubble) {
        width -= 8;
    }
    int diam = Math.min(height, 2 * width);
    if (dinType == AND) {
        // nothing to do
        ;
    } else if (dinType == OR) {
        paintOrLines(painter, width, height, drawBubble);
    } else if (dinType == XOR || dinType == XNOR) {
        int elen = Math.min(diam / 2 - 10, 20);
        int ex0 = xMid + (diam / 2 - elen) / 2;
        int ex1 = ex0 + elen;
        g.drawLine(ex0, -5, ex1, -5);
        g.drawLine(ex0, 0, ex1, 0);
        g.drawLine(ex0, 5, ex1, 5);
        if (dinType == XOR) {
            int exMid = ex0 + elen / 2;
            g.drawLine(exMid, -8, exMid, 8);
        }
    } else {
        throw new IllegalArgumentException("unrecognized shape");
    }
    GraphicsUtil.switchToWidth(g, 2);
    int x0 = xMid - diam / 2;
    Color oldColor = g.getColor();
    if (painter.getShowState()) {
        Value val = painter.getPortValue(0);
        g.setColor(val.getColor());
    }
    g.drawLine(x0 + diam, 0, 0, 0);
    g.setColor(oldColor);
    if (height <= diam) {
        g.drawArc(x0, y0, diam, diam, -90, 180);
    } else {
        int x1 = x0 + diam;
        int yy0 = -(height - diam) / 2;
        int yy1 = (height - diam) / 2;
        g.drawArc(x0, y0, diam, diam, 0, 90);
        g.drawLine(x1, yy0, x1, yy1);
        g.drawArc(x0, y0 + height - diam, diam, diam, -90, 90);
    }
    g.drawLine(xMid, y0, xMid, y0 + height);
    if (drawBubble) {
        g.fillOval(x0 + diam - 4, -4, 8, 8);
        xMid += 4;
    }
}
Also used : Graphics(java.awt.Graphics) Color(java.awt.Color) Value(com.cburch.logisim.data.Value)

Example 65 with Value

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

the class PainterShaped method paintInputLines.

static void paintInputLines(InstancePainter painter, AbstractGate factory) {
    Location loc = painter.getLocation();
    boolean printView = painter.isPrintView();
    GateAttributes attrs = (GateAttributes) painter.getAttributeSet();
    Direction facing = attrs.facing;
    int inputs = attrs.inputs;
    int negated = attrs.negated;
    int[] lengths = getInputLineLengths(attrs, factory);
    if (painter.getInstance() == null) {
        // only
        for (int i = 0; i < inputs; i++) {
            boolean iNegated = ((negated >> i) & 1) == 1;
            if (iNegated) {
                Location offs = factory.getInputOffset(attrs, i);
                Location loci = loc.translate(offs.getX(), offs.getY());
                Location cent = loci.translate(facing, lengths[i] + 5);
                painter.drawDongle(cent.getX(), cent.getY());
            }
        }
    } else {
        Graphics g = painter.getGraphics();
        Color baseColor = g.getColor();
        GraphicsUtil.switchToWidth(g, 3);
        for (int i = 0; i < inputs; i++) {
            Location offs = factory.getInputOffset(attrs, i);
            Location src = loc.translate(offs.getX(), offs.getY());
            int len = lengths[i];
            if (len != 0 && (!printView || painter.isPortConnected(i + 1))) {
                if (painter.getShowState()) {
                    Value val = painter.getPortValue(i + 1);
                    g.setColor(val.getColor());
                } else {
                    g.setColor(baseColor);
                }
                Location dst = src.translate(facing, len);
                g.drawLine(src.getX(), src.getY(), dst.getX(), dst.getY());
            }
            if (((negated >> i) & 1) == 1) {
                Location cent = src.translate(facing, lengths[i] + 5);
                g.setColor(baseColor);
                painter.drawDongle(cent.getX(), cent.getY());
                GraphicsUtil.switchToWidth(g, 3);
            }
        }
    }
}
Also used : Graphics(java.awt.Graphics) Color(java.awt.Color) Value(com.cburch.logisim.data.Value) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

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