Subversion Repositories Kolibri OS

Rev

Rev 593 | Rev 641 | 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: 603 $
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
   @@:
92 diamond 180
       test  ch,ch
181
       js    .writekey
582 Rus 182
       movzx eax,ch		 ; plain key
1 ha 183
       mov   bl,[keymap+eax]
184
       mov   edx,[kb_state]
582 Rus 185
       test  dl,VKEY_CONTROL	 ; ctrl alt del
1 ha 186
       jz    .noctrlaltdel
187
       test  dl,VKEY_ALT
188
       jz    .noctrlaltdel
92 diamond 189
       cmp   ch,53h
1 ha 190
       jne   .noctrlaltdel
191
       mov   [ctrl_alt_del],1
192
   .noctrlaltdel:
582 Rus 193
       test  dl,VKEY_CONTROL	 ; ctrl on ?
1 ha 194
       jz    @f
195
       sub   bl,0x60
582 Rus 196
   @@: test  dl,VKEY_SHIFT	 ; shift on ?
1 ha 197
       jz    @f
198
       mov   bl,[keymap_shift+eax]
582 Rus 199
   @@: test  dl,VKEY_ALT	 ; alt on ?
1 ha 200
       jz    @f
201
       mov   bl,[keymap_alt+eax]
202
   @@:
582 Rus 203
	mov	bh, 0
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
280
 
281
	cmp	ch, 55
282
	jnz	@f
283
	mov	bl, 0x2A	;*
284
	jmp	.dowrite
285
      @@:
286
	cmp	ch, 71
287
	jb	.dowrite
288
	cmp	ch, 83
289
	ja	.dowrite
603 Rus 290
	;push    eax
582 Rus 291
	movzx	eax, ch
292
	mov	bl, [numlock_map + eax - 71]
603 Rus 293
	;pop     eax
582 Rus 294
 
295
;.........................Part1 End.................................................
296
 
297
	jmp	.dowrite
92 diamond 298
.scancode:
582 Rus 299
	mov	bl, ch
92 diamond 300
.dowrite:
381 serge 301
       movzx eax,byte[KEY_COUNT]
1 ha 302
       cmp   al,120
92 diamond 303
       jae   .exit.irq1
304
       inc   eax
381 serge 305
       mov   [KEY_COUNT],al
306
       mov   [KEY_COUNT+eax],bl
1 ha 307
 
308
   .exit.irq1:
309
       mov   [check_idle_semaphore],5
310
 
164 serge 311
;       mov   al,0x20                  ; ready for next irq
312
;       out   0x20,al
1 ha 313
 
164 serge 314
;       restore_ring3_context
315
;       iret
582 Rus 316
	ret
1 ha 317
 
318
set_lights:
319
       mov   al,0xED
320
       call  kb_write
321
       mov   al,[kb_lights]
322
       call  kb_write
323
       ret
324
 
325
;// mike.dld ]
582 Rus 326
;..........................Part2 Start.......Code by Rus.......................................
327
numlock_map:
328
    db	 0x37	;Num 7
329
    db	 0x38	;Num 8
330
    db	 0x39	;Num 9
331
    db	 0x2D	;Num -
332
    db	 0x34	;Num 4
333
    db	 0x35	;Num 5
334
    db	 0x36	;Num 6
335
    db	 0x2B	;Num +
336
    db	 0x31	;Num 1
337
    db	 0x32	;Num 2
338
    db	 0x33	;Num 3
339
    db	 0x30	;Num 0
340
    db	 0x2E	;Num .
341
;..........................Part2 End................................................