Subversion Repositories Kolibri OS

Rev

Rev 2434 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
769 Rus 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2465 Serge 3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
769 Rus 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
774 Rus 6
;; Includes source code by Kulakov Vladimir Gennadievich.       ;;
7
;; Modified by Mario79 and Rus.                                 ;;
2434 Serge 8
;; 02.12.2009                                              ;;
769 Rus 9
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10
 
11
;driver sceletone
12
 
13
format MS COFF
14
 
802 serge 15
DEBUG        equ 0
769 Rus 16
 
17
include 'proc32.inc'
18
include 'imports.inc'
19
 
2434 Serge 20
API_VERSION     equ 5  ;debug
769 Rus 21
 
22
struc IOCTL
2434 Serge 23
{  .handle      dd ?
24
   .io_code     dd ?
25
   .input       dd ?
26
   .inp_size    dd ?
27
   .output      dd ?
28
   .out_size    dd ?
769 Rus 29
}
30
 
31
virtual at 0
32
  IOCTL IOCTL
33
end virtual
34
 
35
public START
36
public version
37
 
38
 
39
DRV_ENTRY    equ 1
40
DRV_EXIT     equ -1
2434 Serge 41
STRIDE       equ 4      ;size of row in devices table
769 Rus 42
 
2434 Serge 43
SRV_GETVERSION  equ 0
769 Rus 44
 
45
section '.flat' code readable align 16
46
 
47
proc START stdcall, state:dword
48
 
2434 Serge 49
        cmp     [state], 1
50
        jne     .exit
769 Rus 51
.entry:
2434 Serge 52
        ;Detect_COM_Mouse:
769 Rus 53
if DEBUG
2434 Serge 54
        mov     esi, msgInit
55
        call    Boot_Log
769 Rus 56
end if
2434 Serge 57
        mov     bx, 0x3f8
58
        call    MSMouseSearch
59
        cmp     AL, 'M'
60
        jne     @f
61
        ;mov    [com1_mouse_detected],1
62
        ;mov     [irq_owner+4*4], 1      ; IRQ4 owner is System
769 Rus 63
 
2434 Serge 64
        mov     dx, bx
65
        inc     dx                       ; 0x3f8 + 1
66
        mov     al, 1
67
        out     dx, al
769 Rus 68
 
2434 Serge 69
        stdcall AttachIntHandler, 4, irq4_handler, dword 0
769 Rus 70
if DEBUG
2434 Serge 71
        test    eax, eax
72
        jne     .label1
769 Rus 73
 
2434 Serge 74
        mov     esi, msg_error_attach_int_handler
75
        call    Boot_Log
769 Rus 76
end if
77
     .label1:
2434 Serge 78
;       mov     eax, 0
79
;       mov     ebx, 0x3F8
80
;       mov     ecx, 0x3FF
81
        xor     ebx, ebx
82
        mov     ecx, 0x3F8
83
        mov     edx, 0x3FF
84
        call    ReservePortArea
769 Rus 85
 
86
if DEBUG
2434 Serge 87
        cmp     eax, 1
88
        jne     .go
769 Rus 89
 
2434 Serge 90
        mov     esi, msg_error_reserve_ports
91
        call    Boot_Log
769 Rus 92
 
93
     .go:
2434 Serge 94
        mov     esi, boot_setmouse_type
95
        call    Boot_Log
769 Rus 96
end if
97
     @@:
2434 Serge 98
        mov     bx, 0x2f8
99
        call    MSMouseSearch
100
        cmp     AL, 'M'
101
        jne     .resume
102
        ;mov     [com2_mouse_detected],1
103
        ;mov     [irq_owner+3*4], 1      ; IRQ3 owner is System
769 Rus 104
 
2434 Serge 105
        stdcall AttachIntHandler, 3, irq3_handler, dword 0
769 Rus 106
 
2434 Serge 107
;       mov     eax, 0
108
;       mov     ebx, 0x2F8
109
;       mov     ecx, 0x3F8
110
        xor     ebx, ebx
111
        mov     ecx, 0x2F8
112
        mov     edx, 0x3F8
1306 Lrz 113
 
2434 Serge 114
        call    ReservePortArea
769 Rus 115
if DEBUG
2434 Serge 116
        cmp     eax, 1
117
        jne     @f
769 Rus 118
 
2434 Serge 119
        mov     esi, msg_error_reserve_ports
120
        call    Boot_Log
769 Rus 121
      @@:
122
 
2434 Serge 123
        mov     esi, boot_setmouse_type + 22
124
        call    Boot_Log
769 Rus 125
end if
126
      .resume:
127
 
2434 Serge 128
        stdcall RegService, my_service, service_proc
769 Rus 129
if DEBUG
2434 Serge 130
        test    eax, eax
131
        jne     @f
769 Rus 132
 
2434 Serge 133
        mov     esi, msg_exit
134
        call    Boot_Log
769 Rus 135
end if
2434 Serge 136
         @@:
137
        ret
