+ public final OutPort out = new DockOutPort("out", ship.getDock("out"));
+ public final InPort val2 = new DockInPort("val2", ship.getDock("in2"));
+ public final InPort count = new DockInPort("count", ship.getDock("inOp")) {
+ protected void _build(LoopFactory lf) {
+
+ // FlagA set means we have a count value ready to use
+ // FlagB+FlagD means a torpedo has struck
+ // therefore, every recieve is folowed by if-flag-d-then-set-FlagB
+ // therefore, every set/dec olc is folowed by if-flag-d-then-copy-NotFlagB-to-FlagA ; if-flag-d-then-clear-FlagD ; if-FlagB-then-set-FlagD
+ lf = lf.makeNext(1);
+ lf.setFlags(FlagFunction.ZERO, FlagFunction.ZERO);
+ lf = lf.makeNext(0);
+
+ // new iteration or decrement
+ lf.setPredicate(Predicate.NotFlagA);
+ sendTokenAndRecvWord(lf);
+ lf.setPredicate(Predicate.FlagD);
+ lf.setFlags(FlagFunction.ZERO.add(Predicate.FlagA), FlagFunction.ONE);
+ lf.setPredicate(Predicate.FlagA);
+ lf.decOlc();
+ lf.setPredicate(Predicate.NotFlagA);
+ lf.setOlcFromWord();
+ lf.setFlags(FlagFunction.ONE, FlagFunction.ZERO.add(Predicate.FlagB));
+ lf.setPredicate(Predicate.FlagD);
+ lf.setFlags(FlagFunction.ZERO, FlagFunction.ZERO.add(Predicate.FlagB));
+ lf.setOlc(1);
+ lf.setPredicate(Predicate.FlagB);
+ lf.setOlc(0);
+ lf.setPredicate(null);
+
+ lf.setPredicate(Predicate.NotFlagA);
+ lf.literal(passPunctuationInsteadOfValues ? "IN1" : "DROP1");
+ lf.setPredicate(Predicate.FlagA);
+ lf.literal(passPunctuationInsteadOfValues ? "DROP1" : "IN1");
+ lf.setPredicate(null);
+ lf.abortLoopIfTorpedoPresent();
+ lf.deliver();
+ lf.setPredicate(Predicate.FlagD);
+ lf.setFlags(FlagFunction.ZERO.add(Predicate.FlagA), FlagFunction.ONE);
+ lf.setPredicate(null);
+
+ }
+ };
+ private boolean passPunctuationInsteadOfValues;
+ public UnPunctuatorNode2(DataFlowGraph dfg) { this(dfg, false); }
+ public UnPunctuatorNode2(DataFlowGraph dfg, boolean passPunctuationInsteadOfValues) {
+ super(dfg);
+ this.passPunctuationInsteadOfValues = passPunctuationInsteadOfValues;
+ }
+
+ public static void main(String[] s) throws Exception {
+ Fleet fleet = new Fpga();
+ ShipPool pool = new ShipPool(fleet);
+ DataFlowGraph dfg = new DataFlowGraph(fleet, pool);
+ DebugNode dn = new DebugNode(dfg);
+ DownCounterNode fn = new DownCounterNode(dfg);
+ fn.start.connect(new OnceNode(dfg, 100).out);
+ fn.incr.connect(new OnceNode(dfg, 1).out);
+ UnPunctuatorNode2 up = new UnPunctuatorNode2(dfg);
+ up.val.connect(fn.out);
+ up.count.connect(new ForeverNode(dfg, 12).out);
+ up.out.connect(dn.in);
+ CodeBag cb = new CodeBag(fleet);
+ dfg.build(cb);
+ FleetProcess fp = fleet.run(new Instruction[0]);
+ cb.dispatch(fp);
+ fp.flush();
+ while(true) {
+ System.out.println("word = " + fp.recvWord().toLong());
+ }
+ }
+
+
+ */