þ a‹R þ d þ w ÿÿÿÿÿÿÿÿÿÿþ mx9    þ hý	 oP     þ nSystem-wide		NAME	GPIBIfce

DGROUP		GROUP	DATA
CGROUP		GROUP	CODE

STACK		SEGMENT	STACK 'STACK'
STACK		ENDS

		ASSUME	CS:CGROUP, DS:DGROUP, SS:STACK

; ---------------------------------------------------------------------------
;  Code Size    Data Size
;  ---------	---------
;    small        large
; ---------------------------------------------------------------------------

;  data structure for accessing parameters on the stack
nparams		struc		; for a near procedure
nold_bp		dw      ?
nreturn		dw      ?
nptr_1		dd      ?
nptr_2		dd      ?
nparams		ends

;  data structure for accessing parameters on the stack
rwparams	struc		; for a near procedure
rwold_bp	dw      ?
rwreturn	dw      ?
rwperror	dd      ?
rwlength	dw      ?
rwpbuffer	dd	?
rwhandle	dw	?
rwparams	ends


DATA		SEGMENT	PUBLIC 'DATA'
DATA		ENDS


CODE 		SEGMENT PUBLIC 'CODE'

		PUBLIC itopenraw, itclose
		PUBLIC itreadioctl, itwriteioctl, itread, itwrite

;-------------------------------------------------------------------------

itopenraw	PROC	NEAR	
; WORD handle = itopenraw (pname, perror)

		PUSH	BP
		MOV	BP, SP
		SUB	SP, 2		; make space for file handle

		PUSH	DS		; save original DS
		LDS	DX, [BP].nptr_2	; load pointer to name string
		MOV	AX, 3D01H	; DOS open file for write
;		MOV	AX, 3D02H	; DOS open file for read/write
		INT	21H
		POP	DS		; restore original DS
		JC	itopenrawexit	; branch if error
		MOV	WORD PTR[BP - 2], AX  ; save file handle

		MOV	BX, AX		; put file handle in BX
		MOV	AX, 4400H	; DOS Ioctl get device info
		INT	21H
		JC	errinioctl	; branch if error

		MOV	BX, WORD PTR[BP - 2]  ; load file handle
		MOV	DH, 0		; force DH = 0
		OR	DL, 20H		; set raw mode bit
		MOV	AX, 4401H	; DOS Ioctl set device info
		INT	21H
		JC	errinioctl	; branch if error

		XOR	AX, AX		; done ok, so set error to zero
		JMP	itopenrawexit
errinioctl:				; error returned in ioctl
		PUSH	AX		; save error temporarily
		MOV	BX, WORD PTR[BP - 2]  ; load file handle
		MOV	AH, 3EH		; DOS close file
		INT	21H
		MOV	WORD PTR[BP - 2], 0FFFFh  ; put 'bad' value in handle
		POP	AX		; put saved error back in AX
itopenrawexit:				; done, error is in AX
		LES	BX, [BP].nptr_1	; load pointer to error word
		MOV	ES:[BX], AX	; return error
		MOV	AX, WORD PTR[BP - 2]  ; load file handle to return

		MOV	SP, BP		; remove local variable
		POP	BP		; restore original base pointer
		RET	8		; pop address of arguments

itopenraw	ENDP

;-------------------------------------------------------------------------

itclose		PROC	NEAR		; itclose (handle, perror)

		PUSH	BP
		MOV	BP, SP

		MOV	BX, [BP].rwlength  ; load file handle
		MOV	AH, 3EH		; DOS close file
		INT	21H
		JC	itcloseexit	; branch if error

		XOR	AX, AX		; done ok, so set error to zero
itcloseexit:				; done, error is in AX
		LES	BX, [BP].rwperror  ; load pointer to error word
		MOV	ES:[BX], AX	; return error

		POP	BP		; restore original base pointer
		RET	6		; pop address of arguments

itclose		ENDP

;-------------------------------------------------------------------------

