Subversion Repositories Kolibri OS

Rev

Rev 593 | Rev 641 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 593 Rev 603
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
4
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
4
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
5
;; Distributed under terms of the GNU General Public License    ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
7
 
8
$Revision: 593 $
8
$Revision: 603 $
9
 
9
 
10
 
10
 
11
;// mike.dld [
11
;// mike.dld [
12
 
12
 
13
VKEY_LSHIFT   = 0000000000000001b
13
VKEY_LSHIFT   = 0000000000000001b
14
VKEY_RSHIFT   = 0000000000000010b
14
VKEY_RSHIFT   = 0000000000000010b
15
VKEY_LCONTROL = 0000000000000100b
15
VKEY_LCONTROL = 0000000000000100b
16
VKEY_RCONTROL = 0000000000001000b
16
VKEY_RCONTROL = 0000000000001000b
17
VKEY_LALT     = 0000000000010000b
17
VKEY_LALT     = 0000000000010000b
18
VKEY_RALT     = 0000000000100000b
18
VKEY_RALT     = 0000000000100000b
19
VKEY_CAPSLOCK = 0000000001000000b
19
VKEY_CAPSLOCK = 0000000001000000b
20
VKEY_NUMLOCK  = 0000000010000000b
20
VKEY_NUMLOCK  = 0000000010000000b
21
VKEY_SCRLOCK  = 0000000100000000b
21
VKEY_SCRLOCK  = 0000000100000000b
22
 
22
 
23
VKEY_SHIFT    = 0000000000000011b
23
VKEY_SHIFT    = 0000000000000011b
24
VKEY_CONTROL  = 0000000000001100b
24
VKEY_CONTROL  = 0000000000001100b
25
VKEY_ALT      = 0000000000110000b
25
VKEY_ALT      = 0000000000110000b
26
 
26
 
27
uglobal
27
uglobal
28
  align 4
28
  align 4
29
  kb_state	dd 0
29
  kb_state	dd 0
30
  ext_code	db 0
30
  ext_code	db 0
31
 
31
 
32
  keyboard_mode db 0
32
  keyboard_mode db 0
33
  keyboard_data db 0
33
  keyboard_data db 0
34
 
34
 
35
  altmouseb	db 0
35
  altmouseb	db 0
36
  ctrl_alt_del	db 0
36
  ctrl_alt_del	db 0
37
 
37
 
38
  kb_lights	db 0
38
  kb_lights	db 0
39
 
39
 
40
align 4
40
align 4
41
	hotkey_scancodes	rd	256	; we have 256 scancodes
41
	hotkey_scancodes	rd	256	; we have 256 scancodes
42
	hotkey_list		rd	256*4	; max 256 defined hotkeys
42
	hotkey_list		rd	256*4	; max 256 defined hotkeys
43
	hotkey_buffer		rd	120*2	; buffer for 120 hotkeys
43
	hotkey_buffer		rd	120*2	; buffer for 120 hotkeys
44
endg
44
endg
45
 
45
 
46
iglobal
46
iglobal
47
hotkey_tests	dd	hotkey_test0
47
hotkey_tests	dd	hotkey_test0
48
		dd	hotkey_test1
48
		dd	hotkey_test1
49
		dd	hotkey_test2
49
		dd	hotkey_test2
50
		dd	hotkey_test3
50
		dd	hotkey_test3
51
		dd	hotkey_test4
51
		dd	hotkey_test4
52
hotkey_tests_num = 5
52
hotkey_tests_num = 5
53
endg
53
endg
54
 
54
 
55
hotkey_test0:
55
hotkey_test0:
56
	test	al, al
56
	test	al, al
57
	setz	al
57
	setz	al
58
	ret
58
	ret
59
hotkey_test1:
59
hotkey_test1:
60
	test	al, al
60
	test	al, al
61
	setnp	al
61
	setnp	al
62
	ret
62
	ret
63
hotkey_test2:
63
hotkey_test2:
64
	cmp	al, 3
64
	cmp	al, 3
65
	setz	al
65
	setz	al
66
	ret
66
	ret
67
hotkey_test3:
67
hotkey_test3:
68
	cmp	al, 1
68
	cmp	al, 1
69
	setz	al
69
	setz	al
70
	ret
70
	ret
71
hotkey_test4:
71
hotkey_test4:
72
	cmp	al, 2
72
	cmp	al, 2
73
	setz	al
73
	setz	al
74
	ret
74
	ret
