Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.Value


    if (dirtyThreads.isEmpty()) return;

    // determine values of affected threads
    HashSet<ThreadBundle> bundles = new HashSet<ThreadBundle>();
    for (WireThread t : dirtyThreads) {
      Value v = getThreadValue(circState, t);
      s.thr_values.put(t, v);
      bundles.addAll(t.getBundles());
    }

    // now propagate values through circuit
    for (ThreadBundle tb : bundles) {
      WireBundle b = tb.b;

      Value bv = null;
      if (!b.isValid() || b.threads == null) {
        ; // do nothing
      } else if (b.threads.length == 1) {
        bv = s.thr_values.get(b.threads[0]);
      } else {
        Value[] tvs = new Value[b.threads.length];
        boolean tvs_valid = true;
        for (int i = 0; i < tvs.length; i++) {
          Value tv = s.thr_values.get(b.threads[i]);
          if (tv == null) { tvs_valid = false; break; }
          tvs[i] = tv;
        }
        if (tvs_valid) bv = Value.create(tvs);
      }
View Full Code Here


      b.addPullValue(PullResistor.getPullValue(instance));
    }
  }

  private Value getThreadValue(CircuitState state, WireThread t) {
    Value ret = Value.UNKNOWN;
    Value pull = Value.UNKNOWN;
    for (ThreadBundle tb : t.getBundles()) {
      for (Location p : tb.b.points) {
        Value val = state.getComponentOutputAt(p);
        if (val != null && val != Value.NIL) {
          ret = ret.combine(val.get(tb.loc));
        }
      }
      Value pullHere = tb.b.getPullValue();
      if (pullHere != Value.UNKNOWN) pull = pull.combine(pullHere);
    }
    if (pull != Value.UNKNOWN) {
      ret = pullValue(ret, pull);
    }
View Full Code Here

     
      if (changedPoints != null) changedPoints.add(state, data.loc);

      // change the information about value
      SetData oldHead = state.causes.get(data.loc);
      Value   oldVal  = computeValue(oldHead);
      SetData newHead = addCause(state, oldHead, data);
      Value   newVal  = computeValue(newHead);

      // if the value at point has changed, propagate it
      if (!newVal.equals(oldVal)) {
        state.markPointAsDirty(data.loc);
      }
    }

    clearDirtyPoints();
View Full Code Here

  //
  void checkComponentEnds(CircuitState state, Component comp) {
    for (EndData end : comp.getEnds()) {
      Location loc    = end.getLocation();
      SetData oldHead = state.causes.get(loc);
      Value   oldVal  = computeValue(oldHead);
      SetData newHead = removeCause(state, oldHead, loc, comp);
      Value   newVal  = computeValue(newHead);
      Value   wireVal = state.getValueByWire(loc);

      if (!newVal.equals(oldVal) || wireVal != null) {
        state.markPointAsDirty(loc);
      }
      if (wireVal != null) state.setValueByWire(loc, Value.NIL);
View Full Code Here

  //
  // static methods
  //
  static Value computeValue(SetData causes) {
    if (causes == null) return Value.NIL;
    Value ret = causes.val;
    for (SetData n = causes.next; n != null; n = n.next) {
      ret = ret.combine(n.val);
    }
    return ret;
  }
View Full Code Here

    }
  }

  @Override
  public void propagate(InstanceState state) {
    Value val = state.getPort(0);
    ClockState q = getState(state);
    if (!val.equals(q.sending)) { // ignore if no change
      state.setPort(0, q.sending, 1);
    }
  }
View Full Code Here

      state = new ClockState();
      circState.setData(comp, state);
    }
    boolean curValue = ticks % (durationHigh + durationLow) < durationLow;
    if (state.clicks % 2 == 1) curValue = !curValue;
    Value desired = (curValue ? Value.FALSE : Value.TRUE);
    if (!state.sending.equals(desired)) {
      state.sending = desired;
      Instance.getInstanceFor(comp).fireInvalidated();
      return true;
    } else {
View Full Code Here

      GraphicsUtil.drawCenteredText(g, "x" + attrs.width.getWidth(),
          bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
    } else {
      PinState state = getState(painter);
      if (attrs.width.getWidth() <= 1) {
        Value receiving = state.receiving;
        g.setColor(receiving.getColor());
        g.fillOval(x + 4, y + 4, 13, 13);
 
        if (attrs.width.getWidth() == 1) {
          g.setColor(Color.WHITE);
          GraphicsUtil.drawCenteredText(g,
View Full Code Here

  }
 
  @Override
  public void propagate(InstanceState state) {
    PinAttributes attrs = (PinAttributes) state.getAttributeSet();
    Value val = state.getPort(0);
 
    PinState q = getState(state);
    if (attrs.type == EndData.OUTPUT_ONLY) {
      q.sending = val;
      q.receiving = val;
      state.setPort(0, Value.createUnknown(attrs.width), 1);
    } else {
      if (!val.isFullyDefined() && !attrs.threeState
          && state.isCircuitRoot()) {
        q.sending = pull2(q.sending, attrs.width);
        q.receiving = pull2(val, attrs.width);
        state.setPort(0, q.sending, 1);
      } else {
        q.receiving = val;
        if (!val.equals(q.sending)) { // ignore if no change
          state.setPort(0, q.sending, 1);
        }
      }
    }
  }
View Full Code Here

  private static PinState getState(InstanceState state) {
    PinAttributes attrs = (PinAttributes) state.getAttributeSet();
    BitWidth width = attrs.width;
    PinState ret = (PinState) state.getData();
    if (ret == null) {
      Value val = attrs.threeState ? Value.UNKNOWN : Value.FALSE;
      if (width.getWidth() > 1) {
        Value[] arr = new Value[width.getWidth()];
        java.util.Arrays.fill(arr, val);
        val = Value.create(arr);
      }
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.