;
; ++++++++++++++++++++++++
; +++ KERMIT main part +++
; ++++++++++++++++++++++++
;
start:
	sub	a		; Test correct CPU
	jp	po,Z80ok
	ld	de,errmach
	jp	prxit		; Tell illegal machine
Z80ok:
	call	getcpm		; Get CP/M version
	cp	vcpm3		; Must be version 3.0
	jr	c,amserr
	call	getenv		; Get environment
	jr	z,goon		; .. ok
amserr:
	ld	de,errver	; Else tell error
prxit:
	call	prtstr		; Tell error
	jp	warm		; Bye, bye
goon:
	call	sysini		; Init the system
	ld	hl,(BDOS+1)
	call	syspdm		; Init menue control
	call	sysxy		; Get cursor
	ld	ix,cur.w+2
	ld	hl,32*256+32
	add	hl,bc
	ld	(ix+0),h	; Save as ESCape sequence
	ld	(ix+1),l
	ld	hl,32*256+32
	add	hl,de
	ld	(ix+2),h
	ld	(ix+3),l
	ld	de,big.w
	call	pr.window	; Print big window
reenter:
	call	ClrTop
	call	prvers		; Print version header
	jr	kermit
..reent:
	call	prtstr
;
; This is the main KERMIT loop.
; It prompts for and gets the users commands.
;
kermit:
	ld	sp,stack	; Move in our own stack.
	call	getdrv		; Get our logged in drive
	inc	a		; Relative 1 !
	ld	(curdsk),a	; And save it for later
	add	a,'A'-1
	ld	(kerm0),a
	call	getusr		; Get current user
	ld	(curusr),a
	ld	ix,kerm1
	ld	a,l		; Test tens
	cp	' '
	jr	z,..usr.0..9
	ld	(ix),a		; .. set it
	inc	ix
..usr.0..9:
	ld	(ix+0),h	; Set user units
	ld	(ix+1),':'	; .. and delimiter
	ld	(ix+2),'>'
	ld	(ix+3),eot
	call	Visib		; Make cursor visible
	ld	de,kerm
	call	prompt		; Prompt the user.
	ld	de,comtab
	ld	hl,tophlp
	call	keycmd
	ex	de,hl		; Get the address of the jump table.
	jp	(hl)
kermt2:
	ld	de,ermes1	; "Unrecognized Command"
	jr	.kermit3	; Do it again.
kermt3:
	ld	de,ermes3	; "Not confirmed"
.kermit3:
	call	prtstr
	jr	kermit		; Do it again.
;
; The command table
;
comtab:	db	24		; Number of entries
				; (currently 24.)
	db	3,'BYE',eot
	dw	bye
	db	5,'CLEAR',eot
	dw	clrscr
	db	7,'CONNECT',eot
	dw	telnet
	db	4,'COPY',eot
	dw	copy
	db	3,'DIR',eot
	dw	dir
	db	10,'DISCONNECT',eot
	dw	disconnect
	db	3,'ERA',eot
	dw	era
	db	4,'EXIT',eot
	dw	exit
	db	6,'FINISH',eot
	dw	finish
	db	3,'GET',eot
	dw	read
	db	6,'HANGUP',eot
	dw	hangup
	db	4,'HELP',eot
	dw	help
	db	3,'LOG',eot
	dw	log
	db	6,'LOGOUT',eot
	dw	logout
	db	5,'PRINT',eot
	dw	print
	db	4,'QUIT',eot
	dw	quit
	db	7,'RECEIVE',eot
	dw	read
	db	6,'REMOTE',eot
	dw	remote
	db	4,'SEND',eot
	dw	send
	db	3,'SET',eot
	dw	setcom
	db	6,'STATUS',eot
	dw	status
	db	8,'TRANSMIT',eot
	dw	xmit
	db	4,'TYPE',eot
	dw	type
	db	7,'VERSION',eot
	dw	version
tophlp:
	db	eot		; Indicate special
	dw	HdHelp
	dw	TxHelp