75
 
75
 
76
hotkey_do_test:
76
hotkey_do_test:
77
	push	eax
77
	push	eax
78
	mov	edx, [kb_state]
78
	mov	edx, [kb_state]
79
	shr	edx, cl
79
	shr	edx, cl
80
	add	cl, cl
80
	add	cl, cl
81
	mov	eax, [eax+4]
81
	mov	eax, [eax+4]
82
	shr	eax, cl
82
	shr	eax, cl
83
	and	eax, 15
83
	and	eax, 15
84
	cmp	al, hotkey_tests_num
84
	cmp	al, hotkey_tests_num
85
	jae	.fail
85
	jae	.fail
86
	xchg	eax, edx
86
	xchg	eax, edx
87
	and	al, 3
87
	and	al, 3
88
	call	[hotkey_tests + edx*4]
88
	call	[hotkey_tests + edx*4]
89
	cmp	al, 1
89
	cmp	al, 1
90
	pop	eax
90
	pop	eax
91
	ret
91
	ret
92
.fail:
92
.fail:
93
	stc
93
	stc
94
	pop	eax
94
	pop	eax
95
	ret
95
	ret
96
 
96
 
97
align 4
97
align 4
98
irq1:
98
irq1:
99
;       save_ring3_context
99
;       save_ring3_context
100
;       mov   ax, os_data
100
;       mov   ax, os_data
101
;       mov   ds, ax
101
;       mov   ds, ax
102
;       mov   es, ax
102
;       mov   es, ax
103
 
103
 
104
       movzx eax,word[TASK_COUNT] ; top window process
104
       movzx eax,word[TASK_COUNT] ; top window process
105
       movzx eax,word[WIN_POS+eax*2]
105
       movzx eax,word[WIN_POS+eax*2]
106
       shl   eax,8
106
       shl   eax,8
107
       mov   al,[SLOT_BASE+eax+APPDATA.keyboard_mode]
107
       mov   al,[SLOT_BASE+eax+APPDATA.keyboard_mode]
108
       mov   [keyboard_mode],al
108
       mov   [keyboard_mode],al
109
 
109
 
110
       in    al,0x60
110
       in    al,0x60
111
       mov   [keyboard_data],al
111
       mov   [keyboard_data],al
112
 
112
 
113
; ch = scancode
113
; ch = scancode
114
; cl = ext_code
114
; cl = ext_code
115
; bh = 0 - normal key
115
; bh = 0 - normal key
116
; bh = 1 - modifier (Shift/Ctrl/Alt)
116
; bh = 1 - modifier (Shift/Ctrl/Alt)
117
; bh = 2 - extended code
117
; bh = 2 - extended code
118
 
118
 
119
       mov   ch,al
119
       mov   ch,al
120
       cmp   al,0xE0
120
       cmp   al,0xE0
121
       je    @f
121
       je    @f
122
       cmp   al,0xE1
122
       cmp   al,0xE1
123
       jne   .normal_code
123
       jne   .normal_code
124
   @@:
124
   @@:
125
	mov	bh, 2
125
	mov	bh, 2
126
	mov	[ext_code], al
126
	mov	[ext_code], al
127
	jmp	.writekey
127
	jmp	.writekey
128
   .normal_code:
128
   .normal_code:
129
	mov	cl, 0
129
	mov	cl, 0
130
	xchg	cl, [ext_code]
130
	xchg	cl, [ext_code]
131
       and   al,0x7F
131
       and   al,0x7F
132
	mov	bh, 1
132
	mov	bh, 1
133
   @@: cmp   al,0x2A
133
   @@: cmp   al,0x2A
134
       jne   @f
134
       jne   @f
135
       cmp   cl,0xE0
135
       cmp   cl,0xE0
136
       je    .writekey
136
       je    .writekey
137
       mov   eax,VKEY_LSHIFT
137
       mov   eax,VKEY_LSHIFT
138
       jmp   .modifier
138
       jmp   .modifier
139
   @@: cmp   al,0x36
139
   @@: cmp   al,0x36
140
       jne   @f
140
       jne   @f
141
       cmp   cl,0xE0
141
       cmp   cl,0xE0
142
       je    .writekey
142
       je    .writekey
143
       mov   eax,VKEY_RSHIFT
143
       mov   eax,VKEY_RSHIFT
144
       jmp   .modifier
144
       jmp   .modifier
145
   @@: cmp   al,0x38
145
   @@: cmp   al,0x38
