Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
2288 clevermous 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
10051 ace_dent 3
;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;;
2288 clevermous 4
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
8
 
8892 dunkaist 9
VKEY_LSHIFT   = 00000000_00000001b
10
VKEY_RSHIFT   = 00000000_00000010b
11
VKEY_LCONTROL = 00000000_00000100b
12
VKEY_RCONTROL = 00000000_00001000b
13
VKEY_LALT     = 00000000_00010000b
14
VKEY_RALT     = 00000000_00100000b
15
VKEY_CAPSLOCK = 00000000_01000000b
16
VKEY_NUMLOCK  = 00000000_10000000b
17
VKEY_SCRLOCK  = 00000001_00000000b
18
VKEY_LWIN     = 00000010_00000000b
19
VKEY_RWIN     = 00000100_00000000b
2288 clevermous 20
 
8892 dunkaist 21
VKEY_SHIFT    = VKEY_LSHIFT + VKEY_RSHIFT
22
VKEY_CONTROL  = VKEY_LCONTROL + VKEY_RCONTROL
23
VKEY_ALT      = VKEY_LALT + VKEY_RALT
2288 clevermous 24
 
25
uglobal
5797 leency 26
  align 4
27
  kb_state      dd 0
2288 clevermous 28
  ext_code      db 0
29
 
30
  keyboard_mode db 0
31
  keyboard_data db 0
32
 
33
  altmouseb     db 0
34
  ctrl_alt_del  db 0
35
 
5797 leency 36
  kb_lights     db 0
2601 clevermous 37
  old_kb_lights db 0
2288 clevermous 38
 
39
align 4
40
        hotkey_scancodes        rd      256     ; we have 256 scancodes
41
        hotkey_list             rd      256*4   ; max 256 defined hotkeys
42
        hotkey_buffer           rd      120*2   ; buffer for 120 hotkeys
43
endg
44
 
45
iglobal
46
hotkey_tests    dd      hotkey_test0
47
                dd      hotkey_test1
48
                dd      hotkey_test2
49
                dd      hotkey_test3
50
                dd      hotkey_test4
51
hotkey_tests_num = 5
52
endg
53
;---------------------------------------------------------------------
54
hotkey_test0:
55
        test    al, al
56
        setz    al
57
        ret
58
;---------------------------------------------------------------------
59
hotkey_test1:
60
        test    al, al
61
        setnp   al
62
        ret
63
;---------------------------------------------------------------------
64
hotkey_test2:
65
        cmp     al, 3
66
        setz    al
67
        ret
68
;---------------------------------------------------------------------
69
hotkey_test3:
70
        cmp     al, 1
71
        setz    al
72
        ret
73
;---------------------------------------------------------------------
74
hotkey_test4:
75
        cmp     al, 2
76
        setz    al
77
        ret
78
;---------------------------------------------------------------------
79
hotkey_do_test:
80
        push    eax
81
        mov     edx, [kb_state]
82
        shr     edx, cl
83
        add     cl, cl
84
        mov     eax, [eax+4]
85
        shr     eax, cl
86
        and     eax, 15
87
        cmp     al, hotkey_tests_num
88
        jae     .fail
10051 ace_dent 89
 
2288 clevermous 90
        xchg    eax, edx
91
        and     al, 3
92
        call    [hotkey_tests + edx*4]
93
        cmp     al, 1
94
        pop     eax
95
        ret
96
;--------------------------------------
97
.fail:
98
        stc
99
        pop     eax
100
        ret
101
;---------------------------------------------------------------------
102
align 4
9911 Doczom 103
; @brief Export function - Add new scancode in buffer
104
; @param ecx - scancode
105
; @return  not return
2288 clevermous 106
set_keyboard_data:
8866 rgimad 107
        movzx   eax, word[thread_count]; top window process
9715 Doczom 108
        movzx   eax, word[WIN_POS + eax*2]
9828 Doczom 109
        shl     eax, BSF sizeof.APPDATA
