shithub: orca

Download patch

ref: 92afdcee4daa17b824d586d21bf3cf9f6b4e693c
parent: fe3172919d12a024a78f9cc071e7cfc96ee1624e
author: cancel <cancel@cancel.fm>
date: Fri Nov 30 05:48:49 EST 2018

Add 'D'

--- a/sim.c
+++ b/sim.c
@@ -264,6 +264,7 @@
   _('Z', 'z', southeast)                                                       \
   _('A', 'a', add)                                                             \
   _('B', 'b', banger)                                                          \
+  _('D', 'd', delay)                                                           \
   _('F', 'f', if)                                                              \
   _('G', 'g', generator)                                                       \
   _('H', 'h', halt)                                                            \
@@ -333,6 +334,28 @@
     result = '.';
   }
   POKE(1, 0, result);
+END_PHASE
+
+BEGIN_DUAL_PHASE_0(delay)
+  PSEUDO_DUAL;
+  bool out_is_nonlocking = false;
+  if (DUAL_IS_ACTIVE) {
+    BEGIN_HASTE
+      out_is_nonlocking = INDEX(PEEK(0, -2)) == 0;
+    END_HASTE
+  }
+  BEGIN_DUAL_PORTS
+    PORT(0, -2, IN | HASTE);
+    PORT(0, -1, IN | HASTE);
+    PORT(1, 0, OUT | (out_is_nonlocking ? NONLOCKING : 0));
+  END_PORTS
+END_PHASE
+BEGIN_DUAL_PHASE_1(delay)
+  REALIZE_DUAL;
+  STOP_IF_DUAL_INACTIVE;
+  Usz tick = INDEX(PEEK(0, -2));
+  Glyph timer = PEEK(0, -1);
+  POKE(0, -2, tick == 0 ? timer : GLYPH(tick - 1));
 END_PHASE
 
 BEGIN_DUAL_PHASE_0(if)