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   set-cursor-position screen, 0, 0
13   {
14     draw-cursor screen, 0x20/space
15     var key/eax: byte <- read-key keyboard
16     {
17       compare key, 0x80/left-arrow
18       break-if-!=
19       draw-code-point-at-cursor screen, 0x2d/dash, 0x31/fg, 0/bg
20       move-cursor-left 0
21     }
22     {
23       compare key, 0x81/down-arrow
24       break-if-!=
25       draw-code-point-at-cursor screen, 0x7c/vertical-bar, 0x31/fg, 0/bg
26       move-cursor-down 0
27     }
28     {
29       compare key, 0x82/up-arrow
30       break-if-!=
31       draw-code-point-at-cursor screen, 0x7c/vertical-bar, 0x31/fg, 0/bg
32       move-cursor-up 0
33     }
34     {
35       compare key, 0x83/right-arrow
36       break-if-!=
37       var g/eax: code-point <- copy 0x2d/dash
38       draw-code-point-at-cursor screen, 0x2d/dash, 0x31/fg, 0/bg
39       move-cursor-right 0
40     }
41     loop
42   }
43 }