title: Assembly Mouse w/o int33h
body: <p>ALRIGHTY, so I have been working on assembly long enough to understand decent code.</p>
  
  <p>I have been trying to get a mouse up w/o int 33h mainly because there is no 33h in VMware or Bochs (emulators w/o MS-DOS).</p>
  
  <p>Does my code seem right? I followed <a href="http://wiki.osdev.org/Mouse_Input" rel="nofollow noreferrer">OSDev Wiki</a> and Cosmos c#</p>
  
  <pre>
  ;====================================
  ;#Handles the mouse routines        #
  ;                                   #
  ;#TODO: Find a way to make it so    #
  ;#  the mouse_wait_signal times out #
  ;====================================
  
  mouse_initalize:
      ;first enable IRQ12
      mov al, 0xA8        
      out 0x64, al        
  
      ;wait for signal
      call mouse_wait_signal
  
      ;next enable interrupt
      mov al, 0x20    ;command
      out 0x64, al
  
      ;wait for data
      call mouse_wait_data
  
      ;get data
      in al, 0x60
      mov [mouse_status], al
  
      ;wait for more signal
      call mouse_wait_signal
  
      ;command
      mov al, 0x60
      out 0x64, al
  
      ;wait le sig
      call mouse_wait_signal
  
      ;set the status
      in al, 0x60
      mov [mouse_status], al
  
      ;finnaly enable mouse
  
      ;---DEFAULT-----
      mov al, 0xF6
      call mouse_write
      call mouse_read ;acknowlage
      ;---DEFAULT-----
  
      ;---ENABLE------
      mov al, 0xF4
      call mouse_write
      call mouse_read ;acknowlage
      ;---ENABLE------
  
      ret
  
  ;------------------------------------
  ;Waits for signal from mouse port
  mouse_wait_signal:
      ;save prev al
      mov [.buffer], al
  
  .a1:;jump into this loop until we rec a signal
      in al, 0x64 
      cmp al, 0
      je .a1
  
      ;loop stoped meaning we have a signal
      mov al, [.buffer]
      ret
  
  .buffer db 0x00
  
  ;------------------------------------
  ;Waits for data signal from port 0x64
  mouse_wait_data:
      ;save prev al
      mov [.buffer], al
  
  .a1:;jump into this loop until we rec a signal
      in al, 0x64 
      cmp al, 1
      jne .a1
  
      ;loop stoped meaning we have a signal
      mov al, [.buffer]
      ret
  
  .buffer db 0x00
  
  ;------------------------------------
  ;Writes to the mouse
  ;IN: AL = cmd
  mouse_write:
      ;save prev al
      mov [.buffer], al
  
      ;wait,send1,wait,sendcmd
      call mouse_wait_signal
      mov al, 0xD4
      out 0x64, al
      call mouse_wait_signal
      mov al, [.buffer]
      out 0x60, al
  
      ;loop stoped meaning we have a signal
      mov al, [.buffer]
      ret
  
  .buffer db 0x00
  
  ;------------------------------------
  ;Reads the mouse
  ;RET: AL = data
  mouse_write:
      call mouse_wait_data
      in al, 0x60
      ret
  
  ;===VARIABLES========================
  mouse_status    db  0x00
  </pre>