Browse Source

press '+' and '-' to zoom in and out respectively

main
Kartik K. Agaram 1 year ago
parent
commit
fb0f0748bc
  1. 32
      506math.mu
  2. 30
      hest-life.mu

32
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
}

30
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) {

Loading…
Cancel
Save