Subversion Repositories Kolibri OS

Rev

Rev 1579 | Rev 2171 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
  4. ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
  5. ;; Distributed under terms of the GNU General Public License    ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. $Revision: 1874 $
  9.  
  10.  
  11. ;// mike.dld [
  12.  
  13. VKEY_LSHIFT   = 0000000000000001b
  14. VKEY_RSHIFT   = 0000000000000010b
  15. VKEY_LCONTROL = 0000000000000100b
  16. VKEY_RCONTROL = 0000000000001000b
  17. VKEY_LALT     = 0000000000010000b
  18. VKEY_RALT     = 0000000000100000b
  19. VKEY_CAPSLOCK = 0000000001000000b
  20. VKEY_NUMLOCK  = 0000000010000000b
  21. VKEY_SCRLOCK  = 0000000100000000b
  22.  
  23. VKEY_SHIFT    = 0000000000000011b
  24. VKEY_CONTROL  = 0000000000001100b
  25. VKEY_ALT      = 0000000000110000b
  26.  
  27. uglobal
  28.   align 4
  29.   kb_state      dd 0
  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.  
  38.   kb_lights     db 0
  39.  
  40. align 4
  41.         hotkey_scancodes        rd      256     ; we have 256 scancodes
  42.         hotkey_list             rd      256*4   ; max 256 defined hotkeys
  43.         hotkey_buffer           rd      120*2   ; buffer for 120 hotkeys
  44. endg
  45.  
  46. iglobal
  47. hotkey_tests    dd      hotkey_test0
  48.                 dd      hotkey_test1
  49.                 dd      hotkey_test2
  50.                 dd      hotkey_test3
  51.                 dd      hotkey_test4
  52. hotkey_tests_num = 5
  53. endg
  54.  
  55. hotkey_test0:
  56.         test    al, al
  57.         setz    al
  58.         ret
  59. hotkey_test1:
  60.         test    al, al
  61.         setnp   al
  62.         ret
  63. hotkey_test2:
  64.         cmp     al, 3
  65.         setz    al
  66.         ret
  67. hotkey_test3:
  68.         cmp     al, 1
  69.         setz    al
  70.         ret
  71. hotkey_test4:
  72.         cmp     al, 2
  73.         setz    al
  74.         ret
  75.  
  76. hotkey_do_test:
  77.         push    eax
  78.         mov     edx, [kb_state]
  79.         shr     edx, cl
  80.         add     cl, cl
  81.         mov     eax, [eax+4]
  82.         shr     eax, cl
  83.         and     eax, 15
  84.         cmp     al, hotkey_tests_num
  85.         jae     .fail
  86.         xchg    eax, edx
  87.         and     al, 3
  88.         call    [hotkey_tests + edx*4]
  89.         cmp     al, 1
  90.         pop     eax
  91.         ret
  92. .fail:
  93.         stc
  94.         pop     eax
  95.         ret
  96.  
  97.  
  98. align 4
  99.  
  100. set_keyboard_data:
  101.  
  102.            movzx eax,word[TASK_COUNT] ; top window process
  103.            movzx eax,word[WIN_POS+eax*2]
  104.            shl   eax,8
  105.            mov   al,[SLOT_BASE+eax+APPDATA.keyboard_mode]
  106.            mov   [keyboard_mode],al
  107.  
  108.            mov eax, ecx
  109.  
  110.            push ebx
  111.            push esi
  112.            push edi
  113.            push ebp
  114.  
  115.            call send_scancode
  116.  
  117.            pop ebp
  118.            pop edi
  119.            pop esi
  120.            pop ebx
  121.            ret
  122.  
  123. align 4
  124. irq1:
  125.  
  126.        movzx eax,word[TASK_COUNT] ; top window process
  127.        movzx eax,word[WIN_POS+eax*2]
  128.        shl   eax,8
  129.        mov   al,[SLOT_BASE+eax+APPDATA.keyboard_mode]
  130.        mov   [keyboard_mode],al
  131.  
  132.        in    al,0x60
  133.  
  134. send_scancode:
  135.  
  136.        mov   [keyboard_data],al
  137.  
  138. ; ch = scancode
  139. ; cl = ext_code
  140. ; bh = 0 - normal key
  141. ; bh = 1 - modifier (Shift/Ctrl/Alt)
  142. ; bh = 2 - extended code
  143.  
  144.        mov   ch,al
  145.        cmp   al,0xE0
  146.        je    @f
  147.        cmp   al,0xE1
  148.        jne   .normal_code
  149.    @@:
  150.         mov     bh, 2
  151.         mov     [ext_code], al
  152.         jmp     .writekey
  153.    .normal_code:
  154.         mov     cl, 0
  155.         xchg    cl, [ext_code]
  156.        and   al,0x7F
  157.         mov     bh, 1
  158.    @@: cmp   al,0x2A
  159.        jne   @f
  160.        cmp   cl,0xE0
  161.        je    .writekey
  162.        mov   eax,VKEY_LSHIFT
  163.        jmp   .modifier
  164.    @@: cmp   al,0x36
  165.        jne   @f
  166.        cmp   cl,0xE0
  167.        je    .writekey
  168.        mov   eax,VKEY_RSHIFT
  169.        jmp   .modifier
  170.    @@: cmp   al,0x38
  171.        jne   @f
  172.         mov     eax, VKEY_LALT
  173.         test    cl, cl
  174.         jz      .modifier
  175.         mov     al, VKEY_RALT
  176.         jmp     .modifier
  177.    @@: cmp   al,0x1D
  178.        jne   @f
  179.         mov     eax, VKEY_LCONTROL
  180.         test    cl, cl
  181.         jz      .modifier
  182.         mov     al, VKEY_RCONTROL
  183.         cmp     cl, 0xE0
  184.         jz      .modifier
  185.         mov     [ext_code], cl
  186.         jmp     .writekey
  187.    @@: cmp   al,0x3A
  188.        jne   @f
  189.        mov   bl,4
  190.        mov   eax,VKEY_CAPSLOCK
  191.        jmp   .no_key.xor
  192.    @@: cmp   al,0x45
  193.        jne   @f
  194.         test    cl, cl
  195.         jnz     .writekey
  196.        mov   bl,2
  197.        mov   eax,VKEY_NUMLOCK
  198.        jmp   .no_key.xor
  199.    @@: cmp   al,0x46
  200.        jne   @f
  201.        mov   bl,1
  202.        mov   eax,VKEY_SCRLOCK
  203.        jmp   .no_key.xor
  204.    @@:
  205.        xor   ebx,ebx
  206.        test  ch,ch
  207.        js    .writekey
  208.        movzx eax,ch              ; plain key
  209.        mov   bl,[keymap+eax]
  210.        mov   edx,[kb_state]
  211.        test  dl,VKEY_CONTROL     ; ctrl alt del
  212.        jz    .noctrlaltdel
  213.        test  dl,VKEY_ALT
  214.        jz    .noctrlaltdel
  215.        cmp   ch,53h
  216.        jne   .noctrlaltdel
  217.        mov   [ctrl_alt_del],1
  218.    .noctrlaltdel:
  219.        test  dl,VKEY_CONTROL     ; ctrl on ?
  220.        jz    @f
  221.        sub   bl,0x60
  222.    @@: test  dl,VKEY_SHIFT       ; shift on ?
  223.        jz    @f
  224.        mov   bl,[keymap_shift+eax]
  225.    @@: test  dl,VKEY_ALT         ; alt on ?
  226.        jz    @f
  227.        mov   bl,[keymap_alt+eax]
  228.    @@:
  229.         jmp     .writekey
  230. .modifier:
  231.         test    ch, ch
  232.         js      .modifier.up
  233.         or      [kb_state], eax
  234.         jmp     .writekey
  235. .modifier.up:
  236.         not     eax
  237.         and     [kb_state], eax
  238.         jmp     .writekey
  239. .no_key.xor:
  240.         mov     bh, 0
  241.         test    ch, ch
  242.         js      .writekey
  243.         xor     [kb_state], eax
  244.         xor     [kb_lights], bl
  245.         call    set_lights
  246.  
  247. .writekey:
  248. ; test for system hotkeys
  249.         movzx   eax, ch
  250.         cmp     bh, 1
  251.         ja      .nohotkey
  252.         jb      @f
  253.         xor     eax, eax
  254. @@:
  255.         mov     eax, [hotkey_scancodes + eax*4]
  256. .hotkey_loop:
  257.         test    eax, eax
  258.         jz      .nohotkey
  259.         mov     cl, 0
  260.         call    hotkey_do_test
  261.         jc      .hotkey_cont
  262.         mov     cl, 2
  263.         call    hotkey_do_test
  264.         jc      .hotkey_cont
  265.         mov     cl, 4
  266.         call    hotkey_do_test
  267.         jnc     .hotkey_found
  268. .hotkey_cont:
  269.         mov     eax, [eax]
  270.         jmp     .hotkey_loop
  271. .hotkey_found:
  272.         mov     eax, [eax+8]
  273. ; put key in buffer for process in slot eax
  274.         mov     edi, hotkey_buffer
  275. @@:
  276.         cmp     dword [edi], 0
  277.         jz      .found_free
  278.         add     edi, 8
  279.         cmp     edi, hotkey_buffer+120*8
  280.         jb      @b
  281. ; no free space - replace first entry
  282.         mov     edi, hotkey_buffer
  283. .found_free:
  284.         mov     [edi], eax
  285.         movzx   eax, ch
  286.         cmp     bh, 1
  287.         jnz     @f
  288.         xor     eax, eax
  289. @@:
  290.         mov     [edi+4], ax
  291.         mov     eax, [kb_state]
  292.         mov     [edi+6], ax
  293.         jmp     .exit.irq1
  294. .nohotkey:
  295.        cmp   [keyboard_mode],0 ; return from keymap
  296.        jne   .scancode
  297.         test    bh, bh
  298.         jnz     .exit.irq1
  299.         test    bl, bl
  300.         jz      .exit.irq1
  301.  
  302. ;.........................Part1 Start.......Code by Rus, optimize by Ghost...................................
  303.         test  [kb_state], VKEY_NUMLOCK
  304.         jz     .dowrite
  305.         cmp     cl, 0xE0
  306.         jz      .dowrite
  307.  
  308.         cmp     ch, 55
  309.         jnz     @f
  310.         mov     bl, 0x2A        ;*
  311.         jmp     .dowrite
  312.       @@:
  313.         cmp     ch, 71
  314.         jb      .dowrite
  315.         cmp     ch, 83
  316.         ja      .dowrite
  317.         ;push    eax
  318.         movzx   eax, ch
  319.         mov     bl, [numlock_map + eax - 71]
  320.         ;pop     eax
  321.  
  322. ;.........................Part1 End.................................................
  323.  
  324.         jmp     .dowrite
  325. .scancode:
  326.         mov     bl, ch
  327. .dowrite:
  328.        movzx eax,byte[KEY_COUNT]
  329.        cmp   al,120
  330.        jae   .exit.irq1
  331.        inc   eax
  332.        mov   [KEY_COUNT],al
  333.        mov   [KEY_COUNT+eax],bl
  334.  
  335.    .exit.irq1:
  336.        mov   [check_idle_semaphore],5
  337.  
  338.         ret
  339.  
  340. set_lights:
  341.        mov   al,0xED
  342.        call  kb_write
  343.        mov   al,[kb_lights]
  344.        call  kb_write
  345.        ret
  346.  
  347. ;// mike.dld ]
  348. ;..........................Part2 Start.......Code by Rus.......................................
  349. numlock_map:
  350.     db   0x37   ;Num 7
  351.     db   0x38   ;Num 8
  352.     db   0x39   ;Num 9
  353.     db   0x2D   ;Num -
  354.     db   0x34   ;Num 4
  355.     db   0x35   ;Num 5
  356.     db   0x36   ;Num 6
  357.     db   0x2B   ;Num +
  358.     db   0x31   ;Num 1
  359.     db   0x32   ;Num 2
  360.     db   0x33   ;Num 3
  361.     db   0x30   ;Num 0
  362.     db   0x2E   ;Num .
  363. ;..........................Part2 End................................................
  364.