Rev 109 | Rev 485 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 109 | Rev 317 | ||
---|---|---|---|
1 | ; |
1 | ; |
2 | ; KEYBOARD SCANCODE EXAMPLE |
2 | ; KEYBOARD SCANCODE EXAMPLE |
3 | ; |
3 | ; |
4 | ; Compile with FASM for Menuet |
4 | ; Compile with FASM for Menuet |
5 | ; |
5 | ; |
6 | 6 | ||
7 | include "lang.inc" |
7 | include "lang.inc" |
8 | include "macros.inc" |
8 | include "macros.inc" |
9 | 9 | ||
10 | use32 |
10 | use32 |
11 | org 0x0 |
11 | org 0x0 |
12 | 12 | ||
13 | db 'MENUET01' ; 8 byte id |
13 | db 'MENUET01' ; 8 byte id |
14 | dd 0x01 ; header version |
14 | dd 0x01 ; header version |
15 | dd START ; start of code |
15 | dd START ; start of code |
16 | dd I_END ; size of image |
16 | dd I_END ; size of image |
17 | dd 0x1000 ; memory for app |
17 | dd 0x1000 ; memory for app |
18 | dd 0x1000 ; esp |
18 | dd 0x1000 ; esp |
19 | dd 0x0 , 0x0 ; I_Param , I_Icon |
19 | dd 0x0 , 0x0 ; I_Param , I_Icon |
20 | 20 | ||
21 | START: ; start of execution |
21 | START: ; start of execution |
22 | 22 | ||
23 | mov eax,66 ; keyboard mode definitions |
23 | mov eax,66 ; keyboard mode definitions |
24 | mov ebx,1 ; set |
24 | mov ebx,1 ; set |
25 | mov ecx,1 ; return scancodes |
25 | mov ecx,1 ; return scancodes |
26 | int 0x40 |
26 | int 0x40 |
27 | 27 | ||
28 | mov eax,26 ; get setup for keyboard |
28 | mov eax,26 ; get setup for keyboard |
29 | mov ebx,2 |
29 | mov ebx,2 |
30 | mov ecx,1 ; base keymap |
30 | mov ecx,1 ; base keymap |
31 | mov edx,keymap |
31 | mov edx,keymap |
32 | int 0x40 |
32 | int 0x40 |
33 | 33 | red: |
|
34 | call draw_window |
34 | call draw_window |
35 | 35 | ||
36 | still: |
36 | still: |
37 | 37 | ||
38 | mov eax,10 ; wait here for event |
38 | mov eax,10 ; wait here for event |
39 | int 0x40 |
39 | int 0x40 |
40 | 40 | ||
41 | cmp eax,1 ; redraw request ? |
41 | cmp eax,1 ; redraw request ? |
42 | je red |
42 | je red |
43 | cmp eax,2 ; key in buffer ? |
43 | cmp eax,2 ; key in buffer ? |
44 | je key |
44 | je key |
45 | cmp eax,3 ; button in buffer ? |
45 | cmp eax,3 ; button in buffer ? |
46 | je button |
46 | je button |
47 | 47 | ||
48 | jmp still |
48 | jmp still |
49 | 49 | ||
50 | - | ||
51 | red: ; redraw |
- | |
52 | call draw_window |
- | |
53 | jmp still |
- | |
54 | - | ||
55 | 50 | ||
56 | key: ; key |
51 | key: ; key |
57 | mov eax,2 ; just read it and ignore |
52 | mov eax,2 ; just read it and ignore |
58 | int 0x40 |
53 | int 0x40 |
59 | 54 | ||
60 | mov esi,scan_codes+1 |
55 | mov esi,scan_codes+1 |
61 | mov edi,scan_codes+0 |
56 | mov edi,scan_codes+0 |
62 | mov ecx,15 |
57 | mov ecx,15 |
63 | cld |
58 | cld |
64 | rep movsb |
59 | rep movsb |
65 | 60 | ||
66 | mov esi,key_codes+12 |
61 | mov esi,key_codes+12 |
67 | mov edi,key_codes+0 |
62 | mov edi,key_codes+0 |
68 | mov ecx,15*12 |
63 | mov ecx,15*12 |
69 | cld |
64 | cld |
70 | rep movsb |
65 | rep movsb |
71 | 66 | ||
72 | shr eax,8 ; scancode |
67 | shr eax,8 ; scancode |
73 | and eax,0xff |
68 | and eax,0xff |
74 | mov [scan_codes+15],al |
69 | mov [scan_codes+15],al |
75 | 70 | ||
76 | mov [key_codes+15*12+8],dword 'Down' |
71 | mov [key_codes+15*12+8],dword 'Down' |
77 | cmp eax,128 |
72 | cmp eax,128 |
78 | jb no_up |
73 | jb no_up |
79 | mov [key_codes+15*12+8],dword 'Up ' |
74 | mov [key_codes+15*12+8],dword 'Up ' |
80 | no_up: |
75 | no_up: |
81 | 76 | ||
82 | mov ebx,eax |
77 | mov ebx,eax |
83 | and ebx,0x7f |
78 | and ebx,0x7f |
84 | 79 | ||
85 | movzx edx,byte [keymap+ebx] ; key from keymap |
80 | movzx edx,byte [keymap+ebx] ; key from keymap |
86 | mov [key_codes+15*12+0],edx |
81 | mov [key_codes+15*12+0],edx |
87 | mov [key_codes+15*12+4],dword ' ' |
82 | mov [key_codes+15*12+4],dword ' ' |
88 | 83 | ||
89 | movzx edx,byte [ext] |
84 | movzx edx,byte [ext] |
90 | shl edx,8 |
85 | shl edx,8 |
91 | add ebx,edx |
86 | add ebx,edx |
92 | 87 | ||
93 | mov esi,ext0-10 |
88 | mov esi,ext0-10 |
94 | new_ext0: |
89 | new_ext0: |
95 | add esi,10 |
90 | add esi,10 |
96 | cmp esi,ext0end |
91 | cmp esi,ext0end |
97 | jg exit_ext0 |
92 | jg exit_ext0 |
98 | movzx edx,word [esi] |
93 | movzx edx,word [esi] |
99 | cmp edx,ebx |
94 | cmp edx,ebx |
100 | jne new_ext0 |
95 | jne new_ext0 |
101 | mov edx,[esi+2] |
96 | mov edx,[esi+2] |
102 | mov [key_codes+15*12+0],edx |
97 | mov [key_codes+15*12+0],edx |
103 | mov edx,[esi+6] |
98 | mov edx,[esi+6] |
104 | mov [key_codes+15*12+4],edx |
99 | mov [key_codes+15*12+4],edx |
105 | exit_ext0: |
100 | exit_ext0: |
106 | no_ext_off: |
101 | no_ext_off: |
107 | 102 | ||
108 | cmp [ext2],0 |
103 | cmp [ext2],0 |
109 | je noext2dec |
104 | je noext2dec |
110 | dec [ext2] |
105 | dec [ext2] |
111 | jne noext2dec |
106 | jne noext2dec |
112 | mov [key_codes+15*12+0],dword '----' |
107 | mov [key_codes+15*12+0],dword '----' |
113 | mov [key_codes+15*12+4],dword '----' |
108 | mov [key_codes+15*12+4],dword '----' |
114 | noext2dec: |
109 | noext2dec: |
115 | 110 | ||
116 | mov [ext],0 |
111 | mov [ext],0 |
117 | 112 | ||
118 | cmp eax,224 |
113 | cmp eax,224 |
119 | jne no_ext |
114 | jne no_ext |
120 | mov [key_codes+15*12+0],dword ' ' |
115 | mov [key_codes+15*12+0],dword ' ' |
121 | mov [key_codes+15*12+4],dword ' ' |
116 | mov [key_codes+15*12+4],dword ' ' |
122 | mov [key_codes+15*12+8],dword 'Ext ' |
117 | mov [key_codes+15*12+8],dword 'Ext ' |
123 | mov [ext],1 |
118 | mov [ext],1 |
124 | no_ext: |
119 | no_ext: |
125 | 120 | ||
126 | cmp eax,225 |
121 | cmp eax,225 |
127 | jne no_ext2 |
122 | jne no_ext2 |
128 | mov [key_codes+15*12+0],dword ' ' |
123 | mov [key_codes+15*12+0],dword ' ' |
129 | mov [key_codes+15*12+4],dword ' ' |
124 | mov [key_codes+15*12+4],dword ' ' |
130 | mov [key_codes+15*12+8],dword 'Ext2' |
125 | mov [key_codes+15*12+8],dword 'Ext2' |
131 | mov [ext],2 |
126 | mov [ext],2 |
132 | mov [ext2],2 |
127 | mov [ext2],2 |
133 | no_ext2: |
128 | no_ext2: |
134 | 129 | ||
135 | 130 | ||
136 | call draw_codes |
131 | call draw_codes |
137 | jmp still |
132 | jmp still |
138 | 133 | ||
139 | 134 | ||
140 | 135 | ||
141 | button: ; button |
136 | button: ; button |
142 | or eax, -1 ; close this program |
137 | or eax, -1 ; close this program |
143 | int 0x40 |
138 | int 0x40 |
144 | 139 | ||
145 | 140 | ||
146 | 141 | ||
147 | 142 | ||
148 | ; ********************************************* |
143 | ; ********************************************* |
149 | ; ******* WINDOW DEFINITIONS AND DRAW ******** |
144 | ; ******* WINDOW DEFINITIONS AND DRAW ******** |
150 | ; ********************************************* |
145 | ; ********************************************* |
151 | 146 | ||
152 | 147 | ||
153 | draw_window: |
148 | draw_window: |
154 | 149 | ||
155 | mov eax, 48 ; GET SYSTEM COLORS |
150 | mov eax, 48 ; GET SYSTEM COLORS |
156 | mov ebx, 3 |
151 | mov ebx, 3 |
157 | mov ecx, sc |
152 | mov ecx, sc |
158 | mov edx, sizeof.system_colors |
153 | mov edx, sizeof.system_colors |
159 | int 0x40 |
154 | int 0x40 |
160 | 155 | ||
161 | mov eax,12 ; function 12:tell os about windowdraw |
156 | mov eax,12 ; function 12:tell os about windowdraw |
162 | mov ebx,1 ; 1, start of draw |
157 | mov ebx,1 ; 1, start of draw |
163 | int 0x40 |
158 | int 0x40 |
164 | 159 | ||
165 | ; DRAW WINDOW |
160 | ; DRAW WINDOW |
166 | mov eax, 0 ; function 0 : define and draw window |
161 | mov eax, 0 ; function 0 : define and draw window |
167 | mov ebx, 100*65536+200 ; [x start] *65536 + [x size] |
162 | mov ebx, 100*65536+200 ; [x start] *65536 + [x size] |
168 | mov ecx, 100*65536+275 ; [y start] *65536 + [y size] |
163 | mov ecx, 100*65536+275 ; [y start] *65536 + [y size] |
169 | mov edx, [sc.work] ; color of work area RRGGBB,8->color gl |
164 | mov edx, [sc.work] ; color of work area RRGGBB,8->color gl |
170 | or edx, 0x03000000 |
165 | or edx, 0x33000000 |
171 | mov esi, [sc.grab] ; color of grab bar RRGGBB,8->color gl |
- | |
172 | or esi, 0x80000000 |
- | |
173 | mov edi, [sc.frame] ; color of frames RRGGBB |
- | |
174 | int 0x40 |
- | |
175 | - | ||
176 | ; WINDOW LABEL |
166 | mov edi, header ; WINDOW LABEL |
177 | mov eax, 4 ; function 4 : write text to window |
- | |
178 | mov ebx, 8*65536+8 ; [x start] *65536 + [y start] |
- | |
179 | mov ecx, [sc.grab_text] ; font 1 & color ( 0xF0RRGGBB ) |
- | |
180 | or ecx, 0x10000000 |
- | |
181 | mov edx, header ; pointer to text beginning |
- | |
182 | mov esi, header.len ; text length |
- | |
183 | int 0x40 |
167 | int 0x40 |
184 | 168 | ||
185 | mov eax, 4 |
169 | mov eax, 4 |
186 | mov ebx, 20*65536+35 |
170 | mov ebx, 15*65536+10 |
187 | mov ecx, 0 |
171 | xor ecx, ecx |
188 | mov edx, text |
172 | mov edx, text |
189 | mov esi, text.len |
173 | mov esi, text.len |
190 | int 0x40 |
174 | int 0x40 |
191 | 175 | ||
192 | call draw_codes |
176 | call draw_codes |
193 | 177 | ||
194 | mov eax,12 ; function 12:tell os about windowdraw |
178 | mov eax,12 ; function 12:tell os about windowdraw |
195 | mov ebx,2 ; 2, end of draw |
179 | mov ebx,2 ; 2, end of draw |
196 | int 0x40 |
180 | int 0x40 |
197 | 181 | ||
198 | ret |
182 | ret |
199 | 183 | ||
200 | 184 | ||
201 | draw_codes: |
185 | draw_codes: |
202 | 186 | ||
203 | mov eax,47 |
187 | mov eax,47 |
204 | mov ebx,6*65536 |
188 | mov ebx,6*65536 |
205 | mov edx,20*65536+60 |
189 | mov edx,15*65536+35 |
206 | mov edi,0 |
190 | mov edi,0 |
207 | mov esi,0 |
191 | mov esi,0 |
208 | newscan: |
192 | newscan: |
209 | pusha |
193 | pusha |
210 | mov cx,dx |
194 | mov cx,dx |
211 | shl ecx,16 |
195 | shl ecx,16 |
212 | add ecx,10 |
196 | add ecx,10 |
213 | mov eax,13 ; filled rectangle |
197 | mov eax,13 ; filled rectangle |
214 | mov ebx,20*65536+160 |
198 | mov ebx,15*65536+160 |
215 | mov edx,[sc.work] |
199 | mov edx,[sc.work] |
216 | int 0x40 |
200 | int 0x40 |
217 | popa |
201 | popa |
218 | pusha |
202 | pusha |
219 | mov ebx,edx |
203 | mov ebx,edx |
220 | add ebx,70*65536 |
204 | add ebx,70*65536 |
221 | mov eax,4 ; text |
205 | mov eax,4 ; text |
222 | mov ecx,[sc.work_text] |
206 | mov ecx,[sc.work_text] |
223 | mov edx,key_codes |
207 | mov edx,key_codes |
224 | imul edi,12 |
208 | imul edi,12 |
225 | add edx,edi |
209 | add edx,edi |
226 | mov esi,12 |
210 | mov esi,12 |
227 | int 0x40 |
211 | int 0x40 |
228 | popa |
212 | popa |
229 | movzx ecx,byte [scan_codes+edi] |
213 | movzx ecx,byte [scan_codes+edi] |
230 | int 0x40 ; number |
214 | int 0x40 ; number |
231 | inc ecx |
215 | inc ecx |
232 | add edx,12 |
216 | add edx,12 |
233 | inc edi |
217 | inc edi |
234 | cmp edi,16 |
218 | cmp edi,16 |
235 | jne newscan |
219 | jne newscan |
236 | 220 | ||
237 | ret |
221 | ret |
238 | 222 | ||
239 | 223 | ||
240 | ; DATA AREA |
224 | ; DATA AREA |
241 | 225 | ||
242 | ext0: |
226 | ext0: |
243 | 227 | ||
244 | db 1,0,'Esc ' |
228 | db 1,0,'Esc ' |
245 | db 28,0,'Enter ' |
229 | db 28,0,'Enter ' |
246 | db 29,0,'L-Ctrl ' |
230 | db 29,0,'L-Ctrl ' |
247 | db 41,0,'1/2 ' |
231 | db 41,0,'1/2 ' |
248 | db 42,0,'L-Shift ' |
232 | db 42,0,'L-Shift ' |
249 | db 54,0,'R-Shift ' |
233 | db 54,0,'R-Shift ' |
250 | db 55,0,'Num * ' |
234 | db 55,0,'Num * ' |
251 | db 56,0,'Alt ' |
235 | db 56,0,'Alt ' |
252 | db 58,0,'CapsLck ' |
236 | db 58,0,'CapsLck ' |
253 | db 59,0,'F1 ' |
237 | db 59,0,'F1 ' |
254 | db 60,0,'F2 ' |
238 | db 60,0,'F2 ' |
255 | db 61,0,'F3 ' |
239 | db 61,0,'F3 ' |
256 | db 62,0,'F4 ' |
240 | db 62,0,'F4 ' |
257 | db 63,0,'F5 ' |
241 | db 63,0,'F5 ' |
258 | db 64,0,'F6 ' |
242 | db 64,0,'F6 ' |
259 | db 65,0,'F7 ' |
243 | db 65,0,'F7 ' |
260 | db 66,0,'F8 ' |
244 | db 66,0,'F8 ' |
261 | db 67,0,'F9 ' |
245 | db 67,0,'F9 ' |
262 | db 68,0,'F10 ' |
246 | db 68,0,'F10 ' |
263 | db 69,0,'NumLock ' |
247 | db 69,0,'NumLock ' |
264 | db 70,0,'SclLock ' |
248 | db 70,0,'SclLock ' |
265 | db 71,0,'Num 7 ' |
249 | db 71,0,'Num 7 ' |
266 | db 72,0,'Num 8 ' |
250 | db 72,0,'Num 8 ' |
267 | db 73,0,'Num 9 ' |
251 | db 73,0,'Num 9 ' |
268 | db 74,0,'Num - ' |
252 | db 74,0,'Num - ' |
269 | db 75,0,'Num 4 ' |
253 | db 75,0,'Num 4 ' |
270 | db 76,0,'Num 5 ' |
254 | db 76,0,'Num 5 ' |
271 | db 77,0,'Num 6 ' |
255 | db 77,0,'Num 6 ' |
272 | db 78,0,'Num + ' |
256 | db 78,0,'Num + ' |
273 | db 79,0,'Num 1 ' |
257 | db 79,0,'Num 1 ' |
274 | db 80,0,'Num 2 ' |
258 | db 80,0,'Num 2 ' |
275 | db 81,0,'Num 3 ' |
259 | db 81,0,'Num 3 ' |
276 | db 82,0,'Num 0 ' |
260 | db 82,0,'Num 0 ' |
277 | db 83,0,'Num , ' |
261 | db 83,0,'Num , ' |
278 | db 87,0,'F11 ' |
262 | db 87,0,'F11 ' |
279 | db 88,0,'F12 ' |
263 | db 88,0,'F12 ' |
280 | 264 | ||
281 | db 28,1,'Num Ent ' |
265 | db 28,1,'Num Ent ' |
282 | db 29,1,'R-Ctrl ' |
266 | db 29,1,'R-Ctrl ' |
283 | db 53,1,'Num / ' |
267 | db 53,1,'Num / ' |
284 | db 55,1,'PrScr ' |
268 | db 55,1,'PrScr ' |
285 | db 56,1,'Alt Gr ' |
269 | db 56,1,'Alt Gr ' |
286 | db 71,1,'Home ' |
270 | db 71,1,'Home ' |
287 | db 72,1,'Up-A ' |
271 | db 72,1,'Up-A ' |
288 | db 73,1,'PgUp ' |
272 | db 73,1,'PgUp ' |
289 | db 75,1,'Left-A ' |
273 | db 75,1,'Left-A ' |
290 | db 77,1,'Right-A ' |
274 | db 77,1,'Right-A ' |
291 | db 79,1,'End ' |
275 | db 79,1,'End ' |
292 | db 80,1,'Down-A ' |
276 | db 80,1,'Down-A ' |
293 | db 81,1,'PgDown ' |
277 | db 81,1,'PgDown ' |
294 | db 82,1,'Insert ' |
278 | db 82,1,'Insert ' |
295 | db 83,1,'Delete ' |
279 | db 83,1,'Delete ' |
296 | db 91,1,'Menu-1 ' |
280 | db 91,1,'Menu-1 ' |
297 | db 92,1,'Menu-2 ' |
281 | db 92,1,'Menu-2 ' |
298 | db 93,1,'Menu-3 ' |
282 | db 93,1,'Menu-3 ' |
299 | 283 | ||
300 | db 29,2,'Break ' |
284 | db 29,2,'Break ' |
301 | 285 | ||
302 | ext0end: |
286 | ext0end: |
303 | 287 | ||
304 | 288 | ||
305 | if lang eq ru |
289 | if lang eq ru |
306 | text: |
290 | text: |
307 | db ' ' |
291 | db ' ' |
308 | .len = $ - text |
292 | .len = $ - text |
309 | - | ||
310 | header: |
293 | |
311 | db ' ' |
- | |
312 | .len = $ - header |
294 | header db ' ',0 |
313 | else |
295 | else |
314 | text: |
296 | text: |
315 | db 'READING RAW SCANCODE DATA' |
297 | db 'READING RAW SCANCODE DATA' |
316 | .len = $ - text |
298 | .len = $ - text |
317 | - | ||
318 | header: |
299 | |
319 | db 'KEYBOARD SCANCODES' |
- | |
320 | .len = $ - header |
300 | header db 'KEYBOARD SCANCODES',0 |
321 | end if |
301 | end if |
322 | 302 | ||
323 | ext db 0x0 |
303 | ext db 0x0 |
324 | ext2 db 0x0 |
304 | ext2 db 0x0 |
325 | 305 | ||
326 | pos dd 0x0 |
306 | pos dd 0x0 |
327 | 307 | ||
328 | I_END: |
308 | I_END: |
329 | 309 | ||
330 | sc system_colors |
310 | sc system_colors |
331 | 311 | ||
332 | scan_codes: times 16 db ? |
312 | scan_codes: times 16 db ? |
333 | 313 | ||
334 | key_codes: times 16 dd ?,?,? |
314 | key_codes: times 16 dd ?,?,? |
335 | 315 | ||
336 | keymap: |
316 | keymap: |