;
; +++++++++++++++++++++++++++
; +++ KERMIT Pure storage +++
; +++++++++++++++++++++++++++
;
kerm:
	db	'KERMIT-80 '
kerm0:				; With USER number
	db	'd'		; 'd' filled in at startup
				; With DRIVE name
kerm1:
	db	'uu'		; 'uu' filled in at startup
				; With USER number
	db	':>',eot
errmach:
IF	GERMAN
	db	'Dieses KERMIT ben|tigt eine Z80 CPU'
ELSE
	db	'This KERMIT requires a Z80 CPU, sorry'
ENDIF;GERMAN
	db	cr,lf,eot
delstr:
	db	bs,' ',bs,bs,eot ; Delete string.
clrspc:
	db	' ',bs,eot	; Clear space.
outln2:
IF	GERMAN
	_goto	10,5
	db	'Anzahl Pakete:'
	_goto	10,8
	db	'Wiederholungen:'
	_goto	10,11
	db	'Dateiname:'
	_goto	10,14
	db	'Zustand:'
	_goto	10,28
	_invers
	db	'Ctrl-X und Ctrl-Y beendet ]bertragung '
	db	' - Ctrl-C bricht sie ab'
ELSE
	_goto	10,5
	db	'Number of packets:'
	_goto	10,8
	db	'Number of retries:'
	_goto	10,11
	db	'File name:'
	_goto	10,14
	db	'State:'
	_goto	10,28
	_invers
	db	'Ctrl-X and Ctrl-Y cancel transfer '
	db	' - Ctrl-C aborts'
ENDIF;GERMAN
	_normal
	db	eot
scrnp:	_goto	29,5
	db	eot		; Place for number of packets.
scrnrt:	_goto	29,8
	db	eot		; Place for number of retries.
scrfln:	_goto	21,11
	db	eot		; Place for file name.
scrst:	_goto	17,14
	db	eot		; Place for status.
screrr:	_goto	30,17
	db	eot		; Place for error messages.
scrend:	db	cr,lf,eot

IF	GERMAN
delpr:	db	'L|schen? ',eot
ermes1:	db	cr,lf,'?Unbekannter Befehl',eot
ermes3:	db	cr,lf,'?Nicht best{tigt',eot
ermes4:	db	'?Initialisierung kann nicht empfangen werden'
$CRLF:
	db	cr,lf,eot
ermes5:	db	'?Dateiname kann nicht empfangen werden',cr,lf,eot
ermes6:	db	'?Ende der Datei kann nicht empfangen werden',cr,lf,eot
erms10:	db	'?Daten k|nnen nicht empfangen werden',cr,lf,eot
erms11:	db	'?Disk voll',cr,lf,eot
erms12:	db	'?Inhaltsverzeichnis voll',cr,lf,eot
erms14:	db	'?Best{tigung vom Host kann nicht empfangen werden'
	db	cr,lf,eot
erms15:	db	cr,lf,'?Datei nicht gefunden',cr,lf,eot
erms16:	db	'?Umbenennung unm|glich',eot
erms17:	db	cr,lf,'?Disk voll',eot
erms18:	db	cr,lf,'?Host reagiert nicht auf FINISH',eot
erms19:	db	cr,lf,'?Host reagiert nicht auf LOGOUT',eot
erms20:	db	cr,lf,'?Keine Datei gel|scht',cr,lf,eot
erms28:	db	cr,lf,'?Zu viele Versuche',eot
erms29:	db	cr,lf,'?Fehler beim Parameteraustausch',eot
samems:	db	cr,lf,'?Quell- und Zieldatei sind gleich',eot
nofile:	db	cr,lf,'?Datei nicht gefunden',eot
infms3:	db	bell,'Fertig',eot
infms4:	db	bell,'Fehlerhaft',eot
infms5:	db	'%Datei umbenannt in ',eot
infms6:	db	cr,lf,'(- Schliessen der Log Datei -)',eot
infms7:
	_goto	0,32
	_invers
	db	'(- Verbindung zum Host hergestellt, Eingabe ',eot
