Subversion Repositories Kolibri OS

Rev

Rev 2010 | Rev 2434 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2209 Serge 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: 2209 $
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
2209 Serge 52
;---------------------------------------------------------------------
92 diamond 53
hotkey_test0:
2209 Serge 54
	test	al,al
582 Rus 55
	setz	al
56
	ret
2209 Serge 57
;---------------------------------------------------------------------
92 diamond 58
hotkey_test1:
2209 Serge 59
	test	al,al
582 Rus 60
	setnp	al
61
	ret
2209 Serge 62
;---------------------------------------------------------------------
92 diamond 63
hotkey_test2:
2209 Serge 64
	cmp	al,3
582 Rus 65
	setz	al
66
	ret
2209 Serge 67
;---------------------------------------------------------------------
92 diamond 68
hotkey_test3:
2209 Serge 69
	cmp	al,1
582 Rus 70
	setz	al
71
	ret
2209 Serge 72
;---------------------------------------------------------------------
92 diamond 73
hotkey_test4:
2209 Serge 74
	cmp	al,2
582 Rus 75
	setz	al
76
	ret
2209 Serge 77
;---------------------------------------------------------------------
92 diamond 78
hotkey_do_test:
582 Rus 79
	push	eax
2209 Serge 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
2209 Serge 88
 
89
	xchg	eax,edx
90
	and	al,3
582 Rus 91
	call	[hotkey_tests + edx*4]
2209 Serge 92
	cmp	al,1
582 Rus 93
	pop	eax
94
	ret
2209 Serge 95
;--------------------------------------
92 diamond 96
.fail:
582 Rus 97
	stc
98
	pop	eax
99
	ret
2209 Serge 100
;---------------------------------------------------------------------
1 ha 101
align 4
2010 serge 102
set_keyboard_data:
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
 
2209 Serge 109
	mov	eax,ecx
2010 serge 110
 
2209 Serge 111
	push	ebx esi edi ebp
2010 serge 112
           call send_scancode
2209 Serge 113
	pop	ebp edi esi ebx
2010 serge 114
           ret
2209 Serge 115
;---------------------------------------------------------------------
2010 serge 116
align 4
1 ha 117
irq1:
379 serge 118
       movzx eax,word[TASK_COUNT] ; top window process
380 serge 119
       movzx eax,word[WIN_POS+eax*2]
1 ha 120
       shl   eax,8
380 serge 121
       mov   al,[SLOT_BASE+eax+APPDATA.keyboard_mode]
1 ha 122
       mov   [keyboard_mode],al
123
 
124
       in    al,0x60
2209 Serge 125
;--------------------------------------
2010 serge 126
send_scancode:
1 ha 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
1 ha 133
       mov   ch,al
134
       cmp   al,0xE0
135
       je    @f
2209 Serge 136
 
1 ha 137
       cmp   al,0xE1
138
       jne   .normal_code
2209 Serge 139
@@:
140
	mov	bh,2
141
	mov	[ext_code],al
582 Rus 142
	jmp	.writekey
2209 Serge 143
;--------------------------------------
144
.normal_code:
145
	mov	cl,0
146
	xchg	cl,[ext_code]
1 ha 147
       and   al,0x7F
2209 Serge 148
	mov	bh,1
149
@@:
150
	cmp	al,0x2A
1 ha 151
       jne   @f
2209 Serge 152
 
1 ha 153
       cmp   cl,0xE0
92 diamond 154
       je    .writekey
2209 Serge 155
 
1 ha 156
       mov   eax,VKEY_LSHIFT
92 diamond 157
       jmp   .modifier
2209 Serge 158
;--------------------------------------
159
@@:
160
	cmp	al,0x36
1 ha 161
       jne   @f
2209 Serge 162
 
1 ha 163
       cmp   cl,0xE0
92 diamond 164
       je    .writekey
2209 Serge 165
 
1 ha 166
       mov   eax,VKEY_RSHIFT
92 diamond 167
       jmp   .modifier
2209 Serge 168
;--------------------------------------
169
@@:
170
	cmp	al,0x38
