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

📄 install.asm

📁 random.zip 随机数产生器的汇编源代码 cmdsrc.zip 一个文本编辑器的汇编源代码
💻 ASM
📖 第 1 页 / 共 2 页
字号:
; INSTALL.ASM
; (c) 1989, 1990 Ashok P. Nadkarni
;
; This code is the installation code for CMDEDIT. This file must be
; linked last !

	INCLUDE common.inc
	INCLUDE ascii.inc
	INCLUDE dos.inc
	INCLUDE general.inc

	PUBLIC	install_begin
	PUBLIC	install
	PUBLIC	file_error
	PUBLIC	abort_install
	PUBLIC	dirstk_error
	PUBLIC	process_args

CSEG	SEGMENT	PARA PUBLIC 'CODE'
	EXTRN	getargs:PROC
	EXTRN	cmdlen:BYTE
	EXTRN	default_imode:BYTE
	EXTRN	auto_recall:BYTE
	EXTRN	pgm_name:BYTE
	EXTRN	silent:BYTE
	EXTRN	macrosize:WORD
	EXTRN	macro_ignore_char:BYTE
	EXTRN	symsize:WORD
	EXTRN	dossize:WORD
	EXTRN	dirsize:WORD
	EXTRN	mfilename:BYTE
	EXTRN	mfile_seen:BYTE
	EXTRN	prev_isr1b:WORD
	EXTRN	enable_dircmds:BYTE
	EXTRN	dos_version_major:BYTE
	EXTRN	dos_version_minor:BYTE
	EXTRN	old_int21vec:WORD
	EXTRN	cmdedit:PROC
	EXTRN	our_break_handler:PROC
	EXTRN	init_over:PROC
	EXTRN	cmdedit_isr:PROC

DGROUP	GROUP	CSEG


	ASSUME	CS:DGROUP,DS:DGROUP,ES:DGROUP,SS:DGROUP

; install_begin MUST be start of installation code.
install_begin	LABEL BYTE
msg_nomem    db	'* Insufficient Memory - Reduce buffer sizes *',CR,LF,DOLLAR
option_error db '* Unknown or illegal options *',CR,LF,DOLLAR
file_error   db '* Error processing command file *',CR,LF,DOLLAR
dirstk_error db '* Error processing directory stack commands *',CR,LF,DOLLAR
inv_dosver   db '* Unsupported DOS version. *',CR,LF,DOLLAR
msg_dup	     db '* CMDEDIT already installed in memory. *',CR,LF,DOLLAR
options_dup  db '* Only options /g /i /r /p may be specified. *',CR,LF,DOLLAR
msg_notdup   db '* No copy of CMDEDIT found in memory. *',CR,LF,DOLLAR
msg_unload   db '* Unable to unload CMDEDIT.		*',CR,LF
	     db '* Uninstall TSRs in reverse order.	*',CR,LF,DOLLAR
msg_memerr   db '* DOS memory allocation error! *',CR,LF,BEL
	     db '* Recommend you reboot!        *',CR,LF,BEL,DOLLAR
msg_uninstalled db '* CMDEDIT uninstalled successfully *',CR,LF,DOLLAR
msg_omode db '* Default overwrite mode enabled. *',CR,LF,DOLLAR
msg_imode db '* Default insert mode enabled. *',CR,LF,DOLLAR
msg_enable_autorecall db '* CMDEDIT autorecall enabled. *',CR,LF,DOLLAR
msg_disable_autorecall db '* CMDEDIT autorecall disabled. *',CR,LF,DOLLAR
msg_enable_bell db '* CMDEDIT error bell enabled. *',CR,LF,DOLLAR
msg_disable_bell db '* CMDEDIT error bell disabled. *',CR,LF,DOLLAR
msg_ignore_char db '* CMDEDIT ignore character changed. *',CR,LF,DOLLAR

cmdedit_seg  dw	0				;Segment of the first copy
;						 of CMDEDIT loaded into memory.

argflags 	db	0	;Used to remember what args have been seen.
dosarg		equ	1
applarg		equ	2
filearg		equ	4
dirarg		equ	8
macroarg	equ	16
symarg		equ	32
uninstall_arg	equ	64
ignore_arg	equ	128

argument_buffer db	LINEBUF_SIZE DUP (?)

;	This location is jumped to when the program is run from the DOS
;	command line. The program parses the input line, takes
;	appropriate actions, initializes buffers etc. and then TSR's
;	after taking over interrupt 21h. The memory taken up by the ISEG
;	segment will then be used for various data buffers since this
;	code is no longer needed.
install proc	near
	cld			;Entire program assumes direction flag will
