eliminate use of the `XXX_draining macro
[fleet.git] / ships / Counter.ship
index 2e71152..f82bc14 100644 (file)
@@ -31,6 +31,7 @@ public void service() { }
 
   reg [`WORDWIDTH-1:0] temp;
   initial temp   = {`WORDWIDTH{1'b1}};
+  reg     out_draining;
   reg     full;
   initial full = 0;
   wire    op_count;  assign op_count  = inOp_d_trunc==12;
@@ -49,15 +50,17 @@ public void service() { }
     if (!rst) begin
       `reset
       full <= 0;
+      out_draining <= 0;
     end else begin
       `flush
       `cleanup
       if (`inOp_empty)         full   <= 0;
-      if (`out_draining) begin
+      if (out_draining && `out_empty) begin
         if (op_count) temp   <= temp - in2_d;
         else          temp   <= temp - 1;
         if (op_pass && op_v1) `drain_in1
         if (op_pass && op_v2) `drain_in2
+        out_draining <= 0;
       end else if (`inOp_full) begin
         if (!full) begin
           if (op_count && `in1_full && `in2_full) begin
@@ -86,12 +89,13 @@ public void service() { }
         end else if (`out_empty) begin
           if (op_count) begin
             `fill_out
+            out_draining <= 1;
           end else if (op_v1 && `in1_full) begin
             if (op_drop)    begin `drain_in1 temp <= temp-1; end
-            else            `fill_out
+            else            begin `fill_out out_draining <= 1; end
           end else if (op_v2 && `in2_full) begin
             if (op_drop)    begin `drain_in2 temp <= temp-1; end
-            else            `fill_out
+            else            begin `fill_out out_draining <= 1; end
           end
         end
       end