Subversion Repositories Kolibri OS

Rev

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