;
;  dosio.asm
;  Support for BIOS calls in NCSA PCShow
;****************************************************************************
;*																			*
;*																			*
;*	  part of NCSA PCShow												 	*
;*	  by Quincey Koziol													 	*
;*																			*
;*	  National Center for Supercomputing Applications						*
;*	  152 Computing Applications Building									*
;*	  605 E. Springfield Ave.												*
;*	  Champaign, IL  61820													*
;*																		 	*
;*																		 	*
;****************************************************************************

	TITLE	DOSIO	-- LOW-LEVEL I/O FOR SANE HARDWARE HANDLING

;
;	From original code by Tim Krauskopf	1984-1985
;	National Center for Supercomputing Applications
;
	NAME	DOSIO

;
;  Macros for reading and writing I/O ports
;
MOUT	MACRO	REG,STUFF		; one byte to the given I/O register
	MOV	DX,REG
	MOV	AL,STUFF
	OUT	DX,AL
	ENDM
;
MIN	MACRO	REG		 	; get one byte to al
	MOV	DX,REG
	IN	AL,DX
	ENDM
;
;  Internal data 
;
	X EQU	6				;  for the large model programs

	INCLUDE	DOS.MAC
	DSEG

	PUBLIC	DTAPTR				; POINTER TO DTA LOCATION

DTAPTR	DW	0000H				; dta ADDRESS FOR ME
DTADS	DW	0000H				; ds FOR dta

	ENDDS
;
;
;
;	The subroutines to call from C
;
	PSEG

	PUBLIC  FIND_1ST,FINDNEXT


;**********************************************************************
;
;  find first
;	make dos find file names according to wildcards
;  findfirst(filename,attr)
;	char *filename; int attr;
;
FIND_1ST	PROC	FAR
	PUSH	BP
	MOV		BP,SP
	PUSH	ES
	PUSH	DS
	
	MOV		AH,02FH					; dos FUNCTION GET dta
	INT		21H
	MOV		DTAPTR,BX				; SQUIRREL A COPY FOR ME
	MOV		AX,ES
	MOV		DTADS,AX

	MOV		AX,[BP+X+2]				; DS OF FILENAME PTR
	MOV		DS,AX
	MOV		DX,[BP+X]				; PTR PART OF FILENAME
	MOV		CX,[BP+X+4]				; ATTRIBUTE TO SEARCH FOR
	MOV		AH,04EH					; FIND MATCHING FILE dos CALL
	INT		21H
	JC		BADRET					; AX ALREADY CONTAINS ERROR CODE
	XOR		AX,AX

BADRET:
	POP		DS
	POP		ES
	POP		BP
	RET
FIND_1ST	ENDP

;
;  findnext()
;  will find entries that follow findfirst
;  no need to respecify file name
;
FINDNEXT	PROC	FAR
	PUSH	BP

	MOV		AH,04FH					; FIND NEXT dos CALL
	INT		21H
	JC		NBADRET
	XOR		AX,AX

NBADRET:
	POP		BP
	RET
FINDNEXT	ENDP

	ENDPS
	END
