Subversion Repositories Kolibri OS

Rev

Rev 5596 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
5565 serge 3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
431 serge 4
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
593 mikedld 8
$Revision: 5984 $
9
 
10
 
1 ha 11
VKEY_LSHIFT   = 0000000000000001b
12
VKEY_RSHIFT   = 0000000000000010b
13
VKEY_LCONTROL = 0000000000000100b
14
VKEY_RCONTROL = 0000000000001000b
15
VKEY_LALT     = 0000000000010000b
16
VKEY_RALT     = 0000000000100000b
17
VKEY_CAPSLOCK = 0000000001000000b
18
VKEY_NUMLOCK  = 0000000010000000b
19
VKEY_SCRLOCK  = 0000000100000000b
3500 Serge 20
VKEY_LWIN     = 0000001000000000b
21
VKEY_RWIN     = 0000010000000000b
1 ha 22
 
23
VKEY_SHIFT    = 0000000000000011b
24
VKEY_CONTROL  = 0000000000001100b
25
VKEY_ALT      = 0000000000110000b
26
 
27
uglobal
5984 serge 28
  align 4
29
  kb_state      dd 0
2434 Serge 30
  ext_code      db 0
1 ha 31
 
32
  keyboard_mode db 0
33
  keyboard_data db 0
34
 
2434 Serge 35
  altmouseb     db 0
36
  ctrl_alt_del  db 0
1 ha 37
 
5984 serge 38
  kb_lights     db 0
2987 Serge 39
  old_kb_lights db 0
92 diamond 40
 
41
align 4
2434 Serge 42
        hotkey_scancodes        rd      256     ; we have 256 scancodes
43
        hotkey_list             rd      256*4   ; max 256 defined hotkeys
44
        hotkey_buffer           rd      120*2   ; buffer for 120 hotkeys
1 ha 45
endg
46
 
92 diamond 47
iglobal
2434 Serge 48
hotkey_tests    dd      hotkey_test0
49
                dd      hotkey_test1
50
                dd      hotkey_test2
51
                dd      hotkey_test3
52
                dd      hotkey_test4
92 diamond 53
hotkey_tests_num = 5
54
endg
2209 Serge 55
;---------------------------------------------------------------------
92 diamond 56
hotkey_test0:
2434 Serge 57
        test    al, al
58
        setz    al
59
        ret
2209 Serge 60
;---------------------------------------------------------------------
92 diamond 61
hotkey_test1:
2434 Serge 62
        test    al, al
63
        setnp   al
64
        ret
2209 Serge 65
;---------------------------------------------------------------------
92 diamond 66
hotkey_test2:
2434 Serge 67
        cmp     al, 3
68
        setz    al
69
        ret
2209 Serge 70
;---------------------------------------------------------------------
92 diamond 71
hotkey_test3:
2434 Serge 72
        cmp     al, 1
73
        setz    al
74
        ret
2209 Serge 75
;---------------------------------------------------------------------
92 diamond 76
hotkey_test4:
2434 Serge 77
        cmp     al, 2
78
        setz    al
79
        ret
2209 Serge 80
;---------------------------------------------------------------------
92 diamond 81
hotkey_do_test:
2434 Serge 82
        push    eax
83
        mov     edx, [kb_state]
84
        shr     edx, cl
85
        add     cl, cl
86
        mov     eax, [eax+4]
87
        shr     eax, cl
88
        and     eax, 15
89
        cmp     al, hotkey_tests_num
90
        jae     .fail
91
 
92
        xchg    eax, edx
93
        and     al, 3
94
        call    [hotkey_tests + edx*4]
95
        cmp     al, 1
96
        pop     eax
97
        ret
2209 Serge 98
;--------------------------------------
92 diamond 99
.fail:
2434 Serge 100
        stc
101
        pop     eax
102
        ret
2209 Serge 103
;---------------------------------------------------------------------
1 ha 104
align 4
2010 serge 105
set_keyboard_data:
2434 Serge 106
        movzx   eax, word[TASK_COUNT]; top window process
107
        movzx   eax, word[WIN_POS+eax*2]
108
        shl     eax, 8
109
        mov     al, [SLOT_BASE+eax+APPDATA.keyboard_mode]
110
        mov     [keyboard_mode], al
111
 
112
        mov     eax, ecx
113
 
