Subversion Repositories Kolibri OS

Rev

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

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