9715 Doczom 110
        mov     al, [SLOT_BASE + eax + APPDATA.keyboard_mode]
2288 clevermous 111
        mov     [keyboard_mode], al
10051 ace_dent 112
 
2288 clevermous 113
        mov     eax, ecx
10051 ace_dent 114
 
2288 clevermous 115
        push    ebx esi edi ebp
116
        call    send_scancode
117
        pop     ebp edi esi ebx
118
        ret
119
;---------------------------------------------------------------------
9911 Doczom 120
struct  KEYBOARD
121
        next           dd      ?
122
        prev           dd      ?
123
        functions      dd      ?
124
        userdata       dd      ?
2601 clevermous 125
ends
9911 Doczom 126
 
127
struct  KBDFUNC
128
        strucsize      dd      ?
129
        close          dd      ?
130
        setlights      dd      ?
2601 clevermous 131
ends
132
 
133
iglobal
134
keyboards:
135
        dd      keyboards
136
        dd      keyboards
137
endg
138
uglobal
139
keyboard_list_mutex     MUTEX
140
endg
141
 
9911 Doczom 142
; @brief Export function - Registration new keyboard
143
; @param [esp + 4] - pointer on KBDFUNC this keyboard
144
; @param [esp + 8] - userdata for callback function
145
; @return  eax = pointer on KEYBOARD structure or 0 on error
2601 clevermous 146
register_keyboard:
147
        push    ebx
3598 clevermous 148
        movi    eax, sizeof.KEYBOARD
2601 clevermous 149
        call    malloc
150
        test    eax, eax
151
        jz      .nothing
152
        mov     ecx, [esp+4+4]
9715 Doczom 153
        mov     [eax + KEYBOARD.functions], ecx
2601 clevermous 154
        mov     ecx, [esp+8+4]
9715 Doczom 155
        mov     [eax + KEYBOARD.userdata], ecx
2601 clevermous 156
        xchg    eax, ebx
157
        mov     ecx, keyboard_list_mutex
158
        call    mutex_lock
159
        mov     ecx, keyboards
9715 Doczom 160
        mov     edx, [ecx + KEYBOARD.prev]
161
        mov     [ebx + KEYBOARD.next], ecx
162
        mov     [ebx + KEYBOARD.prev], edx
163
        mov     [edx + KEYBOARD.next], ebx
164
        mov     [ecx + KEYBOARD.prev], ebx
165
        mov     ecx, [ebx + KEYBOARD.functions]
166
        cmp     [ecx + KBDFUNC.strucsize], KBDFUNC.setlights
2601 clevermous 167
        jbe     .unlock
9715 Doczom 168
        mov     ecx, [ecx + KBDFUNC.setlights]
2601 clevermous 169
        test    ecx, ecx
170
        jz      .unlock
9715 Doczom 171
        stdcall ecx, [ebx + KEYBOARD.userdata], dword [kb_lights]
2601 clevermous 172
.unlock:
173
        mov     ecx, keyboard_list_mutex
174
        call    mutex_unlock
175
        xchg    eax, ebx
176
.nothing:
177
        pop     ebx
178
        ret     8
179
 
9911 Doczom 180
; @brief Export function - Delete keyboard
181
; @param [esp + 4] -  pointer on KEYBOARD structure
182
; @return  not return
2601 clevermous 183
delete_keyboard:
184
        push    ebx
185
        mov     ebx, [esp+4+4]
186
        mov     ecx, keyboard_list_mutex
187
        call    mutex_lock
9715 Doczom 188
        mov     eax, [ebx + KEYBOARD.next]
189
        mov     edx, [ebx + KEYBOARD.prev]
190
        mov     [eax + KEYBOARD.prev], edx
191
        mov     [edx + KEYBOARD.next], eax
2601 clevermous 192
        call    mutex_unlock
9715 Doczom 193
        mov     ecx, [ebx + KEYBOARD.functions]
194
        cmp     [ecx + KBDFUNC.strucsize], KBDFUNC.close
2601 clevermous 195
        jbe     .nothing
