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

📄 misc.asm

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	mov	cx,bx
	mov	di,offs start+40h
	rep	movsb
	xor	al,al
	stosb
@@full:	pop	es ds
	stc
	ret
@@done:	pop	es ds
	clc
	ret

;=============================================================================
update_environment:
	push	ds es
	call	check_if_fullname		; check if full path provided
	jc	@@skip				; if yes, skip copying
	mov	ah,19h
	int	21h				; get drive letter
	mov	dl,al
	add	al,'A'
	mov	byte ptr [start+40h],al		; set drive
	mov	word ptr [start+41h],'\:'
	inc	dx
	mov	ah,47h
	mov	esi,offs start+43h
	int	21h				; get current directory
	push	ds
	pop	es
	xor	al,al
	mov	di,si
	mov	cx,64
	repne	scasb				; get length of dir string
	cmp	byte ptr [di-2],'\'
	jnz	@@0
	dec	di
@@0:	mov	byte ptr [di-1],'\'
	mov	si,offs start
	mov	cx,64
@@1:	lodsb
	stosb
	test	al,al
	loopne	@@1
@@skip:	push	ds
	pop	es
	xor	al,al
	mov	cx,-1
	mov	di,offs start+40h
	repne	scasb
	not	cx
	mov	bx,cx
	pop	es
	push	es
	mov	ax,es:[002Ch]		; get environment selector
	test	ax,ax			; check if selector is NULL
	jz	@@err			; if yes, jump to error
	lar	cx,ax
	jnz	@@err
	mov	es,ax
	xor	al,al
	xor	di,di
	mov	cx,-1
@@2:	repne	scasb
	scasb
	jnz	@@2
	inc	di
	inc	di
	mov	cx,-1
	mov	dx,di
	repne	scasb
	not	cx
	cmp	bx,cx
	ja	create_new_environment
	mov	cx,bx
	mov	di,dx
	mov	si,offs start+40h
	rep	movsb
	pop	es ds
	ret
@@err:	mov	ax,2000h
	jmp	report_error

create_new_environment:
	push	bx
	mov	cx,-1
	xor	di,di
@@1:	repne	scasb			; get size of environment
	dec	cx
	scasb
	jnz	@@1
	not	cx
	inc	cx
	inc	cx
	push	cx
	add	bx,cx
	shr	bx,4
	inc	bx
	mov	ax,0100h
	int	31h
	pop	cx
	jc	@@err
	push	es
	pop	ds
	mov	es,dx
	xor	si,si
	xor	di,di
	rep	movsb
	pop	cx
	mov	si,offs start+40h
	push	cs
	pop	ds
	rep	movsb
	pop	es ds
	mov	es:[002Ch],dx
	ret
@@err:	mov	ax,2000h
	jmp	report_error


;=============================================================================
open_exec:
	push	ds es
	mov	ax,es:[002Ch]		; get environment selector
	test	ax,ax			; check if selector is NULL
	jz	@@err			; if yes, jump to error
	lar	cx,ax
	jnz	@@err
	mov	es,ax
	xor	ax,ax
	xor	di,di
	mov	cx,0FFFFh
@@1:	repne	scasb			; look for end of environment
	scasb
	jcxz	@@err			; reached end of environment
	jnz	@@1
	inc	di
	inc	di
	push	ds es
	pop	ds es
	push	di
	mov	si,di
	mov	di,offs start
@@2:	lodsb
	stosb
	test	al,al
	jnz	@@2
	pop	di
	movzx	edx,di			; DS:EDX = pointer to exec name
	mov	ax,3DC0h		; open file
	int	21h
	pop	es ds
	mov	_exec_handle,ax		; store file handle
	mov	ax,2001h
	jc	file_error		; if error, jump
	ret
@@err:	mov	ax,2000h
	jmp	report_error




