switch from using RS-232 BREAKs and no flow control to new command mode reset and...
[fleet.git] / ships / Alu.ship
index 3b2117f..2588447 100644 (file)
@@ -88,31 +88,43 @@ public void service() {
               b = box_in2.removeDataForShip();
               box_out.addDataFromShip(a-b); // SUB
               break;
+
+          case 9: // MAXMERGE
+              if (box_in1.peekDataForShip()<0 && box_in2.peekDataForShip()<0) {
+                a = box_in1.removeDataForShip();
+                b = box_in2.removeDataForShip();
+                box_out.addDataFromShip(a, false);
+                break;
+              }
+              // fall through to MAX
           case 4:
               a = box_in1.peekDataForShip();
               b = box_in2.peekDataForShip();
-              box_out.addDataFromShip(Math.max(a,b)); // MAX
-              box_out.flag_c = !(a>b);
-              if (a<b) box_in1.removeDataForShip(); else box_in2.removeDataForShip();
+              box_out.addDataFromShip(Math.max(a,b), !(a>b)); // MAX
+              if (a>b) box_in1.removeDataForShip(); else box_in2.removeDataForShip();
               break;
+
           case 5:
               a = box_in1.peekDataForShip();
               b = box_in2.peekDataForShip();
-              box_out.addDataFromShip(Math.min(a,b)); // MIN
-              box_out.flag_c = a>b;
-              if (a>b) box_in1.removeDataForShip(); else box_in2.removeDataForShip();
+              box_out.addDataFromShip(Math.min(a,b), a>b); // MIN
+              if (a<b) box_in1.removeDataForShip(); else box_in2.removeDataForShip();
               break;
           case 6:
               a = box_in1.removeDataForShip();
               b = box_in2.removeDataForShip();
-              box_out.addDataFromShip(0); // CMP
-              box_out.flag_c = a==b;
+              box_out.addDataFromShip(0, a==b); // CMP
               break;
-          default:
-              a = box_in1.removeDataForShip();
-              b = box_in2.removeDataForShip();
-              box_out.addDataFromShip(0);
+/*
+          case 7:
+              box_in1.removeDataForShip();      // DROP1
               break;
+          case 8:
+              box_in2.removeDataForShip();      // DROP2
+              break;
+*/
+          default:
+              throw new RuntimeException("invalid opcode: " + op);
       }
   }
 }
@@ -143,6 +155,8 @@ public void service() {
   assign eq            = in1_d == in2_d;
   assign cout          = sum[`WORDWIDTH];
 
+  reg out_draining;
+
   assign out_d_[`WORDWIDTH] =
           (inOp_d_trunc==0) ? 1'b0 :
           (inOp_d_trunc==1) ? 1'b0 :
@@ -166,13 +180,14 @@ public void service() {
           0;
 
   always @(posedge clk) begin
-    if (!rst) begin
+    if (rst) begin
       `reset
+      out_draining <= 0;
     end else begin
-      `flush
       `cleanup
-      if (`out_draining) begin
+      if (out_draining && `out_empty) begin
         `drain_inOp
+        out_draining <= 0;
         if      (inOp_d_trunc==0) `drain_in1
         else if (inOp_d_trunc==1) `drain_in2
         else if (inOp_d_trunc==9 &&  both_negative) begin `drain_in1 `drain_in2 end
@@ -187,8 +202,9 @@ public void service() {
           `drain_in2
         end
       end
-      if (`out_empty && `in1_full && `in2_full && `inOp_full) begin
+      if (!out_draining && `out_empty && `in1_full && `in2_full && `inOp_full) begin
         `fill_out
+        out_draining <= 1;
       end
     end
   end