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

📄 dosif.asm

📁 一个dos操作系统DRDOS的源码
💻 ASM
📖 第 1 页 / 共 5 页
字号:
;    File              : $Workfile: DOSIF.ASM$
;
;    Description       :
;
;    Original Author   : 
;
;    Last Edited By    : $Author: RGROSS$
;
;    Copyright         : (C) 1992 Digital Research (UK), Ltd.
;                                 Charnham Park
;                                 Hungerford, Berks.
;                                 U.K.
;
;    *** Current Edit History ***
;    *** End of Current Edit History ***
;
;    $Log: $
;    DOSIF.ASM 1.1 94/06/28 16:01:14 RGROSS
;    Initial PUT
;    DOSIF.ASM 1.16 94/06/28 16:01:28 IJACK
;    ms_x_expand returns error codes (for benefit of TRUENAME)
;    DOSIF.ASM 1.15 93/11/29 19:57:24 IJACK
;    
;    --------
;    
;    DOSIF.ASM 1.13 93/09/09 10:24:50 RFREEBOR
;    call_novell() now returns all allowed error codes.
;    
;    DOSIF.ASM 1.12 93/02/24 17:42:49 EHILL
;    _get_scr_width() function added.
;    
;    DOSIF.ASM 1.11 93/01/21 16:19:31 EHILL
;    
;    DOSIF.ASM 1.10 93/01/21 14:32:32 EHILL
;    
;    DOSIF.ASM 1.8 92/09/11 10:46:28 EHILL
;    
;    DOSIF.ASM 1.7 92/08/06 09:56:07 EHILL
;    Added DOS 5 calls to get and set memory allocation strategy and
;    upper memory link.
;    
;    DOSIF.ASM 1.6 92/07/10 17:47:13 EHILL
;    No comment
;
;    ENDLOG
;
;	This file provides all the assembler level interfaces to the
;	underlying operating system that are required by COMMAND.COM.
;	The type of functions calls that will be made is controlled
;	by a Assemble time flag.
;
;	Currently the Operating System Interfaces that are supported
;	are MS-DOS and Concurrent DOS 6.0.
;
;
;	Command Line Flags
;	==================
;
;	MSDOS		If defined then USE MSDOS function Calls
;	CDOS		If defined then Use Concurrent DOS Calls
;
;
;  2/Sep/87 jc	Convert the Concurrent IOCTL function to use the FDOS
;		command.
; 19/Oct/87 jc	Handle Fail on Get current directory correctly
; 23/Feb/88 jc	Use Text substitution function to get the path assigned
;		to floating drives (ms_x_subst).
;  3/Mar/88 jc	Support Server Password Error
;  9/Mar/88 jc	Return a NULL terminated string when an error occurs on the
;		ms_x_subst function.
; 15/Mar/88 jc	Correct ms_x_subst register corruption bug
; 13/Apr/88 jc	Support the FAR_READ and FAR_WRITE routines as well as external
;		copy buffer allocation via MEM_ALLOC and MEM_FREE
; 20/May/88 jc	Return the current country code to the calling application
; 25/May/88 jc	Missing dataOFFSET causing garbage offset to be passed
;		ms_x_subst.
; 18/Jul/88 jc	Modify LOGICAL_DRV test to detect substituted physical drives
; 17/Aug/88 jc	Return the current Break Status using DL not AL
; 22/Sep/88 jc	Replace MS_X_SUBST with more general MS_X_EXPAND routine
; 25/Jan/89 ij	If new DRDOS internal data layout get DPHTBL the new way
; 07/Feb/89 jc	Add the Get and Set Global Codepage MS_X_GETCP/MS_X_SETCP
; 25/Jan/89 ij	Get DPHTBL using DRDOS_DPHTBL_OFFSET equate
; 14/Apr/89 jjs	Add ms_x_setdev
; 31/May/89 ij	Get SYSDAT for DPHTBL using new f4458 function 
; 19/May/89 jc	Remove "Alternative" techniques of getting SYSDAT:DPHTABLE
; 20/Jun/89 js	ms_f_parse, ms_f_delete, for DEL cmd
; 30/Aug/89 js  ms_idle_ptr
;  6/Sep/89 ij	network_drvs really does something on DRDOS
; 16/Oct/89 ach Added double byte character set support routines: dbcs_init,
;		dbcs_expected and dbcs_lead.
; 18/Jan/90 ij	HILOAD interfaces added
;  4/Apr/90 ij	dbcs_init moved to cstart, use system table, then we can throw
;		away the init code
; 24-May-90 ij	ms_x_expand sets up ES....
; 17 Sep 90 ij	TMP Control Break kludge echo's ^C to console
;  4 Oct 90 ij	Use P_CAT, not P_HDS
; 15 Mar 91 jc	DRDOS_DPHTBL is now called SYSDAT_DPHTBL cos thats where it lives
; 28 May 91 ejh No longer use SYSDAT to determine if drives are physical,
;		logical or networked. See _physical_drive, _logical_drive and
;		_network_drive.
; 23 Jun 91 ejh SUBST and ASSIGN are now external commands, so the following
;		are no longer required:
;			_physical_drvs, _logical_drvs, _network_drvs
;			_physical_drive,_logical_drive,_network_drive
;  3 jul 91 ij	except for NETDRIVE in MDOS
;
; 18 Jun 92 ejh Added get_lines_page() function.
; 24 Jun 92 ejh Added novell_copy() function.