114
        push    ebx esi edi ebp
115
        call    send_scancode
116
        pop     ebp edi esi ebx
117
        ret
2209 Serge 118
;---------------------------------------------------------------------
2987 Serge 119
struct KEYBOARD
120
next           dd      ?
121
prev           dd      ?
122
functions      dd      ?
123
userdata       dd      ?
124
ends
125
struct KBDFUNC
126
strucsize      dd      ?
127
close          dd      ?
128
setlights      dd      ?
129
ends
130
 
131
iglobal
132
keyboards:
133
        dd      keyboards
134
        dd      keyboards
135
endg
136
uglobal
137
keyboard_list_mutex     MUTEX
138
endg
139
 
140
register_keyboard:
141
        push    ebx
3626 Serge 142
        movi    eax, sizeof.KEYBOARD
2987 Serge 143
        call    malloc
144
        test    eax, eax
145
        jz      .nothing
146
        mov     ecx, [esp+4+4]
147
        mov     [eax+KEYBOARD.functions], ecx
148
        mov     ecx, [esp+8+4]
149
        mov     [eax+KEYBOARD.userdata], ecx
150
        xchg    eax, ebx
151
        mov     ecx, keyboard_list_mutex
152
        call    mutex_lock
153
        mov     ecx, keyboards
154
        mov     edx, [ecx+KEYBOARD.prev]
155
        mov     [ebx+KEYBOARD.next], ecx
156
        mov     [ebx+KEYBOARD.prev], edx
157
        mov     [edx+KEYBOARD.next], ebx
158
        mov     [ecx+KEYBOARD.prev], ebx
159
        mov     ecx, [ebx+KEYBOARD.functions]
160
        cmp     [ecx+KBDFUNC.strucsize], KBDFUNC.setlights
161
        jbe     .unlock
162
        mov     ecx, [ecx+KBDFUNC.setlights]
163
        test    ecx, ecx
164
        jz      .unlock
165
        stdcall ecx, [ebx+KEYBOARD.userdata], dword [kb_lights]
166
.unlock:
167
        mov     ecx, keyboard_list_mutex
168
        call    mutex_unlock
169
        xchg    eax, ebx
170
.nothing:
171
        pop     ebx
172
        ret     8
173
 
174
delete_keyboard:
175
        push    ebx
176
        mov     ebx, [esp+4+4]
177
        mov     ecx, keyboard_list_mutex
178
        call    mutex_lock
179
        mov     eax, [ebx+KEYBOARD.next]
180
        mov     edx, [ebx+KEYBOARD.prev]
181
        mov     [eax+KEYBOARD.prev], edx
182
        mov     [edx+KEYBOARD.next], eax
183
        call    mutex_unlock
184
        mov     ecx, [ebx+KEYBOARD.functions]
185
        cmp     [ecx+KBDFUNC.strucsize], KBDFUNC.close
186
        jbe     .nothing
187
        mov     ecx, [ecx+KBDFUNC.close]
188
        test    ecx, ecx
189
        jz      .nothing
190
        stdcall ecx, [ebx+KEYBOARD.userdata]
191
.nothing:
192
        pop     ebx
193
        ret     4
194
;---------------------------------------------------------------------
2010 serge 195
align 4
1 ha 196
irq1:
2434 Serge 197
        movzx   eax, word[TASK_COUNT]; top window process
198
        movzx   eax, word[WIN_POS+eax*2]
199
        shl     eax, 8
200
        mov     al, [SLOT_BASE+eax+APPDATA.keyboard_mode]
201
        mov     [keyboard_mode], al
202
 
203
        in      al, 0x60
2209 Serge 204
;--------------------------------------
2010 serge 205
send_scancode:
2434 Serge 206
        mov     [keyboard_data], al
92 diamond 207
; ch = scancode
208
; cl = ext_code
209
; bh = 0 - normal key
210
; bh = 1 - modifier (Shift/Ctrl/Alt)
211
; bh = 2 - extended code
2434 Serge 212
        mov     ch, al
213
        cmp     al, 0xE0
214
        je      @f
215
 
216
        cmp     al, 0xE1
217
        jne     .normal_code
2209 Serge 218
@@:
2434 Serge 219
        mov     bh, 2
220
        mov     [ext_code], al
221
        jmp     .writekey