itreadioctl	PROC	NEAR
; WORD lengthread = itreadioctl (handle, pbuffer, length, pError)

		PUSH	BP
		MOV	BP, SP

		PUSH	DS		; restore original DS
		MOV	BX, [BP].rwhandle  ; load file handle
		LDS	DX, [BP].rwpbuffer  ; load buffer pointer
		MOV	CX, [BP].rwlength  ; load length to read
		MOV	AX, 4402H	; DOS IOCTL read
		INT	21H
		POP	DS		; restore original DS
		XOR	CX, CX		; either length or error will be zero
		JC	itreadioctlexit	; branch if error

		XCHG	AX, CX		; done ok, so error gets the zero
itreadioctlexit:			; done, error is in AX, length is in CX
		LES	BX, [BP].rwperror  ; load pointer to error word
		MOV	ES:[BX], AX	; return error
		MOV	AX, CX		; return length

		POP	BP		; restore original base pointer
		RET	12		; pop address of arguments

itreadioctl	ENDP

;-------------------------------------------------------------------------

itwriteioctl	PROC	NEAR
; WORD lengthwritten = itwriteioctl (handle, pbuffer, length, pError)

		PUSH	BP
		MOV	BP, SP

		PUSH	DS		; restore original DS
		MOV	BX, [BP].rwhandle  ; load file handle
		LDS	DX, [BP].rwpbuffer  ; load buffer pointer
		MOV	CX, [BP].rwlength  ; load length to read
		MOV	AX, 4403H	; DOS IOCTL read
		INT	21H
		POP	DS		; restore original DS
		XOR	CX, CX		; either length or error will be zero
		JC	itwriteioctlexit  ; branch if error

		XCHG	AX, CX		; done ok, so error gets the zero
itwriteioctlexit:			; done, error is in AX, length is in CX
		LES	BX, [BP].rwperror  ; load pointer to error word
		MOV	ES:[BX], AX	; return error
		MOV	AX, CX		; return length

		POP	BP		; restore original base pointer
		RET	12		; pop address of arguments

itwriteioctl	ENDP

;-------------------------------------------------------------------------

itread		PROC	NEAR
; WORD lengthread = itread (handle, pbuffer, length, pError)

		PUSH	BP
		MOV	BP, SP

		PUSH	DS		; restore original DS
		MOV	BX, [BP].rwhandle  ; load file handle
		LDS	DX, [BP].rwpbuffer  ; load buffer pointer
		MOV	CX, [BP].rwlength  ; load length to read
		MOV	AH, 3FH		; DOS read
		INT	21H
		POP	DS		; restore original DS
		XOR	CX, CX		; either length or error will be zero
		JC	itreadexit	; branch if error

		XCHG	AX, CX		; done ok, so error gets the zero
itreadexit:				; done, error is in AX, length is in CX
		LES	BX, [BP].rwperror  ; load pointer to error word
		MOV	ES:[BX], AX	; return error
		MOV	AX, CX		; return length

		POP	BP		; restore original base pointer
		RET	12		; pop address of arguments

itread		ENDP

;-------------------------------------------------------------------------

itwrite		PROC	NEAR
; WORD lengthwritten = itwrite (handle, pbuffer, length, pError)

		PUSH	BP
		MOV	BP, SP

		PUSH	DS		; restore original DS
		MOV	BX, [BP].rwhandle  ; load file handle
		LDS	DX, [BP].rwpbuffer  ; load buffer pointer
		MOV	CX, [BP].rwlength  ; load length to read
		MOV	AH, 40H		; DOS read
		INT	21H
		POP	DS		; restore original DS
		XOR	CX, CX		; either length or error will be zero
		JC	itwriteexit  	; branch if error

		XCHG	AX, CX		; done ok, so error gets the zero
itwriteexit:				; done, error is in AX, length is in CX
		LES	BX, [BP].rwperror  ; load pointer to error word
		MOV	ES:[BX], AX	; return error
		MOV	AX, CX		; return length

		POP	BP		; restore original base pointer
		RET	12		; pop address of arguments

itwrite		ENDP

;-------------------------------------------------------------------------

CODE		ENDS
		END
