;       SCCSID = @(#)i_devctu.asm	6.1 91/02/15
;	SCCSID = @(#)i_devctu.asm	6.2 90/01/22
; ****************************************************************************
; *									     *
; *			  IBM/Microsoft Confidential			     *
; *									     *
; *		    Copyright (c) IBM Corporation  1987, 1990		     *
; *		    Copyright (c) Microsoft Corp.  1987, 1990		     *
; *			      All Rights Reserved			     *
; *									     *
; ****************************************************************************
;***  i_devctu.asm - routines for user category IOCTL calls
;
;	Internal routines used by API IOCTL library routines
;	Robert L. Chernow
;	Copyright IBM Corporation, 1987
;	30-Sep-1987
;
;	This file contains support routines for user IOCTLs

include dos2equ.inc
include error.inc
include d_ioctl.inc


; The purpose of this segment is to share a reusable data area between api
; library routines. This is a win since it decreases the total api library
; overhead in the application's executable.

APIBUF	segment byte common 'CODE'

__api_buffer	db	40 dup(?)

APIBUF	ends


_TEXT	segment byte public 'CODE'
	assume	CS:_TEXT, DS:nothing

	PUBLIC	USERIOCTL

	EXTRN	_api_getvrsn :NEAR
	EXTRN	DosErrAdd:far
	EXTRN	api_get_extended:far

USERIOCTL	proc	near

	push	ds
	push	cx
	push	dx
	push	si
	push	di

	mov	ch, [Category]
	lds	di, [ParmList]		; si:di <= parameter list pointer ;@@
	mov	ax, ds							  ;@@
	mov	si, ax							  ;@@
	lds	dx, [DataArea]		; ds:dx <= data packet pointer	  ;@@
	mov	ax, D2_IOCTL SHL 8 + D2_HANDLE_IOCTL
	mov	cl,[Function]
	mov	bx, [DevHandle]		; get passed device handle
	int	21h			; call Dos 3.x IOCTL for handles
	jc	ErrorExit		; if this failed, get extended error
	xor	ax, ax
	jmp	short NormalExit	; go return sucessfull


	; get the extended error code - hopefully what the driver returned.
	; Because this code only runs in above 3.x, we don't have to worry about
	; Get Extended Error not being supported in Dos 2.x.

ErrorExit:
	call	api_get_extended
NormalExit:
	pop	di
	pop	si
	pop	dx
	pop	cx
	pop	ds
	ret

USERIOCTL	endp
_TEXT		ends
		end