146
       jne   @f
146
       jne   @f
147
	mov	eax, VKEY_LALT
147
	mov	eax, VKEY_LALT
148
	test	cl, cl
148
	test	cl, cl
149
	jz	.modifier
149
	jz	.modifier
150
	mov	al, VKEY_RALT
150
	mov	al, VKEY_RALT
151
	jmp	.modifier
151
	jmp	.modifier
152
   @@: cmp   al,0x1D
152
   @@: cmp   al,0x1D
153
       jne   @f
153
       jne   @f
154
	mov	eax, VKEY_LCONTROL
154
	mov	eax, VKEY_LCONTROL
155
	test	cl, cl
155
	test	cl, cl
156
	jz	.modifier
156
	jz	.modifier
157
	mov	al, VKEY_RCONTROL
157
	mov	al, VKEY_RCONTROL
158
	cmp	cl, 0xE0
158
	cmp	cl, 0xE0
159
	jz	.modifier
159
	jz	.modifier
160
	mov	[ext_code], cl
160
	mov	[ext_code], cl
161
	jmp	.writekey
161
	jmp	.writekey
162
   @@: cmp   al,0x3A
162
   @@: cmp   al,0x3A
163
       jne   @f
163
       jne   @f
164
       mov   bl,4
164
       mov   bl,4
165
       mov   eax,VKEY_CAPSLOCK
165
       mov   eax,VKEY_CAPSLOCK
166
       jmp   .no_key.xor
166
       jmp   .no_key.xor
167
   @@: cmp   al,0x45
167
   @@: cmp   al,0x45
168
       jne   @f
168
       jne   @f
169
	test	cl, cl
169
	test	cl, cl
170
	jnz	.writekey
170
	jnz	.writekey
171
       mov   bl,2
171
       mov   bl,2
172
       mov   eax,VKEY_NUMLOCK
172
       mov   eax,VKEY_NUMLOCK
173
       jmp   .no_key.xor
173
       jmp   .no_key.xor
174
   @@: cmp   al,0x46
174
   @@: cmp   al,0x46
175
       jne   @f
175
       jne   @f
176
       mov   bl,1
176
       mov   bl,1
177
       mov   eax,VKEY_SCRLOCK
177
       mov   eax,VKEY_SCRLOCK
178
       jmp   .no_key.xor
178
       jmp   .no_key.xor
179
   @@:
179
   @@:
180
       test  ch,ch
180
       test  ch,ch
181
       js    .writekey
181
       js    .writekey
182
       movzx eax,ch		 ; plain key
182
       movzx eax,ch		 ; plain key
183
       mov   bl,[keymap+eax]
183
       mov   bl,[keymap+eax]
184
       mov   edx,[kb_state]
184
       mov   edx,[kb_state]
185
       test  dl,VKEY_CONTROL	 ; ctrl alt del
185
       test  dl,VKEY_CONTROL	 ; ctrl alt del
186
       jz    .noctrlaltdel
186
       jz    .noctrlaltdel
187
       test  dl,VKEY_ALT
187
       test  dl,VKEY_ALT
188
       jz    .noctrlaltdel
188
       jz    .noctrlaltdel
189
       cmp   ch,53h
189
       cmp   ch,53h
190
       jne   .noctrlaltdel
190
       jne   .noctrlaltdel
191
       mov   [ctrl_alt_del],1
191
       mov   [ctrl_alt_del],1
192
   .noctrlaltdel:
192
   .noctrlaltdel:
193
       test  dl,VKEY_CONTROL	 ; ctrl on ?
193
       test  dl,VKEY_CONTROL	 ; ctrl on ?
194
       jz    @f
194
       jz    @f
195
       sub   bl,0x60
195
       sub   bl,0x60
196
   @@: test  dl,VKEY_SHIFT	 ; shift on ?
196
   @@: test  dl,VKEY_SHIFT	 ; shift on ?
197
       jz    @f
197
       jz    @f
198
       mov   bl,[keymap_shift+eax]
198
       mov   bl,[keymap_shift+eax]
199
   @@: test  dl,VKEY_ALT	 ; alt on ?
199
   @@: test  dl,VKEY_ALT	 ; alt on ?
200
       jz    @f
200
       jz    @f
201
       mov   bl,[keymap_alt+eax]
201
       mov   bl,[keymap_alt+eax]
202
   @@:
202
   @@:
203
	mov	bh, 0
203
	mov	bh, 0
