;
; ++++++++++++++++++++++++++++++
; +++ KERMIT Packet routines +++
; ++++++++++++++++++++++++++++++
;
; Update counter and display
;
updrtr:
	ld	de,scrnrt	; Position cursor
	call	prtstr
	ld	hl,(numrtr)
	inc	hl		; Increment the number of retries
	ld	(numrtr),hl
	call	nout		; Write the number of retries.
	ret
;
; Initialize buffers and clear line.
;
init:
	call	ClrTop
	call	prvers		; Put Banner on screen
	ld	de,outln2	; Put statistics headers on the screen
	call	prtstr		; Only for screen-formatting versions.
	call	Invis		; Turn off cursor
init1:
	ld	a,bufsiz	; Buffer size.
	ld	(chrcnt),a	; Number of chars left.
	ld	hl,buff		; Addr for beginning.
	ld	(bufpnt),hl	; Store addr for beginning.
	ret
;
; Give final message after xfer
;
finmes:
	push	de		; Save message.
	ld	de,scrst	; Position the cursor
	call	prtstr
	call	ClrEol		; Clear rest of line
	pop	de		; Print the termination message
	call	prtstr
	ld	de,scrend	; Position cursor for prompt
	call	prtstr
	ret
;
; Abort
;
abort:
	ld	a,'A'		; Set abort state.
	ld	(state),a
	ret
;
; This routine prints parity warnings.  All registers are
; saved except for a.
;
parwrn:
	push	bc
	push	de
	push	hl
	ld	de,inms25
	call	error3
	pop	hl
	pop	de
	pop	bc
	ret
;
; This routine sets up the data for init packet
; (either the Send_init or ACK packet).
;
rpar:
	ld	a,(rpsiz)	; Get the receive packet size.
	add	a,' '		; Add a space to make it printable.
	ld	(hl),a		; Put it in the packet.
	inc	hl		; Point to the next char.
	ld	a,(rtime)	; Get the receive packet time out.
	add	a,' '		; Add a space.
	ld	(hl),a		; Put it in the packet.
	inc	hl
	ld	a,(rpad)	; Get the number of padding chars.
	add	a,' '
	ld	(hl),a
	inc	hl
	ld	a,(rpadch)	; Get the padding char.
	add	a,'@'		; Uncontrol it.
	and	NoMSB
	ld	(hl),a
	inc	hl
	ld	a,(reol)	; Get the EOL char.
	add	a,' '
	ld	(hl),a
	inc	hl
	ld	a,(rquote)	; Get the quote char.
	ld	(hl),a
	inc	hl
	ld	(hl),'Y'	; We know how to do 8-bit quoting
	ld	a,(parity)
	cp	parnon		; Parity none?
	jr	z,rpar1		; Yes, keep going
	ld	a,(qbchr)	; No, better request 8-bit quoting
	ld	(hl),a
rpar1:
	inc	hl		; Advance to next
	ld	a,(inichk)	; Get desired block check type
	ld	(hl),a		; Store it
	inc	hl		; Advance pointer
	ld	a,8		; Six pieces of data.
	ret
;
; This routine reads in all the send_init packet information.
;
spar:
	ld	(temp4),a	; Save the number of arguments.
	ld	a,(hl)		; Get the max packet size.
	sbc	a,' '		; Subtract a space.
	ld	(spsiz),a	; Save it.
	ld	a,(temp4)
	cp	3		; Fewer than three pieces?
	ret	m		; If so we are done.
	inc	hl
	inc	hl		; Increment past the time out info.
	ld	a,(hl)		; Get the number of padding chars.
	sbc	a,' '
	ld	(spad),a
	ld	a,(temp4)
	cp	4		; Fewer than four pieces?
	ret	m		; If so we are done.
	inc	hl
	ld	a,(hl)		; Get the padding char.
	add	a,'@'		; Re-controlify it.
	and	NoMSB
	ld	(spadch),a
	ld	a,(temp4)
	cp	5		; Fewer than five pieces?
	ret	m		; If so we are done.
	inc	hl
	ld	a,(hl)		; Get the EOL char.
	sbc	a,' '
	ld	(seol),a
	ld	a,(temp4)
	cp	6		; Fewer than six pieces?
	ret	m		; If so we are done.
	inc	hl
	ld	a,(hl)		; Get the quote char.
	ld	(squote),a
	ld	a,(temp4)	; Get the amount of data supplied
	cp	7		; Have an 8-bit quote?
	ret	m		; If not there, all done
	inc	hl		; Yes, get the character
	ld	a,false
	ld	(quot8),a	; Assume not quoting
	ld	a,(hl)		; Get	the	supplied character
	cp	'N'		; No?
	jr	z,spar1		; Then don't try to do it
	cp	' '		; Maybe they don't know about it...
	jr	z,spar1		; Then don't try to do it.
	cp	'Y'		; Yes?
	jr	nz,spar2
	ld	a,(parity)	; Using parity?
	cp	parnon		; No, don't need quoting...
	jr	z,spar1
	ld	a,true		; Else turn on...
	ld	(quot8),a	; ...quote flag
	jr	spar1