infms8:	db	'C f}r R}ckkehr -)'
	_normal
	_goto	0,0
	db	eot
infms9:	db	'(- Verbindung beendet, zur}ck in KERMIT -)',eot
inms10:	db	'Control-',eot
inms11:	db	' (Eingbe Linkspfeil zum Senden von CTRL-S)',cr,lf,eot
inms13:	db	bell,'Unterbrechung',eot
inms14:	db	tab,tab,'    Inhaltsverzeichnis f}r Laufwerk '
dnam14:	db	'x:',cr,lf,eot	; Filled in by dir routine.
inms15:	db	cr,lf,tab,tab,'  Laufwerk ',eot
inms16:	db	'  hat ',eot	; Filled in by summary code
				; With drive letter
inms17:	db	'K Bytes frei',cr,lf,eot
inms18:	db	cr,lf,'Datei(en) gel|scht',eot,cr,lf
inms19:	db	cr,lf,'(- Senden einer Datei zum Host:'
	db	cr,lf,' 1. Beliebige Zeichen eingeben zum Senden einer Zeile.'
	db	cr,lf,' 2. Eingabe RETURN zum Beenden der Zeile '
	db	'und na{chste Zeile eingeben (Zur}ck zu 1.)'
	db	cr,lf,'    (Es k|nnen Zeichen vorm RETURN geschickt wrerden.),'
	db	cr,lf,'   oder Eingabe ',eot
inms20:	db	'R um gleiche Zeile nochmal zu senden,'
	db	cr,lf,'   oder Einbabe ',eot
inms21:	db	'C um Senden abzubrechen. -)',cr,lf,eot
inms22:	db	cr,lf,'(- Fertig mit Senden. Normale Verbindung zum Host,'
	db	cr,lf,' Eingabe ',eot
inms23:	db	'Senden...',eot
inms24:	db	'Empfangen...',eot
inms25:	db	bell,'Achtung: Das 8. Bit kann nicht gesendet werden',eot
inms26:	db	cr,lf,bell,'LOG Datei existiert - ]berschreiben oder '
	db	'Anh{ngen',eot
inms27:	db	cr,lf,tab,tab,tab,'Keine Datei gefunden',cr,lf,eot
inms28:	db	bell,' R/O Datei - L|schen',eot
inms29:	db	'KERMIT beendet -- Zur}ck in CP/M',cr,lf,eot
inms30:	db	' (1/2) : ',eot
inms31:	db	' Datei l|schen ',eot
mid.w:	_window	0,0,30,90
big.w:	_window	0,0,31,90
cur.w:	_window	0,0,0,0

baddrv:	db	cr,lf,'++ Falsches Laufwerk',eot
cfrmes:	db	' Best{tigen mit RETURN ',eot
filhlp:	db	' Eingabedateiangabe (eventuell Wildcard) ',eot
escmes:	db	cr,lf,'Eingabe des neuen ESCAPE Zeichens: ',eot

cmer00:	db	cr,lf,'?Programm Fehler:  Ung}ltiger COMND Aufruf',eot
cmer01:	db	cr,lf,'?Nicht eindeutig',eot
cmer02:	db	cr,lf,'?Fehlerhafte CP/M Dateiangabe',eot
cmer03:	db	cr,lf,'?"*" nicht erlaubt in Dateiangabe',eot
cmer04:	db	cr,lf,'?Falsches Laufwerk',eot
cmer05:	db	cr,lf,'?Keine Diskette im Laufwerk',eot
cmer06:	db	cr,lf,'?Ung}ltiger Benutzer',eot
cmin00:	db	' Best{tigen mit RETURN',eot

giv.cr:	db	'Weiter mit RETURN oder Abbruch mit Ctrl-C',eot
ELSE
delpr:	db	'Delete it? ',eot
ermes1:	db	cr,lf,'?Unrecognized command',eot
ermes3:	db	cr,lf,'?Not confirmed',eot
ermes4:	db	'?Unable to receive initiate'
$CRLF:
	db	cr,lf,eot
