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 ex3.mu # emits code.img 6 # To run: 7 # qemu-system-i386 code.img 8 # Or: 9 # bochs -f bochsrc # bochsrc loads code.img 10 # 11 # Expected output: a new green pixel starting from the top left corner of the 12 # screen every time you press a key (letter or digit) 13 14 fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) { 15 var x/ecx: int <- copy 0 16 var y/edx: int <- copy 0 17 { 18 var key/eax: byte <- read-key keyboard 19 compare key, 0 20 loop-if-= # busy wait 21 pixel-on-real-screen x, y, 0x31/green 22 x <- increment 23 compare x, 0x400/screen-width=1024 24 { 25 break-if-< 26 y <- increment 27 x <- copy 0 28 } 29 loop 30 } 31 }