Skip to content

Commit 78841e9

Browse files
committed
changed implimentation of split merge to match hardware. ie. if multiple bit are connected to same input just or them. Also connecting two inputs in to split side will cause as error dialogue
1 parent 32f370f commit 78841e9

7 files changed

Lines changed: 37 additions & 11 deletions

File tree

src/com/modsim/modules/Link.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@ else if (source.canInput() && target.canOutput()) {
167167
// Changes are done
168168
Main.opStack.endCompoundOp();
169169

170-
// Propagate
171170
newLink.targ.setVal(newLink.src.getVal());
172-
Main.sim.propagate(newLink.targ.owner);
173171

174172
return newLink;
175173
}

src/com/modsim/modules/SplitMerge.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
import java.util.Collections;
99
import java.util.List;
1010

11+
import javax.swing.JOptionPane;
12+
1113
import com.modsim.modules.ports.BidirPort;
14+
import com.modsim.Main;
1215
import com.modsim.modules.parts.Port;
1316
import com.modsim.res.Colors;
1417
import com.modsim.simulator.PickableEntity;
@@ -133,12 +136,22 @@ public void propagate() {
133136

134137
// Switch based on propagation direction
135138
if (portA0.wasUpdated() || portA1.wasUpdated()) {
139+
if(portA0.isConnected() && portA1.isConnected())
140+
{
141+
JOptionPane.showMessageDialog(Main.ui.pane, "Error: There must only be one connection to that size of split/merge.");
142+
Port port = portA0.wasUpdated()?portA0:portA1;
143+
synchronized (Main.sim)
144+
{
145+
Main.sim.removeLink(port.link);
146+
}
147+
return;
148+
}
136149
b0_val.setBit(0, a0_val.getBit(0)); // A0-a0
137150
b1_val.setBit(0, a0_val.getBit(1)); // A1-b1
138151
b0_val.setBit(1, a0_val.getBit(1)); // A1-a1
139152

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

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

157169
// Resolution of 3-state logic for merges
158-
a1_val.setBit(1, b2_val.getBit(1)); // c1-B1
159-
a1_val.resolveBit(1, b3_val.getBit(0)); // d0-B1
160-
161-
a0_val.setBit(1, b0_val.getBit(1)); // a1-A1
162-
a0_val.resolveBit(1, b1_val.getBit(0)); // b0-A1
170+
int val = b2_val.getBit(1) | b3_val.getBit(0);
171+
a1_val.setBit(1, val);
172+
a0_val.setBit(3, val);
173+
174+
val = b0_val.getBit(1) | b1_val.getBit(0);
175+
a0_val.setBit(1, val);
163176
}
164177

165178
// Set the values

src/com/modsim/modules/ports/BidirPort.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,13 @@ public boolean hasDirection() {
107107
return !(mode == Mode.MODE_BIDIR);
108108
}
109109

110+
public boolean isConnected() {
111+
BinData data = this.getVal();
112+
for(int i = 0; i<4; i++)
113+
{
114+
if(data.getBit(i)!=BinData.NOCON) return true;
115+
}
116+
return false;
117+
}
118+
110119
}

src/com/modsim/simulator/Sim.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import static com.modsim.modules.BaseModule.AvailableModules;
1212
import com.modsim.modules.parts.Port;
1313
import sun.awt.Mutex;
14+
15+
import com.modsim.util.BinData;
1416
import com.modsim.util.CtrlPt;
1517

1618
public class Sim implements Runnable {
@@ -197,6 +199,8 @@ public void removeLink(Link l) {
197199
synchronized (this) {
198200
links.remove(l);
199201
}
202+
l.src.link = null;
203+
l.targ.setVal(new BinData());
200204
}
201205

202206
/**

src/com/modsim/tools/MakeLinkTool.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ public boolean endLink(int x, int y) {
120120
Main.opStack.beginCompoundOp();
121121
Link l = Link.createLink(source, targ, curve);
122122
if (l != null) {
123-
Main.sim.addLink(l);
123+
Main.sim.addLink(l);
124+
Main.sim.propagate(l.targ.owner);
124125
Main.opStack.pushOp(new CreateOperation(l));
125126
}
126127
Main.opStack.endCompoundOp();

src/com/modsim/util/ModuleClipboard.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ protected void doCopy(List<BaseModule> src, List<BaseModule> destModules, List<L
152152
// Store the new link
153153
if (newLink != null) {
154154
assert newLink.path != oldPort.link.path;
155-
155+
Main.sim.propagate(newLink.targ.owner);
156156
newPort.link = newLink;
157157
destLinks.add(newLink);
158158
}

src/com/modsim/util/XMLReader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ else if (p.ID == targID) {
188188
// Add to the simulation
189189
if (l != null) {
190190
Main.sim.addLink(l);
191+
Main.sim.propagate(l.targ.owner);
191192
}
192193
else {
193194
badLinks++;

0 commit comments

Comments
 (0)