Subversion Repositories Kolibri OS

Rev

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