; begin kermit7.asm [18]
 
; This is the SET command.
 
SETCOM  PROC    NEAR
        mov dx,offset settab    ; Parse a keyword from the set table.
        mov bx,offset sethlp
        mov ah,cmkey
        call comnd
         jmp r
        call bx
        jmp rskp
SETCOM  ENDP
 
 
;       This is the ESCAPE character SET subcommand.     [6 start]
 
ESCAPE  PROC    NEAR
	call cmgtch		; Get a char.
	cmp ah,0
	jns es1			; Terminator or no?
	and ah,7FH		; Turn off minus bit.
	cmp ah,'?'
	jne es0
	mov dx,offset eschlp
	mov ah,prstr
	int dos
	mov dx,offset crlf
	int dos
	mov dx,offset kerm
	int dos
	mov bx,cmdptr
	mov al,'$'
	mov [bx],al
	mov dx,offset cmdbuf
	int dos
	dec cmcptr		; Ignore dollar sign.
	dec cmccnt
	mov cmaflg,0
	jmp repars
es0:	mov ah,prstr
	mov dx,offset ermes3
	int dos
	ret
es1:  	mov temp,ax
	call cmcfrm
	 jmp es0
	 nop			; Take up 3 bytes.
	mov ax,temp
	mov escchr,ah		; Save new value.
	ret
ESCAPE  ENDP			; [6 end]

; 	This is the End-of-line character SET subcommand.       [5 start]

EOLSET	PROC	NEAR
	call cmgtch		; Get the first char into AH.
	cmp ah,0
	jns eol1
	cmp ah,0BFH		; Question mark?
	je eol4
	jmp eol3
eol1:	sub ah,030H		; Digit --> real number.
	mov temp,ax		; Save the input.
	call cmcfrm
	 jmp eol0		; Got a char.
	mov ax,0
	mov bx,temp
	jmp eol2
eol0:	sub ah,030H		; Digit --> real number.
	mov temp1,ax
	call cmcfrm
	 jmp eol3		; Too many chars.
	mov bx,temp1
	mov ax,temp
	xchg al,ah
	mov ah,0
eol2:	mov temp,ax		; Save our registers.
	mov temp1,bx
	call cmcfrm
	 jmp eol3
	mov bx,temp1
	mov ax,temp
	mov temp2,10		; Get numerical value of char.
	mul temp2
	add al,bh
	mov ah,0
	cmp al,0
	jl eol3
	cmp al,1FH
	jg eol3
	mov seol,al		; Use new eol char.
	ret
eol3:	mov ah,prstr
	mov dx,offset eolerr	; Bad end-of-line char
	int dos
	jmp prserr
eol4:	mov ah,prstr
	mov dx,offset eolhlp
	int dos
	mov dx,offset crlf
	int dos
	mov dx,offset kerm
	int dos
	mov bx,cmdptr
	mov al,'$'
	mov [bx],al
	mov dx,offset cmdbuf
	int dos
	dec cmcptr			; Don't count the dollar sign.
	dec cmccnt			; Or the question mark.
	mov cmaflg,0			; Check for more input.
	jmp repars
EOLSET	ENDP						     ;	[5 end]
 
;       This is the LOCAL echo SET subcommand.
 
LCAL    PROC    NEAR
        mov dx,offset ontab
        mov bx,offset onhlp
        mov ah,cmkey
        call comnd
         jmp r
        push bx                 ; Save the parsed value.
        mov ah,cmcfm
        call comnd              ; Get a confirm.
         jmp r                  ;  Didn't get a confirm.
        pop bx
        mov ecoflg,bl           ; Set the local echo flag.
	ret
LCAL    ENDP
 
;       This is the VT52 emulation SET subcommand.
 
IF ibmpc
VT52EM  PROC    NEAR
        mov dx,offset ontab
        mov bx,offset onhlp
        mov ah,cmkey
        call comnd
         jmp r
        push bx
        mov ah,cmcfm
        call comnd              ; Get a confirm.
         jmp r                  ;  Didn't get a confirm.
        pop bx
        mov vtflg,bl            ; Set the VT52 emulation flag.
	ret
VT52EM  ENDP
ENDIF
 
;       This is the SET IBM command.
 
IBMSET  PROC    NEAR
        mov dx,offset ontab
        mov bx,offset onhlp
        mov ah,cmkey
        call comnd
         jmp r
        push bx
        mov ah,cmcfm
        call comnd              ; Get a confirm.
         jmp r                  ;  Didn't get a confirm.
        pop bx
        mov ibmflg,bl           ; Set the IBM flag.
	cmp bl,0		; Turning on or off?    [12 start]
	je ibmst1		; If off, set parity & local echo to defaults.
	mov ah,ibmpar		; Set IBM parity.
	mov al,1		; Set local echo on.
	jmp ibmst2