1 ha 171
       jne   @f
2209 Serge 172
 
173
	mov	eax,VKEY_LALT
174
	test	cl,cl
582 Rus 175
	jz	.modifier
2209 Serge 176
 
177
	mov	al,VKEY_RALT
582 Rus 178
	jmp	.modifier
2209 Serge 179
;--------------------------------------
180
@@:
181
	cmp	al,0x1D
1 ha 182
       jne   @f
2209 Serge 183
 
184
	mov	eax,VKEY_LCONTROL
185
	test	cl,cl
582 Rus 186
	jz	.modifier
2209 Serge 187
 
188
	mov	al,VKEY_RCONTROL
189
	cmp	cl,0xE0
582 Rus 190
	jz	.modifier
2209 Serge 191
 
192
	mov	[ext_code],cl
582 Rus 193
	jmp	.writekey
2209 Serge 194
;--------------------------------------
195
@@:
196
	cmp	al,0x3A
1 ha 197
       jne   @f
2209 Serge 198
 
1 ha 199
       mov   bl,4
200
       mov   eax,VKEY_CAPSLOCK
201
       jmp   .no_key.xor
2209 Serge 202
;--------------------------------------
203
@@:
204
	cmp	al,0x45
1 ha 205
       jne   @f
2209 Serge 206
	test	cl,cl
582 Rus 207
	jnz	.writekey
2209 Serge 208
 
1 ha 209
       mov   bl,2
210
       mov   eax,VKEY_NUMLOCK
211
       jmp   .no_key.xor
2209 Serge 212
;--------------------------------------
213
@@:
214
	cmp	al,0x46
1 ha 215
       jne   @f
2209 Serge 216
 
1 ha 217
       mov   bl,1
218
       mov   eax,VKEY_SCRLOCK
219
       jmp   .no_key.xor
2209 Serge 220
;--------------------------------------
221
@@:
1579 diamond 222
       xor   ebx,ebx
92 diamond 223
       test  ch,ch
224
       js    .writekey
2209 Serge 225
 
582 Rus 226
       movzx eax,ch		 ; plain key
1 ha 227
       mov   bl,[keymap+eax]
228
       mov   edx,[kb_state]
582 Rus 229
       test  dl,VKEY_CONTROL	 ; ctrl alt del
1 ha 230
       jz    .noctrlaltdel
2209 Serge 231
 
1 ha 232
       test  dl,VKEY_ALT
233
       jz    .noctrlaltdel
2209 Serge 234
 
92 diamond 235
       cmp   ch,53h
1 ha 236
       jne   .noctrlaltdel
2209 Serge 237
 
1 ha 238
       mov   [ctrl_alt_del],1
2209 Serge 239
.noctrlaltdel:
582 Rus 240
       test  dl,VKEY_CONTROL	 ; ctrl on ?
1 ha 241
       jz    @f
2209 Serge 242
 
1 ha 243
       sub   bl,0x60
2209 Serge 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 ?
1 ha 255
       jz    @f
2209 Serge 256
.keymap_shif:
1 ha 257
       mov   bl,[keymap_shift+eax]
2209 Serge 258
@@:
259
	test	dl,VKEY_ALT	 ; alt on ?
1 ha 260
       jz    @f
2209 Serge 261
 
1 ha 262
       mov   bl,[keymap_alt+eax]
2209 Serge 263
@@:
582 Rus 264
	jmp	.writekey
2209 Serge 265
;--------------------------------------
92 diamond 266
.modifier:
582 Rus 267
	test	ch, ch
268
	js	.modifier.up
2209 Serge 269
	or	[kb_state],eax
582 Rus 270
	jmp	.writekey
2209 Serge 271
;--------------------------------------
92 diamond 272
.modifier.up:
582 Rus 273
	not	eax
2209 Serge 274
	and	[kb_state],eax
582 Rus 275
	jmp	.writekey
2209 Serge 276
;--------------------------------------
92 diamond 277
.no_key.xor:
2209 Serge 278
	mov	bh,0
