Subversion Repositories Kolibri OS

Rev

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

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