Subversion Repositories Kolibri OS

Rev

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

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