9715 Doczom 196
        mov     ecx, [ecx + KBDFUNC.close]
2601 clevermous 197
        test    ecx, ecx
198
        jz      .nothing
9715 Doczom 199
        stdcall ecx, [ebx + KEYBOARD.userdata]
2601 clevermous 200
.nothing:
201
        pop     ebx
202
        ret     4
203
;---------------------------------------------------------------------
2288 clevermous 204
align 4
205
irq1:
8866 rgimad 206
        movzx   eax, word[thread_count]; top window process
9715 Doczom 207
        movzx   eax, word[WIN_POS + eax*2]
8892 dunkaist 208
        shl     eax, BSF sizeof.APPDATA
9715 Doczom 209
        mov     al, [SLOT_BASE + eax + APPDATA.keyboard_mode]
2288 clevermous 210
        mov     [keyboard_mode], al
10051 ace_dent 211
 
2288 clevermous 212
        in      al, 0x60
213
;--------------------------------------
214
send_scancode:
9828 Doczom 215
        ;DEBUGF  1, "K : Scan code: %x \n", al
2288 clevermous 216
        mov     [keyboard_data], al
217
; ch = scancode
218
; cl = ext_code
219
; bh = 0 - normal key
220
; bh = 1 - modifier (Shift/Ctrl/Alt)
221
; bh = 2 - extended code
222
        mov     ch, al
223
        cmp     al, 0xE0
224
        je      @f
10051 ace_dent 225
 
2288 clevermous 226
        cmp     al, 0xE1
227
        jne     .normal_code
228
@@:
229
        mov     bh, 2
230
        mov     [ext_code], al
231
        jmp     .writekey
232
;--------------------------------------
233
.normal_code:
234
        mov     cl, 0
235
        xchg    cl, [ext_code]
236
        and     al, 0x7F
237
        mov     bh, 1
3355 mario79 238
;--------------------------------------
2288 clevermous 239
@@:
3355 mario79 240
        cmp     al, 0x5B
241
        jne     @f
10051 ace_dent 242
 
3355 mario79 243
        cmp     cl, 0xE0
3356 mario79 244
        jne     @f
10051 ace_dent 245
 
3355 mario79 246
        mov     eax, VKEY_LWIN
3356 mario79 247
        mov     bh, 0
3355 mario79 248
        jmp     .modifier
249
;--------------------------------------
250
@@:
251
        cmp     al, 0x5C
252
        jne     @f
10051 ace_dent 253
 
3355 mario79 254
        cmp     cl, 0xE0
3356 mario79 255
        jne     @f
10051 ace_dent 256
 
3355 mario79 257
        mov     eax, VKEY_RWIN
3356 mario79 258
        mov     bh, 0
3355 mario79 259
        jmp     .modifier
260
;--------------------------------------
261
@@:
2288 clevermous 262
        cmp     al, 0x2A
263
        jne     @f
10051 ace_dent 264
 
2288 clevermous 265
        cmp     cl, 0xE0
266
        je      .writekey
10051 ace_dent 267
 
2288 clevermous 268
        mov     eax, VKEY_LSHIFT
269
        jmp     .modifier
270
;--------------------------------------
271
@@:
272
        cmp     al, 0x36
273
        jne     @f
10051 ace_dent 274
 
2288 clevermous 275
        cmp     cl, 0xE0
276
        je      .writekey
10051 ace_dent 277
 
2288 clevermous 278
        mov     eax, VKEY_RSHIFT
279
        jmp     .modifier
280
;--------------------------------------
281
@@:
282
        cmp     al, 0x38
283
        jne     @f
10051 ace_dent 284
 
2288 clevermous 285
        mov     eax, VKEY_LALT
286
        test    cl, cl
287
        jz      .modifier
10051 ace_dent 288
 
2288 clevermous 289
        mov     al, VKEY_RALT
290
        jmp     .modifier
291
;--------------------------------------
292
@@:
293
        cmp     al, 0x1D
