Subversion Repositories Kolibri OS

Rev

Rev 116 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. MouseSearch_PS2:
  2.         jmp     MouseSearch_PS2_begin
  3.  
  4. mouse_error equ MouseSearch_PS2_begin.error
  5.  
  6.  kb_cmd_c:
  7.         call    kb_cmd
  8.         jmp     check_kbd
  9.  
  10.  kb_write_c:
  11.         call    kb_write
  12.         jmp     check_kbd
  13.  
  14.  kb_read_c:
  15.         call    kb_read
  16.         ;jmp    check_kbd
  17.  
  18.  check_kbd:
  19.         cmp     ah, 1
  20.         je      mouse_error
  21.         ret
  22.  
  23. uglobal
  24.   mouse_cmd_byte   db 0
  25.   mouse_nr_tries   db 0
  26.   mouse_nr_resends db 0
  27.  
  28.   mouse_error_esp  dd 0
  29. endg
  30.  
  31.  
  32.  mouse_cmd:
  33.         mov     [mouse_cmd_byte], al
  34.         mov     [mouse_nr_resends], 5
  35.    .resend:
  36.         mov     bl, 0xd4
  37.         call    kb_cmd_c
  38.         mov     al, [mouse_cmd_byte]
  39.         call    kb_write_c
  40.  
  41.         call    mouse_read
  42.  
  43.         cmp     al, 0xFA        ; ack
  44.         jne     .noack
  45.         ret
  46.    .noack:
  47.         cmp     al, 0xFE        ; resend
  48.         jne     .noresend
  49.         dec     [mouse_nr_resends]
  50.         jnz     .resend
  51.    .noresend:
  52.         jmp     mouse_error
  53.  
  54.  
  55.  mouse_read:
  56.         mov     [mouse_nr_tries], 100
  57.    .repeat:
  58.         call    kb_read
  59.         cmp     ah, 1
  60.         jne     .fin
  61.         mov     esi, 10
  62.         call    delay_ms
  63.         dec     [mouse_nr_tries]
  64.         jnz     .repeat
  65.         jmp     mouse_error
  66.    .fin:
  67.         ret
  68.  
  69.  
  70. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  71. MouseSearch_PS2_begin:
  72.         pushad
  73.  
  74.         mov     [mouse_error_esp], esp
  75.  
  76.         mov     bl, 0xAD        ; disable keyboard interface
  77.         call    kb_cmd_c
  78.      
  79.         mov     bl, 0xA8        ; enable mouse interface
  80.         call    kb_cmd_c
  81.  
  82.         mov     al, 0xFF        ; reset
  83.         call    mouse_cmd
  84.  
  85.         ; now the mouse is in Reset Mode
  86.         ; get the Basic Assurance Test completion code
  87.         call    mouse_read
  88.         cmp     al, 0xAA
  89.         jne     .error          ; dead mouse
  90.  
  91.         ; get device ID
  92.         call    mouse_read
  93.         cmp     al, 0x00
  94.         jne     .error          ; unknown device
  95.  
  96.         ; reset completed successfully
  97.  
  98.         ; enable mouse interrupt - IRQ12
  99.         mov     bl, 0x20        ; read command byte
  100.         call    kb_cmd_c
  101.         call    kb_read_c
  102.         or      al, 10b
  103.         push    eax
  104.         mov     bl, 0x60        ; write command byte
  105.         call    kb_cmd_c
  106.         pop     eax
  107.         call    kb_write_c
  108.  
  109.         mov     al, 0xF4        ; enable data reporting
  110.         call    mouse_cmd
  111.  
  112.         mov     [ps2_mouse_detected], 1
  113.         mov     bl, 0xAE        ; enable keyboard interface
  114.         call    kb_cmd
  115.  
  116.         mov     esi, boot_setmouse_type
  117.         call    boot_log
  118.  
  119.         jmp     .finish
  120.  
  121.  
  122. .error:
  123.         mov     esp, [mouse_error_esp]    ; clear stack frame
  124.         mov     [ps2_mouse_detected], 0
  125.         mov     bl, 0xA7 ; disable mouse interface
  126.         call    kb_cmd
  127.         mov     bl, 0xAE ; enable keyboard interface
  128.         call    kb_cmd
  129.  
  130. .finish:
  131.         popad
  132.