about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-05-16 21:29:38 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-05-16 21:29:38 -0700
commit92984d557e4ead80ba3e52cdb6be6e6c578a5f9b (patch)
treebd29a4bb4df60f72a791909c6b296156685b16bd
parent3f916e641409ade08774860f0428bd7ffc1c8786 (diff)
downloadmu-92984d557e4ead80ba3e52cdb6be6e6c578a5f9b.tar.gz
press 'l' to loop, 'L' to stop looping
-rw-r--r--hest-life.mu28
1 files changed, 28 insertions, 0 deletions
diff --git a/hest-life.mu b/hest-life.mu
index 8f68a073..cb732580 100644
--- a/hest-life.mu
+++ b/hest-life.mu
@@ -36,6 +36,7 @@ type environment {
   zoom: int  # 0 = 1024 px per cell; 5 = 4px per cell; each step adjusts by a factor of 4
   tick: int
   play?: boolean
+  loop: int  # if non-zero, return tick to 0 after this point
 }
 
 type cell {
@@ -221,6 +222,24 @@ fn edit keyboard: (addr keyboard), _self: (addr environment) {
     clear-environment self
     return
   }
+  # l: loop from here to start
+  {
+    compare key, 0x6c/l
+    break-if-!=
+    var tick-a/eax: (addr int) <- get self, tick
+    var tick/eax: int <- copy *tick-a
+    var loop/ecx: (addr int) <- get self, loop
+    copy-to *loop, tick
+    return
+  }
+  # L: reset loop
+  {
+    compare key, 0x4c/L
+    break-if-!=
+    var loop/eax: (addr int) <- get self, loop
+    copy-to *loop, 0
+    return
+  }
 }
 
 fn pause _self: (addr environment) {
@@ -255,6 +274,15 @@ fn step _self: (addr environment) {
     break-if-!=
     step4 self
   }
+  var loop-a/eax: (addr int) <- get self, loop
+  compare *loop-a, 0
+  {
+    break-if-=
+    var loop/eax: int <- copy *loop-a
+    compare *tick-a, loop
+    break-if-<
+    clear-environment self
+  }
 }
 
 fn initialize-environment _self: (addr environment) {