shithub: orca

Download patch

ref: 0ee5dd21d0f2e81c5d9f763a605a56d970bc1c9e
parent: 90f3383dd02d23eb430a70bfa53ce810d7eb4bce
author: cancel <cancel@cancel.fm>
date: Fri Nov 30 10:44:14 EST 2018

Add 'R'

--- a/sim.c
+++ b/sim.c
@@ -291,6 +291,7 @@
   _('M', 'm', modulo)                                                          \
   _('O', 'o', offset)                                                          \
   _('P', 'p', push)                                                            \
+  _('R', 'r', random)                                                          \
   _('T', 't', track)                                                           \
   _('U', 'u', uturn)                                                           \
   _('V', 'v', beam)                                                            \
@@ -549,6 +550,35 @@
     write_val_x[0] = 0;
   }
   POKE(1, write_val_x[0], PEEK(0, 1));
+END_PHASE
+
+BEGIN_DUAL_PHASE_0(random)
+  REALIZE_DUAL;
+  BEGIN_DUAL_PORTS
+    PORT(0, 1, IN);
+    PORT(0, 2, IN);
+    PORT(1, 0, OUT);
+  END_PORTS
+END_PHASE
+BEGIN_DUAL_PHASE_1(random)
+  REALIZE_DUAL;
+  STOP_IF_DUAL_INACTIVE;
+  Usz a = INDEX(PEEK(0, 1));
+  Usz b = INDEX(PEEK(0, 2));
+  // we should ask if this is an ok behavior as defined in the existing js.
+  Usz min, max;
+  if (a == b) {
+    POKE(1, 0, GLYPH(a));
+    return;
+  } else if (b > a) {
+    min = a;
+    max = b;
+  } else {
+    max = a;
+    min = b;
+  }
+  Usz val = (y * 5 + x * 3) * Tick_number % (max - min) + min;
+  POKE(1, 0, GLYPH(val));
 END_PHASE
 
 BEGIN_DUAL_PHASE_0(track)