;       SCCSID = @(#)d_qfhans.asm	6.1 91/02/15
;	SCCSID = @(#)d_qfhans.asm	1.4 90/01/22
; ****************************************************************************
; *									     *
; *			  IBM/Microsoft Confidential			     *
; *									     *
; *		    Copyright (c) IBM Corporation  1987, 1990		     *
; *		    Copyright (c) Microsoft Corp.  1987, 1990		     *
; *			      All Rights Reserved			     *
; *									     *
; ****************************************************************************
;***  d_qfhans.asm - API stub routine DosQFHandState
;
;	Member of API library
;	Bill Mershon
;	Copyright MicroSoft Corporation, 1986
;	18-Feb-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.
;
;	15-Jan-87 (billme): Change reference to __api_dev_table to
;	call to __api_devtab_ptr ... to reduce code size.
;
;	17-June-87 (stevee): fix to insure that all FAPI file handles are
;	less than MAX_HANDLES (p5553)
;


INCLUDE dos2equ.inc
INCLUDE basemaca.inc
INCLUDE error.inc
INCLUDE api.inc

	EXTRN	__api_devtab_ptr:near
	EXTRN	__api_begin:near
	EXTRN	__api_end:near


;***	DOSQFHANDSTATE - stub to emulate DOSQFHANDSTATE function call
;
;	simulates DOS 5.0 call from DOS 2.x,3.x environment
;
;	errorcode = unsigned far pascal
;	DosQFHandState (FileHandle,ptr_FileHandState)
;
;	ENTRY:
;		FileHandle - file handle
;		ptr_FileHandState - file handle state
;
;	RETURN:
;		AX = 0 if no error, else error code (see DOS 5 spec)
;
;	EXIT:
;
;	USES:
;		AX
;
;	WARNING:
;		may return error code from Dos 2.x, 3.x (see dos manuals)
;
;	EFFECTS:
;		none
;

	title	DOSQFHANDSTATE - stub to emulate DOSQFHANDSTATE function call
;
;	EXTRN	DOSQFHANDSTATE:FAR
;
;	PUSH	WORD Handle
;	CALL	DOSQFHANDSTATE
;


_TEXT	segment byte public 'CODE'

	assume	CS:_TEXT,DS:NOTHING

	extrn __api_dev_table : word

	public	DOSQFHANDSTATE

FileHandle	equ	[BP+10]
ptr_FileState	equ	[BP+6]

DOSQFHANDSTATE	proc	far

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

	mov	ax,FileHandle		; BX <- file handle
	cmp	ah,0ffh			; if handle is mapped high
	je	short qfhans5		; then it is a block open
					; so just return
	cmp	ax,MAX_HANDLES		; if handle is too large
	jae	qfhanserr		; then report error

	; load AX with correct handle state from table
	call	__api_devtab_ptr	; BX <- address of entry
	mov	ax,cs:[bx].hi_hands	; AX <- handle state

	jmp	short qfhans7
qfhans5:
	xor	ax,ax			; AX <- null handle state (no info)
qfhans7:
	lds	bx,ptr_FileState	; store handle state
	mov	ds:[bx],ax
	xor	ax,ax
	jmp	short ErrorExit
qfhanserr:
	mov	ax,ERROR_INVALID_HANDLE
ErrorExit:

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

	ret	6	; clear stack of entry parameters (bytes)
DOSQFHANDSTATE	endp

_TEXT	ends

	end
