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

📄 cmdline.a86

📁 一个dos操作系统DRDOS的源码
💻 A86
📖 第 1 页 / 共 3 页
字号:
;			DX	 No. of bytes in buffer
;
;	On Exit:	Update RL_SAVMAX, RL_SAVPOS, RL_SAVBUF
;
save_line:
	xor	ax,ax
	mov	RL_SAVPOS,ax
	mov	RL_SAVMAX,ax
	mov	cx,dx			; Current Line Length
	 jcxz	save_l10
	cmp	cx,savbuf_size		; clip the amount saved
	 jb	save_l5			; to be a maximum of
	mov	cx,savbuf_size		; the save buffer size
save_l5:
	mov	RL_SAVMAX,cx		; Set the Save Data Length
	push ds ! push es
	push si ! push di

	push ds ! pop es
	lds	si,RL_BUFPTR
	mov	di,offset savbuf
	rep	movsb			; save the data
	pop di ! pop si
	pop es ! pop ds
save_l10:
;	ret

ignore_char:
	ret

mem_line:		;; JFL save from beginning of line 
	call	save_line
	jmp	goto_bol
;	ret	


eof_char:		;; JFL make F6 return a CTL Z
	mov	al,01Ah
	mov	cx,1
	jmp	intsave_char
;	ret

ctlat_char:		;; JFL make F7 return a CTL @
	mov	al,0h
	mov	cx,1
	jmp	intsave_char
;	ret


eject
;
;	CHAR_TYPE get the next character from the buffer ES:SI and returns
;	its type in AH using the equates CHAR_????. The character is returned
;	in AL.
;
;
;	
char_type:
	mov ah,CHAR_SPACE or CHAR_STD	; WhiteSpace
	cmp al,' ' ! jz char_t100
	mov	ah,CHAR_TAB		; Tab Character
	cmp al,TAB ! jz char_t100
	mov ah,CHAR_ALPHAN or CHAR_STD	
	cmp al,CTLU ! jz char_t100	; Control-U and Control-T are treated
	cmp al,CTLT ! jz char_t100	; as normal characters
	mov	ah,CHAR_CTL		; Control Character
	cmp al,' ' ! jb char_t100

	mov ah,CHAR_ALPHAN or CHAR_STD	
	cmp al,'0' ! jb  char_t90	; Return SYMBOL
	cmp al,'9' ! jbe char_t100	; Return AlphaNumeric
	cmp al,'A' ! jb  char_t90	; Return Symbol
	cmp al,'Z' ! jbe char_t100	; Return AlphaNumeric
	cmp al,'a' ! jb  char_t90	; Return Symbol
	cmp al,'z' ! jbe char_t100	; Return AlphaNumeric
	cmp al,80h ! jb  char_t90	; Return Symbol

	mov	ah, CHAR_KANJI		; assume character is 16 bits
	call	dbcs_lead		; is byte a DBCS lead?
	je	char_t100		;  yes - done
char_t90:
	mov	ah,CHAR_OTHER or CHAR_STD ; no - Normal Character Symbol

char_t100:
	ret





;
;	CHAR_INFO will return various information about the character
;	at ES:SI
;
;	On Entry:	ES:SI	Character Pointer
;			BX	Current Column No.
;			CX	Byte Scan Count
;
;	On Exit:	ES:SI	Points to the next Character
;			BX	Updates Column No.
;			CX	Updates Byte Scan Count
;			AH	Character type Flags
;			AL	First byte of Character
char_info:
	lods	es:al
	call	char_type		; Test the character type and assume
	inc	bx			; it will take 1 Screen location
	test	ah,CHAR_ONECOL
	jnz	char_i20

	inc	bx			; Now check for the Control Characters
	test	ah,CHAR_CTL		; which take up 2 cols
	jnz	char_i20

	test	ah,CHAR_KANJI		; If this was the first byte of a 
	jz	char_i10		; KANJI character then skip the
	inc si ! dec cx			; next byte
	jmps	char_i20

char_i10:
	push	ax			; Save AX and calculate the number
	dec bx ! dec bx			; of screen locations that this TAB
	mov	ax,bx			; character will use based on the fact
	and 	ax,7			; BX contains the current column
	neg ax ! add ax,8
	add	bx,ax
	pop	ax

char_i20:
	ret