294
        jne     @f
10051 ace_dent 295
 
2288 clevermous 296
        mov     eax, VKEY_LCONTROL
297
        test    cl, cl
298
        jz      .modifier
10051 ace_dent 299
 
2288 clevermous 300
        mov     al, VKEY_RCONTROL
301
        cmp     cl, 0xE0
302
        jz      .modifier
10051 ace_dent 303
 
2288 clevermous 304
        mov     [ext_code], cl
305
        jmp     .writekey
306
;--------------------------------------
307
@@:
308
        cmp     al, 0x3A
309
        jne     @f
10051 ace_dent 310
 
2288 clevermous 311
        mov     bl, 4
312
        mov     eax, VKEY_CAPSLOCK
313
        jmp     .no_key.xor
314
;--------------------------------------
315
@@:
316
        cmp     al, 0x45
317
        jne     @f
318
        test    cl, cl
319
        jnz     .writekey
10051 ace_dent 320
 
2288 clevermous 321
        mov     bl, 2
322
        mov     eax, VKEY_NUMLOCK
323
        jmp     .no_key.xor
324
;--------------------------------------
325
@@:
326
        cmp     al, 0x46
327
        jne     @f
10051 ace_dent 328
 
2288 clevermous 329
        mov     bl, 1
330
        mov     eax, VKEY_SCRLOCK
331
        jmp     .no_key.xor
332
;--------------------------------------
333
@@:
334
        xor     ebx, ebx
335
        test    ch, ch
336
        js      .writekey
10051 ace_dent 337
 
2288 clevermous 338
        movzx   eax, ch          ; plain key
9715 Doczom 339
        mov     bl, [keymap + eax]
2288 clevermous 340
        mov     edx, [kb_state]
341
        test    dl, VKEY_CONTROL ; ctrl alt del
342
        jz      .noctrlaltdel
10051 ace_dent 343
 
2288 clevermous 344
        test    dl, VKEY_ALT
345
        jz      .noctrlaltdel
10051 ace_dent 346
 
2288 clevermous 347
        cmp     ch, 53h
348
        jne     .noctrlaltdel
10051 ace_dent 349
 
2288 clevermous 350
        mov     [ctrl_alt_del], 1
3534 clevermous 351
        call    wakeup_osloop
2288 clevermous 352
.noctrlaltdel:
353
        test    dl, VKEY_CONTROL ; ctrl on ?
354
        jz      @f
10051 ace_dent 355
 
2288 clevermous 356
        sub     bl, 0x60
357
@@:
358
        test    dl, VKEY_CAPSLOCK        ; caps lock on ?
359
        jz      .no_caps_lock
10051 ace_dent 360
 
2288 clevermous 361
        test    dl, VKEY_SHIFT   ; shift on ?
362
        jz      .keymap_shif
10051 ace_dent 363
 
2288 clevermous 364
        jmp     @f
365
;--------------------------------------
366
.no_caps_lock:
367
        test    dl, VKEY_SHIFT   ; shift on ?
368
        jz      @f
10051 ace_dent 369
.keymap_shif:
9715 Doczom 370
        mov     bl, [keymap_shift + eax]
2288 clevermous 371
@@:
372
        test    dl, VKEY_ALT     ; alt on ?
373
        jz      @f
10051 ace_dent 374
 
9715 Doczom 375
        mov     bl, [keymap_alt + eax]
2288 clevermous 376
@@:
377
        jmp     .writekey
378
;--------------------------------------
379
.modifier:
380
        test    ch, ch
381
        js      .modifier.up
382
        or      [kb_state], eax
383
        jmp     .writekey
384
;--------------------------------------
385
.modifier.up:
386
        not     eax
387
        and     [kb_state], eax
388
        jmp     .writekey
389
;--------------------------------------
390
.no_key.xor:
391
        mov     bh, 0
392
        test    ch, ch
393
        js      .writekey
10051 ace_dent 394
 
2288 clevermous 395
        xor     [kb_state], eax
396
        xor     [kb_lights], bl
