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