;=============================================================================
load_exec_header:
	xor	edx,edx			; DS:EDX = ptr
	mov	ecx,64			; ECX = 64 bytes to load
	mov	_err_code,2002h		; "error in exec file"
	call	load_fs_block
	cmp	word ptr fs:[0000h],'ZM'; exec must be 'MZ' file type
	jnz	file_errorm
	mov	eax,fs:[003Ch]		; get start of 32-bit code
	mov	edx,fs:[0018h]		; get start of MZ reloc-table
	mov	_exec_start,eax
	ret




;=============================================================================
open_extrn_exec:
	push	ds es
	push	ds es			; swap DS and ES
	pop	ds es
	mov	di,offs start		; copy application exec name
	rep	movsb
	push	es
	pop	ds
	mov	byte ptr [di],0
	mov	edx,offs start
	mov	ax,3DC0h
	int	21h
	jc	@@1			; if error opening, try ".EXE"
	pop	es ds
	mov	_exec_handle,ax
	ret

@@1:	mov	bx,offs start
@@2:	cmp	byte ptr [bx],2Eh
	stc
	jz	@@err
	inc	bx
	cmp	bx,di
	jb	@@2
	mov	eax,4558452Eh
	cmp	eax,[di-4]
	stc
	jz	@@err
	mov	eax,6578652Eh
	cmp	eax,[di-4]
	stc
	jz	@@err
	mov	[di],eax
	mov	byte ptr [di+4],0
	mov	ax,3DC0h
	int	21h
@@err:	pop	es ds
	mov	_exec_handle,ax
	mov	ax,3001h
	jc	file_error
	ret


;=============================================================================
load_extrn_exec_header:
	xor	edx,edx			; DS:EDX = ptr
	mov	ecx,64			; ECX = 64 bytes to load
	mov	_err_code,3002h		; "error in app file"
	call	load_fs_block
	call	seek_from_start		; move to file start

	xor	ebp,ebp
	mov	_exec_start,ebp		; default start of exec offset and
	mov	_app_off_datapages,ebp	;  LE/LX data offset in file
	cmp	word ptr fs:[0000h],'ZM'; is exec 'MZ' file type
	jnz	search_for_le		; if not, search for known exec type
	mov	eax,fs:[0018h]		; MZ reloc-tab must be at offset 0040h
	cmp	ax,40h
	jnz	search_for_mz
	mov	eax,fs:[003Ch]		; if yes, get start of 32-bit code
	test	ax,ax			; check if it is bound
	jz	search_for_mz		; if not, search
	mov	_exec_start,eax
	ret


search_for_mz:
	xor	esi,esi
@@0:	movzx	eax,word ptr fs:[0004h]	; get pages in file
	shl	eax,9			; *512
	movzx	ebx,word ptr fs:[0002h]	; get bytes on last page
	add	eax,ebx
	mov	bx,fs:[0000h]
	cmp	bx,'ZM'
	jz	@@1
	cmp	bx,'WB'
	jz	@@2
	jmp	@@3
@@1:	sub	eax,0200h
@@2:	mov	esi,ebp
	add	ebp,eax
	mov	edx,ebp
	call	seek_from_start
	mov	ecx,64
	xor	edx,edx
	call	load_fs_block
	test	eax,eax
	jnz	@@0
	mov	ax,3003h
	jmp	file_error		; if zero, no app in file
@@3:	mov	bx,fs:[0000h]
	cmp	bx,'EL'
	jz	@@4
	cmp	bx,'XL'
	jz	@@4
	cmp	bx,'CL'
	jz	@@4
	mov	edx,ebp
	call	seek_from_start
	call	search_for_le
@@4:	cmp	eax,esi
	jz	@@5
	mov	edx,esi
	add	eax,10h
	add	edx,10h
	and	al,0F0h
	and	dl,0F0h
	cmp	eax,edx
	jz	@@5
	mov	_exec_start,ebp
	mov	_app_off_datapages,esi
@@5:	ret