397
.writekey:
2611 mario79 398
        pushad
2288 clevermous 399
; test for system hotkeys
400
        movzx   eax, ch
401
        cmp     bh, 1
402
        ja      .nohotkey
403
        jb      @f
10051 ace_dent 404
 
2288 clevermous 405
        xor     eax, eax
406
@@:
407
        mov     eax, [hotkey_scancodes + eax*4]
408
.hotkey_loop:
409
        test    eax, eax
410
        jz      .nohotkey
10051 ace_dent 411
 
2288 clevermous 412
        mov     cl, 0
413
        call    hotkey_do_test
414
        jc      .hotkey_cont
10051 ace_dent 415
 
2288 clevermous 416
        mov     cl, 2
417
        call    hotkey_do_test
418
        jc      .hotkey_cont
10051 ace_dent 419
 
2288 clevermous 420
        mov     cl, 4
421
        call    hotkey_do_test
422
        jnc     .hotkey_found
423
.hotkey_cont:
424
        mov     eax, [eax]
425
        jmp     .hotkey_loop
426
;--------------------------------------
427
.hotkey_found:
428
        mov     eax, [eax+8]
429
; put key in buffer for process in slot eax
430
        mov     edi, hotkey_buffer
431
@@:
432
        cmp     dword [edi], 0
433
        jz      .found_free
10051 ace_dent 434
 
2288 clevermous 435
        add     edi, 8
436
        cmp     edi, hotkey_buffer+120*8
437
        jb      @b
438
; no free space - replace first entry
439
        mov     edi, hotkey_buffer
440
.found_free:
441
        mov     [edi], eax
442
        movzx   eax, ch
443
        cmp     bh, 1
444
        jnz     @f
10051 ace_dent 445
 
2288 clevermous 446
        xor     eax, eax
447
@@:
448
        mov     [edi+4], ax
449
        mov     eax, [kb_state]
450
        mov     [edi+6], ax
2709 mario79 451
 
452
        cmp     [PID_lock_input], dword 0
453
        je      .nohotkey
454
 
455
        popad
456
        jmp     .exit.irq1
2288 clevermous 457
;--------------------------------------
458
.nohotkey:
2611 mario79 459
        popad
2709 mario79 460
 
2288 clevermous 461
        cmp     [keyboard_mode], 0; return from keymap
462
        jne     .scancode
10051 ace_dent 463
 
2288 clevermous 464
        test    bh, bh
465
        jnz     .exit.irq1
10051 ace_dent 466
 
2288 clevermous 467
        test    bl, bl
468
        jz      .exit.irq1
469
 
4929 hidnplayr 470
        cmp     cl, 0xE0        ; extended keycode
471
        jne     @f
472
 
473
        cmp     ch, 53
474
        jne     .dowrite
10051 ace_dent 475
 
4929 hidnplayr 476
        mov     bl, '/'
477
        jmp     .dowrite
478
@@:
479
 
2288 clevermous 480
        cmp     ch, 55
4929 hidnplayr 481
        jne     @f
10051 ace_dent 482
 
4929 hidnplayr 483
        mov     bl, '*'
2288 clevermous 484
        jmp     .dowrite
485
@@:
4929 hidnplayr 486
 
487
        cmp     ch, 74
488
        jne     @f
10051 ace_dent 489
 
4929 hidnplayr 490
        mov     bl, '-'
491
        jmp     .dowrite
492
@@:
493
 
494
        cmp     ch, 78
495
        jne     @f
10051 ace_dent 496
 
4929 hidnplayr 497
        mov     bl, '+'
498
        jmp     .dowrite
499
@@:
500
 
501
        test    [kb_state], VKEY_NUMLOCK
502
        jz      .dowrite
503
 
2288 clevermous 504
        cmp     ch, 71
505
        jb      .dowrite
10051 ace_dent 506
 
2288 clevermous 507
        cmp     ch, 83
508
        ja      .dowrite
10051 ace_dent 509
 