CGROUP	group	_TEXT
DGROUP	group	_DATA

codeOFFSET	equ	offset CGROUP:
dataOFFSET	equ	offset DGROUP:

EXT_SUBST	equ	1		; External Subst and Assign commands

CRET	MACRO	num
	ret
	ENDM

ifndef	??Version			;; Turbo Assembler always knows RETF
ifndef	retf				;; some versions of MASM do as well
retf	macro				;; define far return macro for others
	db	0cbh
	endm
endif
endif


ifndef	CDOSTMP
include	msdos.equ
endif

ifndef DOSPLUS
include system.def
include pd.def
include	ccpm.equ
;include udaa.def
include	net.def
include	mserror.equ
else
include	f52data.def
endif
;
ifdef	CDOSTMP
OK_RIF		equ	00111000b	; All Responsese are Valid
OK_RI		equ	00110000b	; Retry and Ignore are Valid
OK_RF		equ	00011000b	; Retry and Fail are Valid
;
;		      Structure of DOS DPB
;		      --------------------
;	The  layout  of  this  structure  is  a  guess  based  on
;	examples.  It is returned by PC MODE on functions 1Fh and
;	32h  and is required  by various  disk-related  utilities
;	like disk editors and CHKDSK.

DDSC_UNIT	equ	es:byte ptr 0		; absolute drive number
DDSC_RUNIT	equ	es:byte ptr 1		; relative unit number
DDSC_SECSIZE	equ	es:word ptr 2		; sector size in bytes
DDSC_CLMSK	equ	es:byte ptr 4		; sectors/cluster - 1
DDSC_CLSHF	equ	es:byte ptr 5		; log2 (sectors/cluster)
DDSC_FATADDR	equ	es:word ptr 6		; sector address of FAT
DDSC_NFATS	equ	es:byte ptr 8		; # of FAT copies
DDSC_DIRENT	equ	es:word ptr 9		; size of root directory
DDSC_DATADDR	equ	es:word ptr 11		; sector address of cluster #2
DDSC_NCLSTRS	equ	es:word ptr 13		; # of clusters on disk
DDSC_NFATRECS	equ	es:byte ptr 15		; # of sectors per FAT
DDSC_DIRADDR	equ	es:word ptr 16		; sector address of root dir
DDSC_DEVHEAD	equ	es:dword ptr 18		; device driver header
DDSC_MEDIA	equ	es:byte ptr 22		; current media byte
DDSC_FIRST	equ	es:byte ptr 23		; "drive never accessed" flag
DDSC_LINK	equ	es:dword ptr 24		; next drive's DDSC
DDSC_BLOCK	equ	es:word ptr 28		; next block to allocate
DDSC_FREE	equ	es:word ptr 30		; total free clusters on drive
DDSC_MAP	equ	es:word ptr 32		; free blocks/FAT sector
endif

