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

📄 dosif.asm

📁 一个dos操作系统DRDOS的源码
💻 ASM
📖 第 1 页 / 共 5 页
字号:
;
;	ms_x_setcp(globalcp);
;
	Public	_ms_x_setcp
;-----------
_ms_x_setcp:	
;-----------
	push	bp
	mov	bp,sp
	mov	bx,04[bp]			; Get the requested CodePage
	mov	ax,MS_X_SETCP			; and make this the default
	int	DOS_INT
	jc	ms_x_getcp10
	xor	ax,ax
	pop	bp
	ret
endif
endif

ifdef CDOSTMP


	Public	_ms_drv_set
;-----------
_ms_drv_set:
;-----------
	push	bp
	mov	bp,sp
	mov	dl,04[bp]		; Get the Specified drive
	or	dl,80h			; Prevent any Select Errors
	mov	cl,DRV_SET		; and go select the bugger
	int	BDOS_INT
	pop	bp
	ret

	Public	_ms_drv_get
;-----------
_ms_drv_get:
;-----------
	mov	cl,DRV_GET		; Return the Currently selected
	int	BDOS_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	al,OK_RF			; Retry or Fail
	call	fdos_retry
	mov	FD_FUNC, FD_DISKINFO
	mov	ax,04[bp]
	mov	FD_DRIVE,ax
	call	fdos_entry
	or	ax,ax				; Check for Errors
	mov	ax,0FFFFh
	jnz	ms_drv_exit			; Error Exit

	push	es				; Save ES
	push	di
	les	di,FD_DPB			; Get the DPB Address

	mov	ax,es:DDSC_FREE[di]		; Get the number of free
	mov	bx,06[bp]			; clusters on the drive
	mov	[bx],ax

	mov	ax,es:DDSC_SECSIZE[di]		; Get the Physical Sector Size
	mov	bx,08[bp]			; in bytes
	mov	[bx],ax
	
	mov	ax,es:DDSC_NCLSTRS[di]		; Get the disk size in
	mov	bx,10[bp]			; clusters and save in DX
	mov	[bx],ax

	mov	al,es:DDSC_CLMSK[di]		; Get the sectors per Cluster -1
	cbw					; and save in AX
	inc	ax
	pop	di
	pop	es

ms_drv_exit:
	pop	bp
	CRET	8

	Public	_ms_s_country
;------------
_ms_s_country:
;------------
	push	bp
	mov	bp,sp
	mov	ax,04[bp]		; Get the data Block Offset

	mov	cd_country,0		; Get the Current Country	
	mov	cd_codepage,0		; Current CodePage
	mov	cd_table,0		; Country Information
	mov	cd_offset,ax		; Save the Buffer Offset
	mov	cd_segment,ds		; and the Buffer Segment

	mov	dx,dataOFFSET country_data
	mov	cl,S_GETCOUNTRY		; Get the country information
	int	BDOS_INT		; and return the current country
	pop	bp			; code to the caller
	CRET	2

	Public _ms_x_mkdir
;----------
_ms_x_mkdir:
;----------
	push	bp
	mov	bp,sp
	mov	al,OK_RIF			; Retry, Ignore or Fail
	call	fdos_retry
	mov	FD_FUNC,FD_MKDIR	; Make Directory

mkdir_10:
	mov	ax,04[bp]
	mov	FD_NAMEOFF,ax
	mov	FD_NAMESEG,ds
	call	fdos_entry
	pop	bp
	CRET	2
	
	Public	_ms_x_rmdir
;----------
_ms_x_rmdir:
;----------
	push	bp
	mov	bp,sp
	mov	al,OK_RIF			; Retry, Ignore or Fail
	call	fdos_retry
	mov	FD_FUNC,FD_RMDIR
	jmp	mkdir_10

	Public	_ms_x_chdir
;----------
_ms_x_chdir:
;----------
	push	bp
	mov	bp,sp
	mov	al,OK_RF			; Retry or Fail
	call	fdos_retry
	mov	FD_FUNC,FD_CHDIR
	jmp	mkdir_10

	Public	_ms_x_creat
;----------
_ms_x_creat:
;----------
	push	bp
	mov	bp,sp
	mov	al,OK_RF			; Retry or Fail
	call	fdos_retry
	mov	FD_FUNC,FD_CREAT
	jmp	ms_open_creat


	Public	_ms_x_open
