+
+boolean full = false;
+boolean op_count = false;
+boolean op_repeat = false;
+boolean op_pass = false;
+boolean op_drop = false;
+boolean op_c1 = false;
+boolean op_c2 = false;
+boolean op_v1 = false;
+boolean op_v2 = false;
+long temp = 0;
+boolean out_draining;
+
+public void reset() {
+ super.reset();
+ full = false;
+ temp = 0;
+ out_draining = false;
+}
+public void service() {
+
+ if (!box_inOp.dataReadyForShip()) full = false;
+
+ if (out_draining && box_out.readyForDataFromShip()) {
+ if (op_count) temp = temp - box_in2.peekDataForShip();
+ else temp--;
+ if (op_pass && op_v1) box_in1.removeDataForShip();
+ if (op_pass && op_v2) box_in2.removeDataForShip();
+ out_draining = false;
+
+ } else if (box_inOp.dataReadyForShip()) {
+ long op = box_inOp.peekDataForShip();
+ op_count = (op & 15)==12;
+ op_repeat = ((op>>2) & 3)==0;
+ op_pass = ((op>>2) & 3)==1;
+ op_drop = ((op>>2) & 3)==2;
+ op_c1 = (op_repeat || op_pass || op_drop) && !(((op>>1)&1)!=0);
+ op_c2 = (op_repeat || op_pass || op_drop) && (((op>>1)&1)!=0);
+ op_v1 = (op_repeat || op_pass || op_drop) && !(((op>>0)&1)!=0);
+ op_v2 = (op_repeat || op_pass || op_drop) && (((op>>0)&1)!=0);
+ if (!full) {
+ if (op_count && box_in1.dataReadyForShip() && box_in2.dataReadyForShip()) {
+ temp = box_in1.peekDataForShip() - box_in2.peekDataForShip();
+ box_in1.removeDataForShip();
+ full = true;
+ } else if (op_c1 && box_in1.dataReadyForShip()) {
+ temp = box_in1.peekDataForShip() - 1;
+ box_in1.removeDataForShip();
+ full = true;
+ } else if (op_c2 && box_in2.dataReadyForShip()) {
+ temp = box_in2.peekDataForShip() - 1;
+ box_in2.removeDataForShip();
+ full = true;
+ }
+ } else if (temp < 0) {
+ full = false;
+ box_inOp.removeDataForShip();
+ if (op_count) box_in2.removeDataForShip();
+ else if (op_repeat && op_v1) box_in1.removeDataForShip();
+ else if (op_repeat && op_v2) box_in2.removeDataForShip();
+
+ } else if (box_out.readyForDataFromShip()) {
+ if (op_count) {
+ out_draining = true;
+ box_out.addDataFromShip(temp, (temp - box_in2.peekDataForShip()) < 0);
+ } else if (op_v1 && box_in1.dataReadyForShip()) {
+ if (op_drop) { box_in1.removeDataForShip(); temp--; }
+ else { box_out.addDataFromShip(box_in1.peekDataForShip(), temp<=0); out_draining = true; }
+ } else if (op_v2 && box_in2.dataReadyForShip()) {
+ if (op_drop) { box_in2.removeDataForShip(); temp--; }
+ else { box_out.addDataFromShip(box_in2.peekDataForShip(), temp<=0); out_draining = true; }
+ }
+ }
+ }
+}