Rev 1576 | Rev 1874 | 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: 1579 $ |
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 | |
1 | ha | 97 | align 4 |
98 | irq1: |
||
164 | serge | 99 | ; save_ring3_context |
100 | ; mov ax, os_data |
||
101 | ; mov ds, ax |
||
102 | ; mov es, ax |
||
1 | ha | 103 | |
379 | serge | 104 | movzx eax,word[TASK_COUNT] ; top window process |
380 | serge | 105 | movzx eax,word[WIN_POS+eax*2] |
1 | ha | 106 | shl eax,8 |
380 | serge | 107 | mov al,[SLOT_BASE+eax+APPDATA.keyboard_mode] |
1 | ha | 108 | mov [keyboard_mode],al |
109 | |||
110 | in al,0x60 |
||
111 | mov [keyboard_data],al |
||
112 | |||
92 | diamond | 113 | ; ch = scancode |
114 | ; cl = ext_code |
||
115 | ; bh = 0 - normal key |
||
116 | ; bh = 1 - modifier (Shift/Ctrl/Alt) |
||
117 | ; bh = 2 - extended code |
||
118 | |||
1 | ha | 119 | mov ch,al |
120 | cmp al,0xE0 |
||
121 | je @f |
||
122 | cmp al,0xE1 |
||
123 | jne .normal_code |
||
92 | diamond | 124 | @@: |
582 | Rus | 125 | mov bh, 2 |
126 | mov [ext_code], al |
||
127 | jmp .writekey |
||
1 | ha | 128 | .normal_code: |
582 | Rus | 129 | mov cl, 0 |
130 | xchg cl, [ext_code] |
||
1 | ha | 131 | and al,0x7F |
582 | Rus | 132 | mov bh, 1 |
1 | ha | 133 | @@: cmp al,0x2A |
134 | jne @f |
||
135 | cmp cl,0xE0 |
||
92 | diamond | 136 | je .writekey |
1 | ha | 137 | mov eax,VKEY_LSHIFT |
92 | diamond | 138 | jmp .modifier |
1 | ha | 139 | @@: cmp al,0x36 |
140 | jne @f |
||
141 | cmp cl,0xE0 |
||
92 | diamond | 142 | je .writekey |
1 | ha | 143 | mov eax,VKEY_RSHIFT |
92 | diamond | 144 | jmp .modifier |
1 | ha | 145 | @@: cmp al,0x38 |
146 | jne @f |
||
582 | Rus | 147 | mov eax, VKEY_LALT |
148 | test cl, cl |
||
149 | jz .modifier |
||
150 | mov al, VKEY_RALT |
||
151 | jmp .modifier |
||
1 | ha | 152 | @@: cmp al,0x1D |
153 | jne @f |
||
582 | Rus | 154 | mov eax, VKEY_LCONTROL |
155 | test cl, cl |
||
156 | jz .modifier |
||
157 | mov al, VKEY_RCONTROL |
||
158 | cmp cl, 0xE0 |
||
159 | jz .modifier |
||
160 | mov [ext_code], cl |
||
161 | jmp .writekey |
||
1 | ha | 162 | @@: cmp al,0x3A |
163 | jne @f |
||
164 | mov bl,4 |
||
165 | mov eax,VKEY_CAPSLOCK |
||
166 | jmp .no_key.xor |
||
167 | @@: cmp al,0x45 |
||
168 | jne @f |
||
582 | Rus | 169 | test cl, cl |
170 | jnz .writekey |
||
1 | ha | 171 | mov bl,2 |
172 | mov eax,VKEY_NUMLOCK |
||
173 | jmp .no_key.xor |
||
174 | @@: cmp al,0x46 |
||
175 | jne @f |
||
176 | mov bl,1 |
||
177 | mov eax,VKEY_SCRLOCK |
||
178 | jmp .no_key.xor |
||
179 | @@: |
||
1579 | diamond | 180 | xor ebx,ebx |
92 | diamond | 181 | test ch,ch |
182 | js .writekey |
||
582 | Rus | 183 | movzx eax,ch ; plain key |
1 | ha | 184 | mov bl,[keymap+eax] |
185 | mov edx,[kb_state] |
||
582 | Rus | 186 | test dl,VKEY_CONTROL ; ctrl alt del |
1 | ha | 187 | jz .noctrlaltdel |
188 | test dl,VKEY_ALT |
||
189 | jz .noctrlaltdel |
||
92 | diamond | 190 | cmp ch,53h |
1 | ha | 191 | jne .noctrlaltdel |
192 | mov [ctrl_alt_del],1 |
||
193 | .noctrlaltdel: |
||
582 | Rus | 194 | test dl,VKEY_CONTROL ; ctrl on ? |
1 | ha | 195 | jz @f |
196 | sub bl,0x60 |
||
582 | Rus | 197 | @@: test dl,VKEY_SHIFT ; shift on ? |
1 | ha | 198 | jz @f |
199 | mov bl,[keymap_shift+eax] |
||
582 | Rus | 200 | @@: test dl,VKEY_ALT ; alt on ? |
1 | ha | 201 | jz @f |
202 | mov bl,[keymap_alt+eax] |
||
203 | @@: |
||
582 | Rus | 204 | jmp .writekey |
92 | diamond | 205 | .modifier: |
582 | Rus | 206 | test ch, ch |
207 | js .modifier.up |
||
208 | or [kb_state], eax |
||
209 | jmp .writekey |
||
92 | diamond | 210 | .modifier.up: |
582 | Rus | 211 | not eax |
212 | and [kb_state], eax |
||
213 | jmp .writekey |
||
92 | diamond | 214 | .no_key.xor: |
582 | Rus | 215 | mov bh, 0 |
216 | test ch, ch |
||
217 | js .writekey |
||
218 | xor [kb_state], eax |
||
219 | xor [kb_lights], bl |
||
220 | call set_lights |
||
92 | diamond | 221 | |
222 | .writekey: |
||
223 | ; test for system hotkeys |
||
582 | Rus | 224 | movzx eax, ch |
225 | cmp bh, 1 |
||
226 | ja .nohotkey |
||
227 | jb @f |
||
228 | xor eax, eax |
||
92 | diamond | 229 | @@: |
582 | Rus | 230 | mov eax, [hotkey_scancodes + eax*4] |
92 | diamond | 231 | .hotkey_loop: |
582 | Rus | 232 | test eax, eax |
233 | jz .nohotkey |
||
234 | mov cl, 0 |
||
235 | call hotkey_do_test |
||
236 | jc .hotkey_cont |
||
237 | mov cl, 2 |
||
238 | call hotkey_do_test |
||
239 | jc .hotkey_cont |
||
240 | mov cl, 4 |
||
241 | call hotkey_do_test |
||
242 | jnc .hotkey_found |
||
92 | diamond | 243 | .hotkey_cont: |
582 | Rus | 244 | mov eax, [eax] |
245 | jmp .hotkey_loop |
||
92 | diamond | 246 | .hotkey_found: |
582 | Rus | 247 | mov eax, [eax+8] |
92 | diamond | 248 | ; put key in buffer for process in slot eax |
582 | Rus | 249 | mov edi, hotkey_buffer |
92 | diamond | 250 | @@: |
582 | Rus | 251 | cmp dword [edi], 0 |
252 | jz .found_free |
||
253 | add edi, 8 |
||
254 | cmp edi, hotkey_buffer+120*8 |
||
255 | jb @b |
||
92 | diamond | 256 | ; no free space - replace first entry |
582 | Rus | 257 | mov edi, hotkey_buffer |
92 | diamond | 258 | .found_free: |
582 | Rus | 259 | mov [edi], eax |
260 | movzx eax, ch |
||
261 | cmp bh, 1 |
||
262 | jnz @f |
||
263 | xor eax, eax |
||
92 | diamond | 264 | @@: |
582 | Rus | 265 | mov [edi+4], ax |
266 | mov eax, [kb_state] |
||
267 | mov [edi+6], ax |
||
268 | jmp .exit.irq1 |
||
92 | diamond | 269 | .nohotkey: |
1 | ha | 270 | cmp [keyboard_mode],0 ; return from keymap |
92 | diamond | 271 | jne .scancode |
582 | Rus | 272 | test bh, bh |
273 | jnz .exit.irq1 |
||
274 | test bl, bl |
||
275 | jz .exit.irq1 |
||
276 | |||
277 | ;.........................Part1 Start.......Code by Rus, optimize by Ghost................................... |
||
278 | test [kb_state], VKEY_NUMLOCK |
||
279 | jz .dowrite |
||
641 | diamond | 280 | cmp cl, 0xE0 |
281 | jz .dowrite |
||
582 | Rus | 282 | |
283 | cmp ch, 55 |
||
284 | jnz @f |
||
285 | mov bl, 0x2A ;* |
||
286 | jmp .dowrite |
||
287 | @@: |
||
288 | cmp ch, 71 |
||
289 | jb .dowrite |
||
290 | cmp ch, 83 |
||
291 | ja .dowrite |
||
603 | Rus | 292 | ;push eax |
582 | Rus | 293 | movzx eax, ch |
294 | mov bl, [numlock_map + eax - 71] |
||
603 | Rus | 295 | ;pop eax |
582 | Rus | 296 | |
297 | ;.........................Part1 End................................................. |
||
298 | |||
299 | jmp .dowrite |
||
92 | diamond | 300 | .scancode: |
582 | Rus | 301 | mov bl, ch |
92 | diamond | 302 | .dowrite: |
381 | serge | 303 | movzx eax,byte[KEY_COUNT] |
1 | ha | 304 | cmp al,120 |
92 | diamond | 305 | jae .exit.irq1 |
306 | inc eax |
||
381 | serge | 307 | mov [KEY_COUNT],al |
308 | mov [KEY_COUNT+eax],bl |
||
1 | ha | 309 | |
310 | .exit.irq1: |
||
311 | mov [check_idle_semaphore],5 |
||
312 | |||
164 | serge | 313 | ; mov al,0x20 ; ready for next irq |
314 | ; out 0x20,al |
||
1 | ha | 315 | |
164 | serge | 316 | ; restore_ring3_context |
317 | ; iret |
||
582 | Rus | 318 | ret |
1 | ha | 319 | |
320 | set_lights: |
||
321 | mov al,0xED |
||
322 | call kb_write |
||
323 | mov al,[kb_lights] |
||
324 | call kb_write |
||
325 | ret |
||
326 | |||
327 | ;// mike.dld ] |
||
582 | Rus | 328 | ;..........................Part2 Start.......Code by Rus....................................... |
329 | numlock_map: |
||
330 | db 0x37 ;Num 7 |
||
331 | db 0x38 ;Num 8 |
||
332 | db 0x39 ;Num 9 |
||
333 | db 0x2D ;Num - |
||
334 | db 0x34 ;Num 4 |
||
335 | db 0x35 ;Num 5 |
||
336 | db 0x36 ;Num 6 |
||
337 | db 0x2B ;Num + |
||
338 | db 0x31 ;Num 1 |
||
339 | db 0x32 ;Num 2 |
||
340 | db 0x33 ;Num 3 |
||
341 | db 0x30 ;Num 0 |
||
342 | db 0x2E ;Num . |
||
343 | ;..........................Part2 End................................................ |