Subversion Repositories Kolibri OS

Rev

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

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