Search in sources :

Example 36 with BitWidth

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

the class CounterPoker method paint.

/**
 * Draws an indicator that the caret is being selected. Here, we'll draw a
 * red rectangle around the value.
 */
@Override
public void paint(InstancePainter painter) {
    Bounds bds = painter.getBounds();
    BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
    int len = (width.getWidth() + 3) / 4;
    Graphics g = painter.getGraphics();
    g.setColor(Color.RED);
    // width of caret rectangle
    int wid = 7 * len + 2;
    // height of caret rectangle
    int ht = 16;
    g.drawRect(bds.getX() + (bds.getWidth() - wid) / 2, bds.getY() + (bds.getHeight() - ht) / 2, wid, ht);
    g.setColor(Color.BLACK);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Graphics(java.awt.Graphics) Bounds(com.cburch.logisim.data.Bounds)

Example 37 with BitWidth

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

the class GrayCounter method propagate.

@Override
public void propagate(InstanceState state) {
    // This is the same as with SimpleGrayCounter, except that we use the
    // StdAttr.WIDTH attribute to determine the bit width to work with.
    BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
    CounterData cur = CounterData.get(state, width);
    boolean trigger = cur.updateClock(state.getPortValue(0));
    if (trigger)
        cur.setValue(GrayIncrementer.nextGray(cur.getValue()));
    state.setPort(1, cur.getValue(), 9);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Example 38 with BitWidth

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

the class GrayCounter method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    // This is essentially the same as with SimpleGrayCounter, except for
    // the invocation of painter.drawLabel to make the label be drawn.
    painter.drawBounds();
    painter.drawClock(0, Direction.EAST);
    painter.drawPort(1);
    painter.drawLabel();
    if (painter.getShowState()) {
        BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
        CounterData state = CounterData.get(painter, width);
        Bounds bds = painter.getBounds();
        GraphicsUtil.drawCenteredText(painter.getGraphics(), StringUtil.toHexString(width.getWidth(), state.getValue().toIntValue()), bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Bounds(com.cburch.logisim.data.Bounds)

Example 39 with BitWidth

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

the class GrayIncrementer method nextGray.

/*
	 * Note that there are no instance variables. There is only one instance of
	 * this class created, which manages all instances of the component. Any
	 * information associated with individual instances should be handled
	 * through attributes. For GrayIncrementer, each instance has a "bit width"
	 * that it works with, and so we'll have an attribute.
	 */
/**
 * Computes the next gray value in the sequence after prev. This static
 * method just does some bit twiddling; it doesn't have much to do with
 * Logisim except that it manipulates Value and BitWidth objects.
 */
static Value nextGray(Value prev) {
    BitWidth bits = prev.getBitWidth();
    if (!prev.isFullyDefined())
        return Value.createError(bits);
    int x = prev.toIntValue();
    // compute parity of x
    int ct = (x >> 16) ^ x;
    ct = (ct >> 8) ^ ct;
    ct = (ct >> 4) ^ ct;
    ct = (ct >> 2) ^ ct;
    ct = (ct >> 1) ^ ct;
    if ((ct & 1) == 0) {
        // if parity is even, flip 1's bit
        x = x ^ 1;
    } else {
        // else flip bit just above last 1
        // first compute the last 1
        int y = x ^ (x & (x - 1));
        y = (y << 1) & bits.getMask();
        x = (y == 0 ? 0 : x ^ y);
    }
    return Value.createKnown(bits, x);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Example 40 with BitWidth

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

the class ControlledBuffer method propagate.

@Override
public void propagate(InstanceState state) {
    Value control = state.getPortValue(2);
    BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
    if (control == Value.TRUE) {
        Value in = state.getPortValue(1);
        state.setPort(0, isInverter ? in.not() : in, GateAttributes.DELAY);
    } else if (control == Value.ERROR || control == Value.UNKNOWN) {
        state.setPort(0, Value.createError(width), GateAttributes.DELAY);
    } else {
        Value out;
        if (control == Value.UNKNOWN || control == Value.NIL) {
            AttributeSet opts = state.getProject().getOptions().getAttributeSet();
            if (opts.getValue(Options.ATTR_GATE_UNDEFINED).equals(Options.GATE_UNDEFINED_ERROR)) {
                out = Value.createError(width);
            } else {
                out = Value.createUnknown(width);
            }
        } else {
            out = Value.createUnknown(width);
        }
        state.setPort(0, out, GateAttributes.DELAY);
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) AttributeSet(com.cburch.logisim.data.AttributeSet) 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