Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
31 | halyavin | 1 | ; |
2 | ; Example for Inter Process Communication |
||
3 | ; |
||
4 | ; Compile with FASM for Menuet |
||
5 | ; |
||
6 | include 'lang.inc' |
||
7 | include 'macros.inc' |
||
8 | |||
9 | use32 |
||
10 | org 0x0 |
||
11 | |||
12 | db 'MENUET01' ; 8 byte id |
||
13 | dd 0x01 ; header version |
||
14 | dd START ; start of code |
||
15 | dd I_END ; size of image |
||
16 | dd 0x60000 ; memory for app |
||
17 | dd 0x60000 ; esp |
||
18 | dd 0x0 , 0x0 ; I_Param , I_Icon |
||
19 | |||
20 | START: ; start of execution |
||
21 | |||
22 | |||
23 | mov eax,60 ; IPC |
||
24 | mov ebx,1 ; define receive area |
||
25 | mov ecx,received_messages ; pointer to start |
||
26 | mov edx,1000 ; size of area |
||
27 | int 0x40 |
||
28 | |||
29 | mov eax,40 ; WANTED EVENTS |
||
30 | mov ebx,01000111b ; IPC 7 + defaults |
||
31 | int 0x40 |
||
32 | |||
33 | mov [received_messages+8],dword 0*256+0 |
||
34 | mov [received_messages+12],dword 0 |
||
35 | |||
36 | call draw_window ; at first, draw the window |
||
37 | |||
38 | still: |
||
39 | |||
40 | mov eax,23 ; wait here for event |
||
41 | mov ebx,50 |
||
42 | int 0x40 |
||
43 | |||
44 | cmp eax,1 ; redraw request ? |
||
45 | je red |
||
46 | cmp eax,2 ; key in buffer ? |
||
47 | je key |
||
48 | cmp eax,3 ; button in buffer ? |
||
49 | je button |
||
50 | |||
51 | cmp eax,7 ; IPC ? |
||
52 | jne no_ipc |
||
53 | call display_ipc_messages |
||
54 | jmp still |
||
55 | no_ipc: |
||
56 | |||
57 | jmp still |
||
58 | |||
59 | red: ; redraw |
||
60 | call draw_window |
||
61 | jmp still |
||
62 | |||
63 | key: ; key |
||
64 | mov eax,2 ; just read it and ignore |
||
65 | int 0x40 |
||
66 | jmp still |
||
67 | |||
68 | button: ; button |
||
69 | mov eax,17 ; get id |
||
70 | int 0x40 |
||
71 | |||
72 | cmp ah,1 ; button id=1 ? |
||
73 | jne noclose |
||
74 | mov eax,-1 ; close this program |
||
75 | int 0x40 |
||
76 | noclose: |
||
77 | |||
78 | cmp ah,2 |
||
79 | jne no_read |
||
80 | call read_string |
||
81 | |||
82 | movzx eax,byte [message] |
||
83 | sub eax,48 |
||
84 | imul eax,10 |
||
85 | movzx ebx,byte [message+1] |
||
86 | add eax,ebx |
||
87 | sub eax,48 |
||
88 | imul eax,10 |
||
89 | movzx ebx,byte [message+2] |
||
90 | add eax,ebx |
||
91 | sub eax,48 |
||
92 | imul eax,10 |
||
93 | movzx ebx,byte [message+3] |
||
94 | add eax,ebx |
||
95 | sub eax,48 |
||
96 | |||
97 | mov [PID],eax |
||
98 | |||
99 | mov eax,60 ; IPC |
||
100 | mov ebx,2 ; send message |
||
101 | mov ecx,[PID] |
||
102 | mov edx,message+4 |
||
103 | mov esi,20;[message_size] |
||
104 | int 0x40 |
||
105 | |||
106 | jmp still |
||
107 | no_read: |
||
108 | |||
109 | |||
110 | cmp ah,3 |
||
111 | jne no_messages_pop ; pop the first out |
||
112 | call ipc_message_pop |
||
113 | jmp still |
||
114 | no_messages_pop: |
||
115 | |||
116 | jmp still |
||
117 | |||
118 | |||
119 | ipc_message_pop: |
||
120 | |||
121 | pusha |
||
122 | |||
123 | cmp [received_messages+4],dword 8 |
||
124 | je already_empty |
||
125 | |||
126 | mov [received_messages],byte 1 ; lock the area |
||
127 | |||
128 | push dword [received_messages+4] |
||
129 | |||
130 | mov ecx,[received_messages+12] |
||
131 | |||
132 | sub [received_messages+4],ecx |
||
133 | sub [received_messages+4],dword 8 |
||
134 | |||
135 | mov edi,received_messages+8 |
||
136 | mov esi,edi |
||
137 | add esi,ecx |
||
138 | add esi,8 |
||
139 | |||
140 | pop ecx |
||
141 | |||
142 | cld |
||
143 | rep movsb |
||
144 | |||
145 | call display_ipc_messages |
||
146 | |||
147 | mov [received_messages],byte 0 ; free the area |
||
148 | |||
149 | already_empty: |
||
150 | |||
151 | popa |
||
152 | ret |
||
153 | |||
154 | |||
155 | |||
156 | display_ipc_messages: |
||
157 | |||
158 | pusha |
||
159 | |||
160 | mov eax,13 |
||
161 | mov ebx,25*65536+245 |
||
162 | mov ecx,105*65536+90 |
||
163 | mov edx,0xdddddd |
||
164 | int 0x40 |
||
165 | |||
166 | cmp [received_messages+4],dword 8 ; empty list |
||
167 | je ipma1 |
||
168 | |||
169 | mov ebx,25*65536+105 ; draw info text with function 4 |
||
170 | mov ecx,0x224466 |
||
171 | mov edx,received_messages+8 |
||
172 | mov esi,40 |
||
173 | mov [counter],0 |
||
174 | newline2: |
||
175 | pusha |
||
176 | mov ecx,[edx] |
||
177 | and ecx,0xfff |
||
178 | mov edx,ebx |
||
179 | mov eax,47 |
||
180 | mov ebx,4*65536 |
||
181 | mov esi,0xff0000 |
||
182 | int 0x40 |
||
183 | popa |
||
184 | pusha |
||
185 | mov esi,20 |
||
186 | add edx,8 |
||
187 | add ebx,30*65536 |
||
188 | mov eax,4 |
||
189 | int 0x40 |
||
190 | popa |
||
191 | |||
192 | add ebx,10 |
||
193 | mov edi,[edx+4] |
||
194 | add edi,8 |
||
195 | and edi,0xfff |
||
196 | add edx,edi |
||
197 | |||
198 | mov edi,[received_messages+4] |
||
199 | add edi,received_messages |
||
200 | cmp edx,edi |
||
201 | jge ipma1 |
||
202 | |||
203 | inc [counter] |
||
204 | cmp [counter],8 |
||
205 | jbe newline2 |
||
206 | |||
207 | ipma1: |
||
208 | |||
209 | popa |
||
210 | ret |
||
211 | |||
212 | |||
213 | counter dd 0x0 |
||
214 | |||
215 | |||
216 | ; ********************************************* |
||
217 | ; ******* WINDOW DEFINITIONS AND DRAW ******** |
||
218 | ; ********************************************* |
||
219 | |||
220 | |||
221 | draw_window: |
||
222 | |||
223 | mov eax,12 ; function 12:tell os about windowdraw |
||
224 | mov ebx,1 ; 1, start of draw |
||
225 | int 0x40 |
||
226 | |||
227 | ; DRAW WINDOW |
||
228 | mov eax,0 ; function 0 : define and draw window |
||
229 | mov ebx,100*65536+290 ; [x start] *65536 + [x size] |
||
230 | mov ecx,100*65536+220 ; [y start] *65536 + [y size] |
||
231 | mov edx,0x03ffffff ; color of work area RRGGBB,8->color gl |
||
232 | int 0x40 |
||
233 | |||
234 | ; WINDOW LABEL |
||
235 | mov eax,4 ; function 4 : write text to window |
||
236 | mov ebx,8*65536+8 ; [x start] *65536 + [y start] |
||
237 | mov ecx,0x10ffffff ; color of text RRGGBB |
||
238 | mov edx,labelt ; pointer to text beginning |
||
239 | mov esi,labellen-labelt ; text length |
||
240 | int 0x40 |
||
241 | |||
242 | mov eax,9 |
||
243 | mov ebx,process_info |
||
244 | mov ecx,-1 |
||
245 | int 0x40 |
||
246 | |||
247 | mov eax,47 |
||
248 | mov ebx,4*65536 |
||
249 | mov ecx,[process_info+30] |
||
250 | mov edx,180*65536+35 |
||
251 | mov esi,0x000000 |
||
252 | int 0x40 |
||
253 | |||
254 | mov eax,8 ; MESSAGE |
||
255 | mov ebx,25*65536+87 |
||
256 | mov ecx,50*65536+16 |
||
257 | mov edx,2 |
||
258 | mov esi,0x5588dd |
||
259 | int 0x40 |
||
260 | |||
261 | mov eax,8 ; POP |
||
262 | mov ebx,216*65536+53 |
||
263 | mov ecx,80*65536+16 |
||
264 | mov edx,3 |
||
265 | mov esi,0x5588dd |
||
266 | int 0x40 |
||
267 | |||
268 | mov ebx,25*65536+35 ; draw info text with function 4 |
||
269 | mov ecx,0x224466 |
||
270 | mov edx,text |
||
271 | mov esi,40 |
||
272 | newline: |
||
273 | mov eax,4 |
||
274 | int 0x40 |
||
275 | add ebx,10 |
||
276 | add edx,40 |
||
277 | cmp [edx],byte 'x' |
||
278 | jne newline |
||
279 | |||
280 | call display_ipc_messages |
||
281 | |||
282 | mov eax,12 ; function 12:tell os about windowdraw |
||
283 | mov ebx,2 ; 2, end of draw |
||
284 | int 0x40 |
||
285 | |||
286 | ret |
||
287 | |||
288 | |||
289 | |||
290 | |||
291 | read_string: |
||
292 | |||
293 | pusha |
||
294 | |||
295 | mov [addr],dword message |
||
296 | mov [ya],55 |
||
297 | mov [xa],120 |
||
298 | |||
299 | mov ecx,20 |
||
300 | mov edi,[addr] |
||
301 | mov al,' ' |
||
302 | cld |
||
303 | rep stosb |
||
304 | |||
305 | call print_text |
||
306 | |||
307 | mov edi,[addr] |
||
308 | |||
309 | f11: |
||
310 | mov eax,10 |
||
311 | int 0x40 |
||
312 | cmp eax,2 |
||
313 | jz fbu |
||
314 | |||
315 | exit_readkey: |
||
316 | |||
317 | popa |
||
318 | ret |
||
319 | |||
320 | fbu: |
||
321 | mov eax,2 |
||
322 | int 0x40 ; get key |
||
323 | shr eax,8 |
||
324 | |||
325 | cmp eax,13 |
||
326 | je exit_readkey |
||
327 | |||
328 | cmp eax,8 |
||
329 | jnz nobs |
||
330 | cmp edi,[addr] |
||
331 | jz f11 |
||
332 | dec edi |
||
333 | mov [edi],byte ' ' |
||
334 | call print_text |
||
335 | jmp f11 |
||
336 | nobs: |
||
337 | |||
338 | cmp eax,31 |
||
339 | jbe f11 |
||
340 | cmp eax,95 |
||
341 | jb keyok |
||
342 | sub eax,32 |
||
343 | keyok: |
||
344 | mov [edi],al |
||
345 | |||
346 | call print_text |
||
347 | |||
348 | inc edi |
||
349 | mov esi,[addr] |
||
350 | add esi,20 |
||
351 | cmp esi,edi |
||
352 | jnz f11 |
||
353 | |||
354 | popa |
||
355 | ret |
||
356 | |||
357 | |||
358 | |||
359 | print_text: |
||
360 | |||
361 | mov eax,13 |
||
362 | mov ebx,[xa] |
||
363 | shl ebx,16 |
||
364 | add ebx,25*6 |
||
365 | mov ecx,[ya] |
||
366 | shl ecx,16 |
||
367 | mov cx,8 |
||
368 | mov edx,0xffffff |
||
369 | int 0x40 |
||
370 | |||
371 | mov eax,4 |
||
372 | mov ebx,[xa] |
||
373 | shl ebx,16 |
||
374 | add ebx,[ya] |
||
375 | mov ecx,0x000000 |
||
376 | mov edx,[addr] |
||
377 | mov esi,25 |
||
378 | int 0x40 |
||
379 | |||
380 | ret |
||
381 | |||
382 | |||
383 | |||
384 | |||
385 | |||
386 | |||
387 | ; DATA AREA |
||
388 | |||
389 | ya dd 0x0 |
||
390 | xa dd 0x0 |
||
391 | addr dd 0x0 |
||
392 | |||
393 | text: |
||
394 | db 'PROCESS ID FOR THIS APP : ' |
||
395 | db ' ' |
||
396 | db ' PID:MESSAGE 0130 EXAMPLE MESSAGE ' |
||
397 | db ' ' |
||
398 | db ' ' |
||
399 | db 'RECEIVED: POP ' |
||
400 | db 'x' ; <- END MARKER, DONT DELETE |
||
401 | |||
402 | |||
403 | labelt: |
||
404 | db 'IPC - START AT LEAST 2' |
||
405 | labellen: |
||
406 | |||
407 | I_END: |
||
408 | |||
409 | PID: dd 0x0 |
||
410 | message_size: dd 20 |
||
411 | |||
412 | received_messages: |
||
413 | |||
414 | db 0 ; lock byte |
||
415 | db 0,0,0 ; reserved |
||
416 | dd 8 ; pointer to free msg position from received_messages |
||
417 | |||
418 | ; Sender PID |
||
419 | ; Msg length |
||
420 | ; Msg data |
||
421 | |||
422 | rb 0x1000 |
||
423 | message: times 70 db ? |
||
424 | process_info: times 256 dd ?-> |