about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-05-16 21:58:13 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-05-16 21:58:13 -0700
commitfb0f0748bcb7e6d24b87b4d3fc45aa7410c641e0 (patch)
tree5dbb5cf3183519b4fc4df3beef502308949fd603
parent6a47fad86f14e3181542aac671595f7b97ce4b0f (diff)
downloadmu-fb0f0748bcb7e6d24b87b4d3fc45aa7410c641e0.tar.gz
press '+' and '-' to zoom in and out respectively
-rw-r--r--506math.mu32
-rw-r--r--hest-life.mu30
2 files changed, 62 insertions, 0 deletions
diff --git a/506math.mu b/506math.mu
index d4e4194c..40b8ccdb 100644
--- a/506math.mu
+++ b/506math.mu
@@ -19,3 +19,35 @@ fn sgn n: int -> _/eax: int {
   }
   return 0
 }
+
+fn shift-left-by n: int, bits: int -> _/eax: int {
+  var i/eax: int <- copy bits
+  {
+    compare i, 0
+    break-if-<=
+    shift-left n, 1
+    i <- decrement
+    loop
+  }
+  return n
+}
+
+fn shift-right-by n: int, bits: int -> _/eax: int {
+  var i/eax: int <- copy bits
+  {
+    compare i, 0
+    break-if-<=
+    shift-right n, 1
+    i <- decrement
+    loop
+  }
+  return n
+}
+
+fn clear-lowest-bits _n: (addr int), bits: int {
+  var dest/edi: (addr int) <- copy _n
+  var n/eax: int <- copy *dest
+  n <- shift-right-by n, bits
+  n <- shift-left-by n, bits
+  copy-to *dest, n
+}
diff --git a/hest-life.mu b/hest-life.mu
index cb732580..38d6d43e 100644
--- a/hest-life.mu
+++ b/hest-life.mu
@@ -240,6 +240,36 @@ fn edit keyboard: (addr keyboard), _self: (addr environment) {
     copy-to *loop, 0
     return
   }
+  # -: zoom out
+  {
+    compare key, 0x2d/-
+    break-if-!=
+    var zoom/eax: (addr int) <- get self, zoom
+    compare *zoom, 4
+    {
+      break-if->=
+      increment *zoom
+      # set tick to a multiple of zoom
+      var tick-a/edx: (addr int) <- get self, tick
+      clear-lowest-bits tick-a, *zoom
+    }
+    return
+  }
+  # +: zoom in
+  {
+    compare key, 0x2b/+
+    break-if-!=
+    var zoom/eax: (addr int) <- get self, zoom
+    compare *zoom, 0
+    {
+      break-if-<=
+      decrement *zoom
+      # set tick to a multiple of zoom
+      var tick-a/edx: (addr int) <- get self, tick
+      clear-lowest-bits tick-a, *zoom
+    }
+    return
+  }
 }
 
 fn pause _self: (addr environment) {