Rev 1579 | Rev 2171 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
431 | serge | 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 | |||
593 | mikedld | 8 | $Revision: 1874 $ |
9 | |||
10 | |||
1 | ha | 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 |
||
582 | Rus | 29 | kb_state dd 0 |
30 | ext_code db 0 |
||
1 | ha | 31 | |
32 | keyboard_mode db 0 |
||
33 | keyboard_data db 0 |
||
34 | |||
582 | Rus | 35 | altmouseb db 0 |
36 | ctrl_alt_del db 0 |
||
1 | ha | 37 | |
582 | Rus | 38 | kb_lights db 0 |
92 | diamond | 39 | |
40 | align 4 |
||
582 | Rus | 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 |
||
1 | ha | 44 | endg |
45 | |||
92 | diamond | 46 | iglobal |
582 | Rus | 47 | hotkey_tests dd hotkey_test0 |
48 | dd hotkey_test1 |
||
49 | dd hotkey_test2 |
||
50 | dd hotkey_test3 |
||
51 | dd hotkey_test4 |
||
92 | diamond | 52 | hotkey_tests_num = 5 |
53 | endg |
||
54 | |||
55 | hotkey_test0: |
||
582 | Rus | 56 | test al, al |
57 | setz al |
||
58 | ret |
||
92 | diamond | 59 | hotkey_test1: |
582 | Rus | 60 | test al, al |
61 | setnp al |
||
62 | ret |
||
92 | diamond | 63 | hotkey_test2: |
582 | Rus | 64 | cmp al, 3 |
65 | setz al |
||
66 | ret |
||
92 | diamond | 67 | hotkey_test3: |
582 | Rus | 68 | cmp al, 1 |
69 | setz al |
||
70 | ret |
||
92 | diamond | 71 | hotkey_test4: |
582 | Rus | 72 | cmp al, 2 |
73 | setz al |
||
74 | ret |
||
92 | diamond | 75 | |
76 | hotkey_do_test: |
||
582 | Rus | 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 | diamond | 92 | .fail: |
582 | Rus | 93 | stc |
94 | pop eax |
||
95 | ret |
||
92 | diamond | 96 | |
1874 | serge | 97 | |
1 | ha | 98 | align 4 |
1874 | serge | 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 |
||
1 | ha | 124 | irq1: |
125 | |||
379 | serge | 126 | movzx eax,word[TASK_COUNT] ; top window process |
380 | serge | 127 | movzx eax,word[WIN_POS+eax*2] |
1 | ha | 128 | shl eax,8 |
380 | serge | 129 | mov al,[SLOT_BASE+eax+APPDATA.keyboard_mode] |
1 | ha | 130 | mov [keyboard_mode],al |
131 | |||
132 | in al,0x60 |
||
1874 | serge | 133 | |
134 | send_scancode: |
||
135 | |||
1 | ha | 136 | mov [keyboard_data],al |
137 | |||
92 | diamond | 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 | |||
1 | ha | 144 | mov ch,al |
145 | cmp al,0xE0 |
||
146 | je @f |
||
147 | cmp al,0xE1 |
||
148 | jne .normal_code |
||
92 | diamond | 149 | @@: |
582 | Rus | 150 | mov bh, 2 |
151 | mov [ext_code], al |
||
152 | jmp .writekey |
||
1 | ha | 153 | .normal_code: |
582 | Rus | 154 | mov cl, 0 |
155 | xchg cl, [ext_code] |
||
1 | ha | 156 | and al,0x7F |
582 | Rus | 157 | mov bh, 1 |
1 | ha | 158 | @@: cmp al,0x2A |
159 | jne @f |
||
160 | cmp cl,0xE0 |
||
92 | diamond | 161 | je .writekey |
1 | ha | 162 | mov eax,VKEY_LSHIFT |
92 | diamond | 163 | jmp .modifier |
1 | ha | 164 | @@: cmp al,0x36 |
165 | jne @f |
||
166 | cmp cl,0xE0 |
||
92 | diamond | 167 | je .writekey |
1 | ha | 168 | mov eax,VKEY_RSHIFT |
92 | diamond | 169 | jmp .modifier |
1 | ha | 170 | @@: cmp al,0x38 |
171 | jne @f |
||
582 | Rus | 172 | mov eax, VKEY_LALT |
173 | test cl, cl |
||
174 | jz .modifier |
||
175 | mov al, VKEY_RALT |
||
176 | jmp .modifier |
||
1 | ha | 177 | @@: cmp al,0x1D |
178 | jne @f |
||
582 | Rus | 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 |
||
1 | ha | 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 |
||
582 | Rus | 194 | test cl, cl |
195 | jnz .writekey |
||
1 | ha | 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 | @@: |
||
1579 | diamond | 205 | xor ebx,ebx |
92 | diamond | 206 | test ch,ch |
207 | js .writekey |
||
582 | Rus | 208 | movzx eax,ch ; plain key |
1 | ha | 209 | mov bl,[keymap+eax] |
210 | mov edx,[kb_state] |
||
582 | Rus | 211 | test dl,VKEY_CONTROL ; ctrl alt del |
1 | ha | 212 | jz .noctrlaltdel |
213 | test dl,VKEY_ALT |
||
214 | jz .noctrlaltdel |
||
92 | diamond | 215 | cmp ch,53h |
1 | ha | 216 | jne .noctrlaltdel |
217 | mov [ctrl_alt_del],1 |
||
218 | .noctrlaltdel: |
||
582 | Rus | 219 | test dl,VKEY_CONTROL ; ctrl on ? |
1 | ha | 220 | jz @f |
221 | sub bl,0x60 |
||
582 | Rus | 222 | @@: test dl,VKEY_SHIFT ; shift on ? |
1 | ha | 223 | jz @f |
224 | mov bl,[keymap_shift+eax] |
||
582 | Rus | 225 | @@: test dl,VKEY_ALT ; alt on ? |
1 | ha | 226 | jz @f |
227 | mov bl,[keymap_alt+eax] |
||
228 | @@: |
||
582 | Rus | 229 | jmp .writekey |
92 | diamond | 230 | .modifier: |
582 | Rus | 231 | test ch, ch |
232 | js .modifier.up |
||
233 | or [kb_state], eax |
||
234 | jmp .writekey |
||
92 | diamond | 235 | .modifier.up: |
582 | Rus | 236 | not eax |
237 | and [kb_state], eax |
||
238 | jmp .writekey |
||
92 | diamond | 239 | .no_key.xor: |
582 | Rus | 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 |
||
92 | diamond | 246 | |
247 | .writekey: |
||
248 | ; test for system hotkeys |
||
582 | Rus | 249 | movzx eax, ch |
250 | cmp bh, 1 |
||
251 | ja .nohotkey |
||
252 | jb @f |
||
253 | xor eax, eax |
||
92 | diamond | 254 | @@: |
582 | Rus | 255 | mov eax, [hotkey_scancodes + eax*4] |
92 | diamond | 256 | .hotkey_loop: |
582 | Rus | 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 |
||
92 | diamond | 268 | .hotkey_cont: |
582 | Rus | 269 | mov eax, [eax] |
270 | jmp .hotkey_loop |
||
92 | diamond | 271 | .hotkey_found: |
582 | Rus | 272 | mov eax, [eax+8] |
92 | diamond | 273 | ; put key in buffer for process in slot eax |
582 | Rus | 274 | mov edi, hotkey_buffer |
92 | diamond | 275 | @@: |
582 | Rus | 276 | cmp dword [edi], 0 |
277 | jz .found_free |
||
278 | add edi, 8 |
||
279 | cmp edi, hotkey_buffer+120*8 |
||
280 | jb @b |
||
92 | diamond | 281 | ; no free space - replace first entry |
582 | Rus | 282 | mov edi, hotkey_buffer |
92 | diamond | 283 | .found_free: |
582 | Rus | 284 | mov [edi], eax |
285 | movzx eax, ch |
||
286 | cmp bh, 1 |
||
287 | jnz @f |
||
288 | xor eax, eax |
||
92 | diamond | 289 | @@: |
582 | Rus | 290 | mov [edi+4], ax |
291 | mov eax, [kb_state] |
||
292 | mov [edi+6], ax |
||
293 | jmp .exit.irq1 |
||
92 | diamond | 294 | .nohotkey: |
1 | ha | 295 | cmp [keyboard_mode],0 ; return from keymap |
92 | diamond | 296 | jne .scancode |
582 | Rus | 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 |
||
641 | diamond | 305 | cmp cl, 0xE0 |
306 | jz .dowrite |
||
582 | Rus | 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 |
||
603 | Rus | 317 | ;push eax |
582 | Rus | 318 | movzx eax, ch |
319 | mov bl, [numlock_map + eax - 71] |
||
603 | Rus | 320 | ;pop eax |
582 | Rus | 321 | |
322 | ;.........................Part1 End................................................. |
||
323 | |||
324 | jmp .dowrite |
||
92 | diamond | 325 | .scancode: |
582 | Rus | 326 | mov bl, ch |
92 | diamond | 327 | .dowrite: |
381 | serge | 328 | movzx eax,byte[KEY_COUNT] |
1 | ha | 329 | cmp al,120 |
92 | diamond | 330 | jae .exit.irq1 |
331 | inc eax |
||
381 | serge | 332 | mov [KEY_COUNT],al |
333 | mov [KEY_COUNT+eax],bl |
||
1 | ha | 334 | |
335 | .exit.irq1: |
||
336 | mov [check_idle_semaphore],5 |
||
337 | |||
582 | Rus | 338 | ret |
1 | ha | 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 ] |
||
582 | Rus | 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 . |
||
1874 | serge | 363 | ;..........................Part2 End................................................ |