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