1 # Draw pixels in response to keyboard events, starting from the top-left 2 # and in raster order. 3 # 4 # To build a disk image: 5 # ./translate apps/ex3.mu # emits code.img 6 # To run: 7 # qemu-system-i386 code.img 8 # 9 # Expected output: a new green pixel starting from the top left corner of the 10 # screen every time you press a key (letter or digit) 11 12 fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) { 13 var x/ecx: int <- copy 0 14 var y/edx: int <- copy 0 15 { 16 var key/eax: byte <- read-key keyboard 17 compare key, 0 18 loop-if-= # busy wait 19 pixel-on-real-screen x, y, 0x31/green 20 x <- increment 21 compare x, 0x400/screen-width=1024 22 { 23 break-if-< 24 y <- increment 25 x <- copy 0 26 } 27 loop 28 } 29 }