fix bugs in software implementation of Choice ship
[fleet.git] / ships / Choice.ship
index 28fcd96..2aa8129 100644 (file)
@@ -72,7 +72,7 @@ public void service() {
   if (port.startsWith("mux")   && (!box_in1.dataReadyForShip() || !box_in2.dataReadyForShip())) return;
   if (port.startsWith("deMux") && (!box_in1.dataReadyForShip())) return;
 
-  long val = box_in.removeDataForShip();
+  long val = selector.value;
   boolean condition = false;
   if (port.endsWith("IfZero"))        condition = val==0;
   if (port.endsWith("IfNonZero"))     condition = val!=0;
@@ -84,14 +84,18 @@ public void service() {
     if (condition) {
       box_out1.addDataFromShip(box_in2.removeDataForShip());
       box_out2.addDataFromShip(box_in1.removeDataForShip());
+      selector = null;
     } else {
       box_out1.addDataFromShip(box_in1.removeDataForShip());
       box_out2.addDataFromShip(box_in2.removeDataForShip());
+      selector = null;
     }
   } else if (port.startsWith("mux")) {
     box_out1.addDataFromShip(condition ? box_in2.removeDataForShip() : box_in1.removeDataForShip());
+    selector = null;
   } else if (port.startsWith("deMux")) {
     (condition ? box_out2 : box_out1).addDataFromShip(box_in1.removeDataForShip());
+    selector = null;
   }
 }