Search in sources :

Example 16 with BitWidth

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

the class Decoder method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    Object selectLoc = painter.getAttributeValue(Plexers.ATTR_SELECT_LOC);
    BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = painter.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int selMult = selectLoc == Plexers.SELECT_TOP_RIGHT ? -1 : 1;
    int outputs = 1 << select.getWidth();
    // draw stubs for select and enable ports
    GraphicsUtil.switchToWidth(g, 3);
    boolean vertical = facing == Direction.NORTH || facing == Direction.SOUTH;
    int dx = vertical ? selMult : 0;
    int dy = vertical ? 0 : -selMult;
    if (outputs == 2) {
        // draw select wire
        if (painter.getShowState()) {
            g.setColor(painter.getPortValue(outputs).getColor());
        }
        Location pt = painter.getInstance().getPortLocation(outputs);
        g.drawLine(pt.getX(), pt.getY(), pt.getX() + 2 * dx, pt.getY() + 2 * dy);
    }
    if (enable) {
        Location en = painter.getInstance().getPortLocation(outputs + 1);
        int len = outputs == 2 ? 6 : 4;
        if (painter.getShowState()) {
            g.setColor(painter.getPortValue(outputs + 1).getColor());
        }
        g.drawLine(en.getX(), en.getY(), en.getX() + len * dx, en.getY() + len * dy);
    }
    GraphicsUtil.switchToWidth(g, 1);
    // draw a circle indicating where the select input is located
    Multiplexer.drawSelectCircle(g, bds, painter.getInstance().getPortLocation(outputs));
    // draw "0"
    int x0;
    int y0;
    int halign;
    if (facing == Direction.WEST) {
        x0 = 3;
        y0 = 15 + (outputs == 2 ? 5 : 0);
        halign = GraphicsUtil.H_LEFT;
    } else if (facing == Direction.NORTH) {
        x0 = 10 + (outputs == 2 ? 5 : 0);
        y0 = 15;
        halign = GraphicsUtil.H_CENTER;
    } else if (facing == Direction.SOUTH) {
        x0 = 10 + (outputs == 2 ? 5 : 0);
        y0 = bds.getHeight() - 3;
        halign = GraphicsUtil.H_CENTER;
    } else {
        x0 = bds.getWidth() - 3;
        y0 = 15 + (outputs == 2 ? 5 : 0);
        halign = GraphicsUtil.H_RIGHT;
    }
    g.setColor(Color.GRAY);
    GraphicsUtil.drawText(g, "0", bds.getX() + x0, bds.getY() + y0, halign, GraphicsUtil.V_BASELINE);
    // draw trapezoid, "Decd", and ports
    g.setColor(Color.BLACK);
    if (outputs == 2) {
        if (facing == Direction.EAST || facing == Direction.WEST) {
            Plexers.drawTrapezoid(g, Bounds.create(bds.getX(), bds.getY() + 5, bds.getWidth(), bds.getHeight() - 10), facing.reverse(), 10);
        } else {
            Plexers.drawTrapezoid(g, Bounds.create(bds.getX() + 5, bds.getY(), bds.getWidth() - 10, bds.getHeight()), facing.reverse(), 10);
        }
    } else {
        Plexers.drawTrapezoid(g, bds, facing.reverse(), 20);
    }
    GraphicsUtil.drawCenteredText(g, "Decd", bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
    painter.drawPorts();
}
Also used : Graphics(java.awt.Graphics) BitWidth(com.cburch.logisim.data.BitWidth) Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 17 with BitWidth

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

the class BitExtender method propagate.