ibmst1:	mov ah,defpar		; Reset parity to default.
	mov al,0		; Turn off local echo.
ibmst2:	mov parflg,ah		; Set parity.
	mov ecoflg,al		; And local echo.	[12 end]	
	ret
IBMSET  ENDP

;       This is the SET File-Warning command.
 
FILWAR  PROC    NEAR
        mov dx,offset ontab
        mov bx,offset onhlp
        mov ah,cmkey
        call comnd
         jmp r
        push bx
        mov ah,cmcfm
        call comnd              ; Get a confirm.
         jmp r                  ;  Didn't get a confirm.
        pop bx
        mov flwflg,bl           ; Set the IBM flag.
	ret
FILWAR  ENDP

;       This is the SET Parity command.				[10 start]
 
SETPAR  PROC    NEAR
        mov dx,offset partab
        mov bx,offset parhlp
        mov ah,cmkey
        call comnd
         jmp r
        push bx
        mov ah,cmcfm
        call comnd              ; Get a confirm.
         jmp r                  ;  Didn't get a confirm.
        pop bx
        mov parflg,bl           ; Set the parity flag.
	ret
SETPAR  ENDP							; [10 end]

; Sets debugging mode on and off.

DEBST	PROC    NEAR
        mov dx,offset ontab
        mov bx,offset onhlp
        mov ah,cmkey
        call comnd
         jmp r
        push bx
        mov ah,cmcfm
        call comnd              ; Get a confirm.
         jmp r                  ;  Didn't get a confirm.
        pop bx
        mov debug,bl           ; Set the IBM flag.
	ret
DEBST   ENDP

; Turn bell on or off.    [17a start]
; Make bells from remote host long or short.	[18]

BELLST	PROC	NEAR
	mov dx,offset beltab	; [18]
	mov bx,offset belhlp	; [18]
	mov ah,cmkey
	call comnd
	 jmp r
	push bx
	mov ah,cmcfm
	call comnd
	 jmp r
	pop bx
	cmp bl,0		; [18 start]
	je bel1
	cmp bl,1
	je bel1
	mov bellen,bx		; set long or short
	ret
bel1:	mov belflg,bl		; set off or on
	ret			; [18 end]
BELLST	ENDP                      ;  [17a end]

;  This function sets the baud rate.

BAUDST  PROC    NEAR
        mov dx,offset bdtab
        mov bx,offset bdhlp
        mov ah,cmkey
        call comnd
         jmp r
	push bx
	mov ah,cmcfm
	call comnd		; Get a confirm.
	 jmp r			; Didn't get one.
	pop bx
IF ibmpc
        mov baud,bx           ; Set the IBM flag.
	mov dx,03FBH		; LCR
	in al,dx
	mov bl,al
	or ax,80H
	out dx,al
	mov dx,03F8H
	mov ax,baud
	out dx,al
	inc dx
	mov al,ah
	out dx,al
	mov dx,03FBH
	mov al,bl
	out dx,al
ENDIF
IF Z100 
	mov bx,ds		; Set up pointer to config info
	mov es,bx		;  .  .  .
	mov bx,offset auxcnf	;  .  .  .
	mov ah,chr_control	; Function is control
	mov al,chr_cfsu		; Subfunction is set new config
	call bios_auxfunc	; Set the configuration
ENDIF
	ret
BAUDST  ENDP
 
;       This is the STATUS command.
 
STATUS  PROC    NEAR
        call stat0
         jmp r
        jmp rskp
STATUS  ENDP
 
STAT0   PROC    NEAR
        mov ah,cmcfm
        call comnd              ; Get a confirm.
         jmp r                  ;  Didn't get a confirm.
stat01: mov dx,offset locst     ; Assume local echo on.
	cmp ecoflg,0            ; Is the local echo flag on?
        jnz stat1               
        mov dx,offset remst     ; If not say so.
stat1:  mov ah,prstr            ; Print it.
        int dos
IF ibmpc
        mov dx,offset vtemst    ; Get address of the VT52 emulation string.
        cmp vtflg,0             ; Is the VT52 emulation flag on?
        jnz stat2
        mov dx,offset novtst    ; If not say so.
stat2:  mov ah,prstr            ; Print it.
        int dos
ENDIF
	mov dx,offset ibmst	; Is IBM flag on?
	cmp ibmflg,0
	jnz stat3
	mov dx,offset noibm     ; Say it's not.
stat3:  mov ah,prstr
	int dos
	mov dx,offset deboff	; Assume debug mode is off.
	cmp debug,0
	je stat4
	mov dx,offset debon
stat4:	mov ah,prstr
	int dos
	mov dx,offset flwon	; Assume file-warning on.
	cmp flwflg,0
	jne stat5
	mov dx,offset flwoff
stat5:	mov ah,prstr
	int dos
	mov dx,offset pnonst	; Assume no parity.		[10 start]
	cmp parflg,parnon
	je stat6
	mov dx,offset pmrkst	; Mark parity?
	cmp parflg,parmrk
	je stat6
	mov dx,offset pevnst	; Maybe it's even parity.
	cmp parflg,parevn
	je stat6
	mov dx,offset poddst	; Odd parity?
	cmp parflg,parodd
	je stat6
	mov dx,offset pspcst
stat6:	mov ah,prstr
	int dos							;[10 end]
	mov dx,offset belon	; Tell if bells ring at end.  [17a start - DT]
	cmp belflg,0
	jne stat7
	mov dx,offset beloff	; No bells.
stat7:	mov ah,prstr
	int dos			; That's it.  [17a end - DT]
	mov dx,offset bellg	; Say whether remote bell is long [18 start]
	cmp bellen,bellong
	je stat8
	mov dx,offset belsh	; It's short
stat8:	mov ah,prstr
	int dos			; [18 end]	
	mov dx,offset eolst	; Tell the end-of-line char used.  [5 start]
	mov ah,prstr
	int dos
	mov ah,conout
	mov dl,seol
	add dl,40H
	int dos							 ; [5 end]
	mov ah,prstr
	mov dx,offset escmes			; Print escape character.  [6]
	int dos	
	call escprt
	mov dx,offset b48st	; Assume 4800 baud.
	cmp baud,B4800
	jnz stat9a
	jmp stat9
stat9a:	mov dx,offset b12st
	cmp baud,B1200
	jnz stat9b
	jmp stat9
stat9b:	mov dx,offset b18st
	cmp baud,B1800
	jz stat9
	mov dx,offset b24st
	cmp baud,B2400
	jz stat9
	mov dx,offset b96st
	cmp baud,B9600
	jz stat9
	mov dx,offset b03st
IF ibmpc
	jmp stat9
ENDIF
IF Z100
	cmp baud,B0300
	jz stat9
	mov dx,offset b04st
	cmp baud,B00455
	jz stat9
	mov dx,offset b05st
	cmp baud,B0050
	jz stat9
	mov dx,offset b07st
	cmp baud,b0075
	jz stat9
	mov dx,offset b11st
	cmp baud,B0110
	jz stat9
	mov dx,offset b13st
	cmp baud,B01345
	jz stat9
	mov dx,offset b15st
	cmp baud,B0150
	jz stat9
	mov dx,offset b06st
	cmp baud,B0600
	je stat9
	mov dx,offset b20st
	cmp baud,B2000
	jz stat9
	mov dx,offset b19st
	cmp baud,B19200
	jz stat9
	mov dx,offset b38st
ENDIF
stat9:	mov ah,prstr
	int dos
        mov dx,offset cmcrlf    ; Get the address of a crlf.
        mov ah,prstr            ; Print it.
        int dos
        jmp rskp
STAT0   ENDP
 
 
 
;       Utility routines
 
; Jumping to this location is like retskp.  It assumes the instruction
;   after the call is a jmp addr.
 
RSKP    PROC    NEAR
	pop bp
	add bp,3
	push bp
        ret
RSKP    ENDP
 
; Jumping here is the same as a ret.
 
R       PROC    NEAR
        ret
R       ENDP
 
; This routine prints the number in AX on the screen.
;       (Thanks to Jeff Damens)
 
NOUT    PROC    NEAR
        push bx                 ; Save some stuff.
        push cx
        push dx
        push ax
        mov bh,0                ; Don't print leading zeros.
        and ah,0F0H             ; Only want high order nibble.
        mov cl,4
	shr ah,cl
        call pdig               ; Print the digit.
        pop ax                  ; Restore argument.
        and ah,0FH              ; Just the low order nibble.
        call pdig
        mov ah,al
        and ah,0F0H             ; Only want high order nibble.
	mov cl,4
        shr ah,cl
        call pdig               ; Print the digit.
        mov ah,al
        and ah,0FH              ; Just the low order nibble.
        mov bh,0FFH             ; Make sure at least one zero is printed.
        call pdig
        pop dx                  ; Restore some stuff.
        pop cx
        pop bx
        ret
NOUT    ENDP
 
        ; print the digit in register AH
 
PDIG    PROC    NEAR
        push ax                 ; Save it.
        cmp ah,0
        jne pdig2
        cmp bh,0
        jne pdig2
        pop ax
        ret
pdig2:  mov bh,0FFH             ; Set the print zero flag.
        cmp ah,10               ; Do we use digits or a-f?
        jl usedig               ; Digit.
        add ah,'A'-10           ; Compute digit
        jmp havdig              ; and proceed.
usedig: add ah,'0'              ; Convert to digit
havdig: mov dl,ah
        mov ah,conout
        int dos
        pop ax
        ret
PDIG    ENDP
; end kermit7.asm [18]
   mov ah,dconio
        int dos
        jmp rskp

; Another similar I/O routi