Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.BitWidth


    instance.setPorts(ps);
  }

  @Override
  public void propagate(InstanceState state) {
    BitWidth select = state.getAttributeValue(Plexers.ATTR_SELECT);
    int n = 1 << select.getWidth();
    boolean enabled = state.getPort(n + EN_IN) != Value.FALSE;
   
    int out = -1;
    Value outDefault;
    if (enabled) {
      outDefault = Value.createUnknown(select);
      for (int i = n - 1; i >= 0; i--) {
        if (state.getPort(i) == Value.TRUE) {
          out = i;
          break;
        }
      }
    } else {
      Object opt = state.getAttributeValue(Plexers.ATTR_DISABLED);
      Value base = opt == Plexers.DISABLED_ZERO ? Value.FALSE : Value.UNKNOWN;
      outDefault = Value.repeat(base, select.getWidth());
    }
    if (out < 0) {
      state.setPort(n + OUT, outDefault, Plexers.DELAY);
      state.setPort(n + EN_OUT, enabled ? Value.TRUE : Value.FALSE, Plexers.DELAY);
      state.setPort(n + GS, Value.FALSE, Plexers.DELAY);
View Full Code Here


    // draw contents
    if (painter.getShowState()) {
      MemState state = getState(painter);
      state.paint(painter.getGraphics(), bds.getX(), bds.getY());
    } else {
      BitWidth addr = painter.getAttributeValue(ADDR_ATTR);
      int addrBits = addr.getWidth();
      int bytes = 1 << addrBits;
      String label;
      if (this instanceof Rom) {
        if (addrBits >= 30) {
          label = StringUtil.format(Strings.get("romGigabyteLabel"), ""
View Full Code Here

  }

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

    // compute outputs
    Value in = state.getPort(IN);
    Value out;
    if (in.isFullyDefined()) {
      out = Value.createKnown(in.getBitWidth(), -in.toIntValue());
    } else {
      Value[] bits = in.getAll();
      Value fill = Value.FALSE;
      int pos = 0;
      while (pos < bits.length) {
        if (bits[pos] == Value.FALSE) {
          bits[pos] = fill;
        } else if (bits[pos] == Value.TRUE) {
          if (fill != Value.FALSE) bits[pos] = fill;
          pos++;
          break;
        } else if (bits[pos] == Value.ERROR) {
          fill = Value.ERROR;
        } else {
          if (fill == Value.FALSE) fill = bits[pos];
          else bits[pos] = fill;
        }
        pos++;
      }
      while (pos < bits.length) {
        if (bits[pos] == Value.TRUE) {
          bits[pos] = Value.FALSE;
        } else if (bits[pos] == Value.FALSE) {
          bits[pos] = Value.TRUE;
        }
        pos++;
      }
      out = Value.create(bits);
    }

    // propagate them
    int delay = (dataWidth.getWidth() + 2) * Adder.PER_DELAY;
    state.setPort(OUT, out, delay);
  }
View Full Code Here

    if (data == null) {
      data = new RegisterData();
      state.setData(data);
    }

    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
    Object triggerType = state.getAttributeValue(StdAttr.TRIGGER);
    boolean triggered = data.updateClock(state.getPort(CK), triggerType);

    if (state.getPort(CLR) == Value.TRUE) {
      data.value = 0;
View Full Code Here

  @Override
  public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();
    RegisterData state = (RegisterData) painter.getData();
    BitWidth widthVal = painter.getAttributeValue(StdAttr.WIDTH);
    int width = widthVal == null ? 8 : widthVal.getWidth();

    // determine text to draw in label
    String a;
    String b = null;
    if (painter.getShowState()) {
      int val = state == null ? 0 : state.value;
      String str = StringUtil.toHexString(width, val);
      if (str.length() <= 4) {
        a = str;
      } else {
        int split = str.length() - 4;
        a = str.substring(0, split);
        b = str.substring(split);
      }
    } else {
      a = Strings.get("registerLabel");
      b = Strings.get("registerWidthLabel", "" + widthVal.getWidth());
    }

    // draw boundary, label
    painter.drawBounds();
    painter.drawLabel();
View Full Code Here

  }

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

    // compute outputs
    Value gt = Value.FALSE;
    Value eq = Value.TRUE;
    Value lt = Value.FALSE;

    Value a = state.getPort(IN0);
    Value b = state.getPort(IN1);
    Value[] ax = a.getAll();
    Value[] bx = b.getAll();
    int maxlen = Math.max(ax.length, bx.length);
    for (int pos = maxlen - 1; pos >= 0; pos--) {
      Value ab = pos < ax.length ? ax[pos] : Value.ERROR;
      Value bb = pos < bx.length ? bx[pos] : Value.ERROR;
      if (pos == ax.length - 1 && ab != bb) {
        Object mode = state.getAttributeValue(MODE_ATTRIBUTE);
        if (mode != UNSIGNED_OPTION) {
          Value t = ab;
          ab = bb;
          bb = t;
        }
      }

      if (ab == Value.ERROR || bb == Value.ERROR) {
        gt = Value.ERROR;
        eq = Value.ERROR;
        lt = Value.ERROR;
        break;
      } else if (ab == Value.UNKNOWN || bb == Value.UNKNOWN) {
        gt = Value.UNKNOWN;
        eq = Value.UNKNOWN;
        lt = Value.UNKNOWN;
        break;
      } else if (ab != bb) {
        eq = Value.FALSE;
        if (ab == Value.TRUE) gt = Value.TRUE;
        else                 lt = Value.TRUE;
        break;
      }
    }

    // propagate them
    int delay = (dataWidth.getWidth() + 2) * Adder.PER_DELAY;
    state.setPort(GT, gt, delay);
    state.setPort(EQ, eq, delay);
    state.setPort(LT, lt, delay);
  }
View Full Code Here

  }

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

    // compute outputs
    Value a = state.getPort(IN0);
    Value b = state.getPort(IN1);
    Value b_in = state.getPort(B_IN);
    if (b_in == Value.UNKNOWN || b_in == Value.NIL) b_in = Value.FALSE;
    Value[] outs = Adder.computeSum(data, a, b.not(), b_in.not());

    // propagate them
    int delay = (data.getWidth() + 4) * Adder.PER_DELAY;
    state.setPort(OUT,   outs[0],       delay);
    state.setPort(B_OUT, outs[1].not(), delay);
  }
View Full Code Here

    return AttributeSets.fixedSet(ATTRIBUTES, DEFAULTS);
  }

  @Override
  MemState getState(InstanceState state) {
    BitWidth addrBits = state.getAttributeValue(ADDR_ATTR);
    BitWidth dataBits = state.getAttributeValue(DATA_ATTR);

    RamState myState = (RamState) state.getData();
    if (myState == null) {
      MemContents contents = MemContents.create(addrBits.getWidth(), dataBits.getWidth());
      Instance instance = state.getInstance();
      myState = new RamState(instance, contents, new MemListener(instance));
      state.setData(myState);
    } else {
      myState.setRam(state.getInstance());
View Full Code Here

    return myState;
  }

  @Override
  MemState getState(Instance instance, CircuitState state) {
    BitWidth addrBits = instance.getAttributeValue(ADDR_ATTR);
    BitWidth dataBits = instance.getAttributeValue(DATA_ATTR);

    RamState myState = (RamState) instance.getData(state);
    if (myState == null) {
      MemContents contents = MemContents.create(addrBits.getWidth(), dataBits.getWidth());
      myState = new RamState(instance, contents, new MemListener(instance));
      instance.setData(state, myState);
    } else {
      myState.setRam(instance);
    }
View Full Code Here

  }

  @Override
  public void propagate(InstanceState state) {
    RamState myState = (RamState) getState(state);
    BitWidth dataBits = state.getAttributeValue(DATA_ATTR);
    Object busVal = state.getAttributeValue(ATTR_BUS);
    boolean asynch = busVal == null ? false : busVal.equals(BUS_ASYNCH);
    boolean separate = busVal == null ? false : busVal.equals(BUS_SEPARATE);

    Value addrValue = state.getPort(ADDR);
View Full Code Here

TOP

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

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.