769 Rus 138
.fail:
139
.exit:
140
if DEBUG
2434 Serge 141
        mov     esi, msg_exit
142
        call    Boot_Log
769 Rus 143
end if
2434 Serge 144
        xor     eax, eax
145
        ret
769 Rus 146
endp
147
 
2434 Serge 148
handle     equ  IOCTL.handle
149
io_code    equ  IOCTL.io_code
150
input      equ  IOCTL.input
151
inp_size   equ  IOCTL.inp_size
152
output     equ  IOCTL.output
153
out_size   equ  IOCTL.out_size
769 Rus 154
 
155
align 4
156
proc service_proc stdcall, ioctl:dword
157
 
2434 Serge 158
        mov     ebx, [ioctl]
159
        mov     eax, [ebx+io_code]
160
        cmp     eax, SRV_GETVERSION
161
        jne     @F
769 Rus 162
 
2434 Serge 163
        mov     eax, [ebx+output]
164
        cmp     [ebx+out_size], 4
165
        jne     .fail
166
        mov     [eax], dword API_VERSION
167
        xor     eax, eax
168
        ret
769 Rus 169
@@:
170
.fail:
2434 Serge 171
        or      eax, -1
172
        ret
769 Rus 173
endp
174
 
175
align 4
176
MSMouseSearch:
2434 Serge 177
        ; ПОИСК МЫШИ ЧЕРЕЗ COM-ПОРТЫ
769 Rus 178
MouseSearch:
2434 Serge 179
        ; Устанавливаем скорость
180
        ; приема/передачи 1200 бод
181
        ; in bx COM Port Base Address
182
        mov     DX, bx
183
        add     DX, 3
184
        in      AL, DX
185
        or      AL, 80h ;установить бит DLAB
186
        out     DX, AL
187
        mov     DX, bx
188
        mov     AL, 60h ;1200 бод
189
        out     DX, AL
190
        inc     DX
191
        mov     AL, 0
192
        out     DX, AL
193
        ; Установить длину слова 7 бит, 1 стоповый бит,
194
        ; четность не контролировать
195
        mov     DX, bx
196
        add     DX, 3
197
        mov     AL, 00000010b
198
        out     DX, AL
199
        ; Запретить все прерывани
200
        mov     dx, bx
201
        inc     dx
202
        mov     AL, 0
203
        out     DX, AL
769 Rus 204
; Проверить, что устройство подключено и являетс
205
; мышью типа MSMouse
2434 Serge 206
        ; Отключить питание мыши и прерывани
207
        mov     DX, bx
208
        add     EDX, 4  ;регистр управления модемом
209
        mov     AL, 0   ;сбросить DTR, RTS и OUT2
210
        out     DX, AL
211
        ; Ожидать 5 "тиков" (0,2 с)
212
        mov     ecx, 0xFFFF
213
        loop    $
214
        ; Включить питание мыши
215
        mov     al, 1
216
        out     dx, al
217
        mov     ecx, 0xFFFF
218
        loop    $
219
        ; Очистить регистр данных
220
        mov     dx, bx
221
        in      AL, DX
222
        add     edx, 4
223
        mov     AL, 1011b  ;установить DTR и RTS и OUT2
224
        out     DX, AL
225
        mov     ecx, 0x1FFFF
769 Rus 226
; Цикл опроса порта
227
WaitData:
2434 Serge 228
        ; Ожидать еще 10 "тиков"
229
        dec     ecx
230
;        cmp  ecx,0
231
        jz      NoMouse
232
        ; Проверить наличие идентификационного байта
233
        mov     DX, bx
234
        add     DX, 5
235
        in      AL, DX
236
        test    AL, 1  ;Данные готовы?
237
        jz      WaitData
238
        ; Ввести данные
239
        mov     DX, bx
240
        in      AL, DX
769 Rus 241
NoMouse:
2434 Serge 242
        ret
769 Rus 243
 
244
align 4
245
irq3_handler:
2434 Serge 246
        mov     dx, 0x2f8
247
        mov     esi, com2_mouse
248
        jmp     irq_handler
769 Rus 249
 
250
align 4
251
irq4_handler:
2434 Serge 252
        mov     dx, 0x3f8
253
        mov     esi, com1_mouse
769 Rus 254
 
255
irq_handler:
256
 
257
; in: esi -> COM_MOUSE_DATA struc, dx = base port (xF8h)
2434 Serge 258
        add     edx, 5          ; xFDh
259
        in      al, dx
260
        test    al, 1           ; Данные готовы?
261
        jz      .Error
769 Rus 262
; Ввести данные
2434 Serge 263
        sub     edx, 5
264
        in      al, dx
769 Rus 265
; Сбросить старший незначащий бит
2434 Serge 266
        and     al, 01111111b
769 Rus 267
 
268
; Определить порядковый номер принимаемого байта
2434 Serge 269
        cmp     [esi+COM_MOUSE_DATA.MouseByteNumber], 2
270
        ja      .Error