;---------
_ms_x_open:
;---------
	push	bp
	mov	bp,sp
	mov	al,OK_RF			; Retry or Fail
	call	fdos_retry
	mov	FD_FUNC,FD_OPEN
ms_open_creat:
	mov	ax,4[bp]
	mov	FD_NAMEOFF,ax
	mov	FD_NAMESEG,ds
	mov	ax,6[bp]		; get mode for new file (CREAT)
	mov	FD_MODE,ax		; or the OPEN mode
	call	fdos_entry		; Call the FDOS and return either
	pop	bp			; a handle or error code
	CRET	4

	Public _ms_x_close
;----------
_ms_x_close:
;----------
	push	bp
	mov	bp,sp
	mov	al,OK_RIF			; Retry, Ignore or Fail
	call	fdos_retry
	mov	ax,4[bp]		; get the open handle
	mov	FD_FUNC,FD_CLOSE
	mov	FD_HANDLE,ax
	call	fdos_entry
	pop	bp
	CRET	2

	Public	_ms_x_unique
;----------
_ms_x_unique:
;----------
	push	bp
	mov	bp,sp
	mov	al,OK_RF			; Retry or Fail
	call	fdos_retry
	mov	FD_FUNC,FD_MKTEMP
	jmp	ms_open_creat

	Public	_ms_x_fdup
;----------
_ms_x_fdup:
;----------
	push	bp
	mov	bp,sp
	mov	al,OK_RIF			; Retry, Ignore or Fail
	call	fdos_retry
	mov	FD_FUNC,FD_FDUP
	mov	ax,4[bp]		; get the destination handle
	mov	FD_NEWHND,ax
	mov	ax,6[bp]		; Get the current handle	
	mov	FD_HANDLE,ax
	call	fdos_entry
	pop	bp
	CRET	4

	Public	_far_read
;---------
_far_read:
;---------
	push	bp
	mov	bp,sp
	mov	al,OK_RF			; Retry or Fail
	call	fdos_retry
	mov	FD_FUNC,FD_READ
	jmp	far_read_write

	Public	_far_write
;----------
_far_write:
;----------
	push	bp
	mov	bp,sp
	mov	al,OK_RIF			; Retry, Ignore or Fail
	call	fdos_retry
	mov	FD_FUNC,FD_WRITE

far_read_write:
	mov	ax,4[bp]		; get file handle
	mov	FD_HANDLE,ax
	mov	ax,6[bp]		; get buffer offset address
	mov	FD_BUFOFF,ax
	mov	ax,8[bp]		; get buffer Segment address
	mov	FD_BUFSEG,ax
	mov	ax,10[bp]		; get byte count
	mov	FD_COUNT,ax
	call	fdos_entry
	or	ax,ax
	jnz	far_rw_fail	
	mov	ax,FD_COUNT		; Get the Byte Count
far_rw_fail:
	pop	bp
	CRET	6

	Public	_ms_x_read
;---------
_ms_x_read:
;---------
	push	bp
	mov	bp,sp
	mov	al,OK_RF			; Retry or Fail
	call	fdos_retry
	mov	FD_FUNC,FD_READ
	jmp	ms_read_write

	Public	_ms_x_write
;----------
_ms_x_write:
;----------
	push	bp
	mov	bp,sp
	mov	al,OK_RIF			; Retry, Ignore or Fail
	call	fdos_retry
	mov	FD_FUNC,FD_WRITE

ms_read_write:
	mov	ax,4[bp]		; get file handle
	mov	FD_HANDLE,ax
	mov	ax,6[bp]		; get buffer address
	mov	FD_BUFOFF,ax
	mov	FD_BUFSEG,ds
	mov	ax,8[bp]		; get byte count
	mov	FD_COUNT,ax
	call	fdos_entry
	or	ax,ax
	jnz	ms_rw_fail	
	mov	ax,FD_COUNT		; Get the Byte Count
ms_rw_fail:
	pop	bp
	CRET	6

	Public	_ms_x_unlink
;-----------
_ms_x_unlink:
;-----------
	push	bp
	mov	bp,sp
	mov	al,OK_RIF			; Retry, Ignore or Fail
	call	fdos_retry
	mov	FD_FUNC,FD_UNLINK
	jmp	mkdir_10


	Public	_ms_x_lseek