IF	GERMAN
HdHelp:
	db	'VERF]GBARE BEFEHLE',eot
TxHelp:
	db	lf
	db	cr,lf,'Bye        zum Host (LOGOUT) und '
	db	'R}ckkehr nach CP/M'
	db	cr,lf,'CLear      Screen - Bildschirm l|schen'
	db	cr,lf,'CONnect    Verbindung herstellen'
	db	cr,lf,'DISconnect Verbindung abbauen - '
	db	'DTR r}cksetzen'
	db	cr,lf,'HAngup     Verbindung abbauen - '
	db	'DTR kurz r}cksetzen'
	db	cr,lf,'COPy       Kopieren einer CP/M Datei'
	db	cr,lf,'ERa        L|schen  einer CP/M Datei'
	db	cr,lf,'EXit       R}ckkehr zu  CP/M - Setzen '
	db	'des alten DTR Zustandes'
	db	cr,lf,'Quit       KERMIT, R}ckkehr zu CP/M'
	db	' - DTR bleibt bestehen'
	db	cr,lf,'Finish     Beenden von KERMIT '
	db	'auf der entfernten Maschine'
	db	cr,lf,'HElp (?)   Ausgabe dieses Textes'
	db	cr,lf,'DIR        Dateiliste ausgeben'
	db	cr,lf,'LOG        Terminalausgaben protokollieren'
	db	cr,lf,'LOGOut     Aus Host ausloggen'
	db	cr,lf,'RECeive    Empfangen einer Datei vom Host'
	db	cr,lf,'Get        Empfangen einer Datei vom Host'
	db	' (im Server Modus)'
	db	cr,lf,'REMote     Entferntes Kommando'
	db	cr,lf,'SENd       Senden einer Datei zum Host'
	db	cr,lf,'SET        Setzen einer Einstellung'
	db	cr,lf,'STatus     Anzeigen der Einstellungen'
	db	cr,lf,'TRansmit   Senden einer Datei '
	db	'(im direkten Modus)'
	db	cr,lf,'Print      Drucken einer Datei'
	db	cr,lf,'TYpe       Ausgabe einer Datei'
	db	cr,lf,'Version    von KERMIT anzeigen'
	db	cr,lf,eot
ELSE
HdHelp:
	db	'MAIN COMMANDS AVAILABLE',eot
TxHelp:
	db	lf
	db	cr,lf,'Bye         to host (LOGOUT) and '
	db	'exit to CP/M'
	db	cr,lf,'CLear       screen of local terminal'
	db	cr,lf,'CONnect     to host on selected port'
	db	cr,lf,'DISconnect  conncetion - drop DTR'
	db	cr,lf,'HAngup      disconnect dropping DTR'
	db	' a short time'
	db	cr,lf,'COPy        a CP/M file'
	db	cr,lf,'ERa         a CP/M file'
	db	cr,lf,'EXit        to CP/M - Set old DTR'
	db	cr,lf,'Quit        KERMIT, exit to CP/M'
	db	' - Let DTR in tact'
	db	cr,lf,'Finish      running KERMIT on the host'
	db	cr,lf,'HElp (?)    by giving this message'
	db	cr,lf,'DIR         of current used Micro-disk'
	db	cr,lf,'LOG         the terminal session to a file'
	db	cr,lf,'LOGOut      the host'
	db	cr,lf,'RECeive     file from host'
	db	cr,lf,'Get         file from host '
	db	'(in server mode)'
	db	cr,lf,'REMote      command'
	db	cr,lf,'SENd        file to host'
	db	cr,lf,'SET         a parameter'
	db	cr,lf,'STatus      of KERMIT'
	db	cr,lf,'TRansmit    file to host '
	db	'(in connect state)'
	db	cr,lf,'Print       a file'
	db	cr,lf,'TYpe        a file'
	db	cr,lf,'Version     of KERMIT'
	db	cr,lf,eot
ENDIF;GERMAN

