Search in sources :

Example 26 with Value

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

the class GateFunctions method computeExactlyOne.

static Value computeExactlyOne(Value[] inputs, int numInputs) {
    int width = inputs[0].getWidth();
    Value[] ret = new Value[width];
    for (int i = 0; i < width; i++) {
        int count = 0;
        for (int j = 0; j < numInputs; j++) {
            Value v = inputs[j].get(i);
            if (v == Value.TRUE) {
                count++;
            } else if (v == Value.FALSE) {
                // do nothing
                ;
            } else {
                count = -1;
                break;
            }
        }
        if (count < 0) {
            ret[i] = Value.ERROR;
        } else if (count == 1) {
            ret[i] = Value.TRUE;
        } else {
            ret[i] = Value.FALSE;
        }
    }
    return Value.create(ret);
}
Also used : Value(com.cburch.logisim.data.Value)

Example 27 with Value

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

the class RGBLed method propagate.

@Override
public void propagate(InstanceState state) {
    int summary = 0;
    for (int i = 0; i < 3; i++) {
        Value val = state.getPortValue(i);
        if (val == Value.TRUE)
            summary |= 1 << i;
    }
    Object value = Integer.valueOf(summary);
    InstanceDataSingleton data = (InstanceDataSingleton) state.getData();
    if (data == null) {
        state.setData(new InstanceDataSingleton(value));
    } else {
        data.setValue(value);
    }
}
Also used : Value(com.cburch.logisim.data.Value) InstanceDataSingleton(com.cburch.logisim.instance.InstanceDataSingleton)

Example 28 with Value

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

the class SevenSegment method propagate.

@Override
public void propagate(InstanceState state) {
    int summary = 0;
    for (int i = 0; i < 8; i++) {
        Value val = state.getPortValue(i);
        if (val == Value.TRUE)
            summary |= 1 << i;
    }
    Object value = Integer.valueOf(summary);
    InstanceDataSingleton data = (InstanceDataSingleton) state.getData();
    if (data == null) {
        state.setData(new InstanceDataSingleton(value));
    } else {
        data.setValue(value);
    }
}
Also used : Value(com.cburch.logisim.data.Value) InstanceDataSingleton(com.cburch.logisim.instance.InstanceDataSingleton)

Example 29 with Value

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

the class Tty method propagate.

@Override
public void propagate(InstanceState circState) {
    Object trigger = circState.getAttributeValue(StdAttr.EDGE_TRIGGER);
    TtyState state = getTtyState(circState);
    Value clear = circState.getPortValue(CLR);
    Value clock = circState.getPortValue(CK);
    Value enable = circState.getPortValue(WE);
    Value in = circState.getPortValue(IN);
    synchronized (state) {
        Value lastClock = state.setLastClock(clock);
        if (clear == Value.TRUE) {
            state.clear();
        } else if (enable != Value.FALSE) {
            boolean go;
            if (trigger == StdAttr.TRIG_FALLING) {
                go = lastClock == Value.TRUE && clock == Value.FALSE;
            } else {
                go = lastClock == Value.FALSE && clock == Value.TRUE;
            }
            if (go)
                state.add(in.isFullyDefined() ? (char) in.toIntValue() : '?');
        }
    }
}
Also used : Value(com.cburch.logisim.data.Value)

Example 30 with Value

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

the class Button method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    Bounds bds = painter.getBounds();
    int x = bds.getX();
    int y = bds.getY();
    int w = bds.getWidth();
    int h = bds.getHeight();
    Value val;
    if (painter.getShowState()) {
        InstanceDataSingleton data = (InstanceDataSingleton) painter.getData();
        val = data == null ? Value.FALSE : (Value) data.getValue();
    } else {
        val = Value.FALSE;
    }
    Color color = painter.getAttributeValue(Io.ATTR_COLOR);
    if (!painter.shouldDrawColor()) {
        int hue = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
        color = new Color(hue, hue, hue);
    }
    Graphics g = painter.getGraphics();
    int depress;
    if (val == Value.TRUE) {
        x += DEPTH;
        y += DEPTH;
        Object labelLoc = painter.getAttributeValue(Io.ATTR_LABEL_LOC);
        if (labelLoc == Io.LABEL_CENTER || labelLoc == Direction.NORTH || labelLoc == Direction.WEST) {
            depress = DEPTH;
        } else {
            depress = 0;
        }
        Object facing = painter.getAttributeValue(StdAttr.FACING);
        if (facing == Direction.NORTH || facing == Direction.WEST) {
            Location p = painter.getLocation();
            int px = p.getX();
            int py = p.getY();
            GraphicsUtil.switchToWidth(g, Wire.WIDTH);
            g.setColor(Value.TRUE_COLOR);
            if (facing == Direction.NORTH)
                g.drawLine(px, py, px, py + 10);
            else
                g.drawLine(px, py, px + 10, py);
            GraphicsUtil.switchToWidth(g, 1);
        }
        g.setColor(color);
        g.fillRect(x, y, w - DEPTH, h - DEPTH);
        g.setColor(Color.BLACK);
        g.drawRect(x, y, w - DEPTH, h - DEPTH);
    } else {
        depress = 0;
        int[] xp = new int[] { x, x + w - DEPTH, x + w, x + w, x + DEPTH, x };
        int[] yp = new int[] { y, y, y + DEPTH, y + h, y + h, y + h - DEPTH };
        g.setColor(color.darker());
        g.fillPolygon(xp, yp, xp.length);
        g.setColor(color);
        g.fillRect(x, y, w - DEPTH, h - DEPTH);
        g.setColor(Color.BLACK);
        g.drawRect(x, y, w - DEPTH, h - DEPTH);
        g.drawLine(x + w - DEPTH, y + h - DEPTH, x + w, y + h);
        g.drawPolygon(xp, yp, xp.length);
    }
    g.translate(depress, depress);
    painter.drawLabel();
    g.translate(-depress, -depress);
    painter.drawPorts();
}
Also used : Graphics(java.awt.Graphics) Bounds(com.cburch.logisim.data.Bounds) Color(java.awt.Color) Value(com.cburch.logisim.data.Value) InstanceDataSingleton(com.cburch.logisim.instance.InstanceDataSingleton) 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