;----------------------------------------------------------------;
;								 ;
;	MODULE - @CHN						 ;
;	LAST UPDATE: AUG 15, 1980				 ;
;								 ;
;----------------------------------------------------------------;
;
;	NOTE: THE BODY OF THIS ROUTINE IS ACTUALLY EXECUTED AT 80H+SYSBASE
;	THIS ALLOWS THIS ROUTINE TO RESIDE ANYWHERE AND
;	BE MOVED TO 80H+SYSBASE JUST BEFORE EXECUTION THIS ROUTINE ALSO
;	NOW USES THE DEFAULT FILE CONTROL BLOCK.
;

	INCLUDE	BCONFIG.LIB

	IF	TRS80
SYSBASE	SET	4200H
	ELSE
SYSBASE	SET	0
	ENDIF

@CHN::
RTPCHAIN:
	POP	H
	POP	D			;GET FCB ADDRESS
	LXI	B,33
	LXI	H,5CH+SYSBASE
	PUSH	H
	PUSH	D
	PUSH	B
	CALL	@MVL##		;MOVE FCB TO DEFAULT AREA



	IF	TRS80
	LXI	SP,4300H
	ELSE
	LXI	SP,100H
	ENDIF


	LXI	H,100H+SYSBASE
	PUSH	H		;SAVE READ-IN LOCATION (ON THE NEW STACK)


;
;	NOW MOVE THE REAL WORKHORSE ROUTINE TO 80H
;
	LXI	D,RTPCHN1
	LXI	H,80H
	LXI	B,RTNLEN
	PUSH	H
	PUSH	D
	PUSH	B
	CALL	@MVL##
	JMP	80H+SYSBASE	;AND GO FINISH IT OFF

;
;	NOTE: THIS CODE ACTUALLY IS MOVED TO 80H+SYSBASE
;	PRIOR TO EXECUTION
;

RTPCHN1:
			
	POP	D		;GET ADDR OF I/O BUFFER
	PUSH	D		;SAVE IT AGAIN
	MVI	C,26		;SETDMA CALL TO BDOS
	CALL	BDOS		;
	POP	H		;NOW BUMP IT BY 128
	LXI	D,128		;
	DAD	D		;
	PUSH	H		;SAVE IT AGAIN
	LXI	D,5CH+SYSBASE	;GET FCB ADDRESS
	MVI	C,20		;REQUEST A READ
	CALL	BDOS		;
	CPI	1		;END OF FILE?
	JNZ	80H+SYSBASE	;(RTPCHN1) RELOCATED

	POP	H		;WHEN DONE FLUSH THE STACK
	JMP	100H+SYSBASE	;AND OFF TO THE NEWLY LOADED PROGRAM

RTNLEN	EQU	$-RTPCHN1
	END
