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

📄 int21h.asm

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 ASM
📖 第 1 页 / 共 3 页
字号:
	mov	eax,ebx
	cmp	eax,cs:_lobufsize
	jbe	@@1
	mov	eax,cs:_lobufsize
@@1:	mov	[ebp+18h],ax			; store CX in structure
	mov	ecx,eax
	mov	edi,cs:_lobufbase
	jcxz	@@done
	shr	cx,2
	rep	movs dword ptr es:[edi],[esi]
	mov	cl,al
	and	cl,03h
	rep	movs byte ptr es:[edi],[esi]
	mov	ecx,eax				; preserve EAX in ECX
	call	int21h				; DOS write to file
	movzx	eax,word ptr [ebp+1Ch]		; EAX=bytes written
	test	byte ptr [ebp+20h],1		; check for error
	jnz	@@err
	add	edx,eax				; adjust bytes written
	sub	ebx,ecx				; adjust bytes to write
	ja	@@0				; loop until done
@@done:	add	esp,32h
	mov	[esp+1Ch],edx			; store bytes count
	jmp	@__ok
@@err:	add	esp,32h
	mov	[esp+1Ch],eax			; error writing, store errcode
	jmp	@__err

@@low:	mov	ax,cs:_seg_buf
	mov	word ptr [ebp+24h],ax		; store DS in structure
	mov	word ptr [ebp+18h],cx		; store CX in structure
	mov	word ptr [ebp+14h],0		; store DX in structure
	mov	byte ptr [ebp+1Dh],40h		; store AH in structure
	jcxz	@@l1
	mov	edi,cs:_lobufbase
	mov	al,cl
	shr	cx,2
	rep	movs dword ptr es:[edi],[esi]
	mov	cl,al
	and	cl,03h
	rep	movs byte ptr es:[edi],[esi]
@@l1:	call	int21h				; DOS write to file
	movzx	eax,word ptr [ebp+1Ch]		; EAX=bytes written
	test	byte ptr [ebp+20h],1		; check for error
	jnz	@@err
	add	edx,eax				; adjust bytes written
	jmp	@@done


;=============================================================================
; Delete File
;  In:	DS:EDX = file name
;  Out:	-
;
;@__41h:	jmp	@__39h



;=============================================================================
; Move File Ptr
;  In:	ECX:EDX = ptr, AL = mode
;  Out:	EDX:EAX = ptr
;
@__42h:	call	@__all
	mov	[esp+1Ch],eax
	jnz	@__err
	mov	[esp+14h],edx
	jmp	@__ok



;=============================================================================
; Change File Attributes
;  In:	DS:EDX = file name
;  Out:	-
;
@__43h:	call	@__std
	jz	@@1
	mov	[esp+1Ch],eax
	jmp	@__err
@@1:	mov	[esp+18h],ecx
	jmp	@__ok



;=============================================================================
; Get Directory
;  In:	DL = drive
;	DS:ESI = buffer
;  Out:	-
;
@__47h:	sub	esp,32h
	mov	ebp,esp
	mov	[ebp+1Ch],ax
	mov	[ebp+14h],dx
	mov	ax,cs:_seg_buf
	mov	[ebp+24h],ax
	mov	word ptr [ebp+04h],0
	call	int21h
	test	byte ptr [ebp+20h],1
	jnz	@@err
	push	ds
	pop	es
	mov	edi,esi
	mov	ds,cs:_sel_ds
	mov	esi,_lobufbase
@@1:	lods	byte ptr ds:[esi]
	stos	byte ptr es:[edi]
	test	al,al
	jnz	@@1
	add	esp,32h
	jmp	@__ok
@@err:	movzx	eax,word ptr [ebp+1Ch]
	add	esp,32h
	mov	[esp+1Ch],eax
	jmp	@__err



;=============================================================================
; Allocate DOS Memory
;  In:	EBX = bytes to allocate
;  Out:	EAX = selector
;
@__48h:	mov	ax,0100h
	int	31h
	jc	@@1
	movzx	edx,dx
	mov	[esp+1Ch],edx
	jmp	@__ok
@@1:	movzx	eax,ax
	movzx	ebx,bx
	mov	[esp+1Ch],eax
	mov	[esp+10h],ebx
	jmp	@__err



;=============================================================================
; Deallocate DOS Memory
;  In:	ES = selector
;  Out:	-
;
@__49h:	mov	ax,0101h
	mov	dx,es
	int	31h
	jnc	@@0
	movzx	eax,ax
	mov	[esp+1Ch],eax
	jmp	@__err
@@0:	mov	word ptr [esp+20h],0
	jmp	@__ok