BDOS_INT	equ	224		; ##jc##


_DATA	SEGMENT	byte public 'DATA'
	extrn	__psp:word
ifndef DOSPLUS
	extrn	_pd:dword		; Process Descriptor Pointer
endif
	extrn	_country:WORD

ifdef DOSPLUS
	extrn	dbcs_table_ptr:dword	; points to system DBCS table
endif

ifdef CDOSTMP
;
;	The following buffer is used by the P_PATH function.
;	FINDFILE uses the first three fields to get the full path and
;	filename of the command. 
;
exec_block	label	byte
exec_pathoff	dw	?		; Offset of ASCIIZ Load file
exec_pathseg	dw	?		; Segment of ASCIIZ Load File
exec_filetype	db	?		; File Type Index

fdos_data	dw	7 dup(0)	; FDOS parameter Block

mpb_start	dw	?		; Memory parameter Block
mpb_min		dw	?
mpb_max		dw	?
mpb_pdadr	dw	?
mpb_flags	dw	?

mfpb_start	dw	?		; Memory Free Parameter Block
mfpb_res	dw	?

country_data	label	word		; GET country data
cd_country	dw	?		; Requested Country Code
cd_codepage	dw	?		; Requested Code Page
cd_table	dw	?		; Table Number
cd_offset	dw	?		; Buffer Offset
cd_segment	dw	?		; Buffer Segment

valid		dw	0		; Valid Error Responses
retry_ip	dw	0		; Critical Error Retry IP
retry_sp	dw	0		; Critical Error Retry SP
crit_flg	db	FALSE		; Critical Section of Error Handler

include fdos.def
endif

ifdef NETWARE
ipx		label	dword
ipx_offset	dw	0
ipx_segment	dw	0
;
;	Socket Allocation by Novell
;
;	Socket Nos 4000 and 4001 appear to be used by the IPX internally
;	and these are NOT closed by the NET_WARE routine. All other USER
;	sockets are closed.
;
;	List of sockets to be closed on shutdown
;			Start	Count
socket		label	word
;;		dw	0001h,	0BB8h
		dw	4002h,	3FFFh - 2	; User Socket Numbers
		dw	0, 0

aes		label 	byte		; Event Control Block
aes_link	label	dword		; Link Field
aes_linkoff	dw	0
aes_linkseg	dw	0
aes_esr		label	dword		; Service Routine Address
aes_esroff	dw	codeOFFSET aes_retf
aes_esrseg	dw	0000
aes_inuse	db	0		; Flag Field
aes_workspc	db	5 dup(?)	; AES WorkSpace
endif
_DATA	ENDS

_TEXT	SEGMENT	byte public 'CODE'
	assume	cs:CGROUP, ds:DGROUP, es:DGROUP

extrn	_int_break:near		; Control-C Break Handler

ifdef	CDOSTMP
ifdef MWC
extrn	_critical_error:near	; Default Critical Error Handler
CRITICAL_ERR	equ	_critical_error
else
extrn	CRITICAL_ERROR:near	; Default Critical Error Handler
CRITICAL_ERR	equ	CRITICAL_ERROR
endif
endif

;
;	UWORD	psp_poke(WORD handle, BYTE ifn);
;
	Public	_psp_poke
_psp_poke:
	push	bp
	mov	bp,sp
	push	es

ifdef CDOSTMP
	mov	es,__psp		; ES:0 -> our PSP
