projects
/
Mograsim.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Wires now can have a name
[Mograsim.git]
/
net.mograsim.logic.core
/
src
/
net
/
mograsim
/
logic
/
core
/
wires
/
Wire.java
diff --git
a/net.mograsim.logic.core/src/net/mograsim/logic/core/wires/Wire.java
b/net.mograsim.logic.core/src/net/mograsim/logic/core/wires/Wire.java
index
12f0f8a
..
bae4cb4
100644
(file)
--- a/
net.mograsim.logic.core/src/net/mograsim/logic/core/wires/Wire.java
+++ b/
net.mograsim.logic.core/src/net/mograsim/logic/core/wires/Wire.java
@@
-21,18
+21,25
@@
import net.mograsim.logic.core.types.BitVector.BitVectorMutator;
*/
public class Wire
{
*/
public class Wire
{
+ public final String name;
private BitVector values;
public final int travelTime;
private BitVector values;
public final int travelTime;
- private List<ReadEnd> attached = new ArrayList<
ReadEnd
>();
+ private List<ReadEnd> attached = new ArrayList<>();
public final int length;
public final int length;
-
private List<ReadWriteEnd> inputs = new ArrayList<ReadWriteEnd
>();
-
private
Timeline timeline;
+
List<ReadWriteEnd> inputs = new ArrayList<
>();
+ Timeline timeline;
public Wire(Timeline timeline, int length, int travelTime)
public Wire(Timeline timeline, int length, int travelTime)
+ {
+ this(timeline, length, travelTime, null);
+ }
+
+ public Wire(Timeline timeline, int length, int travelTime, String name)
{
if (length < 1)
throw new IllegalArgumentException(
String.format("Tried to create an array of wires with length %d, but a length of less than 1 makes no sense.", length));
{
if (length < 1)
throw new IllegalArgumentException(
String.format("Tried to create an array of wires with length %d, but a length of less than 1 makes no sense.", length));
+ this.name = name;
this.timeline = timeline;
this.length = length;
this.travelTime = travelTime;
this.timeline = timeline;
this.length = length;
this.travelTime = travelTime;
@@
-61,12
+68,12
@@
public class Wire
{
if (values.equals(newValues))
return;
{
if (values.equals(newValues))
return;
-
BitVector oldValues = values;
+
//
BitVector oldValues = values;
values = newValues;
values = newValues;
- notifyObservers(
oldValues
);
+ notifyObservers();
}
}
-
private
void recalculate()
+ void recalculate()
{
switch (inputs.size())
{
{
switch (inputs.size())
{
@@
-174,20
+181,19
@@
public class Wire
*
* @author Fabian Stemmler
*/
*
* @author Fabian Stemmler
*/
-
private
void attachEnd(ReadEnd end)
+ void attachEnd(ReadEnd end)
{
attached.add(end);
}
{
attached.add(end);
}
-
private
void detachEnd(ReadEnd end)
+ void detachEnd(ReadEnd end)
{
attached.remove(end);
}
{
attached.remove(end);
}
- private void notifyObservers(
BitVector oldValues
)
+ private void notifyObservers()
{
{
- for (ReadEnd o : attached)
- o.update(oldValues);
+ attached.forEach(r -> r.update());
}
/**
}
/**
@@
-206,7
+212,7
@@
public class Wire
return new ReadEnd();
}
return new ReadEnd();
}
-
private
void registerInput(ReadWriteEnd toRegister)
+ void registerInput(ReadWriteEnd toRegister)
{
inputs.add(toRegister);
}
{
inputs.add(toRegister);
}
@@
-220,15
+226,15
@@
public class Wire
*/
public class ReadEnd implements LogicObservable
{
*/
public class ReadEnd implements LogicObservable
{
- private List<LogicObserver> observers = new ArrayList<
LogicObserver
>();
+ private List<LogicObserver> observers = new ArrayList<>();
-
private
ReadEnd()
+ ReadEnd()
{
super();
Wire.this.attachEnd(this);
}
{
super();
Wire.this.attachEnd(this);
}
- public void update(
BitVector oldValues
)
+ public void update()
{
notifyObservers();
}
{
notifyObservers();
}
@@
-345,11
+351,16
@@
public class Wire
observers.add(ob);
}
observers.add(ob);
}
+ @Override
+ public void deregisterObserver(LogicObserver ob)
+ {
+ observers.remove(ob);
+ }
+
@Override
public void notifyObservers()
{
@Override
public void notifyObservers()
{
- for (LogicObserver ob : observers)
- ob.update(this);
+ observers.forEach(ob -> ob.update(this));
}
}
}
}
@@
-358,7
+369,7
@@
public class Wire
private boolean open;
private BitVector inputValues;
private boolean open;
private BitVector inputValues;
-
private
ReadWriteEnd()
+ ReadWriteEnd()
{
super();
open = true;
{
super();
open = true;
@@
-487,7
+498,8
@@
public class Wire
@Override
public String toString()
{
@Override
public String toString()
{
- return String.format("wire 0x%08x value: %s inputs: %s", hashCode(), values, inputs);
+ String name = this.name == null ? String.format("0x%08x", hashCode()) : this.name;
+ return String.format("wire %s value: %s inputs: %s", name, values, inputs);
}
public static ReadEnd[] extractEnds(Wire[] w)
}
public static ReadEnd[] extractEnds(Wire[] w)