	.TITLE SPAWN
	.IDENT /130984/

;  An external procedure to provide parent-offspring task services to
;  Pascal-3 programs. The full capabilities of the SPAWN system directive
;  are not implemented by this procedure. No UIC or DEVICE parameters
;  are provided. Thus, the offspring will take the UIC and TI: of the
;  parent in all cases. The exit AST is not available to Pascal.
;
; File: PA3:[22,310]SPAWN.PAS
; Author: Jim Bostwick  13-SEP-1984 16:49:31 (from P2UTIL)
; HISTORY: 
;
; Last Edit: JMB 13-SEP-1984 16:49:54 
; 
;
;
;  PROCEDURE Spawn(Task:Rad56; EFN:Event_Flag; CmdLin:Address; 
;		CmdLen:Integer; VAR Status:SPAWN_Status_array);
;
;{ will spawn task TASK (which must be in RAD50 format), which will take
;  the TI: and UIC of the parent. TASK must be installed.  EFN will be
;  cleared on directive acceptance, and set when the offspring task exits.
;  CMDLIN may be any character array (or record) up to 72. bytes in length.
;  CMDLEN is the length of the command line. IF CMDLEN=0, no command line
;  will be queued to the offspring task, else the contents of CMDLIN will
;  be available to the offspring (see MCR COMMAND LINE section of the
;  OMSI PASCAL USERS GUIDE for how to get the command line). 
;  STATUS must be an array, although only the first word is currently
;  used. This word holds the offspring task exit status. 
;  Non-standard types are defined in ex:[22,320]SPAWN.TYP.
;
;  Directive status (of the SPAWN directive, not the offspring) is
;  available in $DSW upon return.
;
;  NOTE: The variable STATUS MUST remain defined until the offspring
;  task exits. Thus, for safety, it should probably be declared as
;  a global variable in the parent task. }
;


  	PROC SPAWN
	PARAM TASK, 2*INTEGER	; RAD-50 TASK NAME
	PARAM EFN, INTEGER	; event flag
	PARAM CLIN, ADDRESS	; COMMAND LINE POINTER	
	PARAM CLEN, INTEGER	; COMMAND LINE LENGTH
	PARAM STAT, ADDRESS	; STATUS ARRAY POINTER
	SAVE <R0, R1, R2>
	BEGIN

	.MCALL SPWN$S
	MOV SP,R0	;PRESERVE STACK REFERENCE
	MOV SP, R1	;GET POINTER TO STATUS WORD
	ADD #TASK, R1	; R1 -> TASK NAME
	CLR R2
  	MOVB EFN(SP), R2 ; GET BYTE ONLY
	TST CLEN(SP)	; ANY COMMAND LINE ?
	BNE 1$		; BR IF COMMAND LINE
	CLR CLIN(SP)	; FORCE ADDRESS TO ZERO IF NO COMMAND LINE
  	.LIST MEB
1$:	SPWN$S R1,,,,,R2,,STAT(0),CLIN(0),CLEN(0)
	ENDPR

	.END
