fix other mandelbrot variants
[mu.git] / tutorial / counter.mu
blobb1f3cc420e9046e1f76fc012486b05e5d4372ea5
1 # Counter app
2 #   https://eugenkiss.github.io/7guis/tasks/#counter
4 # To build:
5 #   $ ./translate counter.mu
6 # To run:
7 #   $ qemu-system-i386 code.img
9 fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
10   var count/ecx: int <- copy 0
11   # widget title
12   set-cursor-position screen, 0x1f/x 0xe/y
13   draw-text-rightward-from-cursor-over-full-screen screen, " Counter                         ", 0xf/fg 0x16/bg
14   # event loop
15   {
16     # draw current state to screen
17     clear-rect screen, 0x1f/xmin 0xf/ymin, 0x40/xmax 0x14/ymax, 0xc5/color
18     set-cursor-position screen, 0x20/x 0x10/y
19     draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen screen, count, 7/fg 0xc5/bg
20     # render a menu bar
21     set-cursor-position screen, 0x24/x 0x12/y
22     draw-text-rightward-from-cursor-over-full-screen screen, " enter ", 0/fg 0x5c/bg=highlight
23     draw-text-rightward-from-cursor-over-full-screen screen, " increment ", 7/fg 0xc5/bg
24     # process a single keystroke
25     {
26       var key/eax: byte <- read-key keyboard
27       compare key, 0
28       loop-if-=
29       compare key, 0xa/newline
30       break-if-!=
31       count <- increment
32     }
33     loop
34   }