271
        jz      .ThirdByte
272
        jp      .SecondByte
769 Rus 273
; Сохранить первый байт данных
274
.FirstByte:
2434 Serge 275
        test    al, 1000000b    ; Первый байт посылки?
276
        jz      .Error
277
        mov     [esi+COM_MOUSE_DATA.FirstByte], al
278
        inc     [esi+COM_MOUSE_DATA.MouseByteNumber]
279
        jmp     .EndMouseInterrupt
769 Rus 280
; Сохранить второй байт данных
281
.SecondByte:
2434 Serge 282
        test    al, 1000000b
283
        jnz     .Error
284
        mov     [esi+COM_MOUSE_DATA.SecondByte], al
285
        inc     [esi+COM_MOUSE_DATA.MouseByteNumber]
286
        jmp     .EndMouseInterrupt
769 Rus 287
; Сохранить третий байт данных
288
.ThirdByte:
2434 Serge 289
        test    al, 1000000b
290
        jnz     .Error
291
        mov     [esi+COM_MOUSE_DATA.ThirdByte], al
292
        mov     [esi+COM_MOUSE_DATA.MouseByteNumber], 0
769 Rus 293
; (Пакет данных от мыши принят полностью).
294
; Записать новое значение состояния кнопок мыши
2434 Serge 295
        mov     al, [esi+COM_MOUSE_DATA.FirstByte]
296
        mov     ah, al
297
        shr     al, 3
298
        and     al, 2
299
        shr     ah, 5
300
        and     ah, 1
301
        add     al, ah
302
        movzx   eax, al
303
        mov     [BTN_DOWN], eax
769 Rus 304
 
305
; Прибавить перемещение по X к координате X
2434 Serge 306
        mov     al, [esi+COM_MOUSE_DATA.FirstByte]
307
        shl     al, 6
308
        or      al, [esi+COM_MOUSE_DATA.SecondByte]
769 Rus 309
 
2434 Serge 310
        cbw
311
        movzx   eax, ax
312
        mov     [MOUSE_X], eax
769 Rus 313
 
314
; Прибавить перемещение по Y к координате Y
2434 Serge 315
        mov     al, [esi+COM_MOUSE_DATA.FirstByte]
316
        and     al, 00001100b
317
        shl     al, 4
318
        or      al, [esi+COM_MOUSE_DATA.ThirdByte]
769 Rus 319
 
2434 Serge 320
        cbw
321
        movzx   eax, ax
322
        neg     eax
323
        mov     [MOUSE_Y], eax
769 Rus 324
 
2434 Serge 325
        stdcall SetMouseData, [BTN_DOWN], [MOUSE_X], [MOUSE_Y], 0, 0
769 Rus 326
 
2434 Serge 327
        jmp     .EndMouseInterrupt
769 Rus 328
 
329
.Error:
330
; Произошел сбой в порядке передачи информации от
331
; мыши, обнулить счетчик байтов пакета данных
332
 
2434 Serge 333
        mov     [esi+COM_MOUSE_DATA.MouseByteNumber], 0
769 Rus 334
.EndMouseInterrupt:
2434 Serge 335
        mov     al, 1
336
        ret
769 Rus 337
 
338
;all initialized data place here
339
 
340
align 4
341
 
342
struc COM_MOUSE_DATA {
343
; Номер принимаемого от мыши байта
2434 Serge 344
        .MouseByteNumber        db      ?
769 Rus 345
; Трехбайтовая структура данных, передаваемая мышью
2434 Serge 346
        .FirstByte              db      ?
347
        .SecondByte             db      ?
348
        .ThirdByte              db      ?
349
        ;.timer_ticks_com        dd      ?
769 Rus 350
}
351
virtual at 0
352
 COM_MOUSE_DATA COM_MOUSE_DATA
353
end virtual
354
 
355
com1_mouse COM_MOUSE_DATA
356
com2_mouse COM_MOUSE_DATA
357
 
358
MOUSE_X      dd 0
359
MOUSE_Y      dd 0
360
BTN_DOWN     dd 0
361
 
362
COMPortBaseAddr dw 3F8h
363
 
364
 
365
 
366
version      dd (5 shl 16) or (API_VERSION and 0xFFFF)
367
 
774 Rus 368
my_service   db 'COM_Mouse',0  ;max 16 chars include zero
769 Rus 369
 
370
if DEBUG
2434 Serge 371
msgInit                      db   'Preved bugoga!',13,10,0
372
boot_setmouse_type           db   'Detected - COM1 mouse',13,10,0
373
                             db   'Detected - COM2 mouse',13,10,0
769 Rus 374
msg_error_reserve_ports      db   'Error reserving ports!',13,10,0
375
msg_error_attach_int_handler db   'Error attach interrupt handler!',13,10,0
2434 Serge 376
msg_exit                     db   'Exit!',13,10,0
769 Rus 377
end if
378
 
379
section '.data' data readable writable align 16
380
 
381
;all uninitialized data place here
382