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