@Override
public void propagate(InstanceState state) {
    Value in = state.getPortValue(1);
    BitWidth wout = state.getAttributeValue(ATTR_OUT_WIDTH);
    String type = getType(state.getAttributeSet());
    Value extend;
    if (type.equals("one")) {
        extend = Value.TRUE;
    } else if (type.equals("sign")) {
        int win = in.getWidth();
        extend = win > 0 ? in.get(win - 1) : Value.ERROR;
    } else if (type.equals("input")) {
        extend = state.getPortValue(2);
        if (extend.getWidth() != 1)
            extend = Value.ERROR;
    } else {
        extend = Value.FALSE;
    }
    Value out = in.extendWidth(wout.getWidth(), extend);
    state.setPort(0, out, 1);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 18 with BitWidth

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

the class Constant method getOffsetBounds.

@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
    Direction facing = attrs.getValue(StdAttr.FACING);
    BitWidth width = attrs.getValue(StdAttr.WIDTH);
    int chars = (width.getWidth() + 3) / 4;
    Bounds ret = null;
    if (facing == Direction.EAST) {
        switch(chars) {
            case 1:
                ret = Bounds.create(-16, -8, 16, 16);
                break;
            case 2:
                ret = Bounds.create(-16, -8, 16, 16);
                break;
            case 3:
                ret = Bounds.create(-26, -8, 26, 16);
                break;
            case 4:
                ret = Bounds.create(-36, -8, 36, 16);
                break;
            case 5:
                ret = Bounds.create(-46, -8, 46, 16);
                break;
            case 6:
                ret = Bounds.create(-56, -8, 56, 16);
                break;
            case 7:
                ret = Bounds.create(-66, -8, 66, 16);
                break;
            case 8:
                ret = Bounds.create(-76, -8, 76, 16);
                break;
        }
    } else if (facing == Direction.WEST) {
        switch(chars) {
            case 1:
                ret = Bounds.create(0, -8, 16, 16);
                break;
            case 2:
                ret = Bounds.create(0, -8, 16, 16);
                break;
            case 3:
                ret = Bounds.create(0, -8, 26, 16);
                break;
            case 4:
                ret = Bounds.create(0, -8, 36, 16);
                break;
            case 5:
                ret = Bounds.create(0, -8, 46, 16);
                break;
            case 6:
                ret = Bounds.create(0, -8, 56, 16);
                break;
            case 7:
                ret = Bounds.create(0, -8, 66, 16);
                break;
            case 8:
                ret = Bounds.create(0, -8, 76, 16);
                break;
        }
    } else if (facing == Direction.SOUTH) {
        switch(chars) {
            case 1:
                ret = Bounds.create(-8, -16, 16, 16);
                break;
            case 2:
                ret = Bounds.create(-8, -16, 16, 16);
                break;
            case 3:
                ret = Bounds.create(-13, -16, 26, 16);
                break;
            case 4:
                ret = Bounds.create(-18, -16, 36, 16);
                break;
            case 5:
                ret = Bounds.create(-23, -16, 46, 16);
                break;
            case 6:
                ret = Bounds.create(-28, -16, 56, 16);
                break;
            case 7:
                ret = Bounds.create(-33, -16, 66, 16);
                break;
            case 8:
                ret = Bounds.create(-38, -16, 76, 16);
                break;
        }
    } else if (facing == Direction.NORTH) {
        switch(chars) {
            case 1:
                ret = Bounds.create(-8, 0, 16, 16);
                break;
            case 2:
                ret = Bounds.create(-8, 0, 16, 16);
                break;
            case 3:
                ret = Bounds.create(-13, 0, 26, 16);
                break;
            case 4:
                ret = Bounds.create(-18, 0, 36, 16);
                break;
            case 5:
                ret = Bounds.create(-23, 0, 46, 16);
                break;
            case 6:
                ret = Bounds.create(-28, 0, 56, 16);
                break;
            case 7:
                ret = Bounds.create(-33, 0, 66, 16);
                break;
            case 8:
                ret = Bounds.create(-38, 0, 76, 16);
                break;
        }
    }
    if (ret == null) {
        throw new IllegalArgumentException("unrecognized arguments " + facing + " " + width);
    }
    return ret;
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction)

Example 19 with BitWidth

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

the class ConstantConfigurator method getMaximumValue.

@Override
public int getMaximumValue(AttributeSet attrs) {
    BitWidth width = attrs.getValue(StdAttr.WIDTH);
    int ret = width.getMask();
    if (ret >= 0) {
        return ret;
    } else {
        return Integer.MAX_VALUE;
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Example 20 with BitWidth

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

the class Register method propagate.

@Override
public void propagate(InstanceState state) {
    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
    Object triggerType = state.getAttributeValue(StdAttr.TRIGGER);
    RegisterData data = (RegisterData) state.getData();
    if (data == null) {
        data = new RegisterData(dataWidth);
        state.setData(data);
    }
    boolean triggered = data.updateClock(state.getPortValue(CK), triggerType);
    if (state.getPortValue(CLR) == Value.TRUE) {
        data.value = Value.createKnown(dataWidth, 0);
    } else if (triggered && state.getPortValue(EN) != Value.FALSE) {
        Value in = state.getPortValue(IN);
        data.value = in;
    }
    state.setPort(OUT, data.value, DELAY);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

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