	DIM ACIA, ACIA1, XON/:11/, BYTE$(1), LINE$(100), ESC/:1B/
	DIM CHAR, JUNK, DELAY, I
	INPUT 'ACIA: ' ACIA
	ACIA1 = ACIA + 1
	POKE ACIA, :3
	POKE ACIA, :15
	INPUT 'DELAY: ' DELAY
	INPUT 'FILE: ' LINE$
	INPUT 'T/R: ' BYTE$
	IF BYTE$ = 'R' OR BYTE$ = 'r' THEN 1000
	OPEN #1, LINE$
	CHAR = XON
	GOTO 21 \ ! WAIT FOR XON

10	GOSUB 2000
11	IF PEEK(ACIA)&2 = 0 THEN 11
	POKE ACIA1, CHAR
15	IF PEEK(ACIA)&1 = 0 THEN 15 \ ! GET MY OWN ECHO
	JUNK = PEEK(ACIA1)
21	IF PEEK(ACIA)&1 = 0 THEN 21 \ ! GET HIS ECHO
	JUNK = :FF - PEEK(ACIA1)
	IF CHAR <> JUNK THEN 30
	READ #1, BYTE$ \ CHAR = BYTE$(1)
	IF EOF(1) THEN 35
	IF CHAR <> XON AND CHAR <> ESC THEN 10
	GOSUB 2000
22	IF PEEK(ACIA)&2 = 0 THEN 22
	POKE ACIA1, ESC
24	IF PEEK(ACIA)&1 = 0 THEN 24 \ ! GET MY OWN ECHO
	JUNK = PEEK(ACIA1)
25	IF PEEK(ACIA)&1 = 0 THEN 25 \ ! GET HIS ECHO
	JUNK = :FF - PEEK(ACIA1)
	IF JUNK = ESC THEN 10
30	PRINT 'TRANSMISSION ERROR'
	STOP
35	GOSUB 2000
36	IF PEEK(ACIA)&2 = 0 THEN 36
	POKE ACIA1, XON
	PRINT 'EOF HIT'
	STOP

1000	INPUT 'O/C: ' BYTE$
	IF BYTE$ = 'C' OR BYTE$ = 'c' THEN CREATE #1, LINE$ ELSE OPEN #1, LINE$
	CHAR = XON
	GOTO 1010
1005	BYTE$(1) = CHAR \ WRITE #1, BYTE$
	GOSUB 2000
1010	IF PEEK(ACIA)&2 = 0 THEN 1010
	POKE ACIA1, :FF - CHAR
1015	IF PEEK(ACIA)&1 = 0 THEN 1015 \ ! GET MY OWN ECHO
	JUNK = PEEK(ACIA1)
1020	IF PEEK(ACIA)&1 = 0 THEN 1020 \ ! GET THE TRANSMITTED CHAR
	CHAR = PEEK(ACIA1)
	IF CHAR = XON THEN 1060
	IF CHAR <> ESC THEN 1005
1030	GOSUB 2000
1031	IF PEEK(ACIA)&2 = 0 THEN 1031
	POKE ACIA1, :FF - ESC
1040	IF PEEK(ACIA)&1 = 0 THEN 1040 \ ! GET MY OWN ECHO
	JUNK = PEEK(ACIA1)
1050	IF PEEK(ACIA)&1 = 0 THEN 1050 \ ! GET THE TRANSMITTED CHAR
	CHAR = PEEK(ACIA1)
	GOTO 1005
1060	PRINT 'EOF HIT'

2000	IF DELAY = 0 THEN RETURN
	FOR I = 1 TO DELAY
	NEXT I
	RETURN

	END
