Search in sources :

Example 81 with BitWidth

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

the class Counter method getOffsetBounds.

@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
    BitWidth widthVal = attrs.getValue(StdAttr.WIDTH);
    int width = widthVal == null ? 8 : widthVal.getWidth();
    return Bounds.create(0, 0, SymbolWidth(width) + 40, 110 + 20 * width);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Example 82 with BitWidth

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

the class Counter method DrawControl.

private void DrawControl(InstancePainter painter, int xpos, int ypos) {
    Graphics g = painter.getGraphics();
    GraphicsUtil.switchToWidth(g, 2);
    BitWidth widthVal = painter.getAttributeValue(StdAttr.WIDTH);
    int width = widthVal == null ? 8 : widthVal.getWidth();
    g.drawLine(xpos + 20, ypos, xpos + 20 + SymbolWidth(width), ypos);
    g.drawLine(xpos + 20, ypos, xpos + 20, ypos + 100);
    g.drawLine(xpos + 20 + SymbolWidth(width), ypos, xpos + 20 + SymbolWidth(width), ypos + 100);
    g.drawLine(xpos + 20, ypos + 100, xpos + 30, ypos + 100);
    g.drawLine(xpos + 10 + SymbolWidth(width), ypos + 100, xpos + 20 + SymbolWidth(width), ypos + 100);
    g.drawLine(xpos + 30, ypos + 100, xpos + 30, ypos + 110);
    g.drawLine(xpos + 10 + SymbolWidth(width), ypos + 100, xpos + 10 + SymbolWidth(width), ypos + 110);
    /* Draw clock entry symbols */
    painter.drawClockSymbol(xpos + 20, ypos + 80);
    painter.drawClockSymbol(xpos + 20, ypos + 90);
    /* Draw Label */
    int max = painter.getAttributeValue(ATTR_MAX).intValue();
    boolean IsCTRm = (max == painter.getAttributeValue(StdAttr.WIDTH).getMask());
    Object onGoal = painter.getAttributeValue(ATTR_ON_GOAL);
    IsCTRm |= onGoal == ON_GOAL_CONT;
    String Label = (IsCTRm) ? "CTR" + Integer.toString(painter.getAttributeValue(StdAttr.WIDTH).getWidth()) : "CTR DIV0x" + Integer.toHexString(max);
    GraphicsUtil.drawCenteredText(g, Label, xpos + (SymbolWidth(width) / 2) + 20, ypos + 5);
    GraphicsUtil.switchToWidth(g, 2);
    /* Draw Reset Input */
    g.drawLine(xpos, ypos + 20, xpos + 20, ypos + 20);
    GraphicsUtil.drawText(g, "R", xpos + 30, ypos + 20, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    painter.drawPort(CLR);
    /* Draw Load Input */
    g.drawLine(xpos, ypos + 30, xpos + 20, ypos + 30);
    g.drawLine(xpos + 5, ypos + 40, xpos + 12, ypos + 40);
    g.drawLine(xpos + 5, ypos + 30, xpos + 5, ypos + 40);
    g.drawOval(xpos + 12, ypos + 36, 8, 8);
    g.fillOval(xpos + 2, ypos + 27, 6, 6);
    painter.drawPort(LD);
    GraphicsUtil.drawText(g, "M2 [count]", xpos + 30, ypos + 40, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    GraphicsUtil.drawText(g, "M1 [load]", xpos + 30, ypos + 30, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    /* Draw UpDn input */
    g.drawLine(xpos, ypos + 50, xpos + 20, ypos + 50);
    g.drawLine(xpos + 5, ypos + 60, xpos + 12, ypos + 60);
    g.drawLine(xpos + 5, ypos + 50, xpos + 5, ypos + 60);
    g.drawOval(xpos + 12, ypos + 56, 8, 8);
    g.fillOval(xpos + 2, ypos + 47, 6, 6);
    GraphicsUtil.drawText(g, "M3 [up]", xpos + 30, ypos + 50, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    GraphicsUtil.drawText(g, "M4 [down]", xpos + 30, ypos + 60, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    painter.drawPort(UD);
    /* Draw Enable Port */
    g.drawLine(xpos, ypos + 70, xpos + 20, ypos + 70);
    GraphicsUtil.drawText(g, "G5", xpos + 30, ypos + 70, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    painter.drawPort(EN);
    /* Draw Clock */
    boolean inverted = painter.getAttributeValue(StdAttr.EDGE_TRIGGER).equals(StdAttr.TRIG_FALLING);
    int xend = (inverted) ? xpos + 12 : xpos + 20;
    g.drawLine(xpos, ypos + 80, xend, ypos + 80);
    g.drawLine(xpos + 5, ypos + 90, xend, ypos + 90);
    g.drawLine(xpos + 5, ypos + 80, xpos + 5, ypos + 90);
    g.fillOval(xpos + 2, ypos + 77, 6, 6);
    if (inverted) {
        g.drawOval(xend, ypos + 76, 8, 8);
        g.drawOval(xend, ypos + 86, 8, 8);
    }
    GraphicsUtil.drawText(g, "2,3,5+/C6", xpos + 30, ypos + 80, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    GraphicsUtil.drawText(g, "2,4,5-", xpos + 30, ypos + 90, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    painter.drawPort(CK);
    /* Draw Carry */
    g.drawLine(xpos + 20 + SymbolWidth(width), ypos + 50, xpos + 40 + SymbolWidth(width), ypos + 50);
    g.drawLine(xpos + 20 + SymbolWidth(width), ypos + 60, xpos + 35 + SymbolWidth(width), ypos + 60);
    g.drawLine(xpos + 35 + SymbolWidth(width), ypos + 50, xpos + 35 + SymbolWidth(width), ypos + 60);
    g.fillOval(xpos + 32 + SymbolWidth(width), ypos + 47, 6, 6);
    String MaxVal = "3CT=0x" + Integer.toHexString(painter.getAttributeValue(ATTR_MAX).intValue()).toUpperCase();
    GraphicsUtil.drawText(g, MaxVal, xpos + 17 + SymbolWidth(width), ypos + 50, GraphicsUtil.H_RIGHT, GraphicsUtil.V_CENTER);
    GraphicsUtil.drawText(g, "4CT=0", xpos + 17 + SymbolWidth(width), ypos + 60, GraphicsUtil.H_RIGHT, GraphicsUtil.V_CENTER);
    painter.drawPort(CARRY);
    GraphicsUtil.switchToWidth(g, 1);
    /* Draw counter Value */
    RegisterData state = (RegisterData) painter.getData();
    if (painter.getShowState() && (state != null)) {
        int len = (width + 3) / 4;
        int xcenter = SymbolWidth(width) - 25;
        Value val = state.value;
        if (val.isFullyDefined())
            g.setColor(Color.LIGHT_GRAY);
        else if (val.isErrorValue())
            g.setColor(Color.RED);
        else
            g.setColor(Color.BLUE);
        g.fillRect(xpos + xcenter - len * 4, ypos + 22, len * 8, 16);
        String Value = "";
        if (val.isFullyDefined()) {
            g.setColor(Color.DARK_GRAY);
            Value = StringUtil.toHexString(width, val.toIntValue()).toUpperCase();
        } else {
            g.setColor(Color.YELLOW);
            for (int i = 0; i < StringUtil.toHexString(width, val.toIntValue()).length(); i++) Value = (val.isUnknown()) ? Value.concat("?") : Value.concat("!");
        }
        GraphicsUtil.drawText(g, Value, xpos + xcenter - len * 4 + 1, ypos + 30, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
        g.setColor(Color.BLACK);
    }
}
Also used : Graphics(java.awt.Graphics) BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 83 with BitWidth

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

the class CounterAttributes method setValue.

@SuppressWarnings("unchecked")
@Override
public <V> void setValue(Attribute<V> attr, V value) {
    Object oldValue = base.getValue(attr);
    if (oldValue == null ? value == null : oldValue.equals(value))
        return;
    Integer newMax = null;
    if (attr == StdAttr.WIDTH) {
        BitWidth oldWidth = base.getValue(StdAttr.WIDTH);
        BitWidth newWidth = (BitWidth) value;
        int oldW = oldWidth.getWidth();
        int newW = newWidth.getWidth();
        Integer oldValObj = base.getValue(Counter.ATTR_MAX);
        int oldVal = oldValObj.intValue();
        base.setValue(StdAttr.WIDTH, newWidth);
        if (newW > oldW) {
            newMax = Integer.valueOf(newWidth.getMask());
        } else {
            int v = oldVal & newWidth.getMask();
            if (v != oldVal) {
                Integer newValObj = Integer.valueOf(v);
                base.setValue(Counter.ATTR_MAX, newValObj);
                fireAttributeValueChanged(Counter.ATTR_MAX, newValObj, null);
            }
        }
        fireAttributeValueChanged(StdAttr.WIDTH, newWidth, null);
    } else if (attr == Counter.ATTR_MAX) {
        int oldVal = base.getValue(Counter.ATTR_MAX).intValue();
        BitWidth width = base.getValue(StdAttr.WIDTH);
        int newVal = ((Integer) value).intValue() & width.getMask();
        if (newVal != oldVal) {
            V val = (V) Integer.valueOf(newVal);
            value = val;
        }
    }
    base.setValue(attr, value);
    fireAttributeValueChanged(attr, value, (V) oldValue);
    if (newMax != null) {
        base.setValue(Counter.ATTR_MAX, newMax);
        fireAttributeValueChanged(Counter.ATTR_MAX, newMax, null);
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Example 84 with BitWidth

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

the class CounterPoker method keyTyped.

@Override
public void keyTyped(InstanceState state, KeyEvent e) {
    int val = Character.digit(e.getKeyChar(), 16);
    if (val < 0)
        return;
    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
    if (dataWidth == null)
        dataWidth = BitWidth.create(8);
    curValue = (curValue * 16 + val) & dataWidth.getMask();
    RegisterData data = (RegisterData) state.getData();
    data.value = Value.createKnown(dataWidth, curValue);
    state.fireInvalidated();
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Example 85 with BitWidth

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

the class ShiftRegisterLogger method getLogValue.

@Override
public Value getLogValue(InstanceState state, Object option) {
    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
    if (dataWidth == null)
        dataWidth = BitWidth.create(0);
    ShiftRegisterData data = (ShiftRegisterData) state.getData();
    if (data == null) {
        return Value.createKnown(dataWidth, 0);
    } else {
        int index = option == null ? 0 : ((Integer) option).intValue();
        return data.get(index);
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

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