Subversion Repositories Kolibri OS

Rev

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

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