2288 clevermous 510
        movzx   eax, ch
511
        mov     bl, [numlock_map + eax - 71]
512
        jmp     .dowrite
513
;--------------------------------------
514
.scancode:
515
        mov     bl, ch
516
.dowrite:
517
        movzx   eax, byte[KEY_COUNT]
518
        cmp     al, 120
519
        jae     .exit.irq1
520
        inc     eax
521
        mov     [KEY_COUNT], al
4588 mario79 522
; store ascii or scancode
9715 Doczom 523
        mov     [KEY_BUFF + eax -1], bl
4588 mario79 524
; store original scancode
525
        add     eax, 120+2
4612 mario79 526
        push    ecx
527
        cmp     [keyboard_mode], 0; return from keymap
528
        je      @f
529
 
530
        xor     ch, ch
531
@@:
9715 Doczom 532
        mov     [KEY_BUFF + eax -1], ch
4612 mario79 533
        pop     ecx
4588 mario79 534
        sub     eax, 120+2
2288 clevermous 535
.exit.irq1:
536
        ret
537
;---------------------------------------------------------------------
538
set_lights:
2601 clevermous 539
        push    ebx esi
540
        mov     ecx, keyboard_list_mutex
541
        call    mutex_lock
542
        mov     esi, keyboards
543
.loop:
9715 Doczom 544
        mov     esi, [esi + KEYBOARD.next]
2601 clevermous 545
        cmp     esi, keyboards
546
        jz      .done
9715 Doczom 547
        mov     eax, [esi + KEYBOARD.functions]
2601 clevermous 548
        cmp     dword [eax], KBDFUNC.setlights
549
        jbe     .loop
9715 Doczom 550
        mov     eax, [eax + KBDFUNC.setlights]
2601 clevermous 551
        test    eax, eax
552
        jz      .loop
9715 Doczom 553
        stdcall eax, [esi + KEYBOARD.userdata], dword [kb_lights]
2601 clevermous 554
        jmp     .loop
555
.done:
556
        mov     ecx, keyboard_list_mutex
557
        call    mutex_unlock
558
        pop     esi ebx
559
        ret
560
 
561
ps2_set_lights:
3320 clevermous 562
        stdcall disable_irq, 1
2288 clevermous 563
        mov     al, 0xED
5012 clevermous 564
        call    kb_write_wait_ack
2601 clevermous 565
        mov     al, [esp+8]
5012 clevermous 566
        call    kb_write_wait_ack
3320 clevermous 567
        stdcall enable_irq, 1
2601 clevermous 568
        ret     8
569
 
570
;// mike.dld ]
3534 clevermous 571
proc check_lights_state_has_work?
2288 clevermous 572
        mov     al, [kb_lights]
2601 clevermous 573
        cmp     al, [old_kb_lights]
3534 clevermous 574
        ret
575
endp
576
 
577
check_lights_state:
578
        call    check_lights_state_has_work?
2601 clevermous 579
        jz      .nothing
580
        mov     [old_kb_lights], al
581
        call    set_lights
582
.nothing:
2288 clevermous 583
        ret
584
;---------------------------------------------------------------------
8892 dunkaist 585
iglobal
586
numlock_map db '789-456+1230.'
587
endg
2288 clevermous 588
;---------------------------------------------------------------------
9911 Doczom 589
align 4
590
kb_write_wait_ack:
591
 
592
        push    ecx edx
593
 
594
        mov     dl, al
595
        mov     ecx, 0x1ffff; last 0xffff, new value in view of fast CPU's
596
.wait_output_ready:
597
        in      al, 0x64
598
        test    al, 2
599
        jz      @f
600
        loop    .wait_output_ready
601
        mov     ah, 1
602
        jmp     .nothing
603
@@:
604
        mov     al, dl
605
        out     0x60, al
606
        mov     ecx, 0xfffff; last 0xffff, new value in view of fast CPU's
607
.wait_ack:
608
        in      al, 0x64
609
        test    al, 1
610
        jnz     @f
