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