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