Subversion Repositories Kolibri OS

Rev

Rev 774 | Rev 5031 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 774 Rev 3550
Line 1... Line 1...
1
format MS COFF
1
format MS COFF
Line -... Line 2...
-
 
2
 
-
 
3
DEBUG   equ 1
2
 
4
 
3
include '../../../proc32.inc'
5
include '../../../proc32.inc'
Line 4... Line 6...
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 ?
Line 12... Line 14...
12
   .out_size	dd ?
14
   .out_size    dd ?
13
}
15
}
14
 
16
 
Line 20... Line 22...
20
public version
22
public version
Line 21... Line 23...
21
 
23
 
22
DRV_ENTRY  equ 1
24
DRV_ENTRY  equ 1
Line 23... Line 25...
23
DRV_EXIT   equ -1
25
DRV_EXIT   equ -1
24
 
26
 
25
MT_3B	    equ 0
27
MT_3B       equ 0
Line 26... Line 28...
26
MT_3BScroll equ 3
28
MT_3BScroll equ 3
Line 27... Line 29...
27
MT_5BScroll equ 4
29
MT_5BScroll equ 4
Line 28... Line 30...
28
 
30
 
Line 29... Line 31...
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
Line 32... Line 34...
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
Line 49... Line 51...
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
 
Line 79... Line 81...
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
          
Line 85... Line 87...
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
Line 93... Line 95...
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
Line 100... Line 102...
100
	  call kbd_cmd
102
          call kbd_cmd
101
	  xor  eax, eax
103
          xor  eax, eax
102
	  ret
104
          ret
Line 103... Line 105...
103
endp
105
endp
104
 
106
 
105
proc service_proc stdcall, ioctl:dword
107
proc service_proc stdcall, ioctl:dword
Line 106... Line 108...
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
Line 120... Line 122...
120
 
122
 
Line 121... Line 123...
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]
Line 125... Line 127...
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
Line 129... Line 131...
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]
Line 132... Line 134...
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
 
Line 136... Line 138...
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
 
Line 143... Line 145...
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
Line 146... Line 148...
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
 
Line 165... Line 167...
165
  .fail:
167
  .fail:
166
    or	 eax,-1
168
    or   eax,-1
167
    ret
169
    ret
Line 168... Line 170...
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
Line 172... Line 174...
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
Line 177... Line 179...
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
Line 196... Line 198...
196
    jne  .fail
198
    jne  .fail
197
 
199
 
198
    xor  eax,eax
200
    xor  eax,eax
Line 199... Line 201...
199
    ret
201
    ret
200
  .fail:
202
  .fail:
201
    or	 eax,-1
203
    or   eax,-1
202
    ret
204
    ret
Line 203... Line 205...
203
 
205
 
204
try_mode_ID4:
206
try_mode_ID4:
Line 205... Line 207...
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
Line 208... Line 210...
208
    mov  al, 0xC8    ;200d
210
    mov  al, 0xC8    ;200d
209
    call mouse_cmd
211
    call mouse_cmd
Line 210... Line 212...
210
    jc	 .fail
212
    jc   .fail
Line 211... Line 213...
211
    mov  al, 0xF3    ;Set Sample Rate
213
    mov  al, 0xF3    ;Set Sample Rate
212
    call mouse_cmd
214
    call mouse_cmd
Line 213... Line 215...
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
Line 217... Line 219...
217
    mov  al, 0xF3    ;Set Sample Rate
219
    mov  al, 0xF3    ;Set Sample Rate
218
    call mouse_cmd
220
    call mouse_cmd
Line 257... Line 259...
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
Line 260... Line 262...
260
 
262
 
261
;main data
263
;main data
Line 262... Line 264...
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