		SUBTITLE	"< Chain IO. >"
		newpage
		scope

; Update to LSDOS 6.3.1 2022-09-16 dpm
			
$?2		PUSH	HL
		POP	IX
zCHNIO		LD	L,(IX+1) 	;P/u vector address
		LD	H,(IX+2)
$?3		LD	A,(IX+0)	;P/u the DCB type
		OR	A		;File Control Block?
		JP	M,zspace.BYTEIO$
		BIT	3,A		;Test NIL bit 2nd
		JR	NZ,$?5
		BIT	4,A		;Routed?
		JR	NZ,$?2		;Go get routed DCB
		BIT	5,A		;If not linked, then
		JR	Z,$?1		;must be filtered
		PUSH	HL		;Point to the link DCB
		POP	IX
		LD	(IX+3),B	;Save the direction
		PUSH	IX
		CALL	zCHNIO		;I/O to 1st device
		POP	IX
		LD	B,(IX+3)	;P/u the direction
		JR	NZ,$?6		;Go on NZ flag

; Z-flag on return - check input/output

		BIT	0,B		;If input & got char,
$?4		LD	L,(IX+4)	;p/u the linked DCB
		LD	H,(IX+5)
		JR	Z,$?2
$?5		CP	A
		RET

; 1st link got NZ condition - if input, get link

$?6		BIT	0,B		;Was it input/output?
		JR	Z,$?7		;Output is error
		OR	A		;If A=0, then no input
		JR	Z,$?4
$?7		OR	A
		RET