;				 be cleared

	ASSUME CS:DGROUP,DS:DGROUP,ES:DGROUP,SS:DGROUP
	@DispStr pgm_name		;Display program name

; Make sure we are running DOS 2.x or higher
	call	near ptr get_dosversion
	cmp	dos_version_major,1		;DOS 1.x ?
	jne	@install_1
	@DispStr inv_dosver
	mov	ax,-1
	jmp	abort_install			;V1.x not supported.

@install_1:
; Locate the segment of the first copy of CMDEDIT in memory so that
; we can tell if this is a second copy.
	call	near ptr locate_cmdedit
	mov	cmdedit_seg,ax			;Remember it

@install_5:
	mov	si,offset cmdlen ;
	lodsb			;SI == line in PSP, AL == line length
	mov	cl,al
	xor	ch,ch		;CX = line length
	xor	ax,ax		;Function = get argument count
	push	cx		;Save line length
	call 	near ptr getargs ;AX := # arguments in command line
	pop	cx		;Restore line length
	mov	di,ax		; DI == number of arguments
	inc	di		;Prime for loop
@install_10:
	dec	di		;Any more arguments ?
	jz	@install_20	;No
	mov	bx,offset DGROUP:argument_buffer
	mov	dx,SIZE argument_buffer
	mov	ax,di		;Argument number
	push	cx		;save line length
	call 	near ptr getargs ;Get argument into argument_buffer
;				  (no chance of buffer being too short)
	call 	near ptr process_args ;Process the argument
	pop	cx		;Restore line length
	jmp	short @install_10 ;loop back to process remaining args


@install_20:
; OK now we have done all necessary parsing without errors. Now first check
; if the uninstall option was specified.
	test	argflags,uninstall_arg
	je	@install_21		;Nope

; We have to unload a previously installed copy of CMDEDIT. See if it is
; really there.
	mov	ax,ds			;Are we the only copy of CMDEDIT ?
	cmp	ax,cmdedit_seg
	je	@install_20_a		;There is no other copy
	jmp	uninstall

@install_20_a:
	@DispStr msg_notdup		;Indicate no copy to uninstall
	mov	ax,-1
	jmp	abort_install		;Exit 

@install_21:
; No uninstall option specified. Now check if this is the only copy of
; CMDEDIT.
	mov	ax,ds
	cmp	ax,cmdedit_seg
	je	@install_21_a		;We are the only copy. Proceed with
;					 installation 
	jmp	change_installed_options ;Else go change installed options.

@install_21_a:
; At this point all the arguments have been parsed. Now check
; that the sum total of the various buffer sizes does not exceed
; segment limits. Also check for mandatory minimum sizes.
; Finally, transfer control to the resident portion which will
; relocate buffers to overlay the installation code.

	mov	ax,OFFSET DGROUP:install_begin
					;add starting address where buffers
					; will begin
	add	ax,STACK_SIZE
	jnc	@install_23
	jmp	@install_125
@install_23:
	cmp	macrosize,MACROSIZE_MIN
	jnb	@install_22
	mov	macrosize,MACROSIZE_MIN ;Ensure min buffer sizes
@install_22:
	add	ax,macrosize
	jc	@install_125
	cmp	symsize,SYMSIZE_MIN
	jnb	@install_24
	mov	symsize,SYMSIZE_MIN ;Ensure min buffer sizes
@install_24:
	add	ax,symsize
	jc	@install_125
	cmp	dossize,DOSSIZE_MIN
	jnb	@install_26
	mov	dossize,DOSSIZE_MIN ;Ensure min buffer sizes
@install_26:
	add	ax,dossize
	jc	@install_125
	cmp	dirsize,DIRSIZE_MIN
	jnb	@install_30
	mov	dirsize,DIRSIZE_MIN ;Ensure min buffer sizes
@install_30:
	add	ax,dirsize
	jc	@install_125
;Enough memory, so keep resident. Install our Ctrl-Break handler.
	push	es			;Save ES
	mov	ah,35h
	mov	al,1bh			;Ctrl-Break Interrupt
	int	21h			;Get current handler address
	mov	CS:prev_isr1b,bx	;Offset of previous handler
	mov	CS:prev_isr1b+2,es	;Segment of previous handler
	pop	es			;Restore es
	mov	dx,offset CS:our_break_handler
	push	ds			;Save DS
	mov	ax,cs
	mov	ds,ax			;DS:DX->our break handler
	mov	al,1bh
	mov	ah,25h			;Set up our break handler
	int	21h
	pop	ds			;Restore DS
;
	jmp	near ptr init_over



@install_125:
	@DispStr msg_nomem
	mov	ax,-1
	jmp	abort_install

install endp