ermes5:	db	'?Unable to receive file name',cr,lf,eot
ermes6:	db	'?Unable to receive end of file',cr,lf,eot
erms10:	db	'?Unable to receive data',cr,lf,eot
erms11:	db	'?Disk full',cr,lf,eot
erms12:	db	'?Directory full',cr,lf,eot
erms14:	db	'?Unable to receive an acknowledgement from '
	db	'the host',cr,lf,eot
erms15:	db	cr,lf,'?Unable to find file',cr,lf,eot
erms16:	db	'?Unable to rename file',eot
erms17:	db	cr,lf,'?Disk full',eot
erms18:	db	cr,lf,'?Unable to tell host that the session '
	db	'is finished',eot
erms19:	db	cr,lf,'?Unable to tell host to logout',eot
erms20:	db	cr,lf,'?No file erased',cr,lf,eot
erms28:	db	cr,lf,'?Too many retries',eot
erms29:	db	cr,lf,'?Failed to exchange parameters',eot
samems:	db	cr,lf,'?Source and destination files the same'
	db	eot
nofile:	db	cr,lf,'?File not found',eot
infms3:	db	bell,'Completed',eot
infms4:	db	bell,'Failed',eot
infms5:	db	'%Renaming file to ',eot
infms6:	db	cr,lf,'[Closing the log file]',eot
infms7:
	_goto	0,32
	_invers
	db	'[Connected to remote host, type ',eot
infms8:	db	'C to return]'
	_normal
	_goto	0,0
	db	eot
infms9:	db	'[Connection closed, back at micro]',eot
inms10:	db	'Control-',eot
inms11:	db	' (Type Left Arrow to send CTRL-S)',cr,lf,eot
inms13:	db	bell,'Interrupted',eot
inms14:	db	tab,tab,'    Directory for drive '
dnam14:	db	'x:',cr,lf,eot	; Filled in by dir routine.
inms15:	db	cr,lf,tab,tab,'  Drive ',eot
inms16:	db	'  has ',eot	; Filled in by summary code
				; With drive letter
inms17:	db	'K bytes free',cr,lf,eot
inms18:	db	cr,lf,'File(s) erased',eot,cr,lf
inms19:	db	cr,lf,'[Transmitting file to host:'
	db	cr,lf,' 1. Type any character to send a line.'
	db	cr,lf,' 2. Type RETURN to terminate the line '
	db	'and to get the next line (go back to 1.)'
	db	cr,lf,'    (You may send other characters '
	db	'before RETURN.),'
	db	cr,lf,'   or type ',eot
inms20:	db	'R to send the same line again,'
	db	cr,lf,'   or type ',eot
inms21:	db	'C to abort transmission.]',cr,lf,eot
inms22:	db	cr,lf,'[Transmission done. Connected normally '
	db	'to remote host,'
	db	cr,lf,' type ',eot
inms23:	db	'Sending...',eot
inms24:	db	'Receiving...',eot
inms25:	db	bell,'Warning: eighth bit cannot be sent',eot
inms26:	db	cr,lf,bell,'LOG file exist - Overwrite or '
	db	'Append',eot
inms27:	db	cr,lf,tab,tab,tab,'No file found',cr,lf,eot
inms28:	db	bell,' R/O file - Delete',eot
inms29:	db	'KERMIT finished -- back at CP/M',cr,lf,eot
inms30:	db	' (1/2) : ',eot
inms31:	db	' Delete file ',eot
mid.w:	_window	0,0,30,90
big.w:	_window	0,0,31,90
cur.w:	_window	0,0,0,0

baddrv:	db	cr,lf,'++ Bad drive name',eot
cfrmes:	db	' Confirm with carriage return ',eot
filhlp:	db	' Input file spec (possibly wild) ',eot
escmes:	db	cr,lf,'Type the new escape character:  ',eot

