https://github.com/akkartik/mu/blob/main/apps/ex7.mu
 1 # Cursor-based motions.
 2 #
 3 # To build a disk image:
 4 #   ./translate apps/ex7.mu        # emits code.img
 5 # To run:
 6 #   qemu-system-i386 code.img
 7 #
 8 # Expected output: an interactive game a bit like "snakes". Try pressing h, j,
 9 # k, l.
10 
11 fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
12   var space/eax: grapheme <- copy 0x20
13   set-cursor-position screen, 0, 0
14   {
15     draw-cursor screen, space
16     var key/eax: byte <- read-key keyboard
17     {
18       compare key, 0x68/h
19       break-if-!=
20       draw-code-point-at-cursor screen, 0x2d/dash, 0x31/fg, 0/bg
21       move-cursor-left 0
22     }
23     {
24       compare key, 0x6a/j
25       break-if-!=
26       draw-code-point-at-cursor screen, 0x7c/vertical-bar, 0x31/fg, 0/bg
27       move-cursor-down 0
28     }
29     {
30       compare key, 0x6b/k
31       break-if-!=
32       draw-code-point-at-cursor screen, 0x7c/vertical-bar, 0x31/fg, 0/bg
33       move-cursor-up 0
34     }
35     {
36       compare key, 0x6c/l
37       break-if-!=
38       var g/eax: code-point <- copy 0x2d/dash
39       draw-code-point-at-cursor screen, 0x2d/dash, 0x31/fg, 0/bg
40       move-cursor-right 0
41     }
42     loop
43   }
44 }