search_for_le:
@@1:	mov	edx,_lobufzero		; DS:EDX = current ptr
	mov	ecx,_lobufsize		; ECX = bytes to load
	call	load_gs_block
	test	ax,ax			; check if no bytes read
	mov	ax,3003h
	jz	file_error		; if true, no app in file
	shr	cx,1
@@2:	mov	ax,gs:[edx+0]
	mov	bx,gs:[edx+2]
	test	bx,bx
	jnz	@@4
	cmp	ax,'EL'			; 'LE' type
	jz	@@3
	cmp	ax,'XL'			; 'LX' type
	jz	@@3
	cmp	ax,'CL'			; 'LC' type
	jz	@@3
@@4:	add	edx,2
	add	ebp,2			; increment pointer in file
	loop	@@2
	jmp	@@1
@@3:	ret





;=============================================================================
close_exec:
	mov	bx,cs:_exec_handle
	mov	ah,3Eh
	int	21h
	ret


;=============================================================================
seek_from_start:
	push	bx ecx edx eax
	mov	ecx,edx
	shr	ecx,16
	mov	bx,cs:_exec_handle
	mov	ax,4200h
	int	21h
	pop	eax edx ecx bx
	jc	file_errorm
	ret


;=============================================================================
load_fs_block:
	push	bx ds fs
	pop	ds
	jmp	@load_block
load_gs_block:
	push	bx ds gs
	pop	ds
@load_block:
	mov	bx,cs:_exec_handle
	mov	ah,3Fh
	int	21h
	pop	ds bx
	jc	file_errorm
	ret


;=============================================================================
verbose_getmem:
	pop	bp
	mov	ax,0FF90h
	int	21h
	shr	eax,10
	test	eax,0FFFF0000h
	mov	dx,offs v_msg04
	jz	@@1
	mov	dx,offs v_msg05
	shr	eax,10
@@1:	push	dx
	push	ax
	mov	ah,48h
	mov	bx,-1
	int	21h
	shr	bx,6
	push	bx
	jmp	bp

verbose_showsys:
	test	_misc_byte2,00010000b
	jz	@@done
	call	verbose_getmem
	movzx	eax,_sys_type
	lea	eax,v_msg02[eax*4+eax]
	push	ax
	movzx	ax,_cpu_type
	imul	ax,100
	add	ax,86
	push	ax
	mov	dx,offs v_msg01
	call	prints
	add	sp,10
@@done:	ret

verbose_showloadhdr:
	test	_misc_byte2,00010000b
	jz	@@done
	movzx	eax,_app_type
	lea	eax,v_msg03[eax*2+eax]
	push	ax
	push	offs start
	mov	dx,offs v_msg10
	call	prints
	add	sp,4
@@done:	ret

verbose_showloadobj:
	test	_misc_byte2,00010000b
	jz	@@done
	pushad
	mov	ax,dx
	shr	edx,16
	shl	ebx,12
	push	dx
	push	ax
	push	ebp
	push	ebx
	push	edi
	push	cx
	mov	dx,offs v_msg11
	call	prints
	add	sp,18
	popad
@@done:	ret

verbose_showstartup:
	test	_misc_byte2,00010000b
	jz	@@done
	push	word ptr _seg_env
	push	word ptr es:[002Ch]
	push	word ptr _sel_es
	call	verbose_getmem
	mov	eax,_app_eip
	sub	eax,_unreloc_eip
	push	eax
	push	word ptr _app_eip_object
	push	offset excmsgB
	push	dword ptr _app_esp
	push	word ptr _sel32_ss
	push	dword ptr _app_eip
	push	word ptr _sel32_cs
	mov	dx,offs v_msg12
	call	prints
	add	sp,32
@@done:	ret


win_focus_vm:				; Windows - set focus on specified VM
	test	_misc_byte2,00000010b
	jz	@@done
	xor	bx,bx
	mov	ax,168Bh
	int	2Fh
@@done:	ret


PopState

⌨️ 快捷键说明

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