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 # Or:
     8 #   bochs -f bochsrc               # bochsrc loads code.img
     9 #
    10 # Expected output: an interactive game a bit like "snakes". Try pressing h, j,
    11 # k, l.
    12
    13 fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
    14   var space/eax: grapheme <- copy 0x20
    15   set-cursor-position screen, 0, 0
    16   {
    17     draw-cursor screen, space
    18     var key/eax: byte <- read-key keyboard
    19     {
    20       compare key, 0x68/h
    21       break-if-!=
    22       draw-code-point-at-cursor 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 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 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 screen, 0x2d/dash, 0x31/fg, 0/bg
    42       move-cursor-right 0
    43     }
    44     loop
    45   }
    46 }