611
        loop    .wait_ack
612
        mov     ah, 1
613
        jmp     .nothing
614
@@:
615
        in      al, 0x60
616
        xor     ah, ah
617
 
618
.nothing:
619
        pop     edx ecx
620
        ret
621
;-----------------------------------------------------------------------------
622
 
623
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
624
;; 66 sys function.                                                ;;
625
;; in eax=66,ebx in [0..5],ecx,edx                                 ;;
626
;; out eax                                                         ;;
627
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
628
iglobal
629
align 4
630
f66call:
631
           dd sys_process_def.1   ; 1 = set keyboard mode
632
           dd sys_process_def.2   ; 2 = get keyboard mode
633
           dd sys_process_def.3   ; 3 = get keyboard ctrl, alt, shift
634
           dd sys_process_def.4   ; 4 = set system-wide hotkey
635
           dd sys_process_def.5   ; 5 = delete installed hotkey
636
           dd sys_process_def.6   ; 6 = disable input, work only hotkeys
637
           dd sys_process_def.7   ; 7 = enable input, opposition to f.66.6
638
endg
639
;-----------------------------------------------------------------------------
640
align 4
641
sys_process_def:
642
        dec     ebx
643
        cmp     ebx, 7
644
        jae     .not_support    ;if >=8 then or eax,-1
645
 
646
        mov     edi, [current_slot]
647
        jmp     dword [f66call + ebx*4]
648
 
649
.not_support:
650
        or      [esp + SYSCALL_STACK.eax], -1
651
        ret
652
;-----------------------------------------------------------------------------
653
align 4
654
.1:
655
        mov     [edi + APPDATA.keyboard_mode], cl
656
        ret
657
;-----------------------------------------------------------------------------
658
align 4
659
.2:                             ; 2 = get keyboard mode
660
        movzx   eax, byte [edi + APPDATA.keyboard_mode]
661
        mov     [esp + SYSCALL_STACK.eax], eax
662
        ret
663
;-----------------------------------------------------------------------------
664
align 4
665
.3:                             ;3 = get keyboard ctrl, alt, shift
666
        mov     eax, [kb_state]
667
        mov     [esp + SYSCALL_STACK.eax], eax
668
        ret
669
;-----------------------------------------------------------------------------
670
align 4
671
.4:
672
        mov     edi, [current_slot_idx]
673
        mov     eax, hotkey_list
674
@@:
675
        cmp     dword [eax + 8], 0
676
        jz      .found_free
677
        add     eax, 16
678
        cmp     eax, hotkey_list+16*256
679
        jb      @b
680
        mov     dword [esp + SYSCALL_STACK.eax], 1
681
        ret
682
.found_free:
683
        mov     [eax + 8], edi
684
        mov     [eax + 4], edx
685
        movzx   ecx, cl
686
        lea     ecx, [hotkey_scancodes+ecx*4]
687
        mov     edx, [ecx]
688
        mov     [eax], edx
689
        mov     [ecx], eax
690
        mov     [eax + 12], ecx
691
        test    edx, edx
692
        jz      @f
693
        mov     [edx + 12], eax
694
@@:
695
        and     dword [esp + SYSCALL_STACK.eax], 0
696
        ret
697
;-----------------------------------------------------------------------------
698
align 4
699
.5:
700
        mov     edi, [current_slot_idx]
701
        movzx   ebx, cl
702
        lea     ebx, [hotkey_scancodes+ebx*4]
703
        mov     eax, [ebx]
704
.scan:
705
        test    eax, eax
706
        jz      .notfound
707
        cmp     [eax + 8], edi
708
        jnz     .next
709
        cmp     [eax + 4], edx
710
        jz      .found
711
.next:
712
        mov     eax, [eax]
713
        jmp     .scan
714
.notfound:
715
        mov     dword [esp + SYSCALL_STACK.eax], 1
716
        ret
717
.found:
718
        mov     ecx, [eax]
719
        jecxz   @f
720
        mov     edx, [eax + 12]