279
	test	ch,ch
582 Rus 280
	js	.writekey
2209 Serge 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
2209 Serge 287
	movzx	eax,ch
288
	cmp	bh,1
582 Rus 289
	ja	.nohotkey
290
	jb	@f
2209 Serge 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
2209 Serge 298
 
299
	mov	cl,0
582 Rus 300
	call	hotkey_do_test
301
	jc	.hotkey_cont
2209 Serge 302
 
303
	mov	cl,2
582 Rus 304
	call	hotkey_do_test
305
	jc	.hotkey_cont
2209 Serge 306
 
307
	mov	cl,4
582 Rus 308
	call	hotkey_do_test
309
	jnc	.hotkey_found
92 diamond 310
.hotkey_cont:
2209 Serge 311
	mov	eax,[eax]
582 Rus 312
	jmp	.hotkey_loop
2209 Serge 313
;--------------------------------------
92 diamond 314
.hotkey_found:
2209 Serge 315
	mov	eax,[eax+8]
92 diamond 316
; put key in buffer for process in slot eax
2209 Serge 317
	mov	edi,hotkey_buffer
92 diamond 318
@@:
2209 Serge 319
	cmp	dword [edi],0
582 Rus 320
	jz	.found_free
2209 Serge 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
2209 Serge 326
	mov	edi,hotkey_buffer
92 diamond 327
.found_free:
2209 Serge 328
	mov	[edi],eax
329
	movzx	eax,ch
330
	cmp	bh,1
582 Rus 331
	jnz	@f
2209 Serge 332
 
582 Rus 333
	xor	eax, eax
92 diamond 334
@@:
2209 Serge 335
	mov	[edi+4],ax
336
	mov	eax,[kb_state]
337
	mov	[edi+6],ax
582 Rus 338
	jmp	.exit.irq1
2209 Serge 339
;--------------------------------------
92 diamond 340
.nohotkey:
1 ha 341
       cmp   [keyboard_mode],0 ; return from keymap
92 diamond 342
       jne   .scancode
2209 Serge 343
 
344
	test	bh,bh
582 Rus 345
	jnz	.exit.irq1
2209 Serge 346
 
347
	test	bl,bl
582 Rus 348
	jz	.exit.irq1
349
 
2209 Serge 350
	test	[kb_state],VKEY_NUMLOCK
582 Rus 351
	jz     .dowrite
2209 Serge 352
 
353
	cmp	cl,0xE0
641 diamond 354
        jz      .dowrite
582 Rus 355
 
2209 Serge 356
	cmp	ch,55
582 Rus 357
	jnz	@f
2209 Serge 358
 
359
	mov	bl,0x2A		;*
582 Rus 360
	jmp	.dowrite
2209 Serge 361
;--------------------------------------
362
@@:
363
	cmp	ch,71
582 Rus 364
	jb	.dowrite
2209 Serge 365
 
366
	cmp	ch,83
582 Rus 367
	ja	.dowrite
2209 Serge 368
 
582 Rus 369
	movzx	eax, ch
2209 Serge 370
	mov	bl,[numlock_map + eax - 71]
582 Rus 371
	jmp	.dowrite
2209 Serge 372
;--------------------------------------
92 diamond 373
.scancode:
2209 Serge 374
	mov	bl,ch
92 diamond 375
.dowrite:
381 serge 376
       movzx eax,byte[KEY_COUNT]
1 ha 377
       cmp   al,120
92 diamond 378
       jae   .exit.irq1
379
       inc   eax
381 serge 380
       mov   [KEY_COUNT],al
381
       mov   [KEY_COUNT+eax],bl
2209 Serge 382
.exit.irq1:
1 ha 383
       mov   [check_idle_semaphore],5
582 Rus 384
	ret
2209 Serge 385
;---------------------------------------------------------------------
1 ha 386
set_lights:
387
       mov   al,0xED
388
       call  kb_write
389
       mov   al,[kb_lights]
390
       call  kb_write
391
       ret
2209 Serge 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 .
2209 Serge 407
;---------------------------------------------------------------------