Subversion Repositories Kolibri OS

Rev

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

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