eject
;
;	CALC_CHARS calculates the number of character locations used
;	on the screen to display a particular sub-string of the current
;	buffer. This routine takes account of the Kanji, Control and TAB
;	characters.
;
;	On Entry:	SI	Start Buffer Index
;			DI	End Buffer Index
;
;	On Exit:	CX	Count
;
calc_chars:
	push	bx
	push si ! push di
	mov	bx,RL_INICOL		; Get the initial Column
	sub	di,si			; DI = Sub-string length bytes
	mov	cx,si			; Use the Start Index for the
	mov	si,RL_BUFOFF		; initial count and scan from the
	jcxz	calc_c20		; start of the buffer

calc_c10:
	call	char_info
	loop	calc_c10

calc_c20:
	mov	cx,di			; Sub-String Length
	mov	di,bx			; Current Column position

calc_c30:
	call	char_info
	loop	calc_c30

	sub	bx,di
	mov	cx,bx
	pop di ! pop si
	pop	bx
	ret

eject
;
;	The following functions are purely Low level character output
;	functions.
;
space_out:				; Write CX Space characters to the
	mov	al,' '			; Output handle
	jmps	block_out
	
bs_out:
	mov	al,CTLH			; Write CX BackSpace characters to
;;	jmps	block_out		; Output Handle

block_out:
	 jcxz	block_o20
	push	cx
block_o10:
	call	write_char		; output this character
	loop	block_o10
	pop	cx
block_o20:
	ret

;
;	Display CX characters from the string at ES:SI
;
put_string:
	jcxz	puts_s20
	push cx ! push si
put_s10:
	push	cx
	lods	es:al
	call	put_char
	pop	cx
	loop	put_s10
	pop si ! pop cx
puts_s20:
	ret

;
;	Display the character in AL
;
put_char:
	cmp al,' ' ! jae write_char	; skip if it's printable
	cmp al,CTLT! je write_char	; Control-T and Control-U are treated
	cmp al,CTLU! je	write_char	; like normal Characters.
	cmp al,TAB ! je write_char	; skip if it's TAB
	or	al,040h			; Convert Character to Uppercase
	push	ax			; save it
	mov	al,'^'			; display the character
	call	write_char		;  in ^X format
	pop	ax
write_char:
	push	es
	push	dx
	push	cx
	push	si
	push	di
	push	ax			; char on stack
	mov	bx,RL_OUTPUT		; Output AL to the OUTPUT Handle
	push ss ! pop es		; ES:DX -> Character Buffer
	mov	si,sp			; buffer offset
	mov	cx,1			; character count
	call	cooked_write		; Write Character
	pop	ax
	pop	di
	pop	si
	pop	cx
	pop	dx
	pop	es
	ret
;
;	Read 1 a character from RL_INPUT saving all the vital registers
;	from corruption. If the first character is the ESCAPE character
;	set AH to TRUE and read the next byte. Otherwise AH is FALSE
;
get_char:
	push	ds
	push	es
	push	dx
	push	si
	push	di

	call	get_dseg		; point at pcmode data
	lds	si,con_device		; DS:SI -> current console device
	test	ds:DH_ATTRIB[si],DA_IOCTL ; test bit 14: IOCTL bit
	 jz	get_c05			; error if IOCTL not supported
	sub	sp,RH_SIZE		; reserve this many words on the stack
	mov	bx,sp			; SS:BX -> request packet
	push ss ! pop es		; ES:BX -> request packet
	lea	dx,RL_FLAGS		; point at flags
	mov	es:RH_CMD[bx],CMD_OUTPUT_IOCTL
	mov	es:RH_LEN[bx],RH4_LEN
	mov	es:RH4_BUFOFF[bx],dx	; set up for a normal
	mov	es:RH4_BUFSEG[bx],ss	;  IOCTL read/write
	mov	es:RH4_COUNT[bx],WORD
	call	device_driver		; execute the command
	add	sp,RH_SIZE		; reclaim the stack
get_c05:

	call	get_dseg		; point at pcmode data
	mov	bx,RL_INPUT		; BX = input stream
	call	cmdline_read		; get a character

	mov	ah,FALSE		; Assume this is NOT the Escape 
	cmp	al,esc_char		; character and set high byte of the
	 jnz	get_c10			; match word to FALSE

	call	raw_read		; read the second byte of the escape
	mov	ah,ESC_CODE		;  sequence, setting high byte to ESC
get_c10:
	pop	di
	pop	si
	pop	dx
	pop	es
	pop	ds
	ret

PCM_RODATA	CSEG	WORD

EDIT_CNTRL	equ	cs:word ptr 0[bx]	; Character and Esc Flag
EDIT_FUNC	equ	cs:word ptr 2[bx]	; Edit Function Address
EDIT_LEN	equ	4			; Edit Table Entry Size