2209 Serge 222
;--------------------------------------
223
.normal_code:
2434 Serge 224
        mov     cl, 0
225
        xchg    cl, [ext_code]
226
        and     al, 0x7F
227
        mov     bh, 1
3500 Serge 228
;--------------------------------------
2209 Serge 229
@@:
3500 Serge 230
        cmp     al, 0x5B
231
        jne     @f
232
 
233
        cmp     cl, 0xE0
234
        jne     @f
235
 
236
        mov     eax, VKEY_LWIN
237
        mov     bh, 0
238
        jmp     .modifier
239
;--------------------------------------
240
@@:
241
        cmp     al, 0x5C
242
        jne     @f
243
 
244
        cmp     cl, 0xE0
245
        jne     @f
246
 
247
        mov     eax, VKEY_RWIN
248
        mov     bh, 0
249
        jmp     .modifier
250
;--------------------------------------
251
@@:
2434 Serge 252
        cmp     al, 0x2A
253
        jne     @f
254
 
255
        cmp     cl, 0xE0
256
        je      .writekey
257
 
258
        mov     eax, VKEY_LSHIFT
259
        jmp     .modifier
2209 Serge 260
;--------------------------------------
261
@@:
2434 Serge 262
        cmp     al, 0x36
263
        jne     @f
264
 
265
        cmp     cl, 0xE0
266
        je      .writekey
267
 
268
        mov     eax, VKEY_RSHIFT
269
        jmp     .modifier
2209 Serge 270
;--------------------------------------
271
@@:
2434 Serge 272
        cmp     al, 0x38
273
        jne     @f
274
 
275
        mov     eax, VKEY_LALT
276
        test    cl, cl
277
        jz      .modifier
278
 
279
        mov     al, VKEY_RALT
280
        jmp     .modifier
2209 Serge 281
;--------------------------------------
282
@@:
2434 Serge 283
        cmp     al, 0x1D
284
        jne     @f
285
 
286
        mov     eax, VKEY_LCONTROL
287
        test    cl, cl
288
        jz      .modifier
289
 
290
        mov     al, VKEY_RCONTROL
291
        cmp     cl, 0xE0
292
        jz      .modifier
293
 
294
        mov     [ext_code], cl
295
        jmp     .writekey
2209 Serge 296
;--------------------------------------
297
@@:
2434 Serge 298
        cmp     al, 0x3A
299
        jne     @f
300
 
301
        mov     bl, 4
302
        mov     eax, VKEY_CAPSLOCK
303
        jmp     .no_key.xor
2209 Serge 304
;--------------------------------------
305
@@:
2434 Serge 306
        cmp     al, 0x45
307
        jne     @f
308
        test    cl, cl
309
        jnz     .writekey
310
 
311
        mov     bl, 2
312
        mov     eax, VKEY_NUMLOCK
313
        jmp     .no_key.xor
2209 Serge 314
;--------------------------------------
315
@@:
2434 Serge 316
        cmp     al, 0x46
317
        jne     @f
318
 
319
        mov     bl, 1
320
        mov     eax, VKEY_SCRLOCK
321
        jmp     .no_key.xor
2209 Serge 322
;--------------------------------------
323
@@:
2434 Serge 324
        xor     ebx, ebx
325
        test    ch, ch
326
        js      .writekey
327
 
328
        movzx   eax, ch          ; plain key
329
        mov     bl, [keymap+eax]
330
        mov     edx, [kb_state]
331
        test    dl, VKEY_CONTROL ; ctrl alt del
332
        jz      .noctrlaltdel
333
 
334
        test    dl, VKEY_ALT
335
        jz      .noctrlaltdel
336
 
337
        cmp     ch, 53h
338
        jne     .noctrlaltdel
339
 
340
        mov     [ctrl_alt_del], 1
3555 Serge 341
        call    wakeup_osloop
2209 Serge 342
.noctrlaltdel:
2434 Serge 343
        test    dl, VKEY_CONTROL ; ctrl on ?
344
        jz      @f
345
 
346
        sub     bl, 0x60
2209 Serge 347
@@:
2434 Serge 348
        test    dl, VKEY_CAPSLOCK        ; caps lock on ?
349
        jz      .no_caps_lock
350
 
351
        test    dl, VKEY_SHIFT   ; shift on ?
352
        jz      .keymap_shif
353
 
354
        jmp     @f
