Subversion Repositories Kolibri OS

Rev

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

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