Subversion Repositories Kolibri OS

Rev

Rev 479 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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