2209 Serge 355
;--------------------------------------
356
.no_caps_lock:
2434 Serge 357
        test    dl, VKEY_SHIFT   ; shift on ?
358
        jz      @f
359
.keymap_shif:
360
        mov     bl, [keymap_shift+eax]
2209 Serge 361
@@:
2434 Serge 362
        test    dl, VKEY_ALT     ; alt on ?
363
        jz      @f
364
 
365
        mov     bl, [keymap_alt+eax]
2209 Serge 366
@@:
2434 Serge 367
        jmp     .writekey
2209 Serge 368
;--------------------------------------
92 diamond 369
.modifier:
2434 Serge 370
        test    ch, ch
371
        js      .modifier.up
372
        or      [kb_state], eax
373
        jmp     .writekey
2209 Serge 374
;--------------------------------------
92 diamond 375
.modifier.up:
2434 Serge 376
        not     eax
377
        and     [kb_state], eax
378
        jmp     .writekey
2209 Serge 379
;--------------------------------------
92 diamond 380
.no_key.xor:
2434 Serge 381
        mov     bh, 0
382
        test    ch, ch
383
        js      .writekey
384
 
385
        xor     [kb_state], eax
386
        xor     [kb_lights], bl
92 diamond 387
.writekey:
2987 Serge 388
        pushad
92 diamond 389
; test for system hotkeys
2434 Serge 390
        movzx   eax, ch
391
        cmp     bh, 1
392
        ja      .nohotkey
393
        jb      @f
394
 
395
        xor     eax, eax
92 diamond 396
@@:
2434 Serge 397
        mov     eax, [hotkey_scancodes + eax*4]
92 diamond 398
.hotkey_loop:
2434 Serge 399
        test    eax, eax
400
        jz      .nohotkey
401
 
402
        mov     cl, 0
403
        call    hotkey_do_test
404
        jc      .hotkey_cont
405
 
406
        mov     cl, 2
407
        call    hotkey_do_test
408
        jc      .hotkey_cont
409
 
410
        mov     cl, 4
411
        call    hotkey_do_test
412
        jnc     .hotkey_found
92 diamond 413
.hotkey_cont:
2434 Serge 414
        mov     eax, [eax]
415
        jmp     .hotkey_loop
2209 Serge 416
;--------------------------------------
92 diamond 417
.hotkey_found:
2434 Serge 418
        mov     eax, [eax+8]
92 diamond 419
; put key in buffer for process in slot eax
2434 Serge 420
        mov     edi, hotkey_buffer
92 diamond 421
@@:
2434 Serge 422
        cmp     dword [edi], 0
423
        jz      .found_free
424
 
425
        add     edi, 8
426
        cmp     edi, hotkey_buffer+120*8
427
        jb      @b
92 diamond 428
; no free space - replace first entry
2434 Serge 429
        mov     edi, hotkey_buffer
92 diamond 430
.found_free:
2434 Serge 431
        mov     [edi], eax
432
        movzx   eax, ch
433
        cmp     bh, 1
434
        jnz     @f
435
 
436
        xor     eax, eax
92 diamond 437
@@:
2434 Serge 438
        mov     [edi+4], ax
439
        mov     eax, [kb_state]
440
        mov     [edi+6], ax
2987 Serge 441
 
442
        cmp     [PID_lock_input], dword 0
443
        je      .nohotkey
444
 
445
        popad
2434 Serge 446
        jmp     .exit.irq1
2209 Serge 447
;--------------------------------------
92 diamond 448
.nohotkey:
2987 Serge 449
        popad
450
 
2434 Serge 451
        cmp     [keyboard_mode], 0; return from keymap
452
        jne     .scancode
453
 
454
        test    bh, bh
455
        jnz     .exit.irq1
456
 
457
        test    bl, bl
458
        jz      .exit.irq1
582 Rus 459
 
5201 serge 460
        cmp     cl, 0xE0        ; extended keycode
461
        jne     @f
462
 
463
        cmp     ch, 53
464
        jne     .dowrite
2434 Serge 465
 
5201 serge 466
        mov     bl, '/'
467
        jmp     .dowrite
468
@@:
5596 serge 469
 
2434 Serge 470
        cmp     ch, 55
5201 serge 471
        jne     @f
2434 Serge 472
 
5201 serge 473
        mov     bl, '*'
