;       SCCSID = @(#)d_getpid.asm	6.1 91/02/15
;	SCCSID = @(#)d_getpid.asm	6.2 90/01/22
; ****************************************************************************
; *									     *
; *			  IBM/Microsoft Confidential			     *
; *									     *
; *		    Copyright (c) IBM Corporation  1987, 1990		     *
; *		    Copyright (c) Microsoft Corp.  1987, 1990		     *
; *			      All Rights Reserved			     *
; *									     *
; ****************************************************************************
;***  d_getpid.asm - API stub routine DosGetPid
;
;	Member of API library
;	Bill Mershon
;	Copyright MicroSoft Corporation, 1986
;	27-Jun-1986
;
;	library routine for API simulator
;
;	Called from dos 2.x,3.x compatible dos 5.x applications
;
;	Special Information
;		none
;
;	Modification History
;
;	06-Jan-87 (billme): Replace initial pushes and final pops
;	with calls to __api_begin and __api_end resp.  This will
;	reduce the size of FAPI and allow support for signals.
;
; @@	22-July-87 (giacomoa): change __PSP to __api_PSP to avoid name
; @@	conflict with slibc.lib (COBOL compiler problem)
;

INCLUDE dos2equ.inc

	EXTRN	__api_begin:near
	EXTRN	__api_end:near


;***	DOSGETPID - stub to emulate DOSGETPID function call
;
;	simulates DOS 5.0 call from DOS 2.x,3.x environment
;
;	errorcode = unsigned far pascal
;	DosGetPid(ptr_PidBlock)
;
;	ENTRY:
;		ptr_PidBlock - far pointer to block or 3 words to be filled in:
;			process id, thread id, and parent id
;
;	RETURN:
;		AX = 0 if no error, else error code (see DOS 5 spec)
;
;	EXIT:
;		ptr_PidBlock contains the required process ids ... thread
;		id is meaningless since there is only one thread
;
;	USES:
;		AX
;
;	WARNING:
;		may return error code from Dos 2.x, 3.x (see dos manuals)
;
;	EFFECTS:
;		none
;

	title	DOSGETPID - stub to emulate DOSGETPID function call
;
;	EXTRN	DOSGETPID:FAR
;
;	PUSH	@ WORD ptr_PidBlock
;	CALL	DOSGETPID
;

	EXTRN	__api_PSP:word	; @@

_TEXT	segment byte public 'CODE'

	assume	CS:_TEXT,DS:NOTHING

	public	DOSGETPID

ptr_PidBlock	equ	[BP+6]

DOSGETPID	proc	far

	call	__api_begin	; init bp and save bp,ds,bx,cx,dx,si,di,es
				; required to save: bp,es,ds,bx

	mov	ax,cs:__api_PSP		; @@ ES <- psp (process id)
	mov	es,ax
	mov	ax,es:[8]		; AX <- parent process id
					; (at offset 8 within psp)

	lds	bx,ptr_PidBlock		; DS:BX <- pointer to PID block
	mov	ds:[bx],es		; store process id
	mov	ds:[bx+2],word ptr 0	; store (random) thread id
	mov	ds:[bx+4],ax		; store parent process id

	xor	ax,ax			; clear error
ErrorExit:

	call	__api_end	; check sigs & restore es,di,si,dx,cx,bx,ds,bp

	ret	4	; clear stack of entry parameters (bytes)
DOSGETPID	endp

_TEXT	ends

	end