204
	jmp	.writekey
204
	jmp	.writekey
205
.modifier:
205
.modifier:
206
	test	ch, ch
206
	test	ch, ch
207
	js	.modifier.up
207
	js	.modifier.up
208
	or	[kb_state], eax
208
	or	[kb_state], eax
209
	jmp	.writekey
209
	jmp	.writekey
210
.modifier.up:
210
.modifier.up:
211
	not	eax
211
	not	eax
212
	and	[kb_state], eax
212
	and	[kb_state], eax
213
	jmp	.writekey
213
	jmp	.writekey
214
.no_key.xor:
214
.no_key.xor:
215
	mov	bh, 0
215
	mov	bh, 0
216
	test	ch, ch
216
	test	ch, ch
217
	js	.writekey
217
	js	.writekey
218
	xor	[kb_state], eax
218
	xor	[kb_state], eax
219
	xor	[kb_lights], bl
219
	xor	[kb_lights], bl
220
	call	set_lights
220
	call	set_lights
221
 
221
 
222
.writekey:
222
.writekey:
223
; test for system hotkeys
223
; test for system hotkeys
224
	movzx	eax, ch
224
	movzx	eax, ch
225
	cmp	bh, 1
225
	cmp	bh, 1
226
	ja	.nohotkey
226
	ja	.nohotkey
227
	jb	@f
227
	jb	@f
228
	xor	eax, eax
228
	xor	eax, eax
229
@@:
229
@@:
230
	mov	eax, [hotkey_scancodes + eax*4]
230
	mov	eax, [hotkey_scancodes + eax*4]
231
.hotkey_loop:
231
.hotkey_loop:
232
	test	eax, eax
232
	test	eax, eax
233
	jz	.nohotkey
233
	jz	.nohotkey
234
	mov	cl, 0
234
	mov	cl, 0
235
	call	hotkey_do_test
235
	call	hotkey_do_test
236
	jc	.hotkey_cont
236
	jc	.hotkey_cont
237
	mov	cl, 2
237
	mov	cl, 2
238
	call	hotkey_do_test
238
	call	hotkey_do_test
239
	jc	.hotkey_cont
239
	jc	.hotkey_cont
240
	mov	cl, 4
240
	mov	cl, 4
241
	call	hotkey_do_test
241
	call	hotkey_do_test
242
	jnc	.hotkey_found
242
	jnc	.hotkey_found
243
.hotkey_cont:
243
.hotkey_cont:
244
	mov	eax, [eax]
244
	mov	eax, [eax]
245
	jmp	.hotkey_loop
245
	jmp	.hotkey_loop
246
.hotkey_found:
246
.hotkey_found:
247
	mov	eax, [eax+8]
247
	mov	eax, [eax+8]
248
; put key in buffer for process in slot eax
248
; put key in buffer for process in slot eax
249
	mov	edi, hotkey_buffer
249
	mov	edi, hotkey_buffer
250
@@:
250
@@:
251
	cmp	dword [edi], 0
251
	cmp	dword [edi], 0
252
	jz	.found_free
252
	jz	.found_free
253
	add	edi, 8
253
	add	edi, 8
254
	cmp	edi, hotkey_buffer+120*8
254
	cmp	edi, hotkey_buffer+120*8
255
	jb	@b
255
	jb	@b
256
; no free space - replace first entry
256
; no free space - replace first entry
257
	mov	edi, hotkey_buffer
257
	mov	edi, hotkey_buffer
258
.found_free:
258
.found_free:
259
	mov	[edi], eax
259
	mov	[edi], eax
260
	movzx	eax, ch
260
	movzx	eax, ch
261
	cmp	bh, 1
261
	cmp	bh, 1
262
	jnz	@f
262
	jnz	@f
263
	xor	eax, eax
263
	xor	eax, eax
264
@@:
264
@@:
265
	mov	[edi+4], ax
265
	mov	[edi+4], ax
266
	mov	eax, [kb_state]
266
	mov	eax, [kb_state]
267
	mov	[edi+6], ax
267
	mov	[edi+6], ax
268
	jmp	.exit.irq1
268
	jmp	.exit.irq1
269
.nohotkey:
269
.nohotkey:
270
       cmp   [keyboard_mode],0 ; return from keymap
270
       cmp   [keyboard_mode],0 ; return from keymap
271
       jne   .scancode
271
       jne   .scancode
272
	test	bh, bh
272
	test	bh, bh
273
	jnz	.exit.irq1
