Subversion Repositories Kolibri OS

Rev

Rev 56 | Blame | Last modification | View Log | Download | RSS feed

  1. ; for information on PS2 mouse/keyboard programming
  2. ; refer to http://www.computer-engineering.org/ps2mouse/
  3. ; and http://www.computer-engineering.org/ps2keyboard/
  4. ; respectively
  5.  
  6. MouseSearch_PS2:
  7.         jmp .begin
  8.  
  9. .kb_cmd_c:
  10.         call    kb_cmd
  11. .check:
  12.         cmp     ah, 1
  13.         je      @f
  14.         ret
  15. @@:
  16.         add     esp, 4  ; return address
  17.         jmp     .DataInputError
  18.  
  19. .kb_write_c:
  20.         call    kb_write
  21.         jmp     .check
  22.  
  23. .kb_read_c:
  24.         call    kb_read
  25.         jmp     .check
  26.  
  27. ;--------------------------------------------
  28. .begin:
  29.         pushad
  30.  
  31.         mov     bl, 0xAD        ; disable keyboard interface
  32.         call    .kb_cmd_c
  33.  
  34.         mov     bl, 0xa8        ; enable mouse interface
  35.         call    .kb_cmd_c
  36.  
  37.         mov     bl, 0xd4        ; to mouse
  38.         call    .kb_cmd_c
  39.         mov     al, 0xFF        ; reset
  40.         call    .kb_write_c
  41.         call    .kb_read_c
  42.         cmp     al, 0xFA        ; ack
  43.         jne     .no_ack
  44.  
  45.         ; now the mouse is in Reset Mode
  46.         ; get the Basic Assurance Test completion code
  47.         call    .kb_read_c
  48.         cmp     al, 0xAA
  49.         jne     .dead_mouse
  50.         ; get device ID
  51.         call    .kb_read_c
  52.         cmp     al, 0x00
  53.         jne     .unknown_device
  54.  
  55.         ; reset completed successfully
  56.  
  57.         ; enable mouse interrupt - IRQ12
  58.         mov     bl, 0x20        ; read command byte
  59.         call    .kb_cmd_c
  60.         call    .kb_read_c
  61.         or      al, 10b         ; set mouse IRQ bit
  62.         push    eax
  63.         mov     bl, 0x60        ; write command byte
  64.         call    .kb_cmd_c
  65.         pop     eax
  66.         call    .kb_write_c
  67.  
  68.         mov     bl, 0xd4        ; to mouse
  69.         call    .kb_cmd_c
  70.         mov     al, 0xf4        ; enable data reporting
  71.         call    .kb_write_c
  72.         call    .kb_read_c
  73.         cmp     al, 0xFA
  74.         jne     .no_ack
  75.  
  76. ;       jmp     @f
  77. ;.set_sample_rate:
  78. ;       push    eax
  79. ;       mov     bl, 0xd4        ; to mouse
  80. ;       call    .kb_cmd_c
  81. ;       mov     al, 0xF3        ; set sample rate
  82. ;       call    .kb_write_c
  83. ;       call    .kb_read_c      ; ack
  84. ;       pop     eax
  85. ;       call    .kb_write_c
  86. ;       call    .kb_read_c      ; ack
  87. ; @@:
  88. ;       mov     eax, 200
  89. ;       call    .set_sample_rate
  90. ;       mov     eax, 100
  91. ;       call    .set_sample_rate
  92. ;       mov     eax, 80
  93. ;       call    .set_sample_rate
  94. ;       mov     bl, 0xd4
  95. ;       call    .kb_cmd_c
  96. ;       mov     al, 0xF2        ; read device type
  97. ;       call    .kb_write_c
  98. ;       call    .kb_read_c      ; ack
  99. ;       call    .kb_read_c      ; mouse ID
  100. ;       cmp     al, 0x03
  101. ;       jne     .no_scroll
  102. ;       mov     [ps2_mouse_scroll], 1
  103. ;       ; it'll send 4-byte packets instead of 3-byte ones
  104. ;       ; the last byte of a packet represents z-axis movement
  105. ; .no_scroll:
  106.  
  107.         mov     [ps2_mouse_detected], 1
  108.         mov     bl, 0xAE        ; enable keyboard interface
  109.         call    .kb_cmd_c
  110.  
  111.         mov     esi, boot_setmouse_type
  112.         call    boot_log
  113.  
  114.         jmp     .finish
  115.  
  116.  
  117. .DataInputError:
  118. .no_ack:
  119. .dead_mouse:
  120. .unknown_device:
  121.         mov     [ps2_mouse_detected],0
  122.         mov     bl, 0xA7 ; disable mouse interface
  123.         call    kb_cmd
  124.         mov     bl, 0xAE ; enable keyboard interface
  125.         call    kb_cmd
  126.  
  127. .finish:
  128.         popad
  129.