Skip to content

Commit

Permalink
changed implimentation of split merge to match hardware. ie. if multi…
Browse files Browse the repository at this point in the history
…ple bit are connected to same input just or them. Also connecting two inputs in to split side will cause as error dialogue
  • Loading branch information
sr14978 committed Nov 28, 2016
1 parent 32f370f commit 78841e9
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 11 deletions.
2 changes: 0 additions & 2 deletions src/com/modsim/modules/Link.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ else if (source.canInput() && target.canOutput()) {
// Changes are done
Main.opStack.endCompoundOp();

// Propagate
newLink.targ.setVal(newLink.src.getVal());
Main.sim.propagate(newLink.targ.owner);

return newLink;
}
Expand Down
27 changes: 20 additions & 7 deletions src/com/modsim/modules/SplitMerge.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import java.util.Collections;
import java.util.List;

import javax.swing.JOptionPane;

import com.modsim.modules.ports.BidirPort;
import com.modsim.Main;
import com.modsim.modules.parts.Port;
import com.modsim.res.Colors;
import com.modsim.simulator.PickableEntity;
Expand Down Expand Up @@ -133,12 +136,22 @@ public void propagate() {

// Switch based on propagation direction
if (portA0.wasUpdated() || portA1.wasUpdated()) {
if(portA0.isConnected() && portA1.isConnected())
{
JOptionPane.showMessageDialog(Main.ui.pane, "Error: There must only be one connection to that size of split/merge.");
Port port = portA0.wasUpdated()?portA0:portA1;
synchronized (Main.sim)
{
Main.sim.removeLink(port.link);
}
return;
}
b0_val.setBit(0, a0_val.getBit(0)); // A0-a0
b1_val.setBit(0, a0_val.getBit(1)); // A1-b1
b0_val.setBit(1, a0_val.getBit(1)); // A1-a1

// Resolution of 3-state logic for merges
b3_val.setBit(0, a0_val.getBit(3)); // A3-d0
b3_val.setBit(0, a0_val.getBit(3)); // A3-d0
b3_val.resolveBit(0, a1_val.getBit(1)); // B1-d0

b2_val.setBit(0, a0_val.getBit(2)); // A2-c0
Expand All @@ -151,15 +164,15 @@ else if ( portB0.wasUpdated() || portB1.wasUpdated() ||
portB2.wasUpdated() || portB3.wasUpdated()) {
a0_val.setBit(0, b0_val.getBit(0)); // a0-A0
a0_val.setBit(2, b2_val.getBit(0)); // c0-A2
a0_val.setBit(3, b2_val.getBit(1)); // c1-A3
a1_val.setBit(0, b2_val.getBit(0)); // c0-B0

// Resolution of 3-state logic for merges
a1_val.setBit(1, b2_val.getBit(1)); // c1-B1
a1_val.resolveBit(1, b3_val.getBit(0)); // d0-B1

a0_val.setBit(1, b0_val.getBit(1)); // a1-A1
a0_val.resolveBit(1, b1_val.getBit(0)); // b0-A1
int val = b2_val.getBit(1) | b3_val.getBit(0);
a1_val.setBit(1, val);
a0_val.setBit(3, val);

val = b0_val.getBit(1) | b1_val.getBit(0);
a0_val.setBit(1, val);
}

// Set the values
Expand Down
9 changes: 9 additions & 0 deletions src/com/modsim/modules/ports/BidirPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,13 @@ public boolean hasDirection() {
return !(mode == Mode.MODE_BIDIR);
}

public boolean isConnected() {
BinData data = this.getVal();
for(int i = 0; i<4; i++)
{
if(data.getBit(i)!=BinData.NOCON) return true;
}
return false;
}

}
4 changes: 4 additions & 0 deletions src/com/modsim/simulator/Sim.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import static com.modsim.modules.BaseModule.AvailableModules;
import com.modsim.modules.parts.Port;
import sun.awt.Mutex;

import com.modsim.util.BinData;
import com.modsim.util.CtrlPt;

public class Sim implements Runnable {
Expand Down Expand Up @@ -197,6 +199,8 @@ public void removeLink(Link l) {
synchronized (this) {
links.remove(l);
}
l.src.link = null;
l.targ.setVal(new BinData());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/com/modsim/tools/MakeLinkTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public boolean endLink(int x, int y) {
Main.opStack.beginCompoundOp();
Link l = Link.createLink(source, targ, curve);
if (l != null) {
Main.sim.addLink(l);
Main.sim.addLink(l);
Main.sim.propagate(l.targ.owner);
Main.opStack.pushOp(new CreateOperation(l));
}
Main.opStack.endCompoundOp();
Expand Down
2 changes: 1 addition & 1 deletion src/com/modsim/util/ModuleClipboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ protected void doCopy(List<BaseModule> src, List<BaseModule> destModules, List<L
// Store the new link
if (newLink != null) {
assert newLink.path != oldPort.link.path;

Main.sim.propagate(newLink.targ.owner);
newPort.link = newLink;
destLinks.add(newLink);
}
Expand Down
1 change: 1 addition & 0 deletions src/com/modsim/util/XMLReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ else if (p.ID == targID) {
// Add to the simulation
if (l != null) {
Main.sim.addLink(l);
Main.sim.propagate(l.targ.owner);
}
else {
badLinks++;
Expand Down

0 comments on commit 78841e9

Please sign in to comment.