Subversion Repositories Kolibri OS

Rev

Rev 774 | Rev 5031 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. format MS COFF
  2.  
  3. DEBUG   equ 1
  4.  
  5. include '../../../proc32.inc'
  6. include '../../../imports.inc'
  7.  
  8. struc IOCTL
  9. {  .handle      dd ?
  10.    .io_code     dd ?
  11.    .input       dd ?
  12.    .inp_size    dd ?
  13.    .output      dd ?
  14.    .out_size    dd ?
  15. }
  16.  
  17. virtual at 0
  18.   IOCTL IOCTL
  19. end virtual
  20.  
  21. public START
  22. public version
  23.  
  24. DRV_ENTRY  equ 1
  25. DRV_EXIT   equ -1
  26.  
  27. MT_3B       equ 0
  28. MT_3BScroll equ 3
  29. MT_5BScroll equ 4
  30.  
  31. PS2_DRV_VER equ 1
  32.  
  33. section '.flat' code readable align 16
  34.  
  35.  
  36. proc START stdcall, state:dword
  37.  
  38.           cmp [state], DRV_ENTRY
  39.           jne .fin
  40.   .init:
  41.  
  42.           call detect_mouse
  43.           test eax,eax
  44.           jnz  .exit
  45.  
  46.           mov  [MouseType],MT_3B
  47.  
  48.           call try_mode_ID3
  49.           test eax,eax
  50.           jnz  .stop_try
  51.           mov  [MouseType],MT_3BScroll
  52.          
  53.           call try_mode_ID4
  54.           test eax,eax
  55.           jnz  .stop_try
  56.           mov  [MouseType],MT_5BScroll
  57.          
  58.   .stop_try:
  59.  
  60.           mov  bl, 0x20        ; read command byte
  61.           call kbd_cmd
  62.           cmp  ah,1
  63.           je   .exit
  64.  
  65.           call kbd_read
  66.           cmp  ah,1
  67.           je   .exit
  68.  
  69.           or   al, 10b
  70.           push eax
  71.           mov  bl, 0x60        ; write command byte
  72.           call kbd_cmd
  73.           cmp  ah,1
  74.           je   .exit
  75.  
  76.           pop  eax
  77.           call kbd_write
  78.           cmp  ah,1
  79.           je   .exit
  80.  
  81.           mov  al, 0xF4        ; enable data reporting
  82.           call mouse_cmd
  83.  
  84.           mov  bl, 0xAE        ; enable keyboard interface
  85.           call kbd_cmd
  86.          
  87.           stdcall AttachIntHandler, 12, irq_handler, dword 0
  88.           stdcall RegService, my_service, service_proc
  89.                 ret
  90.  
  91.   .fin:
  92.           ;stdcall DetachIntHandler, 12, irq_handler
  93.           mov  bl, 0xA7        ; disable mouse interface
  94.           call kbd_cmd
  95.           xor  eax, eax
  96.           ret
  97.  
  98.   .exit:
  99.           mov  bl, 0xA7        ; disable mouse interface
  100.           call kbd_cmd
  101.           mov  bl, 0xAE        ; enable keyboard interface
  102.           call kbd_cmd
  103.           xor  eax, eax
  104.           ret
  105. endp
  106.  
  107. proc service_proc stdcall, ioctl:dword
  108.     mov  edi, [ioctl]
  109.     mov  eax, [edi+IOCTL.io_code]
  110.     test eax, eax
  111.     jz   .getversion
  112.     cmp  eax,1
  113.     jz   .gettype
  114.  
  115.   .err:
  116.     or   eax, -1
  117.     ret
  118.  
  119.   .ok:
  120.     xor  eax, eax
  121.     ret
  122.  
  123.   .getversion:
  124.     cmp  [edi+IOCTL.out_size], 4
  125.     jb   .err
  126.     mov  edi, [edi+IOCTL.output]
  127.     mov  dword [edi], PS2_DRV_VER               ; version of driver
  128.     jmp  .ok
  129.   .gettype:
  130.     cmp  [edi+IOCTL.out_size], 4
  131.     jb   .err
  132.     mov  edi, [edi+IOCTL.output]
  133.     mov  eax,[MouseType]
  134.     mov  dword [edi], eax               ; mouse type
  135.     jmp  .ok
  136. endp
  137.  
  138. detect_mouse:
  139.  
  140.     mov  bl, 0xAD            ; disable keyboard interface
  141.     call kbd_cmd
  142.     cmp  ah,1
  143.     je   .fail
  144.  
  145.     mov  bl, 0xA8            ; enable mouse interface
  146.     call kbd_cmd
  147.     cmp  ah,1
  148.     je   .fail
  149.  
  150.           mov  al, 0xFF      ; reset
  151.     call mouse_cmd
  152.     jc   .fail
  153.  
  154.     call mouse_read
  155.     jc   .fail
  156.     cmp  al, 0xAA
  157.     jne  .fail         ; dead mouse
  158.  
  159.     ; get device ID
  160.     call mouse_read
  161.     jc   .fail
  162.     cmp  al, 0x00
  163.     jne  .fail        ; unknown device
  164.     xor  eax,eax
  165.     ret
  166.  
  167.   .fail:
  168.     or   eax,-1
  169.     ret
  170.  
  171. try_mode_ID3:
  172.     mov  al, 0xF3    ;Set Sample Rate
  173.     call mouse_cmd
  174.     jc   .fail
  175.     mov  al, 0xC8    ;200d
  176.     call mouse_cmd
  177.     jc   .fail
  178.     mov  al, 0xF3    ;Set Sample Rate
  179.     call mouse_cmd
  180.     jc   .fail
  181.     mov  al, 0x64    ;100d
  182.     call mouse_cmd
  183.     jc   .fail
  184.     mov  al, 0xF3    ;Set Sample Rate
  185.     call mouse_cmd
  186.     jc   .fail
  187.     mov  al, 0x50    ;80d
  188.     call mouse_cmd
  189.     jc   .fail
  190.  
  191.     mov  al, 0xF2    ;Get device id
  192.     call mouse_cmd
  193.     jc   .fail
  194.  
  195.     call mouse_read
  196.     jc   .fail
  197.     cmp  al, 0x03
  198.     jne  .fail
  199.  
  200.     xor  eax,eax
  201.     ret
  202.   .fail:
  203.     or   eax,-1
  204.     ret
  205.  
  206. try_mode_ID4:
  207.     mov  al, 0xF3    ;Set Sample Rate
  208.     call mouse_cmd
  209.     jc   .fail
  210.     mov  al, 0xC8    ;200d
  211.     call mouse_cmd
  212.     jc   .fail
  213.     mov  al, 0xF3    ;Set Sample Rate
  214.     call mouse_cmd
  215.     jc   .fail
  216.     mov  al, 0xC8    ;100d
  217.     call mouse_cmd
  218.     jc   .fail
  219.     mov  al, 0xF3    ;Set Sample Rate
  220.     call mouse_cmd
  221.     jc   .fail
  222.     mov  al, 0x50    ;80d
  223.     call mouse_cmd
  224.     jc   .fail
  225.  
  226.     mov  al, 0xF2    ;Get device id
  227.     call mouse_cmd
  228.     jc   .fail
  229.  
  230.     call mouse_read
  231.     jc   .fail
  232.     cmp  al, 0x04
  233.     jne  .fail
  234.  
  235.     xor  eax,eax
  236.     ret
  237.  
  238.   .fail:
  239.     or   eax,-1
  240.     ret
  241.    
  242. include 'ps2m_iofuncs.inc'
  243. include 'ps2m_irqh.inc'
  244.  
  245. section '.data' data readable writable align 16
  246.  
  247. version           dd  0x00050005
  248. my_service      db  'ps2mouse',0
  249.  
  250. ;iofuncs data
  251. mouse_cmd_byte   db 0
  252. mouse_nr_tries   db 0
  253. mouse_nr_resends db 0
  254.  
  255. ;hid data
  256. mouse_byte  dd 0
  257.  
  258. first_byte  db 0
  259. second_byte db 0
  260. third_byte  db 0
  261. fourth_byte db 0
  262.  
  263. ;main data
  264. MouseType        dd 0
  265.  
  266. XMoving          dd 0
  267. YMoving          dd 0
  268. ZMoving          dd 0
  269. ButtonState      dd 0
  270. ;timerTicks       dd 0
  271.