spar2:
	ld	(qbchr),a	; Use their quote char
				; (should validate)
	ld	a,true
	ld	(quot8),a	; Turn quote flag and fall thru...
spar1:
	ld	a,(temp4)	; Determine if block check type given
	cp	8		; Is the field there?
	ret	m		; If not, all done
	inc	hl		; Point to the character
	ld	a,(hl)		; Get the value
	ld	b,a		; Copy value
	ld	a,(chktyp)	; Get our type
	cp	b		; Is it our desired type?
	jr	z,spar01	; If so, use it
	ld	a,'1'		; No, use single character
spar01:
	ld	(inichk),a	; Store the desired block check type
	ret			; And return
;
; Send_Packet
; This routine assembles a packet from the arguments given and
; sends it to the host.
;
; Expects the following:
;	A	 - Type of packet (D,Y,N,S,R,E,F,Z,T)
;	ARGBLK	 - Packet sequence number
;	ARGBLK+1 - Number of data characters
; Returns: +1 on failure
;	   +2 on success
;
spack:
	ld	(argblk+2),a
	ld	hl,packet	; Get address of the send packet.
	ld	a,soh		; Get the start of header char.
	ld	(hl),a		; Put in the packet.
	inc	hl		; Point to next char.
	ld	a,(curchk)	; Get current checksum type
	sub	'1'		; Determine extra length of checksum
	ld	b,a		; Copy length
	ld	a,(argblk+1)	; Get the number of data chars.
	add	a,' '+3		; Real packet character count made
				; Printable.
	add	a,b		; Determine overall length
	ld	(hl),a		; Put in the packet.
	inc	hl		; Point to next char.
	ld	bc,0		; Zero the checksum AC.
	ld	c,a		; Start the checksum.
	ld	a,(argblk)	; Get the packet number.
	add	a,' '		; Add a space so the number is printable
	ld	(hl),a		; Put in the packet.
	inc	hl		; Point to next char.
	add	a,c
	ld	c,a		; Add the packet number to the checksum.
	ld	a,0		; Clear A (Cannot be XRA A, since we
				; Can't touch carry flag)
	adc	a,b		; Get high order portion of checksum
	ld	b,a		; Copy back to B
	ld	a,(argblk+2)	; Get the packet type.
	ld	(hl),a		; Put in the packet.
	inc	hl		; Point to next char.
	add	a,c
	ld	c,a		; Add the packet number to the checksum.
	ld	a,0		; Clear A
	adc	a,b		; Get high order portion of checksum
	ld	b,a		; Copy back to B
spack2:
	ld	a,(argblk+1)	; Get the packet size.
	or	a		; Are there any chars of data?
	jr	z,spack3	; No, finish up.
	dec	a		; Decrement the char count.
	ld	(argblk+1),a	; Put it back.
	ld	a,(hl)		; Get the next char.
	inc	hl		; Point to next char.
	add	a,c
	ld	c,a		; Add the packet number to the checksum.
	ld	a,0		; Clear A
	adc	a,b		; Get high order portion of checksum
	ld	b,a		; Copy back to B
	jr	spack2		; Go try again.
spack3:
	ld	a,(curchk)	; Get the current checksum type
	cp	'2'		; Two character?
	jr	z,spack4	; Yes, go handle it
	jr	nc,spack5	; No, go handle CRC if '3'
	ld	a,c		; Get the character total.
	and	0c0h		; Turn off all but the two
				; High order bits.
				; Shift them into the low order position
	rlca			; Two left rotates same as 6 rights
	rlca
	add	a,c		; Add it to the old bits.
	and	3fh		; Turn off the two high order bits.
				; (MOD 64)
	add	a,' '		; Add a space so the number is printable
	ld	(hl),a		; Put in the packet.
	inc	hl		; Point to next char.
	jr	spack7		; Go store eol character
;
; Here for 3 character CRC-CCITT
;
spack5:
	ld	(hl),0		; Store a null for current end
	push	hl		; Save H
	ld	hl,packet+1	; Point to first checksumed character
	call	crcclc		; Calculate the CRC
	pop	hl		; Restore the pointer
	ld	c,e		; Get low order half for later
	ld	b,d		; Copy the high order
	ld	a,d		; Get the high order portion
	rlca			; Shift off low 4 bits
	rlca
	rlca
	rlca
	and	0fh		; Keep only low 4 bits
	add	a,' '		; Put into printing range
	ld	(hl),a		; Store the character
	inc	hl		; Point to next position
;
; Here for two character checksum
;
spack4:
	ld	a,b		; Get high order portion
	and	0fh		; Only keep last four bits
	rlca			; Shift up two bits
	rlca
	ld	b,a		; Copy back into safe place
	ld	a,c		; Get low order half
	rlca			; Shift  high two bits
	rlca			; To low two bits
	and	03h		; Keep only two low bits
	or	b		; Get high order portion in
	add	a,' '		; Convert to printing character range
	ld	(hl),a		; Store the character
	inc	hl		; Point to next character
	ld	a,c		; Get low order portion
	and	3fh		; Keep only six bits
	add	a,' '		; Convert to printing range
	ld	(hl),a		; Store it
	inc	hl		; Bump the pointer
spack7:
	ld	a,(seol)	; Get the EOL the other host wants.
	ld	(hl),a		; Put in the packet.
	inc	hl		; Point to next char.
	xor	a		; Get a null.
	ld	(hl),a		; Put in the packet.
	call	outpkt		; Call the system dependent routine.
	 jp	r
	jp	rskp
;
; Receive_Packet
; This routine waits for a packet to arrive from the host.
; It reads characters until it finds a SOH. It then reads
; the packet into packet.
;
; Returns:  +1 failure  (if the checksum is wrong or the
;			 packet trashed)
;	    +2 success with A	    - message type
;		ARGBLK	 - message number
;		ARGBLK+1 - length of data
;
rpack:
	call	inpkt		; Read up to a carriage return.
	 jp	r		; Return bad.
rpack0:
	call	getchr		; Get a character.
	 jp	rpack		; Hit a CR;null line;just start over.
	cp	soh		; Is the char the start of header char?
	jr	nz,rpack0	; No, go until it is.
rpack1:
	call	getchr		; Get a character.
	 jp	r		; Hit the carriage return, return bad.
	cp	soh		; Is the char the start of header char?
	jr	z,rpack1	; Yes, then go start over.
	ld	(packet+1),a	; Store in packet also
	ld	c,a		; Start the checksum.
	ld	a,(curchk)	; Get block check type
	sub	'1'		; Determine extra length of block check
	ld	b,a		; Get a copy
	ld	a,c		; Get back length character
	sub	' '+3		; Get the real data count.
	sub	b		; Get total length
	ld	(argblk+1),a
	ld	b,0		; Clear high order half of checksum
	call	getchr		; Get a character.
	 jp	r		; Hit the carriage return, return bad.
	cp	soh		; Is the char the start of header char?
	jr	z,rpack1	; Yes, then go start over.
	ld	(argblk),a
	ld	(packet+2),a	; Save also in packet
	add	a,c
	ld	c,a		; Add the character to the checksum.
	ld	a,0		; Clear A
	adc	a,b		; Get high order portion of checksum
	ld	b,a		; Copy back to B
	ld	a,(argblk)
	sub	' '		; Get the real packet number.
	ld	(argblk),a
	call	getchr		; Get a character.
	 jp	r		; Hit the carriage return, return bad.
	cp	soh		; Is the char the start of header char?
	jr	z,rpack1	; Yes, then go start over.
	ld	(temp1),a	; Save the message type.
	ld	(packet+3),a	; Save in packet
	add	a,c
	ld	c,a		; Add the character to the checksum.
	ld	a,0		; Clear A
	adc	a,b		; Get high order portion of checksum
	ld	b,a		; Copy back to B
	ld	a,(argblk+1)	; Get the number of data characters.
	ld	(temp2),a
	ld	hl,data		; Point to the data buffer.
	ld	(datptr),hl
rpack2:
	ld	a,(temp2)
	sub	1		; Any data characters?
	jr	c,rpack3	; If not go get the checksum.
	ld	(temp2),a
	call	getchr		; Get a character.
	 jp	r		; Hit the carriage return, return bad.
	cp	soh		; Is the char the start of header char?
	jr	z,rpack1	; Yes, then go start over.
	ld	hl,(datptr)
	ld	(hl),a		; Put the char into the packet.
	inc	hl		; Point to the next character.
	ld	(datptr),hl
	add	a,c
	ld	c,a		; Add the character to the checksum.
	ld	a,0		; Clear A
	adc	a,b		; Get high order portion of checksum
	ld	b,a		; Copy back to B
	jr	rpack2		; Go get another.
rpack3:
	call	getchr		; Get a character.
	 jp	r		; Hit the carriage return, return bad.
	cp	soh		; Is the char the start of header char?
	jp	z,rpack1	; Yes, then go start over.
	sub	' '		; Turn the char back into a number.
	ld	(temp3),a
				; Determine type of checksum
	ld	a,(curchk)	; Get the current checksum type
	cp	'2'		; 1, 2 or 3 character?
	jr	z,rpack4	; If zero, 2 character
	jr	nc,rpack5	; Go handle 3 character
	ld	a,c		; Get the character total.
	and	0c0h		; Turn off all but the two
				; High order bits.
				; Shift them into the low order position
	rlca			; Two left rotates same as six rights
	rlca
	add	a,c		; Add it to the old bits.
	and	3fh		; Turn off the two high order bits.
				; (MOD 64)
	ld	b,a
	ld	a,(temp3)	; Get the real received checksum.
	cp	b		; Are they equal?
	jr	z,rpack7	; If so, proceed.
rpack9:
	call	updrtr		; If not, update the number of retries.
	ret			; Return error.
;
; Here for three character CRC-CCITT
;
rpack5:
	ld	hl,(datptr)	; Get the address of the data
	ld	(hl),0		; Store a zero in the buffer to
				; Terminate packet
	ld	hl,packet+1	; Point at start of checksummed region
	call	crcclc		; Calculate the CRC
	ld	c,e		; Save low order half for later
	ld	b,d		; Also copy high order
	ld	a,d		; Get high byte
	rlca			; Want high four bits
	rlca
	rlca			; And shift two more
	rlca
	and	0fh		; Keep only 4 bits
	ld	d,a		; Back into D
	ld	a,(temp3)	; Get first value back
	cp	d		; Correct?
	jp	nz,rpack9	; No, punt
	call	getchr		; Get a character.
	 jp	r		; Hit the carriage return, return bad.
	cp	soh		; Is the char the start of header char?
	jp	z,rpack1	; Yes, then go start over.
	sub	' '		; Remove space offset
	ld	(temp3),a	; Store for later check
;
; Here for a two character checksum and
; last two characters of CRC
;
rpack4:
	ld	a,b		; Get high order portion
	and	0fh		; Only four bits
	rlca			; Shift up two bits
	rlca
	ld	b,a		; Save back in B
	ld	a,c		; Get low order
	rlca			; Move two high bits to low bits
	rlca
	and	03h		; Save only low two bits
	or	b		; Get other 4 bits
	ld	b,a		; Save back in B
	ld	a,(temp3)	; Get this portion of checksum
	cp	b		; Check first half
	jr	nz,rpack9	; If bad, go give up
	call	getchr		; Get a character.
	 jp	r		; Hit the carriage return, return bad.
	cp	soh		; Is the char the start of header char?
	jp	z,rpack1	; Yes, then go start over.
	sub	' '		; Remove space offset
	ld	b,a		; Save in safe place
	ld	a,c		; Get low 8 bits of checksum
	and	3fh		; Keep only 6 bits
	cp	b		; Correct value
	jr	nz,rpack9	; Bad, give up
rpack7:
	ld	hl,(datptr)
	ld	(hl),0		; Put a null at the end of the data.
	ld	a,(temp1)	; Get the type.
	jp	rskp
;
; Input a packet
;
inpkt:
	ld	hl,recpkt	; Point to the beginning of the packet.
	ld	(pktptr),hl
inpkt1:
	call	inchr		; Get first character
	 jp	r		; Return failure
	cp	soh		; Is it the beginning of a packet?
	jr	nz,inpkt1	; If not, ignore leading junk
	jr	inpkt3		; Else go put it in packet
inpkt2:
	call	inchr		; Get a character.
	 jp	r		; Return failure.
	cp	soh		; Is it a new beginning of packet?
	jr	nz,inpkt3	; If not continue
	ld	hl,recpkt	; Else throw away what we've got so far
	ld	(pktptr),hl
inpkt3:
	ld	hl,(pktptr)
	ld	(hl),a		; Put the char in the packet.
	inc	hl
	ld	(pktptr),hl
	ld	b,a
	ld	de,recpkx	; Start over if packet buffer overflow
	add	hl,de
	jr	c,inpkt		; 
	ld	a,(reol)	; Get the EOL char.
	cp	b
	jr	nz,inpkt2	; If not loop for another.
;
; Begin IBM change/fdc
; This moved from OUTPK7 -- it appears that waiting until we're
; ready to send a packet before looking for turnaround character
; is long enough for it to get lost.  Better to look now.
;
inpkt4:
	ld	a,(ibmflg)	; Is this the IBM?
	or	a
	jr	z,inpkt6	; If not then proceed.
	ld	a,(state)	; Check if this is the Send-Init packet.
	cp	'S'
	jr	z,inpkt6	; If so don't wait for the XON.
inpkt5:
	call	inchr		; Wait for the turn around char.
	 jp	inpkt6
	cp	xon		; Is it the IBM turn around character?
	jr	nz,inpkt5	; If not, go until it is.
inpkt6:
	ld	hl,(pktptr)	; Reload packet pointer
	ld	(hl),cr		; Set a carriage-return to stop rpack:
;
; End IBM change/fdc.
;
	ld	hl,recpkt
	ld	(pktptr),hl	; Save the packet pointer.
	jp	rskp		; If so we are done.
;
; Write out a packet.
;
outpkt:
	ld	a,(spad)	; Get the number of padding chars.
	ld	(temp1),a
outpk2:
	ld	a,(temp1)	; Get the count.
	dec	a
	or	a
	jp	m,outpk6	; If none left proceed.
	ld	(temp1),a
	ld	a,(spadch)	; Get the padding char.
	ld	e,a		; Put the char in right AC.
	call	outchr		; Output it.
	jr	outpk2
outpk6:
	ld	hl,packet	; Point to the packet.
outlup:
	ld	a,(hl)		; Get the next character.
	or	a		; Is it a null?
	jp	z,rskp		; If so return success.
	ld	e,a		; Put the char in right AC.
	call	outchr		; Output the character.
	inc	hl		; Increment the char pointer.
	jr	outlup
;
; Put a char from A to the port.
;
outchr:
	push	hl
	push	bc
	ld	a,e
	call	setpar
	call	prtout		; Output the character
	pop	bc
	pop	hl
	ret
;
; Get a char from the port and return in A.
;
inchr:
	push	hl
	push	bc
inchr2:
	call	auxrdy		; Get auxin status
	jr	nz,inchr3	; We have one
	call	conrdy		; See if char from keyboard
	jr	z,inchr2	; Nothing, check auxin
	call	getcon		; Get Keyboard-Input
	cp	cr		; Carriage return?
	jr	nz,inchr4	; Take only Carriage returns
	pop	bc
	pop	hl
	ret
;
; Here if not a cr, check other possibilities
;
inchr4:
	cp	'Z'-'@'		; Control-Z?
	jr	z,inchr5	; Yes, go flag it
	cp	'C'-'@'		; Control-C?
	jp	z,reenter	; Re-enter, he wants to get out
	cp	'X'-'@'		; Control-X?
	jr	nz,inchr2	; No, try for another character
	pop	bc
	pop	hl
	ret			; And return
inchr5:
	add	a,'@'		; Convert to printing range
	ld	(czseen),a	; Flag we saw a control-Z
	pop	bc		; Restore B
	pop	hl		; And H
	ret			; And return
inchr3:
	call	auxchr		; We got a char at COMM-Port
	ld	b,a
	ld	a,(parity)	; Is the parity none?
	cp	parnon
	ld	a,b
	pop	bc
	pop	hl
	jp	z,rskp		; Return, we have COMM-Character
	and	NoMSB		; Strip Parity bit
	jp	rskp		; And return, we have COMM-Character
;
; Get character from packet
;
getchr:
	ld	hl,(pktptr)	; Get the packet pointer.
	ld	a,(hl)		; Get the char.
	inc	hl
	ld	(pktptr),hl
	cp	cr		; Is it the carriage return?
	jp	nz,rskp		; If not return retskp.
	ret			; If so return failure.
;
; Set the parity for a character in A.
;
setpar:
	push	hl		; Save HL.
	push	bc
	ld	hl,parity
	ld	c,(hl)		; Get the parity routine.
	ld	b,0
	ld	hl,parjmp	; Get the first address.
	add	hl,bc
	jp	(hl)
parjmp:
	jp	even
	jp	mark
	jp	none
	jp	odd
	jp	space
even:
	and	NoMSB		; Strip parity.
	jp	pe,parret	; Already even, leave it.
	or	MSB		; Make it even parity.
	jr	parret
mark:
	or	MSB		; Turn on the parity bit.
	jr	parret
odd:
	and	NoMSB		; Strip parity.
	jp	po,parret	; Already odd, leave it.
	or	MSB		; Make it odd parity.
	jr	parret
space:
	and	NoMSB		; Turn off the parity bit.
none:				; Don't touch the parity bit.
parret:
	pop	bc
	pop	hl		; Restore HL.
	ret
;
; CRCCLC - Routine to calculate a CRC-CCITT for a string.
;
; This routine will calculate a CRC using the CCITT
; polynomial for a string.
;
; Usage:
;	HL/ Address of string
;	A/  Length of string
;	CALL CRCCLC
;
; 16-bit CRC value is returned in DE.
;
; Registers BC and HL are preserved.
;
crcclc:
	push	hl		; Save HL
	push	bc		; And BC
	ld	de,0		; Initial CRC value is 0
crccl0:
	ld	a,(hl)		; Get a character
	or	a		; Check if zero
	jr	z,crccl1	; If so, all done
	push	hl		; Save the pointer
	xor	e		; Add in with previous value
	ld	e,a		; Get a copy
	and	0fh		; Get last 4 bits of combined value
	ld	c,a		; Get into C
	ld	b,0		; And make high order zero
	ld	hl,crctb2	; Point at low order table
	add	hl,bc		; Point to correct entry
	add	hl,bc
	push	hl		; Save the address
	ld	a,e		; Get combined value back again
	rrca			; Shift over to make index
	rrca
	rrca
	and	1eh		; Keep only 4 bits
	ld	c,a		; Set up to offset table
	ld	hl,crctab	; Point at high order table
	add	hl,bc		; Correct entry
	ld	a,(hl)		; Get low order portion of entry
	xor	d		; XOR with previous high order half
	inc	hl		; Point to high order byte
	ld	d,(hl)		; Get into D
	pop	hl		; Get back pointer to other table entry
	xor	(hl)		; Include with new high order half
	ld	e,a		; Copy new low order portion
	inc	hl		; Point to other portion
	ld	a,(hl)		; Get the other portion of
				; The table entry
	xor	d		; Include with other high order portion
	ld	d,a		; Move back into D
	pop	hl		; And H
	inc	hl		; Point to next character
	jr	crccl0		; Go get next character
crccl1:
	pop	bc		; Restore B
	pop	hl		; And HL
	ret			; And return, DE=CRC-CCITT
crctab:
	dw	00000h,01081h,02102h,03183h,04204h,05285h
	dw	06306h,07387h,08408h,09489h,0a50ah,0b58bh
	dw	0c60ch,0d68dh,0e70eh,0f78fh
crctb2:
	dw	00000h,01189h,02312h,0329bh,04624h,057adh
	dw	06536h,074bfh,08c48h,09dc1h,0af5ah,0bed3h
	dw	0ca6ch,0dbe5h,0e97eh,0f8f7h
;
; This is where we go if we get an error during
; a protocol communication.
;   Call error  prints the error packet on line 6 or so.
;   Call error1 print CRLF followed by the error packet.
;   Call error2 just prints the error packet.
;   Call error3 positions cursor and prints error message
;	        specified in DE.
;
error:
	call	error9		; Position the cursor.
	call	abort		; Set the state to abort.
	jr	error2
error1:
	call	crlf		; Print a CRLF.
error2:
	ld	a,(argblk+1)	; Get the length of the data.
	ld	c,a
	ld	b,0		; Put it into BC
	ld	hl,data		; Get the address of the data.
	add	hl,bc		; Get to the end of the string.
	ld	(hl),eot	; Put a sign at the end.
	ld	de,data		; Print error message
	call	prtstr
	ret
error3:
	push	de		; Save the pointer to the message.
	call	error9		; Position the cursor.
	call	DelLin		; Delete the line
	pop	de		; Get the pointer back.
	call	prtstr		; Print error message
	ret
error9:
	ld	de,screrr	; Position cursor
	call	prtstr
	ret

