Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.Value


  }

  @Override
  public void propagate(InstanceState state) {
    int summary = 0;
    Value baseVal = state.getPort(0);
    if (baseVal == null) baseVal = Value.createUnknown(BitWidth.create(4));
    int segs; // each nibble is one segment, in top-down, left-to-right
      // order: middle three nibbles are the three horizontal segments
    switch (baseVal.toIntValue()) {
    case 0:  segs = 0x1110111; break;
    case 1:  segs = 0x0000011; break;
    case 2:  segs = 0x0111110; break;
    case 3:  segs = 0x0011111; break;
    case 4:  segs = 0x1001011; break;
View Full Code Here


    BitWidth data = state.getAttributeValue(StdAttr.WIDTH);
    BitWidth select = state.getAttributeValue(Plexers.ATTR_SELECT);
    Boolean threeState = state.getAttributeValue(Plexers.ATTR_TRISTATE);
    boolean enable = state.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int outputs = 1 << select.getWidth();
    Value en = enable ? state.getPort(outputs + 1) : Value.TRUE;

    // determine output values
    Value others; // the default output
    if (threeState.booleanValue()) {
      others = Value.createUnknown(data);
    } else {
      others = Value.createKnown(data, 0);
    }
    int outIndex = -1; // the special output
    Value out = null;
    if (en == Value.FALSE) {
      Object opt = state.getAttributeValue(Plexers.ATTR_DISABLED);
      Value base = opt == Plexers.DISABLED_ZERO ? Value.FALSE : Value.UNKNOWN;
      others = Value.repeat(base, data.getWidth());
    } else if (en == Value.ERROR && state.isPortConnected(outputs + 1)) {
      others = Value.createError(data);
    } else {
      Value sel = state.getPort(outputs);
      if (sel.isFullyDefined()) {
        outIndex = sel.toIntValue();
        out = state.getPort(outputs + (enable ? 2 : 1));
      } else if (sel.isErrorValue()) {
        others = Value.createError(data);
      } else {
        others = Value.createUnknown(data);
      }
    }
View Full Code Here

      vsPos = 0;
      vs = newV;
    }
    if (oldW != newW) {
      for (int i = 0; i < v.length; i++) {
        Value vi = v[i];
        if (vi.getWidth() != newW) {
          v[i] = vi.extendWidth(newW, Value.FALSE);
        }
      }
      width = newWidth;
    }
  }
View Full Code Here

  @Override
  public void propagate(InstanceState state) {
    int summary = 0;
    for (int i = 0; i < 8; i++) {
      Value val = state.getPort(i);
      if (val == Value.TRUE) summary |= 1 << i;
    }
    Object value = Integer.valueOf(summary);
    InstanceDataSingleton data = (InstanceDataSingleton) state.getData();
    if (data == null) {
View Full Code Here

    instance.setPorts(ports);
  }

  @Override
  public void propagate(InstanceState state) {
    Value control = state.getPort(2);
    BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
    if (control == Value.TRUE) {
      Value in = state.getPort(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);
View Full Code Here

    return Bounds.create(-20, -9, 20, 18);
  }

  @Override
  public void propagate(InstanceState state) {
    Value in = state.getPort(1);
    in = Buffer.repair(state, in);
    state.setPort(0, in, GateAttributes.DELAY);
  }
View Full Code Here

  @Override
  public void propagate(InstanceState state) {
    // compute output
    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
    int bits = dataWidth == null ? 32 : dataWidth.getWidth();
    Value vx = state.getPort(IN0);
    Value vd = state.getPort(IN1);
    Value vy; // y will by x shifted by d
    if (vd.isFullyDefined() && vx.getWidth() == bits) {
      int d = vd.toIntValue();
      Object shift = state.getAttributeValue(ATTR_SHIFT);
      if (d == 0) {
        vy = vx;
View Full Code Here

  //
  static Value repair(InstanceState state, Value v) {
    AttributeSet opts = state.getProject().getOptions().getAttributeSet();
    Object onUndefined = opts.getValue(Options.ATTR_GATE_UNDEFINED);
    boolean errorIfUndefined = onUndefined.equals(Options.GATE_UNDEFINED_ERROR);
    Value repaired;
    if (errorIfUndefined) {
      int vw = v.getWidth();
      BitWidth w = state.getAttributeValue(StdAttr.WIDTH);
      int ww = w.getWidth();
      if (vw == ww && v.isFullyDefined()) return v;
      Value[] vs = new Value[w.getWidth()];
      for (int i = 0; i < vs.length; i++) {
        Value ini = i < vw ? v.get(i) : Value.ERROR;
        vs[i] = ini.isFullyDefined() ? ini : Value.ERROR;
      }
      repaired = Value.create(vs);
    } else {
      repaired = v;
    }
View Full Code Here

      return null;
    }
  }
 
  public Value setLastClock(Value newClock) {
    Value ret = lastClock;
    lastClock = newClock;
    return ret;
  }
View Full Code Here

  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) {
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.