cmer00:	db	cr,lf,'?Program error:  Invalid COMND call',eot
cmer01:	db	cr,lf,'?Ambiguous',eot
cmer02:	db	cr,lf,'?Illegal CP/M file specification',eot
cmer03:	db	cr,lf,'?"*" not allowed in file specification',eot
cmer04:	db	cr,lf,'?Illegal drive',eot
cmer05:	db	cr,lf,'?No disk in selected drive',eot
cmer06:	db	cr,lf,'?Illegal user',eot
cmin00:	db	' Confirm with carriage return',eot

giv.cr:	db	'Press RETURN to Continue or Ctrl-C to abort',eot
ENDIF;GERMAN

;The HELP text

IF	GERMAN
yeshlp:	db	cr,lf,'NEIN JA',eot
xmthlp:	db	cr,lf,'R  Senden der gleichen Zeile',eot
inthlp:	db	cr,lf,'?  Dieser Text'
	db	cr,lf,'C  Verbindung schliessen'
	db	cr,lf,'0  Senden einer NULL'
	db	cr,lf,'B  Senden eines BREAK'
	db	cr,lf,'D  Modem abh{ngen'
	db	cr,lf,'S  Zustand dieser Verbindung'
	db	cr,lf,'W  Bildschirm l|schen'
	db	cr,lf,'P  LOG Datei pausieren oder weiter'
	db	cr,lf,'Weitere Eingabe ',eot
inhlp2:	db	' wird zum Host gesendet'
	db	cr,lf,cr,lf,'Befehl>',eot
onstr:	db	' ein',eot
offstr:	db	' aus',eot
xmtst:	db	cr,lf,'Senden einer Datei',eot

defstr:	db	' Voreinstellung',eot
ascstr:	db	' ASCII',eot
binstr:	db	' bin{r',eot

locst:	db	cr,lf,'Lokales Echo       ',eot
cpmst:	db	cr,lf,'Datei Modus        ',eot
ibmst:	db	cr,lf,'IBM Status         ',eot
erast:	db	cr,lf,'Datei L|schwarnung ',eot
filst:	db	cr,lf,'Dateiwarnung       ',eot
vtst:	db	cr,lf,'VT100 Emulation    ',eot
prst:	db	cr,lf,'Druckerprotokoll   ',eot
parst:	db	cr,lf,'Parit{t             ',eot
bckst:	db	cr,lf,'Block Test Type     ',eot
escst:	db	cr,lf,'ESCAPE Zeichen      ',eot
spdst:	db	'Baud                ',eot
timmsg:	db	'Zeitgeber          ',eot

bckst1:	db	'-Zeichen',eot
pnonst:	db	'keine',eot
pmrkst:	db	'eins',eot
pspcst:	db	'null',eot
poddst:	db	'ungerade',eot
pevnst:	db	'gerade',eot

spdust:	db	'Baud Rate ist nicht bestimmbar (nicht gesetzt)',eot

yestab:	db	2		; Two entries.
	db	4,'NEIN',eot,0,0
	db	2,'JA',eot,1,1
ELSE
yeshlp:	db	cr,lf,'NO YES',eot
xmthlp:	db	cr,lf,'R  Send the same line again',eot
inthlp:	db	cr,lf,'?  This message'
	db	cr,lf,'C  Close the connection'
	db	cr,lf,'0  (zero) Transmit a NULL'
	db	cr,lf,'B  Transmit a BREAK'
	db	cr,lf,'D  Drop DTR'
	db	cr,lf,'S  Status of the connection'
	db	cr,lf,'W  Clear screen'
	db	cr,lf,'P  Pause LOG file or continue'
	db	cr,lf,'Typing another ',eot
inhlp2:	db	' will send it to the host'
	db	cr,lf,cr,lf,'Command>',eot
onstr:	db	' on',eot
offstr:	db	' off',eot
xmtst:	db	cr,lf,'Transmitting a file',eot

