Rev 1874 | Rev 2288 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
431 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
2171 | mario79 | 3 | ;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; |
431 | serge | 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: 2171 $ |
9 | |||
10 | |||
1 | ha | 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 |
||
582 | Rus | 27 | kb_state dd 0 |
28 | ext_code db 0 |
||
1 | ha | 29 | |
30 | keyboard_mode db 0 |
||
31 | keyboard_data db 0 |
||
32 | |||
582 | Rus | 33 | altmouseb db 0 |
34 | ctrl_alt_del db 0 |
||
1 | ha | 35 | |
582 | Rus | 36 | kb_lights db 0 |
92 | diamond | 37 | |
38 | align 4 |
||
582 | Rus | 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 |
||
1 | ha | 42 | endg |
43 | |||
92 | diamond | 44 | iglobal |
582 | Rus | 45 | hotkey_tests dd hotkey_test0 |
46 | dd hotkey_test1 |
||
47 | dd hotkey_test2 |
||
48 | dd hotkey_test3 |
||
49 | dd hotkey_test4 |
||
92 | diamond | 50 | hotkey_tests_num = 5 |
51 | endg |
||
2171 | mario79 | 52 | ;--------------------------------------------------------------------- |
92 | diamond | 53 | hotkey_test0: |
2171 | mario79 | 54 | test al,al |
582 | Rus | 55 | setz al |
56 | ret |
||
2171 | mario79 | 57 | ;--------------------------------------------------------------------- |
92 | diamond | 58 | hotkey_test1: |
2171 | mario79 | 59 | test al,al |
582 | Rus | 60 | setnp al |
61 | ret |
||
2171 | mario79 | 62 | ;--------------------------------------------------------------------- |
92 | diamond | 63 | hotkey_test2: |
2171 | mario79 | 64 | cmp al,3 |
582 | Rus | 65 | setz al |
66 | ret |
||
2171 | mario79 | 67 | ;--------------------------------------------------------------------- |
92 | diamond | 68 | hotkey_test3: |
2171 | mario79 | 69 | cmp al,1 |
582 | Rus | 70 | setz al |
71 | ret |
||
2171 | mario79 | 72 | ;--------------------------------------------------------------------- |
92 | diamond | 73 | hotkey_test4: |
2171 | mario79 | 74 | cmp al,2 |
582 | Rus | 75 | setz al |
76 | ret |
||
2171 | mario79 | 77 | ;--------------------------------------------------------------------- |
92 | diamond | 78 | hotkey_do_test: |
582 | Rus | 79 | push eax |
2171 | mario79 | 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 |
||
582 | Rus | 87 | jae .fail |
2171 | mario79 | 88 | |
89 | xchg eax,edx |
||
90 | and al,3 |
||
582 | Rus | 91 | call [hotkey_tests + edx*4] |
2171 | mario79 | 92 | cmp al,1 |
582 | Rus | 93 | pop eax |
94 | ret |
||
2171 | mario79 | 95 | ;-------------------------------------- |
92 | diamond | 96 | .fail: |
582 | Rus | 97 | stc |
98 | pop eax |
||
99 | ret |
||
2171 | mario79 | 100 | ;--------------------------------------------------------------------- |
1 | ha | 101 | align 4 |
1874 | serge | 102 | set_keyboard_data: |
2171 | mario79 | 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 | ;--------------------------------------------------------------------- |
||
1874 | serge | 116 | align 4 |
1 | ha | 117 | irq1: |
2171 | mario79 | 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 | ;-------------------------------------- |
||
1874 | serge | 126 | send_scancode: |
2171 | mario79 | 127 | mov [keyboard_data],al |
92 | diamond | 128 | ; ch = scancode |
129 | ; cl = ext_code |
||
130 | ; bh = 0 - normal key |
||
131 | ; bh = 1 - modifier (Shift/Ctrl/Alt) |
||
132 | ; bh = 2 - extended code |
||
2171 | mario79 | 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 |
||
582 | Rus | 142 | jmp .writekey |
2171 | mario79 | 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 |
||
582 | Rus | 175 | jz .modifier |
2171 | mario79 | 176 | |
177 | mov al,VKEY_RALT |
||
582 | Rus | 178 | jmp .modifier |
2171 | mario79 | 179 | ;-------------------------------------- |
180 | @@: |
||
181 | cmp al,0x1D |
||
182 | jne @f |
||
183 | |||
184 | mov eax,VKEY_LCONTROL |
||
185 | test cl,cl |
||
582 | Rus | 186 | jz .modifier |
2171 | mario79 | 187 | |
188 | mov al,VKEY_RCONTROL |
||
189 | cmp cl,0xE0 |
||
582 | Rus | 190 | jz .modifier |
2171 | mario79 | 191 | |
192 | mov [ext_code],cl |
||
582 | Rus | 193 | jmp .writekey |
2171 | mario79 | 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 |
||
582 | Rus | 207 | jnz .writekey |
2171 | mario79 | 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 | @@: |
||
582 | Rus | 264 | jmp .writekey |
2171 | mario79 | 265 | ;-------------------------------------- |
92 | diamond | 266 | .modifier: |
582 | Rus | 267 | test ch, ch |
268 | js .modifier.up |
||
2171 | mario79 | 269 | or [kb_state],eax |
582 | Rus | 270 | jmp .writekey |
2171 | mario79 | 271 | ;-------------------------------------- |
92 | diamond | 272 | .modifier.up: |
582 | Rus | 273 | not eax |
2171 | mario79 | 274 | and [kb_state],eax |
582 | Rus | 275 | jmp .writekey |
2171 | mario79 | 276 | ;-------------------------------------- |
92 | diamond | 277 | .no_key.xor: |
2171 | mario79 | 278 | mov bh,0 |
279 | test ch,ch |
||
582 | Rus | 280 | js .writekey |
2171 | mario79 | 281 | |
282 | xor [kb_state],eax |
||
283 | xor [kb_lights],bl |
||
582 | Rus | 284 | call set_lights |
92 | diamond | 285 | .writekey: |
286 | ; test for system hotkeys |
||
2171 | mario79 | 287 | movzx eax,ch |
288 | cmp bh,1 |
||
582 | Rus | 289 | ja .nohotkey |
290 | jb @f |
||
2171 | mario79 | 291 | |
292 | xor eax,eax |
||
92 | diamond | 293 | @@: |
582 | Rus | 294 | mov eax, [hotkey_scancodes + eax*4] |
92 | diamond | 295 | .hotkey_loop: |
582 | Rus | 296 | test eax, eax |
297 | jz .nohotkey |
||
2171 | mario79 | 298 | |
299 | mov cl,0 |
||
582 | Rus | 300 | call hotkey_do_test |
301 | jc .hotkey_cont |
||
2171 | mario79 | 302 | |
303 | mov cl,2 |
||
582 | Rus | 304 | call hotkey_do_test |
305 | jc .hotkey_cont |
||
2171 | mario79 | 306 | |
307 | mov cl,4 |
||
582 | Rus | 308 | call hotkey_do_test |
309 | jnc .hotkey_found |
||
92 | diamond | 310 | .hotkey_cont: |
2171 | mario79 | 311 | mov eax,[eax] |
582 | Rus | 312 | jmp .hotkey_loop |
2171 | mario79 | 313 | ;-------------------------------------- |
92 | diamond | 314 | .hotkey_found: |
2171 | mario79 | 315 | mov eax,[eax+8] |
92 | diamond | 316 | ; put key in buffer for process in slot eax |
2171 | mario79 | 317 | mov edi,hotkey_buffer |
92 | diamond | 318 | @@: |
2171 | mario79 | 319 | cmp dword [edi],0 |
582 | Rus | 320 | jz .found_free |
2171 | mario79 | 321 | |
322 | add edi,8 |
||
323 | cmp edi,hotkey_buffer+120*8 |
||
582 | Rus | 324 | jb @b |
92 | diamond | 325 | ; no free space - replace first entry |
2171 | mario79 | 326 | mov edi,hotkey_buffer |
92 | diamond | 327 | .found_free: |
2171 | mario79 | 328 | mov [edi],eax |
329 | movzx eax,ch |
||
330 | cmp bh,1 |
||
582 | Rus | 331 | jnz @f |
2171 | mario79 | 332 | |
582 | Rus | 333 | xor eax, eax |
92 | diamond | 334 | @@: |
2171 | mario79 | 335 | mov [edi+4],ax |
336 | mov eax,[kb_state] |
||
337 | mov [edi+6],ax |
||
582 | Rus | 338 | jmp .exit.irq1 |
2171 | mario79 | 339 | ;-------------------------------------- |
92 | diamond | 340 | .nohotkey: |
2171 | mario79 | 341 | cmp [keyboard_mode],0 ; return from keymap |
342 | jne .scancode |
||
343 | |||
344 | test bh,bh |
||
582 | Rus | 345 | jnz .exit.irq1 |
2171 | mario79 | 346 | |
347 | test bl,bl |
||
582 | Rus | 348 | jz .exit.irq1 |
349 | |||
2171 | mario79 | 350 | test [kb_state],VKEY_NUMLOCK |
351 | jz .dowrite |
||
352 | |||
353 | cmp cl,0xE0 |
||
354 | jz .dowrite |
||
355 | |||
356 | cmp ch,55 |
||
582 | Rus | 357 | jnz @f |
2171 | mario79 | 358 | |
359 | mov bl,0x2A ;* |
||
582 | Rus | 360 | jmp .dowrite |
2171 | mario79 | 361 | ;-------------------------------------- |
362 | @@: |
||
363 | cmp ch,71 |
||
582 | Rus | 364 | jb .dowrite |
2171 | mario79 | 365 | |
366 | cmp ch,83 |
||
582 | Rus | 367 | ja .dowrite |
2171 | mario79 | 368 | |
582 | Rus | 369 | movzx eax, ch |
2171 | mario79 | 370 | mov bl,[numlock_map + eax - 71] |
582 | Rus | 371 | jmp .dowrite |
2171 | mario79 | 372 | ;-------------------------------------- |
92 | diamond | 373 | .scancode: |
2171 | mario79 | 374 | mov bl,ch |
92 | diamond | 375 | .dowrite: |
2171 | mario79 | 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 |
||
582 | Rus | 384 | ret |
2171 | mario79 | 385 | ;--------------------------------------------------------------------- |
1 | ha | 386 | set_lights: |
2171 | mario79 | 387 | mov al,0xED |
388 | call kb_write |
||
389 | mov al,[kb_lights] |
||
390 | call kb_write |
||
391 | ret |
||
392 | ;--------------------------------------------------------------------- |
||
582 | Rus | 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 . |
||
2171 | mario79 | 407 | ;--------------------------------------------------------------------- |