Subversion Repositories Kolibri OS

Rev

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

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