defstr:	db	' default',eot
ascstr:	db	' ASCII',eot
binstr:	db	' binary',eot

locst:	db	cr,lf,'Local echo         ',eot
cpmst:	db	cr,lf,'File mode          ',eot
ibmst:	db	cr,lf,'IBM flag           ',eot
erast:	db	cr,lf,'File erase warning ',eot
filst:	db	cr,lf,'File warning       ',eot
vtst:	db	cr,lf,'VT100 emulation    ',eot
prst:	db	cr,lf,'Printer copy       ',eot
parst:	db	cr,lf,'Parity              ',eot
bckst:	db	cr,lf,'Block check type    ',eot
escst:	db	cr,lf,'Escape char         ',eot
spdst:	db	'Baud                ',eot
timmsg:	db	'Timer              ',eot

bckst1:	db	'-character',eot
pnonst:	db	'none',eot
pmrkst:	db	'mark',eot
pspcst:	db	'space',eot
poddst:	db	'odd',eot
pevnst:	db	'even',eot

spdust:	db	'Baud rate is indeterminate (not SET)',eot

yestab:	db	2		; Two entries.
	db	2,'NO',eot,0,0
	db	3,'YES',eot,1,1
ENDIF;GERMAN

;AUXIN or AUXOUT re-direction

IF	IOport	EQ	_BDOS
scb.i.g:db	aux.in,get.		; Get old vector
scb.i.p:db	aux.in,put.wrd		; Set new vector
	dw	aux.vec
scb.i.s:db	aux.in,put.wrd		; Reset old vector
	ds	2

scb.o.g:db	aux.out,get.
scb.o.p:db	aux.out,put.wrd
	dw	aux.vec
scb.o.s:db	aux.out,put.wrd
	ds	2
ENDIF;IOport EQ _BDOS

scb.er:	db	err..,get.
scb.pg:	db	pag.,get.
scb.cp:	db	curp.,get.
pagemode:db	0ffh
pagelen:db	0
pagecur:db	0

;Impure data

;COMND storage

cmstat:	ds	1	; What is presently being parsed.
cmaflg:	ds	1	; Non-zero when an action
			; Char has been found.
cmccnt:	ds	1	; Non-zero if a significant
			; Char is found.
cmsflg:	ds	1	; Non-zero when the last
			; Char was a space.
cmostp:	ds	2	; Old stack pointer for reparse.
cmrprs:	ds	2	; Address to go to on reparse.
cmprmp:	ds	2	; Address of prompt.
cmptab:	ds	2	; Address of present keyword table.
cmhlp:	ds	2	; Address of present help.
cmfcb:	ds	2	; Pointer to FCB.
cmfcb2:	ds	2	; Pointer to position in FCB.
cmfwld:	ds	1	; Wildcard flag
cmcptr:	ds	2	; Pointer for next char input.
cmdptr:	ds	2	; Pointer into the command buffer.
cmkptr:	ds	2	; Pointer to keyword.
cmsptr:	ds	2	; Place to save a pointer.
eoflag:	ds	1	; EOF flag;non-zero on EOF.
filflg:	ds	1	; Non-zero when nothing in DMA buffer.
curdsk:	db	0	; Holds "logged" disk
curusr:	db	0	; Holds "logged" user
olddsk:	db	0	; Holds old "logged" disk
prnflg:	db	0	; Flag copy to printer
timflg:	db	0	; Timer flag: 0 -> no timer
timval:	dw	0	; Timer value
wrn8:	db	0	; Non-zero if 8-bit-lost
			; Warning sent
qbchr:	db	'&'	; Binary quote character.
quot8:	db	0	; Non-zero if doing 8-bit quoting
logflg:	db	0	; Flag for a log file.
alogfl:	db	0	; Flag for an active log file.
ecoflg:	db	0	; Local echo flag (default off).
escflg:	db	0	; Escape flag (start off).

