Subversion Repositories Kolibri OS

Rev

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

  1. $Revision: 431 $
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;                                                              ;;
  4. ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
  5. ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
  6. ;; Distributed under terms of the GNU General Public License    ;;
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8.  
  9. ;// mike.dld [
  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. hotkey_test1:
  58.         test    al, al
  59.         setnp   al
  60.         ret
  61. hotkey_test2:
  62.         cmp     al, 3
  63.         setz    al
  64.         ret
  65. hotkey_test3:
  66.         cmp     al, 1
  67.         setz    al
  68.         ret
  69. hotkey_test4:
  70.         cmp     al, 2
  71.         setz    al
  72.         ret
  73.  
  74. hotkey_do_test:
  75.         push    eax
  76.         mov     edx, [kb_state]
  77.         shr     edx, cl
  78.         add     cl, cl
  79.         mov     eax, [eax+4]
  80.         shr     eax, cl
  81.         and     eax, 15
  82.         cmp     al, hotkey_tests_num
  83.         jae     .fail
  84.         xchg    eax, edx
  85.         and     al, 3
  86.         call    [hotkey_tests + edx*4]
  87.         cmp     al, 1
  88.         pop     eax
  89.         ret
  90. .fail:
  91.         stc
  92.         pop     eax
  93.         ret
  94.  
  95. align 4
  96. irq1:
  97. ;       save_ring3_context
  98. ;       mov   ax, os_data
  99. ;       mov   ds, ax
  100. ;       mov   es, ax
  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.        in    al,0x60
  109.        mov   [keyboard_data],al
  110.  
  111. ; ch = scancode
  112. ; cl = ext_code
  113. ; bh = 0 - normal key
  114. ; bh = 1 - modifier (Shift/Ctrl/Alt)
  115. ; bh = 2 - extended code
  116.  
  117.        mov   ch,al
  118.        cmp   al,0xE0
  119.        je    @f
  120.        cmp   al,0xE1
  121.        jne   .normal_code
  122.    @@:
  123.         mov     bh, 2
  124.         mov     [ext_code], al
  125.         jmp     .writekey
  126.    .normal_code:
  127.         mov     cl, 0
  128.         xchg    cl, [ext_code]
  129.        and   al,0x7F
  130.         mov     bh, 1
  131.    @@: cmp   al,0x2A
  132.        jne   @f
  133.        cmp   cl,0xE0
  134.        je    .writekey
  135.        mov   eax,VKEY_LSHIFT
  136.        jmp   .modifier
  137.    @@: cmp   al,0x36
  138.        jne   @f
  139.        cmp   cl,0xE0
  140.        je    .writekey
  141.        mov   eax,VKEY_RSHIFT
  142.        jmp   .modifier
  143.    @@: cmp   al,0x38
  144.        jne   @f
  145.         mov     eax, VKEY_LALT
  146.         test    cl, cl
  147.         jz      .modifier
  148.         mov     al, VKEY_RALT
  149.         jmp     .modifier
  150.    @@: cmp   al,0x1D
  151.        jne   @f
  152.         mov     eax, VKEY_LCONTROL
  153.         test    cl, cl
  154.         jz      .modifier
  155.         mov     al, VKEY_RCONTROL
  156.         cmp     cl, 0xE0
  157.         jz      .modifier
  158.         mov     [ext_code], cl
  159.         jmp     .writekey
  160.    @@: cmp   al,0x3A
  161.        jne   @f
  162.        mov   bl,4
  163.        mov   eax,VKEY_CAPSLOCK
  164.        jmp   .no_key.xor
  165.    @@: cmp   al,0x45
  166.        jne   @f
  167.         test    cl, cl
  168.         jnz     .writekey
  169.        mov   bl,2
  170.        mov   eax,VKEY_NUMLOCK
  171.        jmp   .no_key.xor
  172.    @@: cmp   al,0x46
  173.        jne   @f
  174.        mov   bl,1
  175.        mov   eax,VKEY_SCRLOCK
  176.        jmp   .no_key.xor
  177.    @@:
  178.        test  ch,ch
  179.        js    .writekey
  180.        movzx eax,ch              ; plain key
  181.        mov   bl,[keymap+eax]
  182.        mov   edx,[kb_state]
  183.        test  dl,VKEY_CONTROL     ; ctrl alt del
  184.        jz    .noctrlaltdel
  185.        test  dl,VKEY_ALT
  186.        jz    .noctrlaltdel
  187.        cmp   ch,53h
  188.        jne   .noctrlaltdel
  189.        mov   [ctrl_alt_del],1
  190.    .noctrlaltdel:
  191.        test  dl,VKEY_CONTROL     ; ctrl on ?
  192.        jz    @f
  193.        sub   bl,0x60
  194.    @@: test  dl,VKEY_SHIFT       ; shift on ?
  195.        jz    @f
  196.        mov   bl,[keymap_shift+eax]
  197.    @@: test  dl,VKEY_ALT         ; alt on ?
  198.        jz    @f
  199.        mov   bl,[keymap_alt+eax]
  200.    @@:
  201.         mov     bh, 0
  202.         jmp     .writekey
  203. .modifier:
  204.         test    ch, ch
  205.         js      .modifier.up
  206.         or      [kb_state], eax
  207.         jmp     .writekey
  208. .modifier.up:
  209.         not     eax
  210.         and     [kb_state], eax
  211.         jmp     .writekey
  212. .no_key.xor:
  213.         mov     bh, 0
  214.         test    ch, ch
  215.         js      .writekey
  216.         xor     [kb_state], eax
  217.         xor     [kb_lights], bl
  218.         call    set_lights
  219.  
  220. .writekey:
  221. ; test for system hotkeys
  222.         movzx   eax, ch
  223.         cmp     bh, 1
  224.         ja      .nohotkey
  225.         jb      @f
  226.         xor     eax, eax
  227. @@:
  228.         mov     eax, [hotkey_scancodes + eax*4]
  229. .hotkey_loop:
  230.         test    eax, eax
  231.         jz      .nohotkey
  232.         mov     cl, 0
  233.         call    hotkey_do_test
  234.         jc      .hotkey_cont
  235.         mov     cl, 2
  236.         call    hotkey_do_test
  237.         jc      .hotkey_cont
  238.         mov     cl, 4
  239.         call    hotkey_do_test
  240.         jnc     .hotkey_found
  241. .hotkey_cont:
  242.         mov     eax, [eax]
  243.         jmp     .hotkey_loop
  244. .hotkey_found:
  245.         mov     eax, [eax+8]
  246. ; put key in buffer for process in slot eax
  247.         mov     edi, hotkey_buffer
  248. @@:
  249.         cmp     dword [edi], 0
  250.         jz      .found_free
  251.         add     edi, 8
  252.         cmp     edi, hotkey_buffer+120*8
  253.         jb      @b
  254. ; no free space - replace first entry
  255.         mov     edi, hotkey_buffer
  256. .found_free:
  257.         mov     [edi], eax
  258.         movzx   eax, ch
  259.         cmp     bh, 1
  260.         jnz     @f
  261.         xor     eax, eax
  262. @@:
  263.         mov     [edi+4], ax
  264.         mov     eax, [kb_state]
  265.         mov     [edi+6], ax
  266.         jmp     .exit.irq1
  267. .nohotkey:
  268.        cmp   [keyboard_mode],0 ; return from keymap
  269.        jne   .scancode
  270.         test    bh, bh
  271.         jnz     .exit.irq1
  272.         test    bl, bl
  273.         jz      .exit.irq1
  274.         jmp     .dowrite
  275. .scancode:
  276.         mov     bl, ch
  277. .dowrite:
  278.        movzx eax,byte[KEY_COUNT]
  279.        cmp   al,120
  280.        jae   .exit.irq1
  281.        inc   eax
  282.        mov   [KEY_COUNT],al
  283.        mov   [KEY_COUNT+eax],bl
  284.  
  285.    .exit.irq1:
  286.        mov   [check_idle_semaphore],5
  287.  
  288. ;       mov   al,0x20                  ; ready for next irq
  289. ;       out   0x20,al
  290.  
  291. ;       restore_ring3_context
  292. ;       iret
  293.         ret
  294.  
  295. set_lights:
  296.        mov   al,0xED
  297.        call  kb_write
  298.        mov   al,[kb_lights]
  299.        call  kb_write
  300.        ret
  301.  
  302. ;// mike.dld ]
  303.