;=============================================================================
; Resize DOS Memory
;  In:	ES = selector, EBX = new size
;  Out:	-
;
@__4Ah:	mov	ax,0102h
	mov	dx,es
	int	31h
	jnc	@__ok
	movzx	eax,ax
	movzx	ebx,bx
	mov	[esp+1Ch],eax
	mov	[esp+10h],ebx
	jmp	@__err



;=============================================================================
; Execute Program (sub-func AL=00h)
;  In:	AL = 00h
;	DS:EDX = path name
;	ES:EBX = parameter block
;  Out:	-
;
@__4Bh:	test	al,al			; only subfunction AL=00h supported
	jnz	@__err
	cmp	cs:_lobufsize,0400h	; buffer size must be at least 1Kb
	jb	@__err			; if less, return -1

	sub	esp,32h
	mov	ebp,esp
	mov	[ebp+1Ch],ax		; put AX in structure

	push	es
	mov	es,cs:_sel_ds
	mov	edi,cs:_lobufbase
	mov	esi,edx
	add	edi,100h
@@1:	lods	byte ptr ds:[esi]	; copy Path\Name into buffer
	stos	byte ptr es:[edi]
	test	al,al
	jnz	@@1
	pop	es

	push	ds es
	mov	esi,es:[ebx+06h]
	mov	edi,cs:_lobufbase
	mov	ds,es:[ebx+0Ah]
	mov	es,cs:_sel_ds
	add	edi,180h
	movzx	ecx,byte ptr ds:[esi]
	inc	cx
	inc	cx
	rep	movs byte ptr es:[edi],[esi]	; copy command line
	pop	es ds

	push	ds es
	mov	edi,es:[ebx+00h]	; get environment
	mov	ax,es:[ebx+04h]
	test	ax,ax			; check env selector is 0
	jz	@@3			; if yes, jump
	mov	es,ax
	xor	ax,ax
	mov	esi,edi
	or	ecx,-1
@@2:	repne	scas byte ptr es:[edi]
	dec	ecx
	scas	byte ptr es:[edi]
	jnz	@@2
	not	ecx
	mov	ax,0100h		; allocate mem for environment
	mov	bx,cx
	shr	bx,4
	inc	bx
	int	31h
	jc	@@4
	push	es
	pop	ds
	mov	es,dx
	xor	edi,edi
	rep	movs byte ptr es:[edi],[esi]	; copy environment
@@3:	mov	ds,cs:_sel_ds
	mov	edi,_lobufbase
	mov	word ptr [edi+00h],ax
	mov	ax,_seg_buf
	mov	word ptr [edi+02h],180h
	mov	word ptr [edi+04h],ax
	mov	ax,_seg_es
	mov	word ptr [edi+06h],5Ch
	mov	word ptr [edi+08h],ax
	mov	word ptr [edi+0Ah],6Ch
	mov	word ptr [edi+0Ch],ax
@@4:	pop	es ds
	jc	@@err

	push	dx			; save env selector
	mov	ds,cs:_sel_ds
	mov	ax,_seg_buf
	mov	word ptr [ebp+22h],ax
	mov	word ptr [ebp+24h],ax
	mov	word ptr [ebp+10h],0000h
	mov	word ptr [ebp+14h],0100h

	cmp	_sys_type,3
	jz	@@5
	mov	eax,cr0
	mov	edi,eax
	and	al,0FBh
	mov	cr0,eax
@@5:	call	uninstall_client_ints
	call	int21h
	call	install_client_ints
	cmp	_sys_type,3
	jz	@@6
	mov	cr0,edi

@@6:	pop	dx				; restore env sel
	mov	ax,0101h
	int	31h

	movzx	eax,word ptr [ebp+1Ch]		; get return code
	test	byte ptr [ebp+20h],01h		; check carry flag
	lea	esp,[esp+32h]
	mov	[esp+1Ch],eax			; put return code in AX
	jnz	@__err				; if error, set carry on ret
	jmp	@__ok

@@err:	add	esp,32h
	mov	dword ptr [esp+1Ch],-1
	jmp	@__err



;=============================================================================
; Terminate Program
;  In:	AL = error code
;  Out:	-
;
@__4Ch:	cli				; disable interrupts
	cld
	mov	ds,cs:_sel_ds		; restore SEG registers
	mov	es,_sel_es
	lss	esp,fword ptr _sel_esp	; set default stack
	push	ax
	mov	ax,_sel_env
	mov	es:[002Ch],ax		; restore default environment

	cmp	_sys_type,3		; if under DPMI, do not clear DRx
	jz	@@1
	xor	eax,eax
	mov	dr7,eax

@@1:	push	es			; undefine Mouse ISR
	mov	ax,000Ch
	xor	edx,edx
	mov	cx,dx
	mov	es,dx
	int	33h
	pop	es

	mov	dx,_mus_backoff		; free mouse callback
	mov	cx,_mus_backseg
	mov	ax,cx
	or	ax,dx
	jz	@@2
	mov	ax,0304h
	int	31h

