about summary refs log blame commit diff stats
path: root/ex10.mu
blob: 858c4a2577a5a4cc5719dabf2a6f9f8b0528b1aa (plain) (tree)
1
2
3
4
5
6
7
8
                        

                        
                                                   
         
                             
     
                                                           




                                                                       
                                                                                  














                                                         
                                                                                                                           


                                  
                                                                                                                      


                                  
                                                                                                                      



        
# Demo of mouse support.
#
# To build a disk image:
#   ./translate ex10.mu            # emits code.img
# To run:
#   qemu-system-i386 code.img
# Or:
#   bochs -f bochsrc               # bochsrc loads code.img
#
# Expected output:
#   Values between -256 and +255 as you move the mouse over the window.
#   You might need to click on the window once.

fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
  # repeatedly print out mouse driver results if non-zero
  $main:event-loop: {
    var dx/eax: int <- copy 0
    var dy/ecx: int <- copy 0
    dx, dy <- read-mouse-event
    {
      compare dx, 0
      break-if-!=
      compare dy, 0
      break-if-!=
      loop $main:event-loop
    }
    {
      var dummy1/eax: int <- copy 0
      var dummy2/ecx: int <- copy 0
      dummy1, dummy2 <- draw-text-wrapping-right-then-down-over-full-screen screen, "         ", 0/x, 0x10/y, 0x31/fg, 0/bg
    }
    {
      var dummy/ecx: int <- copy 0
      dx, dummy <- draw-int32-decimal-wrapping-right-then-down-over-full-screen screen, dx, 0/x, 0x10/y, 0x31/fg, 0/bg
    }
    {
      var dummy/eax: int <- copy 0
      dummy, dy <- draw-int32-decimal-wrapping-right-then-down-over-full-screen screen, dy, 5/x, 0x10/y, 0x31/fg, 0/bg
    }
    loop
  }
}
array-of-ints(Heap, expected) (parse-array-of-ints Heap *(ebp+0xc) %esi) (lookup *esi *(esi+4)) # => eax # (array-equal? *(ebp+8) %eax) (check-ints-equal %eax 1 *(ebp+0x10)) $check-array-equal:end: # . restore registers 5e/pop-to-esi 58/pop-to-eax # . epilogue 89/<- %esp 5/r32/ebp 5d/pop-to-ebp c3/return test-check-array-equal: # . prologue 55/push-ebp 89/<- %ebp 4/r32/esp # var ecx: (array int) = [1, 2, 3] 68/push 3/imm32 68/push 2/imm32 68/push 1/imm32 68/push 0xc/imm32/size 89/<- %ecx 4/r32/esp # (check-array-equal %ecx "1 2 3" "F - test-check-array-equal") # . epilogue 89/<- %esp 5/r32/ebp 5d/pop-to-ebp c3/return # . . vim:nowrap:textwidth=0