;       SCCSID = @(#)d_exit.asm	6.1 91/02/15
;	SCCSID = @(#)d_exit.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_exit.asm - API stub routine DosExit
;
;	Member of API library
;	Bill Mershon
;	Copyright MicroSoft Corporation, 1986
;	15-Apr-1986
;
;	library routine for API simulator
;
;	Called from dos 2.x,3.x compatible dos 5.x applications
;
;	Special Information
;		none
;
;	Modification History
;
;	9/23/86 (davidsi) - Added common segment and cleanup code for
;		cleanup of signal handling and interrupt vectors.
;

include dos2equ.inc

;***	DOSEXIT - stub to emulate DOSEXIT function call
;
;	simulates DOS 5.0 call from DOS 2.x,3.x environment
;
;	errorcode = unsigned far pascal
;	DosExit (ActionCode, ResultCode)
;
;	ENTRY:
;		ActionCode = (ignored)
;		ResultCode = result code of process
;
;	RETURN:
;		does not return
;
;	EXIT:
;
;	USES:
;		AX
;
;	Pseudo Code:
;		abort program
;
;	WARNING:
;		This routine does not return.
;		One byte of information is all that may be returned.
;		Offsets into stack are non-standard since BP IS NOT PUSHED.
;
;	EFFECTS:
;		terminates program
;

	title	DOSEXIT - stub to emulate DOSEXIT function call
;
;	EXTRN	DOSEXIT:FAR
;
;	PUSH	WORD ActionCode	(ignored ... assumed to be 1)
;	PUSH	WORD ResultCode
;	CALL	DOSEXIT
;

; The purpose of this common segment is to define an exit cleanup routine if
; fapisig.obj is loaded.  The address of the cleanup routine is defined
; in this module as ?, and elsewhere as an address.  If this is the only
; module loaded which references this common segment, the cleanup routine
; address will default to zero.

_SIGS	segment byte common 'CODE'

exitlist	dd	?

_SIGS	ends


_TEXT	segment byte public 'CODE'

	assume	CS:_TEXT,DS:NOTHING,ES:_SIGS

	public	DOSEXIT

ActionCode	equ	[BP+6]
ResultCode	equ	[BP+4]

DOSEXIT	proc	far
	mov	bp,sp

	mov	ax, seg _SIGS		; set up address of common segment
	mov	es, ax
	mov	ax, word ptr _SIGS:[exitlist]		; is the address zero?
	or	ax, word ptr _SIGS:[exitlist + 2]
	jz	exit1					; no cleanup routine
	call	dword ptr _SIGS:[exitlist]		; call cleanup routine

exit1:
	mov	ax,ResultCode		; AL <- result code
	mov	ah,D2_EndProc
	int	21H			; end process (no return)
DOSEXIT	endp

_TEXT	ends

	end
