;--------------------------------------------------------
; echo
;
; Another program to test communications cables and
; software setup.  This just echos whatever arrives
; from the auxiliary input device back to the auxiliary
; output device.
;
; The program can be terminated from the auxiliary input
; device or from the console keyboard by pressing the
; ESC key.  The idea of allowing termination from the
; console is so the program can be terminated even if
; the auxiliary device baud rate is wrong.
;--------------------------------------------------------
	.z80
auxist	equ	7
auxin	equ	3
auxout	equ	4
conin	equ	1
conist	equ	11
cpm	equ	5
esc	equ	27
cr	equ	13
lf	equ	10

bdos	macro	fn
	ld	c,fn
	call	cpm
	or	a
	endm

	aseg
	org	100h

chkcon:
	bdos	conist		; Finish if an ESC has been
	jr	z,chkaux	; entered at the console
	bdos	conin
	cp	esc
	jr	z,finis
chkaux:
	bdos	auxist		; Similarly, an ESC from the
	jr	z,chkcon	; auxiliary device terminates
	bdos	auxin		; the program
	cp	esc
	jr	z,finis
	push	af
	ld	e,a
	bdos	auxout
	pop	af
	cp	cr		; A carriage return also
	jr	nz,chkaux	; sends a line feed
	ld	e,lf
	bdos	auxout
	jr	chkaux
finis:
	rst	0
	end