else
	mov	ah,MS_P_GETPSP
	int	DOS_INT			; for software carousel
	mov	es,bx
endif
	les	bx,es:[0034h]		; ES:BX -> external file table
	add	bx,4[bp]		; ES:BX -> XFT entry for our handle
	mov	al,6[bp]		; get new value to use
	xchg	al,es:[bx]		; get old value, set new value
	xor	ah,ah

	pop	es
	pop	bp
	ret

ifndef	CDOSTMP


	Public	_ms_drv_set
;-----------
_ms_drv_set:
;-----------
	push	bp
	mov	bp,sp
	mov	dl,04[bp]
	mov	ah,MS_DRV_SET		; Select the Specified Disk Drive
	int	DOS_INT			; Nothing Returned to caller
	pop	bp
	ret

	Public	_ms_drv_get
;-----------
_ms_drv_get:
;-----------
	mov	ah,MS_DRV_GET		; Return the Currently selected
	int	DOS_INT			; disk drive
	cbw
	ret

	Public	_ms_drv_space
;------------
_ms_drv_space:
;------------
;
;	ret = _ms_drv_space (drive, &free, &secsiz, &nclust);
;	where:	drive	= 0, 1-16 is drive to use
;		free    = free cluster count
;		secsiz  = bytes/sector
;		nclust	= clusters/disk
;		ret	= sectors/cluster -or- (0xFFFFh)

	push	bp
	mov	bp,sp
	mov	dx,4[bp]
	mov	ah,MS_DRV_SPACE
	int	DOS_INT
	push	bx
	mov	bx,6[bp]		; get free cluster count
	pop	word ptr [bx]
	mov	bx,8[bp]
	mov	[bx],cx			; bytes/sector
	mov	bx,10[bp]
	mov	[bx],dx			; clusters/disk
	cbw
	pop	bp
	ret

	Public	_ms_s_country
;------------
_ms_s_country:
;------------
	push	bp
	mov	bp,sp
	mov	ax,MS_S_COUNTRY shl 8	; Get the curremt country information
	mov	dx,4[bp]		; and return the current country code
	int	DOS_INT			; to the calling application.
	mov	ax,bx
	pop	bp
	ret


	Public _ms_x_mkdir
;----------
_ms_x_mkdir:
;----------
	mov	ah,MS_X_MKDIR
	jmp	ms_dx_call


	Public	_ms_x_rmdir
;----------
_ms_x_rmdir:
;----------
	mov	ah,MS_X_RMDIR
	jmp	ms_dx_call


	Public	_ms_x_chdir
;----------
_ms_x_chdir:
;----------
	mov	ah,MS_X_CHDIR
	jmp	ms_dx_call

	Public	_ms_x_creat
;----------
_ms_x_creat:
;----------
	mov	ah,MS_X_CREAT
	jmp	ms_open_creat


	Public	_ms_x_open
;---------
_ms_x_open:
;---------
	mov	ah,MS_X_OPEN
ms_open_creat:
	push	bp
	mov	bp,sp
	mov	dx,4[bp]
	mov	cx,6[bp]		; get mode for new file (CREAT)
	mov	al,cl			;          or open mode (OPEN)
	int	DOS_INT
	jnc	ms_open_ret		; AX = handle if no error
	neg	ax			; else mark as error code
ms_open_ret:
	pop	bp
	ret

	Public _ms_x_close
;----------
_ms_x_close:
;----------
	push	bp
	mov	bp,sp
	mov	bx,4[bp]		; get the open handle
	mov	ah,MS_X_CLOSE		; get the function
	jmp	ms_call_dos		; call DOS, handle errors

	Public	_ms_x_unique
;----------
_ms_x_unique:
;----------
	mov	ah,MS_X_MKTEMP
	jmp	ms_open_creat

	Public	_ms_x_fdup
