From fb0f0748bcb7e6d24b87b4d3fc45aa7410c641e0 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 16 May 2021 21:58:13 -0700 Subject: [PATCH] press '+' and '-' to zoom in and out respectively --- 506math.mu | 32 ++++++++++++++++++++++++++++++++ hest-life.mu | 30 ++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) 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) {