esc_char	db	0		; Command Line Editor Escape Character
edit_size	dw	(offset edit_end - edit_table)/EDIT_LEN

edit_table	db CR	! db NESC_CODE ! dw ret_string
	db LF	! db NESC_CODE ! dw ignore_char
	db CTLH	! db NESC_CODE ! dw delp_char
	db DEL	! db NESC_CODE ! dw delf_char

	db ESC	! db NESC_CODE ! dw del_line
	db ';'  ! db ESC_CODE  ! dw copy_char		; Function 1
	db '<'  ! db ESC_CODE  ! dw copy_till_char	; Function 2
	db '='  ! db ESC_CODE  ! dw copy_all		; Function 3
	db '>'  ! db ESC_CODE  ! dw skip_till_char	; Function 4
	db '?'  ! db ESC_CODE  ! dw mem_line		; Function 5

	db '@'  ! db ESC_CODE  ! dw eof_char		; Function 6
	db 'A'  ! db ESC_CODE  ! dw ctlat_char		; Function 7
	db 'B'	! db ESC_CODE or DISABLE ! dw match_cmd	; Function 8

	db 'R'  ! db ESC_CODE  ! dw toggle_ins		; Insert
	db 'S'  ! db ESC_CODE  ! dw delf_char		; Delete
	db 'K'  ! db ESC_CODE or DISABLE  ! dw prev_char ; Left Arrow 
	db 'M'  ! db ESC_CODE or DISABLE  ! dw next_char	; Right Arrow
; When advanced editing is disabled the match for Left/Right arrows will fall
; through to here
	db 'K'  ! db ESC_CODE  ! dw delp_char		; Left Arrow - compat
	db 'M'  ! db ESC_CODE  ! dw copy_char		; Right Arrow - compat
;
; Extended functions from here on
;
	db 'C'  ! db ESC_CODE or DISABLE ! dw del_cur_history_buffer ; Func 9
	db 'D'  ! db ESC_CODE or DISABLE ! dw del_history_buffers ; Func 10
	db 'G'  ! db ESC_CODE or DISABLE  ! dw goto_bol		; Home
	db 'O'  ! db ESC_CODE or DISABLE  ! dw goto_eol		; End
	db 't'  ! db ESC_CODE or DISABLE  ! dw next_word	; Control Right Arrow
	db 's'  ! db ESC_CODE or DISABLE  ! dw prev_word	; Control Left Arrow


	db CTLV	! db NESC_CODE or DISABLE ! dw toggle_ins
	db CTLQ	! db NESC_CODE or DISABLE ! dw goto_bol
	db CTLW	! db NESC_CODE or DISABLE ! dw goto_eol
	db CTLR	! db NESC_CODE or DISABLE ! dw match_cmd
	db CTLD	! db NESC_CODE or DISABLE ! dw next_char
	db CTLS	! db NESC_CODE or DISABLE ! dw prev_char
	db CTLF	! db NESC_CODE or DISABLE ! dw next_word
	db CTLA	! db NESC_CODE or DISABLE ! dw prev_word
	db CTLG ! db NESC_CODE or DISABLE ! dw deln_char
	db CTLT ! db NESC_CODE or DISABLE ! dw deln_word
	db CTLY ! db NESC_CODE or DISABLE ! dw del_line
	db CTLB ! db NESC_CODE or DISABLE ! dw del_bol
	db CTLK ! db NESC_CODE or DISABLE ! dw del_eol

	db 'I'  ! db ESC_CODE or DISABLE  ! dw ignore_char	; PageUP
	db 'Q'  ! db ESC_CODE or DISABLE  ! dw ignore_char	; PageDown
	db 'H'  ! db ESC_CODE or DISABLE  ! dw prev_cmd 	; Up Arrow
	db 'P'  ! db ESC_CODE or DISABLE  ! dw next_cmd		; Down Arrow
	db CTLE ! db NESC_CODE or DISABLE ! dw prev_cmd
	db CTLX ! db NESC_CODE or DISABLE ! dw next_cmd
	db CTLUB ! db NESC_CODE or DISABLE ! dw toggle_search	; Default search mode
edit_end	rb	0


PCMODE_DATA	DSEG	WORD

	extrn	con_device:dword	; Current Console Device
	extrn	column:byte 		; Console Cursor Location

	savbuf_size	equ	128

	extrn	savbuf:byte		; fixed location in DOS data area

	extrn	cle_state:word		; command line editing state

	end

⌨️ 快捷键说明

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