Subversion Repositories Kolibri OS

Rev

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

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