vt100:	db	1	; VT100 emulation flag (default on).
erawrn:	db	1	; File erase warning flag (default on).
flwflg:	db	1	; File warning flag (default on).
ibmflg:	db	0	; IBM flag (default off).
cpmflg:	db	1	; File was created by CPM.
parity:	db	defpar	; Parity.
escchr:	db	defesc	; Storage for the escape character.
fileio:	db	0	; Line-by-line from file (default off).
xofflg:	db	0	; X-OFF (=^S) received from COMM-line
			; X-ON (=^Q) received resets this
chrcnt:	ds	1	; Number of chars in the file buffer.
filcnt:	ds	1	; Number of chars left to fill.
outpnt:	ds	2	; Position in packet.
bufpnt:	ds	2	; Position in file buffer.
filerc:	ds	1	; File record count
fileex:	ds	1	; File extent
fcbptr:	ds	2	; Position in FCB.
datptr:	ds	2	; Position in packet data buffer.
cbfptr:	ds	2	; Position in character buffer.
pktptr:	ds	2	; Position in receive packet.
size:	ds	1	; Size of data from gtchr.
spsiz:	db	dspsiz	; Send packet size.
rpsiz:	db	drpsiz	; Receive packet size.
stime:	db	dstime	; Send time out.
rtime:	db	drtime	; Receive time out.
spad:	db	dspad	; Send padding.
rpad:	db	drpad	; Receive padding.
spadch:	db	dspadc	; Send padding char.
rpadch:	db	drpadc	; Receive padding char.
seol:	db	dseol	; Send EOL char.
reol:	db	dreol	; Receive EOL char.
squote:	db	dsquot	; Send quote char.
rquote:	db	drquot	; Receive quote char.
chktyp:	db	dschkt	; Checksum type desired
curchk:	db	dschkt	; Current checksum type
inichk:	db	dschkt	; Agreed upon checksum type
czseen:	ds	1	; Flag that control-Z was typed
pktnum:	ds	1	; Packet number.
numpkt:	ds	2	; Total number of packets sent.
numrtr:	ds	2	; Total number of retries.
numtry:	ds	1	; Number of tries on this packet.
oldtry:	ds	1	; Number of tries on previous packet.
state:	ds	1	; Present state of the automaton.
packet:	ds	4	; Packet (data is part of it).
data:	ds	90	; Data and checksum field of packet.
recpkt:	ds	101	; Receive packet storage
			; (use the following).
recpkx:	db	cr,eot	; =	=	= buffer limit
; ** Temp 1 & 2 must be in order
temp1:	ds	1	; Temporary storage.
lstchr	equ	temp1	; Last console input character.
temp2:	ds	1
temp3:	ds	1
temp4:	ds	1

filfnd:	ds	1	; File find flag
eraflg:	ds	1	; Erase flag

remtxt:	db	0	; Set <> 0 if D packets to screen
fcbnum:	ds	1	; Number of FCB's left in the list

equflg:	db	0	; Comparision flag
prflag:	db	0	; File type flag

cFCBs:	ds	FCBlen	; Copy source file
cFCBd:	ds	FCBlen	; Copy destination file
Log.FCB:ds	FCBlen	; Log file

; Unitialized storage for DIRLST
nnams:	ds	1		; Dir - names per line counter.
; Data storage for MFNAME (multi-file access)
mfflg1:	db	0		; First time thru flag for MFNAME
mffptr:	dw	0		; Pointer for MFNAME

filbuf	equ	$		; Character buffer.
fnbuf	equ	filbuf+101	; File name buffer
cmdbuf	equ	fnbuf+32	; Buffer for command parsing.
argblk	equ	cmdbuf+bufsiz
; Used for subroutine arguments
maxfil	equ	32
fcbblk	equ	argblk+32	; Used for a list of FCB's
stlev	equ	fcbblk+maxfil*16
; Room for 32 levels of calls.
stack	equ	stlev+64

@top	equ	stack+2

