Rev 431 | Rev 593 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
425 | victor | 1 | $Revision: 582 $ |
431 | serge | 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 | |||
1 | ha | 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 |
||
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 |
||
52 | |||
53 | hotkey_test0: |
||
582 | Rus | 54 | test al, al |
55 | setz al |
||
56 | ret |
||
92 | diamond | 57 | hotkey_test1: |
582 | Rus | 58 | test al, al |
59 | setnp al |
||
60 | ret |
||
92 | diamond | 61 | hotkey_test2: |
582 | Rus | 62 | cmp al, 3 |
63 | setz al |
||
64 | ret |
||
92 | diamond | 65 | hotkey_test3: |
582 | Rus | 66 | cmp al, 1 |
67 | setz al |
||
68 | ret |
||
92 | diamond | 69 | hotkey_test4: |
582 | Rus | 70 | cmp al, 2 |
71 | setz al |
||
72 | ret |
||
92 | diamond | 73 | |
74 | hotkey_do_test: |
||
582 | Rus | 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 |
||
92 | diamond | 90 | .fail: |
582 | Rus | 91 | stc |
92 | pop eax |
||
93 | ret |
||
92 | diamond | 94 | |
1 | ha | 95 | align 4 |
96 | irq1: |
||
164 | serge | 97 | ; save_ring3_context |
98 | ; mov ax, os_data |
||
99 | ; mov ds, ax |
||
100 | ; mov es, ax |
||
1 | ha | 101 | |
379 | serge | 102 | movzx eax,word[TASK_COUNT] ; top window process |
380 | serge | 103 | movzx eax,word[WIN_POS+eax*2] |
1 | ha | 104 | shl eax,8 |
380 | serge | 105 | mov al,[SLOT_BASE+eax+APPDATA.keyboard_mode] |
1 | ha | 106 | mov [keyboard_mode],al |
107 | |||
108 | in al,0x60 |
||
109 | mov [keyboard_data],al |
||
110 | |||
92 | diamond | 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 | |||
1 | ha | 117 | mov ch,al |
118 | cmp al,0xE0 |
||
119 | je @f |
||
120 | cmp al,0xE1 |
||
121 | jne .normal_code |
||
92 | diamond | 122 | @@: |
582 | Rus | 123 | mov bh, 2 |
124 | mov [ext_code], al |
||
125 | jmp .writekey |
||
1 | ha | 126 | .normal_code: |
582 | Rus | 127 | mov cl, 0 |
128 | xchg cl, [ext_code] |
||
1 | ha | 129 | and al,0x7F |
582 | Rus | 130 | mov bh, 1 |
1 | ha | 131 | @@: cmp al,0x2A |
132 | jne @f |
||
133 | cmp cl,0xE0 |
||
92 | diamond | 134 | je .writekey |
1 | ha | 135 | mov eax,VKEY_LSHIFT |
92 | diamond | 136 | jmp .modifier |
1 | ha | 137 | @@: cmp al,0x36 |
138 | jne @f |
||
139 | cmp cl,0xE0 |
||
92 | diamond | 140 | je .writekey |
1 | ha | 141 | mov eax,VKEY_RSHIFT |
92 | diamond | 142 | jmp .modifier |
1 | ha | 143 | @@: cmp al,0x38 |
144 | jne @f |
||
582 | Rus | 145 | mov eax, VKEY_LALT |
146 | test cl, cl |
||
147 | jz .modifier |
||
148 | mov al, VKEY_RALT |
||
149 | jmp .modifier |
||
1 | ha | 150 | @@: cmp al,0x1D |
151 | jne @f |
||
582 | Rus | 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 |
||
1 | ha | 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 |
||
582 | Rus | 167 | test cl, cl |
168 | jnz .writekey |
||
1 | ha | 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 | @@: |
||
92 | diamond | 178 | test ch,ch |
179 | js .writekey |
||
582 | Rus | 180 | movzx eax,ch ; plain key |
1 | ha | 181 | mov bl,[keymap+eax] |
182 | mov edx,[kb_state] |
||
582 | Rus | 183 | test dl,VKEY_CONTROL ; ctrl alt del |
1 | ha | 184 | jz .noctrlaltdel |
185 | test dl,VKEY_ALT |
||
186 | jz .noctrlaltdel |
||
92 | diamond | 187 | cmp ch,53h |
1 | ha | 188 | jne .noctrlaltdel |
189 | mov [ctrl_alt_del],1 |
||
190 | .noctrlaltdel: |
||
582 | Rus | 191 | test dl,VKEY_CONTROL ; ctrl on ? |
1 | ha | 192 | jz @f |
193 | sub bl,0x60 |
||
582 | Rus | 194 | @@: test dl,VKEY_SHIFT ; shift on ? |
1 | ha | 195 | jz @f |
196 | mov bl,[keymap_shift+eax] |
||
582 | Rus | 197 | @@: test dl,VKEY_ALT ; alt on ? |
1 | ha | 198 | jz @f |
199 | mov bl,[keymap_alt+eax] |
||
200 | @@: |
||
582 | Rus | 201 | mov bh, 0 |
202 | jmp .writekey |
||
92 | diamond | 203 | .modifier: |
582 | Rus | 204 | test ch, ch |
205 | js .modifier.up |
||
206 | or [kb_state], eax |
||
207 | jmp .writekey |
||
92 | diamond | 208 | .modifier.up: |
582 | Rus | 209 | not eax |
210 | and [kb_state], eax |
||
211 | jmp .writekey |
||
92 | diamond | 212 | .no_key.xor: |
582 | Rus | 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 |
||
92 | diamond | 219 | |
220 | .writekey: |
||
221 | ; test for system hotkeys |
||
582 | Rus | 222 | movzx eax, ch |
223 | cmp bh, 1 |
||
224 | ja .nohotkey |
||
225 | jb @f |
||
226 | xor eax, eax |
||
92 | diamond | 227 | @@: |
582 | Rus | 228 | mov eax, [hotkey_scancodes + eax*4] |
92 | diamond | 229 | .hotkey_loop: |
582 | Rus | 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 |
||
92 | diamond | 241 | .hotkey_cont: |
582 | Rus | 242 | mov eax, [eax] |
243 | jmp .hotkey_loop |
||
92 | diamond | 244 | .hotkey_found: |
582 | Rus | 245 | mov eax, [eax+8] |
92 | diamond | 246 | ; put key in buffer for process in slot eax |
582 | Rus | 247 | mov edi, hotkey_buffer |
92 | diamond | 248 | @@: |
582 | Rus | 249 | cmp dword [edi], 0 |
250 | jz .found_free |
||
251 | add edi, 8 |
||
252 | cmp edi, hotkey_buffer+120*8 |
||
253 | jb @b |
||
92 | diamond | 254 | ; no free space - replace first entry |
582 | Rus | 255 | mov edi, hotkey_buffer |
92 | diamond | 256 | .found_free: |
582 | Rus | 257 | mov [edi], eax |
258 | movzx eax, ch |
||
259 | cmp bh, 1 |
||
260 | jnz @f |
||
261 | xor eax, eax |
||
92 | diamond | 262 | @@: |
582 | Rus | 263 | mov [edi+4], ax |
264 | mov eax, [kb_state] |
||
265 | mov [edi+6], ax |
||
266 | jmp .exit.irq1 |
||
92 | diamond | 267 | .nohotkey: |
1 | ha | 268 | cmp [keyboard_mode],0 ; return from keymap |
92 | diamond | 269 | jne .scancode |
582 | Rus | 270 | test bh, bh |
271 | jnz .exit.irq1 |
||
272 | test bl, bl |
||
273 | jz .exit.irq1 |
||
274 | |||
275 | ;.........................Part1 Start.......Code by Rus, optimize by Ghost................................... |
||
276 | test [kb_state], VKEY_NUMLOCK |
||
277 | jz .dowrite |
||
278 | |||
279 | cmp ch, 55 |
||
280 | jnz @f |
||
281 | mov bl, 0x2A ;* |
||
282 | jmp .dowrite |
||
283 | @@: |
||
284 | cmp ch, 71 |
||
285 | jb .dowrite |
||
286 | cmp ch, 83 |
||
287 | ja .dowrite |
||
288 | push eax |
||
289 | movzx eax, ch |
||
290 | mov bl, [numlock_map + eax - 71] |
||
291 | pop eax |
||
292 | |||
293 | ;.........................Part1 End................................................. |
||
294 | |||
295 | jmp .dowrite |
||
92 | diamond | 296 | .scancode: |
582 | Rus | 297 | mov bl, ch |
92 | diamond | 298 | .dowrite: |
381 | serge | 299 | movzx eax,byte[KEY_COUNT] |
1 | ha | 300 | cmp al,120 |
92 | diamond | 301 | jae .exit.irq1 |
302 | inc eax |
||
381 | serge | 303 | mov [KEY_COUNT],al |
304 | mov [KEY_COUNT+eax],bl |
||
1 | ha | 305 | |
306 | .exit.irq1: |
||
307 | mov [check_idle_semaphore],5 |
||
308 | |||
164 | serge | 309 | ; mov al,0x20 ; ready for next irq |
310 | ; out 0x20,al |
||
1 | ha | 311 | |
164 | serge | 312 | ; restore_ring3_context |
313 | ; iret |
||
582 | Rus | 314 | ret |
1 | ha | 315 | |
316 | set_lights: |
||
317 | mov al,0xED |
||
318 | call kb_write |
||
319 | mov al,[kb_lights] |
||
320 | call kb_write |
||
321 | ret |
||
322 | |||
323 | ;// mike.dld ] |
||
582 | Rus | 324 | ;..........................Part2 Start.......Code by Rus....................................... |
325 | numlock_map: |
||
326 | db 0x37 ;Num 7 |
||
327 | db 0x38 ;Num 8 |
||
328 | db 0x39 ;Num 9 |
||
329 | db 0x2D ;Num - |
||
330 | db 0x34 ;Num 4 |
||
331 | db 0x35 ;Num 5 |
||
332 | db 0x36 ;Num 6 |
||
333 | db 0x2B ;Num + |
||
334 | db 0x31 ;Num 1 |
||
335 | db 0x32 ;Num 2 |
||
336 | db 0x33 ;Num 3 |
||
337 | db 0x30 ;Num 0 |
||
338 | db 0x2E ;Num . |
||
339 | ;..........................Part2 End................................................ |