;----------
_ms_x_lseek:
;----------
	push	bp
	mov	bp,sp
	mov	al,OK_RIF			; Retry, Ignore or Fail
	call	fdos_retry
	mov	FD_FUNC,FD_LSEEK	; get the function
	mov	ax,4[bp]		; get the file handle
	mov	FD_HANDLE,ax
	mov	ax,6[bp]		; get the offset
	mov	word ptr FD_OFFSET+0,ax
	mov	ax,8[bp]
	mov	word ptr FD_OFFSET+2,ax
	mov	ax,10[bp]		; get the seek mode
	mov	FD_METHOD,ax
	call	fdos_entry
	cwd
	or	ax,ax
	jnz	ms_lseek_fail		; skip if errors
	mov	ax,word ptr FD_OFFSET+0 ; Return the New Location
	mov	dx,word ptr FD_OFFSET+2
ms_lseek_fail:
	mov	bx,dx			; AX:BX = DRC long return
	pop	bp
	CRET	8


	Public	_ms_x_ioctl
;----------
_ms_x_ioctl:
;----------
	push	bp
	mov	bp,sp
	mov	al,OK_RF		; Retry or Fail
	call	fdos_retry
	mov	ax,4[bp]		; get Enquiry Handle
	mov	FD_FUNC,FD_IOCTL	; Use the IOCTL function
	mov	FD_HANDLE,ax		; For Handle AX
	mov	FD_CTLFUNC,0000		; Get the Handle Status
	mov	FD_CTLSTAT,0		; Invalidate CTLSTAT
	call	fdos_entry		; Call the FDOS
	mov	ax,FD_CTLSTAT		; and return the STATUS
	pop	bp
	CRET	2

	Public	_ms_x_setdev
;------------
_ms_x_setdev:
;------------
	push	bp
	mov	bp,sp
	mov	al,OK_RF		; Retry or Fail
	call	fdos_retry
	mov	ax,4[bp]		; get Handle
	mov	FD_HANDLE,ax
	mov	FD_FUNC,FD_IOCTL	; Use the IOCTL function
	mov	FD_CTLFUNC,1		; Set device info
	mov	ax, 6[bp]		; status to set
	sub	ah, ah
	mov	FD_CTLSTAT,ax
	call	fdos_entry		; Call the FDOS
	mov	ax,FD_CTLSTAT		; and return the STATUS
	pop	bp
	CRET	2

	Public	_ms_x_chmod
;----------
_ms_x_chmod:			;	ms_x_chmod(path, attrib, get/set)
;----------
	push	bp
	mov	bp,sp
	mov	al,OK_RIF		; Retry, Ignore or Fail
	call	fdos_retry
	mov	FD_FUNC,FD_CHMOD
	mov	ax,4[bp]		; Get the FileName
	mov	FD_NAMEOFF,ax
	mov	FD_NAMESEG,ds
	mov	ax,6[bp]		; Get the Required Attributes
	mov	FD_ATTRIB,ax
	mov	ax,8[bp]		; Finally Get the GET/SET flag
	mov	FD_FLAG,ax
	call	fdos_entry		; Returns with AX equal to the  
	or	ax,ax			; error code or with the file
	js	chmod10			; attributes.
	mov	ax,FD_ATTRIB
chmod10:
	pop	bp
	CRET	6


	Public	_ms_x_curdir
;-----------
_ms_x_curdir:
;-----------
	push	bp
	mov	bp,sp
	mov	al,OK_RF		; Retry or Fail
	call	fdos_retry
	mov	FD_FUNC,FD_GETDIR
	mov	ax,04[bp]		; Get the drive
	mov	FD_DRIVE,ax
	mov	bx,06[bp]		; and then the path
	mov	byte ptr [bx],0		; Put a Zero byte in the buffer in
	mov	FD_PATHOFF,bx		; case the command fails and the
	mov	FD_PATHSEG,ds		; user selects the FAIL Option
	call	fdos_entry
	pop	bp
	CRET	4

;
;	ms_x_expand(dstbuf, srcbuf) returns the full path of SRCBUF
;
	Public	_ms_x_expand
;-----------
_ms_x_expand:
;-----------
	push	bp
	mov	bp,sp
	mov	al,OK_RF		; Retry or Fail
	call	fdos_retry
	mov	FD_FUNC,FD_EXPAND
	mov	ax,06[bp]		; Get Source Buffer Offset
	mov	FD_ONAMEOFF,ax
	mov	FD_ONAMESEG,ds
	mov	bx,04[bp]		; Get the destination string
	mov	byte ptr [bx],0		; address and force it to be a NULL
	mov	FD_NNAMEOFF,bx		; terminated string in case of errors
	mov	FD_NNAMESEG,ds
	call	fdos_entry
	pop	bp
	CRET	4

	Public	_ms_x_wait