@@2:	mov	ecx,_app_num_objects	; deallocate selectors
	jcxz	@@4
@@3:	mov	ax,0001h
	mov	bx,_app_buf_allocsel[ecx*2]
	int	31h
	loop	@@3

@@4:	call	check_inttab
	call	restore_inttab
	call	uninstall_client_ints

@@5:	mov	ax,0001h			; free ZERO selector
	mov	bx,cs:_sel_zero
	int	31h

	xor	ax,ax
	mov	fs,ax
	mov	gs,ax
	pop	ax
	db	66h				; 32-bit jump
	jmp	cs:_int21_ip			; exit with errorcode in AL



;=============================================================================
; Find First File
;  In:	CX = file attributes
;	DS:EDX = file name
;  Out:	-
;
@__4Eh:	call	@__std
	jnz	@@err
	mov	ds,cs:_dta_sel
	mov	esi,cs:_dta_off
	mov	es,cs:_app_dta_sel
	mov	edi,cs:_app_dta_off
	mov	ecx,2Bh
	rep	movs byte ptr es:[edi],[esi]
	jmp	@__ok
@@err:	mov	[esp+1Ch],eax
	jmp	@__err



;=============================================================================
; Find Next File
;  In:	-
;  Out:	-
;
@__4Fh:	mov	ds,cs:_app_dta_sel
	mov	esi,cs:_app_dta_off
	mov	es,cs:_dta_sel
	mov	edi,cs:_dta_off
	mov	ecx,2Bh
	rep	movs byte ptr es:[edi],[esi]
	call	@__all
	jnz	@@err
	mov	ds,cs:_dta_sel
	mov	esi,cs:_dta_off
	mov	es,cs:_app_dta_sel
	mov	edi,cs:_app_dta_off
	mov	ecx,2Bh
	rep	movs byte ptr es:[edi],[esi]
	jmp	@__ok
@@err:	mov	[esp+1Ch],eax
	jmp	@__err



;=============================================================================
; Get PSP Segment
;  In:	-
;  Out:	EBX = PSP segment
;
@__51h:	movzx	eax,cs:_seg_es
	mov	[esp+10h],eax
	jmp	@__ok



;=============================================================================
; Rename File
;  In:	DS:EDX = old filename
;	ES:EDI = new filename
;  Out:	-
;
@__56h:	sub	esp,32h
	mov	ebp,esp
	mov	[ebp+1Ch],ax
	or	ecx,-1
	xor	al,al
	repne	scas byte ptr es:[edi]
	not	ecx
	sub	edi,ecx
	mov	esi,edi
	push	ds
	push	es
	pop	ds
	mov	es,cs:_sel_ds
	mov	edi,cs:_lobufbase
	rep	movs byte ptr es:[edi],[esi]
	pop	ds
	mov	ecx,edi
	mov	ebx,cs:_lobufbase
	sub	ecx,ebx
	xchg	ecx,ebx
	push	ds
	pop	es
	mov	esi,edx
	xchg	esi,edi
	or	ecx,-1
	xor	al,al
	repne	scas byte ptr es:[edi]
	not	ecx
	sub	edi,ecx
	xchg	esi,edi
	mov	es,cs:_sel_ds
	rep	movs byte ptr es:[edi],[esi]
	mov	ax,cs:_seg_buf
	mov	[ebp+24h],ax
	mov	[ebp+22h],ax
	mov	word ptr [ebp+00h],0
	mov	[ebp+14h],bx
	call	int21h
	jmp	@__tst



;=============================================================================
; Create Temp File
;  In:	DS:EDX = file name
;  Out:	-
;
;@__5Ah:	jmp	@__39h



;=============================================================================
; Create New File
;  In:	CX = attributes
;	DS:EDX = file name
;  Out:	-
;
;@__5Bh:	jmp	@__39h



;=============================================================================
; Get PSP Selector
;  In:	-
;  Out:	BX = PSP selector
;
@__62h:	movzx	eax,cs:_sel_es
	mov	[esp+10h],eax
	jmp	@__ok



;=============================================================================
; Win95 Get Short (8.3) filename
;  In:	CL = 00/01/02h
;	CH = SUBST expansion flag
;	DS:ESI = ASCIIZ long filename or path
;	ES:EDI = 261/128/261-byte buffer for short name
; Out:	-
;
@_7160:	sub	esp,32h
	mov	ebp,esp
	push	es edi
	mov	[ebp+1Ch],ax
	mov	[ebp+18h],cx
	mov	es,cs:_sel_ds
	mov	edi,cs:_lobufbase
	add	edi,0200h
@@1:	lods	byte ptr ds:[esi]
	stos	byte ptr es:[edi]
	test	al,al
	jnz	@@1

⌨️ 快捷键说明

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