Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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