home *** CD-ROM | disk | FTP | other *** search
- $title ('psamp')
- $optimize(0) word16
- $large( -CONST IN CODE- EXPORTS process_task,
- $ count_task)
- $debug
-
- pmain: do;
- $include(/rmx386/inc/common.lit)
- $include(/rmx386/inc/rmxplm.ext)
- $include(putils.ext)
-
- declare UINT_8 literally 'byte';
- declare UINT_16 literally 'dword';
- declare UINT_32 literally 'word';
- declare NIL_SEL literally 'selectorof(NIL)';
-
- declare COUNT_PRIORITY literally '200'; /* Priority of count task */
- declare PROCESS_PRIORITY literally '200'; /* Priority of process task*/
- declare BUFF_LEN literally '125'; /* Buffer len in MSG_STRUC */
- declare DATA_MBOX literally '20h'; /* Data mailbox code. */
- declare MAX_COUNT literally '65535';/* UI16_MAX */
-
- declare MSG_STRUC literally 'structure (
- count byte,
- fillchar byte,
- buffer(BUFF_LEN) byte)';
-
- declare proc_msg MSG_STRUC public; /* Message processed by process task */
-
- declare counter word public; /* Counter used by count task. */
- declare count_token TOKEN public; /* Token for count task. */
- declare process_token TOKEN public; /* Token for process task. */
-
-
- declare module_data UINT_32; /* Used in the create task system call */
- /* Identifies the data segment */
-
- process_task: procedure public reentrant;
-
- declare exception WORD; /* Status returned from system calls */
- declare main_mbox TOKEN; /* Token for main task's mailbox */
- declare proc_mbox TOKEN; /* Process task's mailbox token */
- declare msg_length UINT_32; /* Actual length of received message */
- declare i byte;
-
- /*
- * Lookup the process task mailbox token from the object
- * directory.
- */
- proc_mbox = rqlookupobject (NIL_SEL, @(11,'Process Box'), 0ffffh, @exception);
- /*
- * Lookup the main task mailbox token from the object
- * directory.
- */
- main_mbox = rqlookupobject (NIL_SEL, @(8,'Main Box'), 0ffffh, @exception);
-
- /*
- * Loop forever responding to requests.
- */
- do FOREVER;
- /*
- * Receive the next request
- */
- msg_length = rqreceivedata (main_mbox,
- @proc_msg,
- 0ffffh,
- @exception);
-
- /*
- * Take action on the received message (fill msg.buffer)
- */
- do i = 0 to (BUFF_LEN - 1);
- msg.buffer(i) = msg.fillchar;
- end;
-
- /*
- * Send response
- */
- call rqsenddata (proc_mbox,
- @proc_msg,
- size (proc_msg),
- @exception);
-
- call delay (1000); /* Sleep for about 1 sec. so others can run.*/
- end;
- end process_task;
-
- count_task: procedure public reentrant;
-
- declare exception WORD; /* Status returned from system calls */
-
- counter = 0;
-
- do FOREVER;
-
- counter = counter + 1;
- call delay(1000); /* Approx. 1 second. */
- call plm_data;
-
- end;
- end count_task;
-
- /**********************************************************************/
- /* Entry point for Soft-Scope demo program */
- /**********************************************************************/
- declare actual WORD;
- declare co_conn TOKEN;
- declare exception WORD; /* Status returned from system calls. */
- declare main_mbox TOKEN; /* Token for main task's mailbox. */
- declare proc_mbox TOKEN; /* Process task's mailbox token. */
- declare msg_length UINT_32;/* Actual length of received message. */
- declare msg MSG_STRUC;/* Message to be sent/received. */
- declare msg_count UINT_16;
- declare i UINT_16;
-
- co_conn = rqsattachfile(@(4,':CO:'),@exception);
- call rqsopen(co_conn,3,0,@exception);
- actual = rqswritemove(co_conn,
- @('Soft-Scope III PLM Sample Program',0dh,0ah), 35,
- @exception);
-
- /*
- * Create the mailbox for main task
- */
- main_mbox = rqcreatemailbox (DATA_MBOX, @exception);
- /*
- * Catalog the mailbox token in the object directory
- */
- call rqcatalogobject (NIL_SEL, main_mbox, @(8,'Main Box'), @exception);
-
- /*
- * Create the process mailbox
- */
- proc_mbox = rqcreatemailbox (DATA_MBOX, @exception);
- /*
- * Catalog the mailbox token in the object directory
- */
- call rqcatalogobject (NIL_SEL, proc_mbox, @(11,'Process Box'),@exception);
-
- /*
- * Create tasks...
- */
- count_token = rqcreatetask (
- COUNT_PRIORITY, /* priority. */
- @count_task, /* start address. */
- selectorof (@module_data), /* data segment. */
- NIL, /* stack pointer. */
- 4096, /* stack size. */
- 0, /* flags (no NPX). */
- @exception); /* exception ptr. */
-
- process_token = rqcreatetask (
- COUNT_PRIORITY, /* priority. */
- @process_task, /* start address. */
- selectorof (@module_data), /* data segment. */
- NIL, /* stack pointer. */
- 4096, /* stack size. */
- 0, /* flags (no NPX). */
- @exception); /* exception ptr. */
-
- msg_count = 0;
- do FOREVER;
- msg.fillchar = '*';
- if (msg_count >= MAX_COUNT) then
- msg_count = 0;
- else
- msg.count = msg_count + 1;
- call setb (0, @msg.buffer, size (msg.buffer));
- /*
- * Send data to process task to fill msg.buffer with fillchar
- */
- call rqsenddata (main_mbox,
- @msg,
- size (msg),
- @exception);
-
- /*
- * Receive data back from process task
- */
- msg_length = rqreceivedata (proc_mbox,
- @msg,
- 0ffffh,
- @exception);
- end;
-
- end pmain;
-