2434 Serge 474
        jmp     .dowrite
2209 Serge 475
@@:
5201 serge 476
 
477
        cmp     ch, 74
478
        jne     @f
479
 
480
        mov     bl, '-'
481
        jmp     .dowrite
482
@@:
483
 
484
        cmp     ch, 78
485
        jne     @f
486
 
487
        mov     bl, '+'
488
        jmp     .dowrite
489
@@:
490
 
491
        test    [kb_state], VKEY_NUMLOCK
492
        jz      .dowrite
493
 
2434 Serge 494
        cmp     ch, 71
495
        jb      .dowrite
496
 
497
        cmp     ch, 83
498
        ja      .dowrite
499
 
500
        movzx   eax, ch
501
        mov     bl, [numlock_map + eax - 71]
502
        jmp     .dowrite
2209 Serge 503
;--------------------------------------
92 diamond 504
.scancode:
2434 Serge 505
        mov     bl, ch
92 diamond 506
.dowrite:
2434 Serge 507
        movzx   eax, byte[KEY_COUNT]
508
        cmp     al, 120
509
        jae     .exit.irq1
510
        inc     eax
511
        mov     [KEY_COUNT], al
5201 serge 512
; store ascii or scancode
513
        mov     [KEY_COUNT+eax], bl ; actually KEY_BUFF + EAX - 1
514
; store original scancode
515
        add     eax, 120+2
516
        push    ecx
517
        cmp     [keyboard_mode], 0; return from keymap
518
        je      @f
519
 
520
        xor     ch, ch
521
@@:
522
        mov     [KEY_COUNT+eax], ch ; actually KEY_BUFF + EAX - 1
523
        pop     ecx
524
        sub     eax, 120+2
2209 Serge 525
.exit.irq1:
2434 Serge 526
        ret
2209 Serge 527
;---------------------------------------------------------------------
1 ha 528
set_lights:
2987 Serge 529
        push    ebx esi
530
        mov     ecx, keyboard_list_mutex
531
        call    mutex_lock
532
        mov     esi, keyboards
533
.loop:
534
        mov     esi, [esi+KEYBOARD.next]
535
        cmp     esi, keyboards
536
        jz      .done
537
        mov     eax, [esi+KEYBOARD.functions]
538
        cmp     dword [eax], KBDFUNC.setlights
539
        jbe     .loop
540
        mov     eax, [eax+KBDFUNC.setlights]
541
        test    eax, eax
542
        jz      .loop
543
        stdcall eax, [esi+KEYBOARD.userdata], dword [kb_lights]
544
        jmp     .loop
545
.done:
546
        mov     ecx, keyboard_list_mutex
547
        call    mutex_unlock
548
        pop     esi ebx
549
        ret
550
 
551
ps2_set_lights:
3500 Serge 552
        stdcall disable_irq, 1
2434 Serge 553
        mov     al, 0xED
5201 serge 554
        call    kb_write_wait_ack
2987 Serge 555
        mov     al, [esp+8]
5201 serge 556
        call    kb_write_wait_ack
3500 Serge 557
        stdcall enable_irq, 1
2987 Serge 558
        ret     8
559
 
560
;// mike.dld ]
3555 Serge 561
proc check_lights_state_has_work?
2434 Serge 562
        mov     al, [kb_lights]
2987 Serge 563
        cmp     al, [old_kb_lights]
3555 Serge 564
        ret
565
endp
566
 
567
check_lights_state:
568
        call    check_lights_state_has_work?
2987 Serge 569
        jz      .nothing
570
        mov     [old_kb_lights], al
571
        call    set_lights
572
.nothing:
2434 Serge 573
        ret
2209 Serge 574
;---------------------------------------------------------------------
582 Rus 575
numlock_map:
2434 Serge 576
    db   0x37   ;Num 7
577
    db   0x38   ;Num 8
578
    db   0x39   ;Num 9
579
    db   0x2D   ;Num -
580
    db   0x34   ;Num 4
581
    db   0x35   ;Num 5
582
    db   0x36   ;Num 6
583
    db   0x2B   ;Num +
584
    db   0x31   ;Num 1
585
    db   0x32   ;Num 2
586
    db   0x33   ;Num 3
587
    db   0x30   ;Num 0
588
    db   0x2E   ;Num .
2209 Serge 589
;---------------------------------------------------------------------