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   {
15     var key/eax: byte <- read-key 0
16     {
17       compare key, 0x68  # 'h'
18       break-if-!=
19       var g/eax: grapheme <- copy 0x2d  # '-'
20       draw-grapheme-at-cursor 0, g, 0x31
21       cursor-left 0
22     }
23     {
24       compare key, 0x6a  # 'j'
25       break-if-!=
26       var g/eax: grapheme <- copy 0x7c  # '|'
27       draw-grapheme-at-cursor 0, g, 0x31
28       cursor-down 0
29     }
30     {
31       compare key, 0x6b  # 'k'
32       break-if-!=
33       var g/eax: grapheme <- copy 0x7c  # '|'
34       draw-grapheme-at-cursor 0, g, 0x31
35       cursor-up 0
36     }
37     {
38       compare key, 0x6c  # 'l'
39       break-if-!=
40       var g/eax: grapheme <- copy 0x2d  # '-'
41       draw-grapheme-at-cursor 0, g, 0x31
42       cursor-right 0
43     }
44     loop
45   }
46 }