projects
/
Mograsim.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Moved WordAddressableMemoryComponent to new package
[Mograsim.git]
/
net.mograsim.logic.core
/
src
/
net
/
mograsim
/
logic
/
core
/
components
/
ManualSwitch.java
diff --git
a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java
b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java
index
e3ae372
..
26238fe
100644
(file)
--- a/
net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java
+++ b/
net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java
@@
-8,6
+8,7
@@
import net.mograsim.logic.core.LogicObservable;
import net.mograsim.logic.core.LogicObserver;
import net.mograsim.logic.core.timeline.Timeline;
import net.mograsim.logic.core.types.Bit;
import net.mograsim.logic.core.LogicObserver;
import net.mograsim.logic.core.timeline.Timeline;
import net.mograsim.logic.core.types.Bit;
+import net.mograsim.logic.core.types.BitVector;
import net.mograsim.logic.core.wires.Wire.ReadEnd;
import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
import net.mograsim.logic.core.wires.Wire.ReadEnd;
import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
@@
-21,49
+22,55
@@
public class ManualSwitch extends Component implements LogicObservable
{
private Collection<LogicObserver> observers;
private ReadWriteEnd output;
{
private Collection<LogicObserver> observers;
private ReadWriteEnd output;
- private boolean isOn;
public ManualSwitch(Timeline timeline, ReadWriteEnd output)
{
super(timeline);
observers = new ArrayList<>();
public ManualSwitch(Timeline timeline, ReadWriteEnd output)
{
super(timeline);
observers = new ArrayList<>();
- if (output.length() != 1)
- throw new IllegalArgumentException("Switch output can be only a single wire");
this.output = output;
}
this.output = output;
}
- public void switchOn()
+ public void switch
Full
On()
{
{
- setState(
true
);
+ setState(
BitVector.of(Bit.ONE, output.length())
);
}
}
- public void switchOff()
+ public void switch
Full
Off()
{
{
- setState(
false
);
+ setState(
BitVector.of(Bit.ZERO, output.length())
);
}
public void toggle()
{
}
public void toggle()
{
- setState(!isOn);
+ if (isFullOn())
+ switchFullOff();
+ else
+ switchFullOn();
}
}
- public void setState(
boolean isOn
)
+ public void setState(
Bit bit
)
{
{
- if (this.isOn == isOn)
+ setState(BitVector.of(bit));
+ }
+
+ public void setState(BitVector bits)
+ {
+ if (bits.length() != output.length())
+ throw new IllegalArgumentException("Incorrect bit vector length");
+ if (bits.equals(output.getInputValues()))
return;
return;
- this.isOn = isOn;
- output.feedSignals(getValue());
+ output.feedSignals(bits);
notifyObservers();
}
notifyObservers();
}
- public boolean isOn()
+ public boolean is
Full
On()
{
{
- return
isOn
;
+ return
BitVector.of(Bit.ONE, output.length()).equals(output.getInputValues())
;
}
}
- public Bit
getValue
()
+ public Bit
Vector getValues
()
{
{
- return
isOn ? Bit.ONE : Bit.ZERO
;
+ return
output.getInputValues()
;
}
@Override
}
@Override