Subversion Repositories Kolibri OS

Rev

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

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