;+
; FUNCTION : process_args
;
;	Processes the argument pointed to by BX. AX contains length 
;	of argument. If a previously seen argument is repeated, it is
;	ignored (ie. the old value is kept). Note that the argument is
;	assumed not to contain any delimiters (like space or tab).
;
;	Options start with either a '-' or '/'. Any associated value must
;	follow immediately after without any intervening space/tab.
;		/f	Macro file to be read.
;		/d	DOS history buffer size
;		/a	Application history buffer size (only if
;			separate histories maintained) (OUTDATED)
;		/m	Macro buffer size
;		/b	symbol buffer size
;		/s	Directory Stack size
;		/r	Auto recall mode
;		/i	Insert mode default
;		/g	Silent mode
;		/p	macro ignore character
;		/e	Enable dir commands all the time (OUTDATED)
;		/u	Uninstall CMDEDIT
;
;	Invalid options result in program abortion. If an option is not
;	followed by a value, the default value for the option is assumed.
;
;	Note that this is NOT a general purpose getopt type routine.
;
; Parameters:
;	BX	= Pointer to argument
;	AX	= Number of characters in argument
;
; Returns:
;	Nothing.
;	Various globals may be set according to the specified argument.
; Register(s) BX (call to aton),CX  are destroyed.
;-
process_args proc near
	@save	si,di
	test	argflags,uninstall_arg
	jne	@process_args_5	;If /U specified, no other arg is allowed

	xchg	ax,cx		;CX = character count
	sub	cx,2		;Delete switch char and option letter
	jb	@process_args_5	;Error in option specification
				;  if num chars less than 2
	mov	si,bx		;SI = arg buffer address
	lodsb			;AL = first character
	cmp	al,'/'		;Should be either '/'
	je	@process_args_10 ;
	cmp	al,'-'		; or '-'
	jne	short @process_args_5	;Else error

@process_args_10:			;Saw a valid switch char
	lodsb				;AL = option letter
	or	al,32			;Lowercase (non alphabetic will be
					; ignored anyway)
	cmp	al,'u'			;Uninstall option ?
	jne	@process_args_11_a	;No
	or	cx,cx			;Ok if no more chars in arg
	jne	short @process_args_5	;Else error

@process_args_11:
	or	argflags,uninstall_arg	;Indicate /U seen
	jmp	@process_args_50	;Return

@process_args_11_a:
	cmp	al,'i'			;insert mode option ?
	jne	@process_args_14	;No
	jcxz	@process_args_12	;Ok if no more chars in arg
@process_args_5:
; Error processing
	@DispStr option_error
	mov	ax,-1
	jmp	abort_install
@process_args_12:
	mov	default_imode,1		;Change default insrt mode
	jmp	@process_args_50	;Return
@process_args_14:
	cmp	al,'g'			;silent mode option ?
	jne	@process_args_15	;No
	jcxz	@process_args_14_a	;Ok if no more chars in arg
	jmp	short @process_args_5	;Else error
@process_args_14_a:
	mov	silent,1		;Silent mode
	jmp	@process_args_50	;Return
@process_args_15:
	cmp	al,'r'			;auto-recall option ?
	jne	@process_args_18	;No
	jcxz	@process_args_16	;Ok if no more chars in arg
	jmp	short @process_args_5	;Else error
@process_args_16:
	mov	auto_recall,1		;Set auto-recall mode
	jmp	@process_args_50	;Return
@process_args_18:
	cmp	al,'e'			;Enable dir commands option?
	jne	@process_args_18_b	;No
	jcxz	@process_args_18_a	;OK if no more chars
	jmp	short @process_args_5	;Else error
@process_args_18_a:
	mov	enable_dircmds,1	;enable directory commands
	jmp	@process_args_50	;Return
@process_args_18_b:
	cmp	al,'p'			;ignore character option
	jne	@process_args_19
	cmp	cx,1			;Should be only one more char
	jne	@process_args_5		;Error
	lodsb
	or	argflags,ignore_arg	;Indicate that an ignore char set
	mov	macro_ignore_char,al
	jmp	@process_args_50	;Return
@process_args_19:
	cmp	al,'f'			;Is it the macro file option ?
	jne	@process_args_20
	test	argflags,filearg	;Already seen file argument ?
	je	@process_args_19_a	;No, then update
	jmp	@process_args_50	;Yes, then don't update
@process_args_19_a:
	or	argflags,filearg	;Remember we've seen this option
	jcxz	@process_args_50	;If 0 count, no file to be read
	cmp	cx,63			;Max path length must be < 64
	ja	@process_args_5		;Error
	mov	di,offset mfilename	;Temp storage for filename
	rep	movsb			;Copy file name

⌨️ 快捷键说明

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