;---------
_ms_x_wait:		; retrieve child return code
;---------
	mov	cl,P_EXITCODE		; Return the Exit Code
	mov	dx,0FFFFh		; Get the Exit Code
	int	BDOS_INT
	CRET	0

	Public	_ms_x_first
;----------
_ms_x_first:
;----------
	push	bp
	mov	bp,sp

	mov	dx,8[bp]		; get DMA buffer address
	mov	cl,F_DMAOFF
	call	bdos_entry

	mov	dx,ds			;##jc##
	mov	cl,F_DMASEG		;##jc##
	call	bdos_entry		;##jc##

	mov	al,OK_RF		; Retry or Fail
	call	fdos_retry

	mov	FD_FUNC,FD_FFIRST	; Search First
	mov	ax,04[bp]		; Get the FileName
	mov	FD_NAMEOFF,ax
	mov	FD_NAMESEG,ds
	mov	ax,06[bp]		; Get the Attributes
	mov	FD_ATTRIB,ax
	mov	FD_COUNT, 0		; Search for a File at a time
	call	fdos_entry
	cmp	ax,1			; Did we match 1 entry
	jnz	ms_x_f10		; No so return Error Code
	mov	ax,0			; Return Zero on sucess
ms_x_f10:
	pop	bp
	CRET	6

	Public	_ms_x_next
;---------
_ms_x_next:
;---------
	push	bp
	mov	bp,sp

	mov	dx,4[bp]		; get DMA buffer address
	mov	cl,F_DMAOFF
	call	bdos_entry

	mov	dx,ds			;##jc##
	mov	cl,F_DMASEG		;##jc##
	call	bdos_entry		;##jc##

	mov	al,OK_RF		; Retry or Fail
	call	fdos_retry

	mov	FD_FUNC,FD_FNEXT	; Search Next
	mov	FD_NEXTCNT, 0		; Search for a File at a time
	call	fdos_entry
	cmp	ax,1			; Did we match 1 entry
	jnz	ms_x_n0		; No so return Error Code
	mov	ax,0			; Return Zero on sucess
ms_x_n0:
	pop	bp
	CRET	2


	Public _ms_x_rename
;-----------
_ms_x_rename:
;-----------
	push	bp
	mov	bp,sp
	mov	al,OK_RIF		; Retry, Ignore or Fail
	call	fdos_retry
	mov	FD_FUNC,FD_RENAME
	mov	ax,04[bp]		; Get the Old Name
	mov	FD_ONAMEOFF,ax
	mov	FD_ONAMESEG,ds
	mov	ax,06[bp]		; Get the New Name
	mov	FD_NNAMEOFF,ax
	mov	FD_NNAMESEG,ds
	call	fdos_entry
	pop	bp
	CRET	4

	Public	_ms_x_datetime
;-------------
_ms_x_datetime:			; ms_x_datetime (gsflag, h, &time, &date);
;-------------
	push	bp
	mov	bp,sp
	mov	al,OK_RIF		; Retry, Ignore or Fail
	call	fdos_retry
	mov	FD_FUNC,FD_DATETIME	; set/get Time Stamp
	mov	ax,4[bp]		; get/set subfunction (0/1)
	mov	FD_SFLAG,ax
	mov	ax,6[bp]		; get handle
	mov	FD_HANDLE,ax
	mov	bx,8[bp]		; get address of time
	mov	ax,[bx]			; get time
	mov	FD_TIME,ax		; and Save
	mov	bx,10[bp]		; get address of date
	mov	ax,[bx]			; get date
	mov	FD_DATE,ax
	call	fdos_entry
	or	ax,ax			; Skip if Failed
	jnz	ms_dt_ret
	mov	ax,FD_TIME
	mov	bx,8[bp]		; get time address
	mov	[bx],ax			; update time
	mov	ax,FD_DATE
	mov	bx,10[bp]		; get date address
	mov	[bx],ax			; update date
	xor	ax,ax
ms_dt_ret:
	pop	bp
	CRET	8


;
;	The following routines allow COMMAND.COM to manipulate
;	the system time and date. Four functions are provided and
;	these are GETDATE, SETDATE, GETTIME and SETTIME
;
;	Date information is passed and return in a structure which 
;	has the following format.
;
;	WORD		Year (1980 - 2099)

⌨️ 快捷键说明

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