Subversion Repositories Kolibri OS

Rev

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

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