Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.Value


  }

  @Override
  public void paintInstance(InstancePainter painter) {
    InstanceDataSingleton data = (InstanceDataSingleton) painter.getData();
    Value val = data == null ? Value.FALSE : (Value) data.getValue();
    Bounds bds = painter.getBounds().expand(-1);

    Graphics g = painter.getGraphics();
    if (painter.getShowState()) {
      Color onColor = painter.getAttributeValue(Io.ATTR_ON_COLOR);
View Full Code Here


      return (ClockState) super.clone();
    } catch (CloneNotSupportedException e) { return null; }
  }
   
  public boolean updateClock(Value newClock, Object trigger) {
    Value oldClock = lastClock;
    lastClock = newClock;
    if (trigger == null || trigger == StdAttr.TRIG_RISING) {
      return oldClock == Value.FALSE && newClock == Value.TRUE;
    } else if (trigger == StdAttr.TRIG_FALLING) {
      return oldClock == Value.TRUE && newClock == Value.FALSE;
View Full Code Here

        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.getPort(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());
View Full Code Here

  public void propagate(InstanceState state) {
    // get attributes
    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);

    // compute outputs
    Value a = state.getPort(IN0);
    Value b = state.getPort(IN1);
    Value c_in = state.getPort(C_IN);
    Value[] outs = Adder.computeSum(dataWidth, a, b, c_in);

    // propagate them
    int delay = (dataWidth.getWidth() + 2) * PER_DELAY;
    state.setPort(OUT,   outs[0], delay);
View Full Code Here

        return new Value[] { Value.createKnown(width, sum),
          ((sum >> w) & 1) == 0 ? Value.FALSE : Value.TRUE };
      }
    } else {
      Value[] bits = new Value[w];
      Value carry = c_in;
      for (int i = 0; i < w; i++) {
        if (carry == Value.ERROR) {
          bits[i] = Value.ERROR;
        } else if (carry == Value.UNKNOWN) {
          bits[i] = Value.UNKNOWN;
        } else {
          Value ab = a.get(i);
          Value bb = b.get(i);
          if (ab == Value.ERROR || bb == Value.ERROR) {
            bits[i] = Value.ERROR;
            carry = Value.ERROR;
          } else if (ab == Value.UNKNOWN || bb == Value.UNKNOWN) {
            bits[i] = Value.UNKNOWN;
View Full Code Here

  public void propagate(InstanceState state) {
    BitWidth data = state.getAttributeValue(StdAttr.WIDTH);
    BitWidth select = state.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = state.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int inputs = 1 << select.getWidth();
    Value en = enable ? state.getPort(inputs + 1) : Value.TRUE;
    Value out;
    if (en == Value.FALSE) {
      Object opt = state.getAttributeValue(Plexers.ATTR_DISABLED);
      Value base = opt == Plexers.DISABLED_ZERO ? Value.FALSE : Value.UNKNOWN;
      out = Value.repeat(base, data.getWidth());
    } else if (en == Value.ERROR && state.isPortConnected(inputs + 1)) {
      out = Value.createError(data);
    } else {
      Value sel = state.getPort(inputs);
      if (sel.isFullyDefined()) {
        out = state.getPort(sel.toIntValue());
      } else if (sel.isErrorValue()) {
        out = Value.createError(data);
      } else {
        out = Value.createUnknown(data);
      }
    }
View Full Code Here

  public void propagate(InstanceState state) {
    // get attributes
    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);

    // compute outputs
    Value a = state.getPort(IN0);
    Value b = state.getPort(IN1);
    Value upper = state.getPort(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);
View Full Code Here

    int width = state.getAttributeValue(StdAttr.WIDTH).getWidth();
    int outWidth = computeOutputBits(width - 1);
    Object type = state.getAttributeValue(TYPE);

    Value[] bits = state.getPort(2).getAll();
    Value want;
    int i;
    if (type == HIGH_ZERO) {
      want = Value.FALSE;
      for (i = bits.length - 1; i >= 0 && bits[i] == Value.TRUE; i--) { }
    } else if (type == LOW_ZERO) {
      want = Value.FALSE;
      for (i = 0; i < bits.length && bits[i] == Value.TRUE; i++) { }
    } else if (type == HIGH_ONE) {
      want = Value.TRUE;
      for (i = bits.length - 1; i >= 0 && bits[i] == Value.FALSE; i--) { }
    } else {
      want = Value.TRUE;
      for (i = 0; i < bits.length && bits[i] == Value.FALSE; i++) { }
    }
   
    Value present;
    Value index;
    if (i < 0 || i >= bits.length) {
      present = Value.FALSE;
      index = Value.createKnown(BitWidth.create(outWidth), 0);
    } else if (bits[i] == want) {
      present = Value.TRUE;
View Full Code Here

    instance.setPorts(ps);
  }

  @Override
  public void propagate(InstanceState state) {
    Value data = state.getPort(1);
    Value select = state.getPort(2);
    BitWidth groupBits = state.getAttributeValue(GROUP_ATTR);
    Value group;
    if (!select.isFullyDefined()) {
      group = Value.createUnknown(groupBits);
    } else {
      int shift = select.toIntValue() * groupBits.getWidth();
      if (shift >= data.getWidth()) {
View Full Code Here

    // compute the number of 1 bits
    int minCount = 0; // number that are definitely 1
    int maxCount = 0; // number that are definitely not 0 (incl X/Z)
    for (int i = 1; i <= inputs; i++) {
      Value v = state.getPort(i);
      Value[] bits = v.getAll();
      for (int j = 0; j < bits.length; j++) {
        Value b = bits[j];
        if (b == Value.TRUE) minCount++;
        if (b != Value.FALSE) maxCount++;
      }
    }
View Full Code Here

TOP

Related Classes of com.cburch.logisim.data.Value

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.