https://github.com/akkartik/mu/blob/main/apps/ex10.mu
 1 # Demo of mouse support.
 2 #
 3 # To build a disk image:
 4 #   ./translate apps/ex10.mu       # emits code.img
 5 # To run:
 6 #   qemu-system-i386 code.img
 7 #
 8 # Expected output:
 9 #   Values between -256 and +255 as you move the mouse over the window.
10 #   You might need to click on the window once.
11 
12 fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
13   # repeatedly print out mouse driver results if non-zero
14   $main:event-loop: {
15     var dx/eax: int <- copy 0
16     var dy/ecx: int <- copy 0
17     dx, dy <- read-mouse-event
18     {
19       compare dx, 0
20       break-if-!=
21       compare dy, 0
22       break-if-!=
23       loop $main:event-loop
24     }
25     {
26       var dummy1/eax: int <- copy 0
27       var dummy2/ecx: int <- copy 0
28       dummy1, dummy2 <- draw-text-wrapping-right-then-down-over-full-screen screen, "         ", 0/x, 0x10/y, 0x31/fg, 0/bg
29     }
30     {
31       var dummy/ecx: int <- copy 0
32       dx, dummy <- draw-int32-decimal-wrapping-right-then-down-over-full-screen screen, dx, 0/x, 0x10/y, 0x31/fg, 0/bg
33     }
34     {
35       var dummy/eax: int <- copy 0
36       dummy, dy <- draw-int32-decimal-wrapping-right-then-down-over-full-screen screen, dy, 5/x, 0x10/y, 0x31/fg, 0/bg
37     }
38     loop
39   }
40 }