;----------
_ms_x_fdup:
;----------
	push	bp
	mov	bp,sp
	mov	cx,4[bp]		; get the destination handle
	mov	bx,6[bp]		; Get the current handle	
	mov	ah,MS_X_DUP2		; get the function
	jmp	ms_call_dos		; call DOS, handle errors


	Public	_far_read
;---------
_far_read:
;---------
	mov	ah,MS_X_READ
	jmp	far_read_write

	Public	_far_write
;----------
_far_write:
;----------
	mov	ah,MS_X_WRITE
far_read_write:
	push	bp
	mov	bp,sp
	push	ds
	mov	bx,4[bp]		; get file handle
	lds	dx,dword ptr 6[bp]	; get buffer address
	mov	cx,10[bp]		; get byte count
	int	DOS_INT			; call the DOS
	jnc	far_rw_ok		; skip if no error
	neg	ax			; else make it negative error code
far_rw_ok:
	pop	ds
	pop	bp
	ret


	Public	_ms_x_read
;---------
_ms_x_read:
;---------
	mov	ah,MS_X_READ
	jmp	ms_read_write

	Public	_ms_x_write
;----------
_ms_x_write:
;----------
	mov	ah,MS_X_WRITE
ms_read_write:
	push	bp
	mov	bp,sp
	mov	bx,4[bp]		; get file handle
	mov	dx,6[bp]		; get buffer address
	mov	cx,8[bp]		; get byte count
	int	DOS_INT			; call the DOS
	jnc	ms_rw_ok		; skip if no error
	neg	ax			; else make it negative error code
ms_rw_ok:
	pop	bp
	ret

	Public	_ms_x_unlink
;-----------
_ms_x_unlink:
;-----------
	mov	ah,MS_X_UNLINK
	jmp	ms_dx_call


	Public	_ms_x_lseek
;----------
_ms_x_lseek:
;----------
	push	bp
	mov	bp,sp
	mov	ah,MS_X_LSEEK		; get the function
	mov	bx,4[bp]		; get the file handle
	mov	dx,6[bp]		; get the offset
	mov	cx,8[bp]
	mov	al,10[bp]		; get the seek mode
	int	DOS_INT
	jnc	ms_lseek_ok		; skip if no errors
	neg	ax			; make error code negative
	cwd				; sign extend to long
ms_lseek_ok:
	mov	bx,dx			; AX:BX = DRC long return
	pop	bp
	ret

	Public	_ms_x_ioctl
;----------
_ms_x_ioctl:
;----------
	push	bp
	mov	bp,sp
	mov	bx,4[bp]		; get our handle
	mov	ah,MS_X_IOCTL		; get IO Control function
	mov	al,0			; get file/device status
	int	DOS_INT			; do INT 21h
	jnc	ms_x_i10
	neg	ax
ms_x_i10:	
	pop	bp			; 
	ret

	Public	_ms_x_setdev
;------------
_ms_x_setdev:
;------------
	push	bp
	mov	bp, sp
	mov	bx, 4[bp]		; handle
	mov	dx, 6[bp]		; byte value to set
	sub	dh, dh
	mov	ah, MS_X_IOCTL
	mov	al, 1
	int	DOS_INT
	jnc	ms_x_sd10
	neg	ax
ms_x_sd10:
	pop	bp
	ret

	Public	_ms_x_chmod
;----------
_ms_x_chmod:
;----------
	push	bp
	mov	bp,sp
	mov	ah,MS_X_CHMOD
	mov	dx,4[bp]
	mov	cx,6[bp]
	mov	al,8[bp]
	int	DOS_INT
	jnc	ms_chmod_ok
	neg	ax			; make error code negative
	jmp	ms_chmod_ret
ms_chmod_ok:
	sub	ax,ax			; assume no error
	cmp	byte ptr 8[bp],0	; getting attributes
	jne	ms_chmod_ret		; return ax = 0 if setting & no error
	xchg	ax,cx			; return ax = attrib otherwise
ms_chmod_ret:
	pop	bp
	ret

⌨️ 快捷键说明

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