Subversion Repositories Kolibri OS

Rev

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

  1. $Revision: 425 $
  2. ;// mike.dld [
  3.  
  4. VKEY_LSHIFT   = 0000000000000001b
  5. VKEY_RSHIFT   = 0000000000000010b
  6. VKEY_LCONTROL = 0000000000000100b
  7. VKEY_RCONTROL = 0000000000001000b
  8. VKEY_LALT     = 0000000000010000b
  9. VKEY_RALT     = 0000000000100000b
  10. VKEY_CAPSLOCK = 0000000001000000b
  11. VKEY_NUMLOCK  = 0000000010000000b
  12. VKEY_SCRLOCK  = 0000000100000000b
  13.  
  14. VKEY_SHIFT    = 0000000000000011b
  15. VKEY_CONTROL  = 0000000000001100b
  16. VKEY_ALT      = 0000000000110000b
  17.  
  18. uglobal
  19.   align 4
  20.   kb_state      dd 0
  21.   ext_code      db 0
  22.  
  23.   keyboard_mode db 0
  24.   keyboard_data db 0
  25.  
  26.   altmouseb     db 0
  27.   ctrl_alt_del  db 0
  28.  
  29.   kb_lights     db 0
  30.  
  31. align 4
  32.         hotkey_scancodes        rd      256     ; we have 256 scancodes
  33.         hotkey_list             rd      256*4   ; max 256 defined hotkeys
  34.         hotkey_buffer           rd      120*2   ; buffer for 120 hotkeys
  35. endg
  36.  
  37. iglobal
  38. hotkey_tests    dd      hotkey_test0
  39.                 dd      hotkey_test1
  40.                 dd      hotkey_test2
  41.                 dd      hotkey_test3
  42.                 dd      hotkey_test4
  43. hotkey_tests_num = 5
  44. endg
  45.  
  46. hotkey_test0:
  47.         test    al, al
  48.         setz    al
  49.         ret
  50. hotkey_test1:
  51.         test    al, al
  52.         setnp   al
  53.         ret
  54. hotkey_test2:
  55.         cmp     al, 3
  56.         setz    al
  57.         ret
  58. hotkey_test3:
  59.         cmp     al, 1
  60.         setz    al
  61.         ret
  62. hotkey_test4:
  63.         cmp     al, 2
  64.         setz    al
  65.         ret
  66.  
  67. hotkey_do_test:
  68.         push    eax
  69.         mov     edx, [kb_state]
  70.         shr     edx, cl
  71.         add     cl, cl
  72.         mov     eax, [eax+4]
  73.         shr     eax, cl
  74.         and     eax, 15
  75.         cmp     al, hotkey_tests_num
  76.         jae     .fail
  77.         xchg    eax, edx
  78.         and     al, 3
  79.         call    [hotkey_tests + edx*4]
  80.         cmp     al, 1
  81.         pop     eax
  82.         ret
  83. .fail:
  84.         stc
  85.         pop     eax
  86.         ret
  87.  
  88. align 4
  89. irq1:
  90. ;       save_ring3_context
  91. ;       mov   ax, os_data
  92. ;       mov   ds, ax
  93. ;       mov   es, ax
  94.  
  95.        movzx eax,word[TASK_COUNT] ; top window process
  96.        movzx eax,word[WIN_POS+eax*2]
  97.        shl   eax,8
  98.        mov   al,[SLOT_BASE+eax+APPDATA.keyboard_mode]
  99.        mov   [keyboard_mode],al
  100.  
  101.        in    al,0x60
  102.        mov   [keyboard_data],al
  103.  
  104. ; ch = scancode
  105. ; cl = ext_code
  106. ; bh = 0 - normal key
  107. ; bh = 1 - modifier (Shift/Ctrl/Alt)
  108. ; bh = 2 - extended code
  109.  
  110.        mov   ch,al
  111.        cmp   al,0xE0
  112.        je    @f
  113.        cmp   al,0xE1
  114.        jne   .normal_code
  115.    @@:
  116.         mov     bh, 2
  117.         mov     [ext_code], al
  118.         jmp     .writekey
  119.    .normal_code:
  120.         mov     cl, 0
  121.         xchg    cl, [ext_code]
  122.        and   al,0x7F
  123.         mov     bh, 1
  124.    @@: cmp   al,0x2A
  125.        jne   @f
  126.        cmp   cl,0xE0
  127.        je    .writekey
  128.        mov   eax,VKEY_LSHIFT
  129.        jmp   .modifier
  130.    @@: cmp   al,0x36
  131.        jne   @f
  132.        cmp   cl,0xE0
  133.        je    .writekey
  134.        mov   eax,VKEY_RSHIFT
  135.        jmp   .modifier
  136.    @@: cmp   al,0x38
  137.        jne   @f
  138.         mov     eax, VKEY_LALT
  139.         test    cl, cl
  140.         jz      .modifier
  141.         mov     al, VKEY_RALT
  142.         jmp     .modifier
  143.    @@: cmp   al,0x1D
  144.        jne   @f
  145.         mov     eax, VKEY_LCONTROL
  146.         test    cl, cl
  147.         jz      .modifier
  148.         mov     al, VKEY_RCONTROL
  149.         cmp     cl, 0xE0
  150.         jz      .modifier
  151.         mov     [ext_code], cl
  152.         jmp     .writekey
  153.    @@: cmp   al,0x3A
  154.        jne   @f
  155.        mov   bl,4
  156.        mov   eax,VKEY_CAPSLOCK
  157.        jmp   .no_key.xor
  158.    @@: cmp   al,0x45
  159.        jne   @f
  160.         test    cl, cl
  161.         jnz     .writekey
  162.        mov   bl,2
  163.        mov   eax,VKEY_NUMLOCK
  164.        jmp   .no_key.xor
  165.    @@: cmp   al,0x46
  166.        jne   @f
  167.        mov   bl,1
  168.        mov   eax,VKEY_SCRLOCK
  169.        jmp   .no_key.xor
  170.    @@:
  171.        test  ch,ch
  172.        js    .writekey
  173.        movzx eax,ch              ; plain key
  174.        mov   bl,[keymap+eax]
  175.        mov   edx,[kb_state]
  176.        test  dl,VKEY_CONTROL     ; ctrl alt del
  177.        jz    .noctrlaltdel
  178.        test  dl,VKEY_ALT
  179.        jz    .noctrlaltdel
  180.        cmp   ch,53h
  181.        jne   .noctrlaltdel
  182.        mov   [ctrl_alt_del],1
  183.    .noctrlaltdel:
  184.        test  dl,VKEY_CONTROL     ; ctrl on ?
  185.        jz    @f
  186.        sub   bl,0x60
  187.    @@: test  dl,VKEY_SHIFT       ; shift on ?
  188.        jz    @f
  189.        mov   bl,[keymap_shift+eax]
  190.    @@: test  dl,VKEY_ALT         ; alt on ?
  191.        jz    @f
  192.        mov   bl,[keymap_alt+eax]
  193.    @@:
  194.         mov     bh, 0
  195.         jmp     .writekey
  196. .modifier:
  197.         test    ch, ch
  198.         js      .modifier.up
  199.         or      [kb_state], eax
  200.         jmp     .writekey
  201. .modifier.up:
  202.         not     eax
  203.         and     [kb_state], eax
  204.         jmp     .writekey
  205. .no_key.xor:
  206.         mov     bh, 0
  207.         test    ch, ch
  208.         js      .writekey
  209.         xor     [kb_state], eax
  210.         xor     [kb_lights], bl
  211.         call    set_lights
  212.  
  213. .writekey:
  214. ; test for system hotkeys
  215.         movzx   eax, ch
  216.         cmp     bh, 1
  217.         ja      .nohotkey
  218.         jb      @f
  219.         xor     eax, eax
  220. @@:
  221.         mov     eax, [hotkey_scancodes + eax*4]
  222. .hotkey_loop:
  223.         test    eax, eax
  224.         jz      .nohotkey
  225.         mov     cl, 0
  226.         call    hotkey_do_test
  227.         jc      .hotkey_cont
  228.         mov     cl, 2
  229.         call    hotkey_do_test
  230.         jc      .hotkey_cont
  231.         mov     cl, 4
  232.         call    hotkey_do_test
  233.         jnc     .hotkey_found
  234. .hotkey_cont:
  235.         mov     eax, [eax]
  236.         jmp     .hotkey_loop
  237. .hotkey_found:
  238.         mov     eax, [eax+8]
  239. ; put key in buffer for process in slot eax
  240.         mov     edi, hotkey_buffer
  241. @@:
  242.         cmp     dword [edi], 0
  243.         jz      .found_free
  244.         add     edi, 8
  245.         cmp     edi, hotkey_buffer+120*8
  246.         jb      @b
  247. ; no free space - replace first entry
  248.         mov     edi, hotkey_buffer
  249. .found_free:
  250.         mov     [edi], eax
  251.         movzx   eax, ch
  252.         cmp     bh, 1
  253.         jnz     @f
  254.         xor     eax, eax
  255. @@:
  256.         mov     [edi+4], ax
  257.         mov     eax, [kb_state]
  258.         mov     [edi+6], ax
  259.         jmp     .exit.irq1
  260. .nohotkey:
  261.        cmp   [keyboard_mode],0 ; return from keymap
  262.        jne   .scancode
  263.         test    bh, bh
  264.         jnz     .exit.irq1
  265.         test    bl, bl
  266.         jz      .exit.irq1
  267.         jmp     .dowrite
  268. .scancode:
  269.         mov     bl, ch
  270. .dowrite:
  271.        movzx eax,byte[KEY_COUNT]
  272.        cmp   al,120
  273.        jae   .exit.irq1
  274.        inc   eax
  275.        mov   [KEY_COUNT],al
  276.        mov   [KEY_COUNT+eax],bl
  277.  
  278.    .exit.irq1:
  279.        mov   [check_idle_semaphore],5
  280.  
  281. ;       mov   al,0x20                  ; ready for next irq
  282. ;       out   0x20,al
  283.  
  284. ;       restore_ring3_context
  285. ;       iret
  286.         ret
  287.  
  288. set_lights:
  289.        mov   al,0xED
  290.        call  kb_write
  291.        mov   al,[kb_lights]
  292.        call  kb_write
  293.        ret
  294.  
  295. ;// mike.dld ]
  296.