⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dvstmt.asm

📁 [随书类]Dos6.0源代码
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	TITLE	DVSTMT - Device Independent I/O Statements
	page	56,132
;***
; DVSTMT - Device Independent I/O Statements
;
;	Copyright <C> 1986, Microsoft Corporation
;
;Purpose:
;
; BASIC Syntax mapping to included runtime entry points:
;
; - EOF Function:
;
;     EOF(file number)
;      |
;    I2 B$FEOF
;
; - LOC Function:
;
;      LOC(file number)
;	|
;     I4 B$FLOC
;
; - LOF Function:
;
;      LOF(file number)
;	|
;     I4 B$FLOF
;
; - CLOSE Statement - B$CLOS, no matter having parameters or not
;
;      CLOSE [[#]file number [,[#]filenumber...]]
;
;    Examples:
;
;      CLOSE		     CLOSE #1		     CLOSE 1,2
;	 |			    |			    |
;    B$CLOS			B$CLOS 		B$CLOS
;    parameter count 0		parameter count 1	parameter count 2
;    no parameter		1 in stack		2 & 1 in stack
;
; - WIDTH Statement:
;
;    Four different Syntax possibilities map to four runtime entry points:
;
;      WIDTH size			 WIDTH LPRINT size
;	 |				   |
;      B$WIDT				 B$LWID
;
;
;      WIDTH filenumber, size		 WIDTH device, size
;	 |				   |
;      B$DWID				 B$DWID
;
; - GET Statement - calls B$GET1 if no record number specified, or
;			  B$GET2 if a record number specified
;			  B$GET3 if record variable, but no record number
;			  B$GET4 if record variable, and record number
;
;      GET [#]filenumber [,[record number][,record variable]]
;
;    Examples:
;
;	GET #1		GET #2,4	GET #2,,FOO	GET #2,4,FOO
;	|		|		|		|
;	B$GET1 	B$GET2 	B$GET3 	B$GET4
;
;	Record Number is I4.
;
; - PUT Statement - calls B$PUT1 if no record number specified, or
;			  B$PUT2 if a record number specified
;			  B$PUT3 if record variable, but no record number
;			  B$PUT4 if record variable, and record number
;
;      PUT [#]filenumber [,[record number][,record variable]]
;
;    Examples:
;
;	PUT #1		PUT #2,4	PUT #2,,FOO	PUT #2,4,FOO
;	|		|		|		|
;	B$PUT1 	B$PUT2 	B$PUT3 	B$PUT4
;
; - OPEN Statement:
;
;    Two syntaxes are allowed:
;
;      OPEN mode,[#]filenumber,"filespec" [,reclength]
;	B$OOPN, which has C definition as follows with parameters in stack.
;	B$OOPN(U2 mode, I2 channel, sd *psdName, I2 cbRecord)
;	(refering the procedure head comments of B$OPEN for detail)
;
;      OPEN "filespec" [FOR mode][locktype] AS [#]filenumber [LEN=reclength]
;	B$OPEN, which has C definition as follows with parameters in stack.
;	B$OPEN(sd *psdName,I2 channel,I2 cbRecord,U2 mode,I2 access,I2 lock)
;	(refering the procedure head comments of B$OPEN for detail)
;
; - FILEATTR function
;
;	FILEATTR(file number, field)
;	|
;	I4 B$FATR
;
; - FREEFILE function
;
;	FREEFILE
;	|
;	I2 B$FREF
;
;******************************************************************************
	INCLUDE switch.inc
	INCLUDE rmacros.inc

;Code segments:
	useSeg	NH_TEXT 	;near heap
	useSeg	ER_TEXT 	;error handling
	useSeg	DV_TEXT 	;device independent I/O

;Data segments:
	useSeg	_DATA		;initialized variables
	useSeg	_BSS		;uninitialized variable

	INCLUDE seg.inc 	;set up segments
	INCLUDE baslibma.inc
	INCLUDE devdef.inc
	INCLUDE files.inc
	INCLUDE ascii.inc
	INCLUDE idmac.inc
	INCLUDE const.inc	
	INCLUDE rtps.inc	; constants shared with QBI

	SUBTTL	local constant definitions
	page

	InpSts	EQU	6	;input status for IOCTL

	TTY	EQU	0	;default b$PTRFIL is TTY

	PRSTM	EQU	0	;print statement
	CHANL	EQU	1	;#
	USING	EQU	2	;using
	WRSTM	EQU	4	;write statement
	LPSTM	EQU	8	;lprint statement

	SUBTTL	data definitions
	page

sBegin	_DATA			;initialized variables
	externB	b$IOFLAG	; Misc. IO flags.  Defined in GWINI.ASM
sEnd				;end of _DATA

sBegin	_BSS			;uninitialized variables

	staticW DispAddr,,1	; kept the dispatch address


	externW b$Buf2		; defined in GWINI.ASM
	PATH_LEN EQU b$Buf2	; save area for pathname length
				; sort of a waste, but convenient
	externW b$RECPTR
sEnd	;_BSS

	SUBTTL	code segments externals
	page

sBegin	DV_TEXT
	externNP	B$PtrDispatch
sEnd

sBegin	NH_TEXT 		;near heap
	externNP	B$LHFDBLOC	
	externNP	B$LHNXTFIL	
	externNP	B$LHLOCFDB	

	externFP	B$STDL		
	externNP	B$STALC 	

sEnd

sBegin	ER_TEXT 		;error code component
	externNP B$ERR_RVR
	externNP B$ERR_BFM
	externNP B$ERR_BRL	; Bad record length
	externNP B$ERR_FSA
	externNP B$ERR_BRN
	externNP B$ERR_IFN
	externNP B$ERR_FC
sEnd

	assumes CS,DV_TEXT	
sBegin	DV_TEXT 		; device I/O

	SUBTTL	LOC interface -- B$FLOC
	page
;***
;B$FLOC -- the current file location
;I4 B$FLOC (I2 channel)
;
;Purpose:
;	This function returns the current file location.  For a random or
;	sequential file, it returns the last record number been read/written
;	(a sequential has fix record length -- 128 bytes).  For a comm.
;	file, it returns the number of bytes in the input buffer waiting to
;	be read.
;Entry:
;	Parameter is in stack.
;	int	Channel
;Exit:
;	[DX|AX] = file location
;Uses:
;	none
;Exceptions:
;	illegal file number -- B$ERR_IFN
;*******************************************************************************

cProc	B$FLOC,<PUBLIC,FAR>
	ParmW	Channel 	;I2, channel #
cBegin
	MOV	AH,DV_LOC	;LOC function
LocLof: 			;common for LOC & LOF
	MOV	BX,Channel	;BX has the file number
	cCall	ComDsp		;dispatch to the actual working routine
				;(xxxx_LOC return results in DX:AX)
cEnd				;exit to caller

	SUBTTL	LOF interface -- B$FLOF
	page
;***
;B$FLOF -- return the length of the file
;I4 B$FLOF(I2 channel)
;
;Purpose:
;	For a disk file, it returns the size of the file.  For a comm.
;	file, it returns the amount of free space in the input buffer.
;Entry:
;	Parameter is in stack.
;	int	channel
;Exit:
;	[DX|AX] = bytes allocated for the file
;Uses:
;	none
;Exceptions:
;	illegal file number -- B$ERR_IFN
;*******************************************************************************

cProc	B$FLOF,<PUBLIC,FAR>
	ParmW	Channel 	;I2 channel #
cBegin
	MOV	AH,DV_LOF	;LOF Function
	JMP	SHORT LocLof	;dispatch to the actual working routine and
				; exit via B$FLOC
cEnd	nogen			;no code generated

	SUBTTL	WIDTH interface -- B$FWID
	page
;***
;B$FWID -- change the width of a file
;void B$FWID(I2 channel, I2 size)
;
;Purpose:
;	This routine changes the file width while the file is opened.
;	This is meaningful for LPT?.
;
;	Syntax is: WIDTH #filenum,filesiz
;
;	The routine sets the file width BEFORE file open is B$DWID.
;	The routine sets the screen width is B$WIDT.
;	The routine sets the LPRINT width is B$LWID.
;Entry:
;	Parameters in stack.
;	int	channel
;	int	wid
;Exit:
;	none
;Uses:
;	none
;Exceptions:
;	illegal file number -- B$ERR_IFN
;*******************************************************************************

cProc	B$FWID,<PUBLIC,FAR>
	ParmW	Channel 	;I2, channel #
	ParmW	Wid		;I2, width
cBegin
	MOV	BX,Channel	;BX has the file number
	MOV	DX,Wid		;DL has the width
	or	dh,dh		; if width > 255 error
	jnz	ercfc		; and
	or	dl,dl		; if width = 0 error
	jz	ercfc		

	MOV	AH,DV_WIDTH	;File width function
	cCall	ComDsp		;dispatch to the actual working routine
cEnd				;exit to caller

ercfc:	JMP	B$ERR_FC


	SUBTTL	Sequential random I/O interfaces -- B$GET1 & B$PUT1
	page
;***
;B$GET1 -- get a record sequentially
;void B$GET1(I2 channel)
;
;Purpose:
;	Get a record into random buffer if there is no record number specified.
;Entry:
;	Parameter in stack.
;	int	Channel
;Exit:
;	a record is read into the random buffer
;
;	Note: while calling RndDsp,
;		[BX]	= file number (used by B$LHFDBLOC/B$LocateFDB)
;		[AL]	= GET + Sequential flag (refer to RndDsp)
;Uses:
;	none
;Exceptions:
;	illegal file number -- B$ERR_IFN
;	bad file mode -- B$ERR_BFM
;*******************************************************************************

cProc	B$GET1,<PUBLIC,FAR>
	ParmW	Channel 	;I2, file number
cBegin
	XOR	AL,AL		;indicate GET without a specified RecNum
RndIO1:
	MOV	BX,Channel	;BX has the channel #
	cCall	RndDsp		;do it
cEnd				;exit to caller

;***
;B$PUT1 -- put a record sequentially
;void B$PUT1(I2 Channel)
;
;Purpose:
;	Put a record into random buffer with no specified record number.
;Entry:
;	Parameter in stack.
;	int		Channel
;Exit:
;	a record is put into the random buffer
;
;	Note: while calling RndDsp,
;		[BX]	= file number (used by B$LHFDBLOC/B$LocateFDB)
;		[AL]	= PUT + Sequential flag (refer to RndDsp)
;Uses:
;	none
;Exceptions:
;	illegal file number -- B$ERR_IFN
;	bad file mode -- B$ERR_BFM
;*******************************************************************************

cProc	B$PUT1,<PUBLIC,FAR>
	ParmW	Channel 	;I2 file number
cBegin
	MOV	AL,PutFlg	;indicate PUT without a specified RecNum
	JMP	SHORT RndIO1	;do it
cEnd	nogen			;exit to caller via B$GET1

	SUBTTL	Relative random I/O interfaces -- B$GET2 & B$PUT2
	page
;***
;B$GET2 -- get the record with record number specified
;void B$GET2(I2 Channel, I4 recnum)
;
;Purpose:
;	Get the record specified into random buffer.
;Entry:
;	Parameters in stack.
;	int		Channel
;	long int	RecNum
;Exit:
;	the record is read into random buffer
;
;	Note: while calling RndDsp,
;		[BX]	= file number (used by B$LHFDBLOC/B$LocateFDB)
;		[AL]	= GET + Relative flag (refer to RndDsp)
;		[CX|DX] = I4 specified record number
;Uses:
;	none
;Exceptions:
;	illegal file number -- B$ERR_IFN
;	bad file mode -- B$ERR_BFM
;	bad record number -- B$ERR_BRN
;*******************************************************************************
cProc	B$GET2,<PUBLIC,FAR>
	ParmW	Channel 	;I2 file number
	ParmD	RecNum		;I4 record number
cBegin
	MOV	AL,RelFlg	;indicate GET with record number specified
RndIO2:
	MOV	CX,Seg_RecNum	;CX = RecNum high
	OR	CX,CX		;can't be negative number
	JS	ERCBRN		;Brif negative, give "bad record number"
	MOV	DX,Off_RecNum	;DX = RecNum low
	MOV	BX,CX		;another copy of RecNum high in BX
	OR	BX,DX		;can't be zero
	JZ	ERCBRN		;Brif zero, give "bad record number"
	MOV	BX,Channel	;BX has the channel number
	cCall	RndDsp		;do the work
cEnd				;exit to caller

ERCBRN: JMP	B$ERR_BRN	;bad record number

;***
;B$PUT2 -- put a record with specified record number
;void B$PUT2(I2 Channel, I4 RecNum)
;
;Purpose:
;	Put a record into random buffer with specified record number.
;Entry:
;	Parmaters in stack.
;	int		Channel
;	long int	RecNum
;Exit:
;	a record is put into the random buffer.
;
;	Note: while calling RndDsp,
;		[BX]	= file number (used by B$LHFDBLOC/B$LocateFDB)
;		[AL]	= PUT + Relative flag (refer to RndDsp)
;		[CX|DX] = I4 specified record number
;Uses:
;	none
;Exceptions:
;	illegal file number -- B$ERR_IFN
;	bad file mode -- B$ERR_BFM
;	bad record number -- B$ERR_BRN
;*******************************************************************************

cProc	B$PUT2,<PUBLIC,FAR>
	ParmW	Channel 	;I2 file number
	ParmD	RecNum		;I4 record number
cBegin
	MOV	AL,RelFlg+PutFlg
				;indicate this is PUT with specified Rec Num
	JMP	SHORT RndIO2	;do it
cEnd	nogen			;exit via B$GET2

	SUBTTL	Relative random I/O interfaces -- B$GET3 & B$PUT3
	page
;***
;B$GET3 -- get the record with a record variable specified
;void B$GET3(I2 Channel, TYP far *recptr, I2 reclen)
;
;Purpose:
;	Get the record specified into the users record variable
;
; NOTE: This routine can take a far pointer to a movable item in a heap. This
; routine cannot directly or indirectly cause heap movement.
;
;Entry:
;	Parameters in stack.
;	int		Channel
;	typ far 	*RecPtr
;	int		RecLen
;
;Exit:
;
;Note: while calling RndDsp,
;	[BX]	= file number (used by B$LHFDBLOC/B$LocateFDB)
;	[AL]	= GET + Record flag (refer to RndDsp)
;	[SI]	= record length
;	[ES:DI] = Pointer to the users record
;
;Uses:
;	none
;
;Exceptions:
;	illegal file number -- B$ERR_IFN
;	bad file mode -- B$ERR_BFM
;	bad record number -- B$ERR_BRN
;*******************************************************************************

cProc	B$GET3,<PUBLIC,FAR>
ParmW	Channel 		; I2 file number
ParmD	RecPtr			; far record pointer
ParmW	RecLen			; i2 record length
cBegin
	MOV	AL,RecFlg	; indicate GET with record variable specified
RndIO3: 			
	MOV	BX,Channel	; [BX] = channel number
	PUSH	SI		
	PUSH	DI		
	PUSH	ES		

	MOV	SI,RecLen	; [SI] = Record length
	LES	DI,RecPtr	; [ES:DI] = Record Pointer
	cCall	RndDsp		; do the work

	POP	ES		
	POP	DI		
	POP	SI		
cEnd				; exit to caller

;***
;B$PUT3 -- put a record from specified record variable
;void B$PUT3(I2 Channel, TYP far *recptr, I2 reclen)
;
;Purpose:
;	Put a record from record var
;
; NOTE: This routine can take a far pointer to a movable item in a heap. This
; routine cannot directly or indirectly cause heap movement.
;
;Entry:
;	Parameters in stack.
;	int		Channel
;	typ far 	*RecPtr
;	int		RecLen
;
;Exit:
;
;Note: while calling RndDsp,
;	[BX]	= file number (used by B$LHFDBLOC/B$LocateFDB)
;	[AL]	= PUT + Record flag (refer to RndDsp)
;	[SI]	= record length
;	[ES:DI] = Pointer to the users record
;
;Uses:
;	none
;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -