;
; +++++++++++++++++++++++++++
; +++ KERMIT SET commands +++
; +++++++++++++++++++++++++++
;
; This is the SET command.
;
setcom:
	ld	de,settab	; Parse a keyword from the set table.
	ld	hl,sethlp
	call	keycmd
	ex	de,hl		; Get the address of the jump table.
	jp	(hl)
settab:
	db	14		; 14 entries
				; Data keys to SETJTB positions
	db	4,'BAUD',eot
	dw	baud
	db	16,'BLOCK-CHECK-TYPE',eot
	dw	blkset
	db	4,'DISK',eot
	dw	setdsk
	db	5,'ERASE',eot
	dw	wrnset
	db	6,'ESCAPE',eot
	dw	escape
	db	9,'FILE-MODE',eot
	dw	setcpm
	db	3,'IBM',eot
	dw	ibmset
	db	10,'LOCAL-ECHO',eot
	dw	locall
	db	6,'PARITY',eot
	dw	parset
	db	7,'PRINTER',eot
	dw	setprn
	db	5,'TIMER',eot
	dw	settim
	db	4,'USER',eot
	dw	setusr
	db	5,'VT100',eot
	dw	vtset
	db	7,'WARNING',eot
	dw	filwar
sethlp:
	db	eot		; Special
	dw	HdSet
	dw	TxSet
IF	GERMAN
HdSet:
	db	'VERF]GBARE SET BEFEHLE',eot
TxSet:
	db	lf
	db	cr,lf,'BAud                  '
	db	'(Rate)'
	db	cr,lf,'BLock-check-type      '
	db	'(f}r Fehler Erkennung)'
	db	cr,lf,'Disk                  '
	db	'(f}r Daten Empfang)'
	db	cr,lf,'Erase (L|sch) Warnung '
	db	'(EIN / AUS)'
	db	cr,lf,'EScape                '
	db	'(Zeichen im CONNECT Modus)'
	db	cr,lf,'File-mode             '
	db	'(f}r zu sendende Dateien)'
	db	cr,lf,'Ibm                   '
	db	'(Parit{t und Turn Around Handhabung)'
	db	cr,lf,'Lokales Echo          '
	db	'(Halb-Duplex)'
	db	cr,lf,'PArit{t               '
	db	'(f}r serielle Schnittstelle)'
	db	cr,lf,'PRinter Protokoll     '
	db	'( EIN / AUS )'
	db	cr,lf,'Timer                 '
	db	'( EIN / AUS )'
	db	cr,lf,'User                  '
	db	'(Bereich)'
	db	cr,lf,'VT100 Emulation       '
	db	'( EIN / AUS )'
	db	cr,lf,'Warnung               '
	db	'(f}r Dateinamenkonflikt)'
	db	cr,lf,eot
ELSE
HdSet:
	db	'SET COMMANDS AVAILABLE',eot
TxSet:
	db	lf
	db	cr,lf,'BAud             (rate)'
	db	cr,lf,'BLock-check-type (for error detection)'
	db	cr,lf,'Disk             (to receive data)'
	db	cr,lf,'ERase file warn  (ON / OFF)'
	db	cr,lf,'EScape           (character during '
	db	'CONNECT)'
	db	cr,lf,'File-mode        (for outgoing files)'
	db	cr,lf,'Ibm              (parity and turn '
	db	'around handling)'
	db	cr,lf,'Local-echo       (half-duplex)'
	db	cr,lf,'PArity           (for communication '
	db	'line)'
	db	cr,lf,'PRinter copy     ( ON / OFF )'
	db	cr,lf,'Timer            ( ON / OFF )'
	db	cr,lf,'User             (area)'
	db	cr,lf,'VT100 emulation  ( ON / OFF )'
	db	cr,lf,'Warning          (for filename '
	db	'conflicts)'
	db	cr,lf,eot
ENDIF;GERMAN
;
; SET BAUD command.
;
baud:
	ld	de,baudtb	; Get the address of the baud rate table
	ld	hl,bdhelp	; .. help
	call	keycmd		; Get command
	ex	de,hl		; Set Transmitter and Receiver
	call	sysbds		; Set rate
	jp	kermit
baudtb:
	db	15		; Number of rates
	db	2,'50',eot,1,1
	db	2,'75',eot,2,2
	db	3,'110',eot,3,3
	db	5,'134.5',eot,4,4
	db	3,'150',eot,5,5
	db	3,'300',eot,6,6
	db	3,'600',eot,7,7
	db	4,'1200',eot,8,8
	db	4,'1800',eot,9,9
	db	4,'2400',eot,10,10
	db	4,'3600',eot,11,11
	db	4,'4800',eot,12,12
	db	4,'7200',eot,13,13
	db	4,'9600',eot,14,14
	db	5,'19200',eot,15,15
bdhelp:
	db	eot		; Special
	dw	HdBaud
	dw	TxBaud
HdBaud:
IF	GERMAN
	db	'VERF]GBARE BAUD RATEN',eot
ELSE
	db	'BAUD RATES AVAILABLE',eot
ENDIF;GERMAN
TxBaud:
	db	cr,lf
	db	'50, 75, 110, 134.5, 150, 300, 600, 1200'
	db	cr,lf
	db	'1800, 2400, 3600, 4800, 7200, 9600, 19200'
	db	cr,lf,eot
;
; SET BLOCK-CHECK-TYPE command.
;
blkset:
	ld	de,blktab	; Get the address of the
				; Block-check table
	ld	hl,blkhlp	; And the address of the help text
	ld	bc,chktyp	; Save desired checksum type
	call	param
	jp	kermit
blktab:
	db	3		; Three entries
IF	GERMAN
	db	19,'1-ZEICHEN-PR]FSUMME',eot,'1','1'
	db	19,'2-ZEICHEN-PR]FSUMME',eot,'2','2'
	db	19,'3-ZEICHEN-CRC-CCITT',eot,'3','3'
ELSE
	db	20,'1-CHARACTER-CHECKSUM',eot,'1','1'
	db	20,'2-CHARACTER-CHECKSUM',eot,'2','2'
	db	21,'3-CHARACTER-CRC-CCITT',eot,'3','3'
ENDIF;GERMAN
blkhlp:
IF	GERMAN
	db	cr,lf,'1-ZEICHEN-PR]FSUMME'
	db	cr,lf,'2-ZEICHEN-PR]FSUMME'
	db	cr,lf,'3-ZEICHEN-CRC-CCITT',eot
ELSE
	db	cr,lf,'1-CHARACTER-CHECKSUM'
	db	cr,lf,'2-CHARACTER-CHECKSUM'
	db	cr,lf,'3-CHARACTER-CRC-CCITT',eot
ENDIF;GERMAN
;
; SET DEFAULT DISK command
;
setdsk:
	ld	a,(curdsk)
	ld	(olddsk),a
	ld	de,fcb
	ld	a,cmifin	; Get "file-spec" silently
	call	comnd
	 jp	setdi1
setdi1:
	ld	a,(fcb)
	or	a		; In case he didn't type ..
	jr	nz,setdi2	; He typed a drive-spec
	ld	a,(curdsk)	; He didn't - give him default
	jr	setdi3
setdi2:
	ld	hl,drvtbl
	ld	bc,drvlen
	cpir			; Find legal drive
	jr	nz,setdi4
	ld	(curdsk),a
	call	inidsk		; Reset disks
	ld	a,(curdsk)
setdi3:
	dec	a		; LOGDSK is relative 0
	call	logdrv		; And "LOG" it
	jp	nc,kermit	; All done
	ld	a,(olddsk)
	ld	(curdsk),a
	dec	a
	call	logdrv		; Reset old disk on error
	ld	de,cmer05
	jr	prtix
setdi4:
	ld	de,cmer04
	jr	prtix
;
; SET DEFAULT USER command
;
setusr:
	ld	de,fcb
	ld	a,cmtxt		; Get text
	call	comnd
	 jp	kermt3		; Not confirmed
	or	a		; Test any character
	jp	z,kermt3
	ld	hl,fcb
	ld	b,a		; Set count
	ld	c,0
usr1:
	ld	a,(hl)		; Test blank
	cp	' '
	jr	nz,usr2
	inc	hl
	djnz	usr1		; Empty is error
	jp	kermt3
usr2:
	call	digit
	jr	c,usrer1
	dec	b		; Test more
	jr	z,usr4
	cp	1		; Check user 10..15
	jr	nz,usrer1
	ld	c,10
	inc	hl
	ld	a,(hl)
	call	digit
	jr	c,usrer1
usr4:	
	add	a,c
	cp	15+1		; Test max
	jr	nc,usrer1
	call	logusr		; Log user
	jp	kermit
digit:
	sub	'0'
	ret	c		; Test range
	cp	9+1
	ccf
	ret
usrer1:
	ld	de,cmer06
prtix:
	call	prtstr
	jp	kermit
;
; This is the ESCAPE character SET subcommand.
;
escape:
	call	cfmcmd
	ld	de,escmes	; Get the address of the escape message.
	call	prtstr
	call	getcon		; Get the char.
	ld	(escchr),a	; Store the new escape character.
	jp	kermit
;
; This is the SET VT100 ON/OFF subcommand.
;
vtset:
	ld	bc,vt100	; Set the vt100 flag.
	jr	param..
;
; This is the LOCAL echo SET subcommand.
;
locall:
	ld	bc,ecoflg	; Set the local echo flag.
	jr	param..
;
; This is SET PRINTER ON/OFF subcommand
;
setprn:
	ld	bc,prnflg	; And store
	jr	param..
;
; This is the set timer ON/OFF subcommand
;
settim:
	ld	bc,timflg	; store flag value
	jr	param..
;
; This is the FILE-ERASE-WARNING SET subcommand
;
wrnset:
	ld	bc,erawrn	; store flag value
	jr	param..
;
; This is the FILE-WARNING SET subcommand
;
filwar:
	ld	bc,flwflg	; Set the file-warning flag.
param..:
	call	param.
	jp	kermit
;
; This is the SET IBM command.
;
ibmset:
	ld	bc,ibmflg	; Set the IBM flag.
	call	param.
	or	a		; Is it turned on?
	jr	z,ibmst1	; If not, set parity to the default.
	ld	a,ibmpar	; Get the IBM parity.
	ld	b,1		; Set local echo on.
	jr	ibmst2
ibmst1:
	ld	a,defpar
	ld	b,0		; Set local echo off.
ibmst2:
	ld	(parity),a	; Save them.
	ld	a,b
	ld	(ecoflg),a
	ld	(timflg),a	; Timer is same as local echo
	jp	kermit
;
; SET FILE-MODE command.
;
setcpm:
	ld	de,typtab
	ld	hl,typhlp
	ld	bc,cpmflg	; Set the CPM flag.
	call	param
	jp	kermit
typtab:
	db	3		; Three entries
IF	GERMAN
	db	5,'ASCII',eot,1,1
	db	5,'BIN[R',eot,2,2
	db	14,'VOREINSTELLUNG',eot,0,0
ELSE
	db	5,'ASCII',eot,1,1
	db	6,'BINARY',eot,2,2
	db	7,'DEFAULT',eot,0,0
ENDIF;GERMAN
typhlp:
IF	GERMAN
	db	cr,lf,'ASCII BIN[R VOREINSTELLUNG',eot
ELSE
	db	cr,lf,'ASCII BINARY DEFAULT',eot
ENDIF;GERMAN
;
; SET PARITY-MODE command.
;
parset:
	ld	de,partab
	ld	hl,parhlp
	ld	bc,parity	; Set the parity flag
	call	param
	jp	kermit
partab:
	db	5		; Five entries.
IF	GERMAN
	db	6,'GERADE',eot,parevn,parevn
	db	4,'EINS',eot,parmrk,parmrk
	db	5,'KEINE',eot,parnon,parnon
	db	8,'UNGERADE',eot,parodd,parodd
	db	4,'NULL',eot,parspc,parspc
ELSE
	db	4,'EVEN',eot,parevn,parevn
	db	4,'MARK',eot,parmrk,parmrk
	db	4,'NONE',eot,parnon,parnon
	db	3,'ODD',eot,parodd,parodd
	db	5,'SPACE',eot,parspc,parspc
ENDIF;GERMAN
parhlp:
IF	GERMAN
	db	cr,lf,'GERADE EINS KEINE UNGERADE NULL',eot
ELSE
	db	cr,lf,'EVEN MARK NONE ODD SPACE',eot
ENDIF;GERMAN
;
; Set parameter ON or OFF
; ENTRY	Reg BC points to parameter to be set
;
param.:
	ld	de,ontab
	ld	hl,onhlp
;
; Set parameter
; ENTRY	Reg BC points to parameter to be set
;	Reg DE points to table
;	Reg HL points to help text
;
param:
	push	bc
	call	keycmd
	ld	(temp1),a	; Save the parsed value.
	call	cfmcmd
	ld	a,(temp1)	; Get the parsed value.
	pop	hl
	ld	(hl),a		; Set the flag.
	ret
ontab:
	db	2		; Two entries.
IF	GERMAN
	db	3,'EIN',eot,1,1
	db	3,'AUS',eot,0,0
ELSE
	db	2,'ON',eot,1,1
	db	3,'OFF',eot,0,0
ENDIF;GERMAN
onhlp:
IF	GERMAN
	db	cr,lf,'AUS EIN',eot
ELSE
	db	cr,lf,'OFF ON',eot
ENDIF;GERMAN
;
; This is the STATUS command.
;
status:
	call	stat0
	jp	kermit
stat0:
	call	cfmcmd
stat01:
	ld	a,(fileio)	; Are we in transmit?
	or	a
	ld	de,xmtst	; Yes,say so
	call	nz,prtstr
	ld	de,locst	; Get the address of the
				; Local echo string.
	call	prtstr
	ld	a,(ecoflg)	; Get the local echo flag.
	call	onoff
	ld	de,cpmst	; Get the address of the
				; CPM created file.
	call	prtstr
	ld	a,(cpmflg)	; Get the CPM flag.
	or	a		; Is it on?
	jr	z,stat2		; If not say so.
	cp	1		; ASCII?
	ld	de,ascstr	; 
	jr	z,stat21	; Say ASCII
	ld	de,binstr	; Say binary
	jr	stat21
stat2:
	ld	de,defstr	; Say default.
stat21:
	call	prtstr
	ld	de,ibmst	; IBM string.
	call	prtstr
	ld	a,(ibmflg)	; IBM flag.
	call	onoff
	ld	de,erast	; File eras warning string.
	call	prtstr
	ld	a,(erawrn)	; File erase warning flag.
	call	onoff
	ld	de,filst	; File warning string.
	call	prtstr
	ld	a,(flwflg)	; File warning flag.
	call	onoff
	ld	de,vtst		; VT100 string.
	call	prtstr
	ld	a,(vt100)	; VT100 flag.
	call	onoff
	ld	de,prst		; Printer copy string
	call	prtstr
	ld	a,(prnflg)	; Printer ON/OFF flag
	call	onoff
	ld	de,parst	; Parity string.
	call	prtstr
	ld	a,(parity)	; Get the parity setting.
	ld	de,pnonst	; None by default.
	cp	parmrk		; Is it mark?
	jr	nz,stat5	; If not say so.
	ld	de,pmrkst	; Say mark.
	jr	stat55
stat5:
	cp	parspc		; Is it space?
	jr	nz,stat51	; If not say so.
	ld	de,pspcst	; Say space.
	jr	stat55
stat51:
	cp	parodd		; Is it odd?
	jr	nz,stat52	; If not say so.
	ld	de,poddst	; Say odd.
	jr	stat55
stat52:
	cp	parevn		; Is it even?
	jr	nz,stat55	; If not say so.
	ld	de,pevnst	; Say even.
stat55:
	call	prtstr
;
; Print out current BLOCK-CHECK-TYPE
;
	ld	de,bckst	; Get the string
	call	prtstr		; Print "Block check type: "
	ld	a,(chktyp)	; Get the type (character 1, 2, or 3)
	call	putcon		; Want to print it
	ld	de,bckst1	; Get rest of text ("-character")
	call	prtstr
;
; Print the current escape character
;
	ld	de,escst	; Escape string.
	call	prtstr
	call	escpr		; Print the escape char.
	call	crlf		; Print a crlf.
	call	SIO.rate	; Tell BAUD rate
	ld	de,timmsg
	call	prtstr
	ld	a,(timflg)
	call	onoff
	call	crlf
	ret
onoff:
	ld	de,offstr
	or	a
	jr	z,off		; OFF
	ld	de,onstr
off:
	call	prtstr
	ret
;
; Display SIO BAUD rate
;
SIO.rate:
	call	sysbdg		; Get rate
	ld	de,spdust	; Set illegal
	or	a
	jr	z,SIO.ill
	and	11110000b
	jr	nz,SIO.ill	; Test 01..0F
	ld	a,b
	ld	hl,baudtb-1	; Start scanning keyword table.
SIO.get:
	inc	hl
	inc	hl
	ld	b,(hl)		; Get string length.
	inc	b		; Account for $.
	inc	hl
	ld	(temp1),hl	; Save string pointer.
SIO.skp:
	inc	hl		; Loop over string.
	djnz	SIO.skp
	ld	c,(hl)		; Get speed value
	cp	c		; Match?
	jr	nz,SIO.get	; No.
	ld	de,spdst
	call	prtstr
	ld	de,(temp1)	; Restore saved string pointer.
SIO.ill:
	call	prtstr
	call	crlf		; Terminate.
	ret