273
	jnz	.exit.irq1
274
	test	bl, bl
274
	test	bl, bl
275
	jz	.exit.irq1
275
	jz	.exit.irq1
276
 
276
 
277
;.........................Part1 Start.......Code by Rus, optimize by Ghost...................................
277
;.........................Part1 Start.......Code by Rus, optimize by Ghost...................................
278
	test  [kb_state], VKEY_NUMLOCK
278
	test  [kb_state], VKEY_NUMLOCK
279
	jz     .dowrite
279
	jz     .dowrite
280
 
280
 
281
	cmp	ch, 55
281
	cmp	ch, 55
282
	jnz	@f
282
	jnz	@f
283
	mov	bl, 0x2A	;*
283
	mov	bl, 0x2A	;*
284
	jmp	.dowrite
284
	jmp	.dowrite
285
      @@:
285
      @@:
286
	cmp	ch, 71
286
	cmp	ch, 71
287
	jb	.dowrite
287
	jb	.dowrite
288
	cmp	ch, 83
288
	cmp	ch, 83
289
	ja	.dowrite
289
	ja	.dowrite
290
	push	eax
290
	;push    eax
291
	movzx	eax, ch
291
	movzx	eax, ch
292
	mov	bl, [numlock_map + eax - 71]
292
	mov	bl, [numlock_map + eax - 71]
293
	pop	eax
293
	;pop     eax
294
 
294
 
295
;.........................Part1 End.................................................
295
;.........................Part1 End.................................................
296
 
296
 
297
	jmp	.dowrite
297
	jmp	.dowrite
298
.scancode:
298
.scancode:
299
	mov	bl, ch
299
	mov	bl, ch
300
.dowrite:
300
.dowrite:
301
       movzx eax,byte[KEY_COUNT]
301
       movzx eax,byte[KEY_COUNT]
302
       cmp   al,120
302
       cmp   al,120
303
       jae   .exit.irq1
303
       jae   .exit.irq1
304
       inc   eax
304
       inc   eax
305
       mov   [KEY_COUNT],al
305
       mov   [KEY_COUNT],al
306
       mov   [KEY_COUNT+eax],bl
306
       mov   [KEY_COUNT+eax],bl
307
 
307
 
308
   .exit.irq1:
308
   .exit.irq1:
309
       mov   [check_idle_semaphore],5
309
       mov   [check_idle_semaphore],5
310
 
310
 
311
;       mov   al,0x20                  ; ready for next irq
311
;       mov   al,0x20                  ; ready for next irq
312
;       out   0x20,al
312
;       out   0x20,al
313
 
313
 
314
;       restore_ring3_context
314
;       restore_ring3_context
315
;       iret
315
;       iret
316
	ret
316
	ret
317
 
317
 
318
set_lights:
318
set_lights:
319
       mov   al,0xED
319
       mov   al,0xED
320
       call  kb_write
320
       call  kb_write
321
       mov   al,[kb_lights]
321
       mov   al,[kb_lights]
322
       call  kb_write
322
       call  kb_write
323
       ret
323
       ret
324
 
324
 
325
;// mike.dld ]
325
;// mike.dld ]
326
;..........................Part2 Start.......Code by Rus.......................................
326
;..........................Part2 Start.......Code by Rus.......................................
327
numlock_map:
327
numlock_map:
328
    db	 0x37	;Num 7
328
    db	 0x37	;Num 7
329
    db	 0x38	;Num 8
329
    db	 0x38	;Num 8
330
    db	 0x39	;Num 9
330
    db	 0x39	;Num 9
331
    db	 0x2D	;Num -
331
    db	 0x2D	;Num -
332
    db	 0x34	;Num 4
332
    db	 0x34	;Num 4
333
    db	 0x35	;Num 5
333
    db	 0x35	;Num 5
334
    db	 0x36	;Num 6
334
    db	 0x36	;Num 6
335
    db	 0x2B	;Num +
335
    db	 0x2B	;Num +
336
    db	 0x31	;Num 1
336
    db	 0x31	;Num 1
337
    db	 0x32	;Num 2
337
    db	 0x32	;Num 2
338
    db	 0x33	;Num 3
338
    db	 0x33	;Num 3
339
    db	 0x30	;Num 0
339
    db	 0x30	;Num 0
340
    db	 0x2E	;Num .
340
    db	 0x2E	;Num .
341
;..........................Part2 End................................................
341
;..........................Part2 End................................................