721
        mov     [ecx + 12], edx
722
@@:
723
        mov     ecx, [eax + 12]
724
        mov     edx, [eax]
725
        mov     [ecx], edx
726
        xor     edx, edx
727
        mov     [eax + 4], edx
728
        mov     [eax + 8], edx
729
        mov     [eax + 12], edx
730
        mov     [eax], edx
731
        mov     [esp + SYSCALL_STACK.eax], edx
732
        ret
733
;-----------------------------------------------------------------------------
734
align 4
735
.6:
736
        pushfd
737
        cli
738
        mov     eax, [PID_lock_input]
739
        test    eax, eax
740
        jnz     @f
741
; get current PID
742
        mov     eax, [current_slot]
743
        mov     eax, [eax + APPDATA.tid]
744
; set current PID for lock input
745
        mov     [PID_lock_input], eax
746
@@:
747
        popfd
748
        ret
749
;-----------------------------------------------------------------------------
750
align 4
751
.7:
752
        mov     eax, [PID_lock_input]
753
        test    eax, eax
754
        jz      @f
755
; get current PID
756
        mov     ebx, [current_slot]
757
        mov     ebx, [ebx + APPDATA.tid]
758
; compare current lock input with current PID
759
        cmp     ebx, eax
760
        jne     @f
761
 
762
        xor     eax, eax
763
        mov     [PID_lock_input], eax
764
@@:
765
        ret
766
;-----------------------------------------------------------------------------
767
uglobal
768
  PID_lock_input dd 0x0
769
endg
770
;-----------------------------------------------------------------------------
771
align 4
772
; @brief System function 2 - Get pressed key
773
; @param eax = 2- number function
774
; @return  eax = 1 - buffer empty, else
775
;          al = 0, ah = code pressed key,
776
;                  16-23 bits - scancode pressed key(in ASCII mode)
777
;          if al=2 ah=scancode pressed key, 16-31 bits - state control keys
778
sys_getkey:
779
        mov     [esp + SYSCALL_STACK.eax], dword 1
780
        ; test main buffer
781
        mov     ebx, [current_slot_idx]                          ; TOP OF WINDOW STACK
782
        movzx   ecx, word [WIN_STACK + ebx * 2]
783
        mov     edx, [thread_count]
784
        cmp     ecx, edx
785
        jne     .finish
786
        cmp     [KEY_COUNT], byte 0
787
        je      .finish
788
        movzx   ax, byte [KEY_BUFF + 120 + 2]
789
        shl     eax, 8
790
        mov     al, byte [KEY_BUFF]
791
        shl     eax, 8
792
        push    eax
793
        dec     byte [KEY_COUNT]
794
        and     byte [KEY_COUNT], 127
795
        movzx   ecx, byte [KEY_COUNT]
796
        add     ecx, 2
797
        mov     eax, KEY_BUFF + 1
798
        mov     ebx, KEY_BUFF
799
        call    memmove
800
        add     eax, 120 + 2
801
        add     ebx, 120 + 2
802
        call    memmove
803
        pop     eax
804
;--------------------------------------
805
align 4
806
.ret_eax:
807
        mov     [esp + SYSCALL_STACK.eax], eax
808
        ret
809
;--------------------------------------
810
align 4
811
.finish:
812
; test hotkeys buffer
813
        mov     ecx, hotkey_buffer
814
;--------------------------------------
815
align 4
816
@@:
817
        cmp     [ecx], ebx
818
        jz      .found
819
        add     ecx, 8
820
        cmp     ecx, hotkey_buffer + 120 * 8
821
        jb      @b
822
        ret
823
;--------------------------------------
824
align 4
825
.found:
826
        mov     ax, [ecx + 6]
827
        shl     eax, 16
828
        mov     ah, [ecx + 4]
829
        mov     al, 2
830
        and     dword [ecx + 4], 0
831
        and     dword [ecx], 0
832
        jmp     .ret_eax
10051 ace_dent 833
;------------------------------------------------------------------------------