	WITH	WI=80,DE=51,NDMP
	IFUND	EXORCISOR
EXORCISOR	EQU	1
	FIN
	IF	EXORCISOR
SR1	EQU	$FCF8
SR2	EQU	$FCF9
RDR	EQU	$FCFA
CPUID	EQU	$FCFB
CR1	EQU	$FCF8
CR2	EQU	$FCF9
CR3	EQU	$FCF9
CR4	EQU	$FCFB
TXD	EQU	$FCFA
TXL	EQU	$FCFB
	ELSE
SR1	EQU	$F518
SR2	EQU	$F519
RDR	EQU	$F51A
CPUID	EQU	$F51B
CR1	EQU	$F518
CR2	EQU	$F519
CR3	EQU	$F519
CR4	EQU	$F51B
TXD	EQU	$F51A
TXL	EQU	$F51B
	FIN
	ORG	$1000
BEGIN	LDAA	#$C1	RESET ADLC
	STAA	CR1
	CLR	CR3
	LDAA	#$9E
	STAA	CR4
	LDAA	#$82
	STAA	CR1
	CLR	CR2
WANTXMIT	LDAA	#1	I WANT TO SEND!
	STAA	CR1
	LDAA	#$80	FALL INTO SYNC
	STAA	CR3
	LDAA	SR2
	LDAA	#$80	HOLD TX RESET, SEL CR2
	STAA	CR1
	LDAA	#$20
	STAA	CR2
	LDAA	SR2
	BITA	#$20	DCD ?
	BNE	SEND
	LDAA	#$1	CARRIER DETECTED, DISABLE DCD INPUT
	STAA	CR1
	LDAA	#0
	STAA	CR3
	LDAA	#0
	STAA	CR1
	BRA	WANTXMIT	SHOULD LOOP ON NOT GONE HIGH YET?

SEND	LDAA	#$C1	SEL CR3, KEEP TX RESET, CLEAR RX
	STAA	CR1
	LDAA	#0	DISABLE DTR (DCD SENSE)
	STAA	CR3
	LDAA	#$40	SEL CR2, KEEP RX RESET
	STAA	CR1
	LDAA	#$E0	ISSUE RTS, ACK DCD, CLEAR TXSTS
	STAA	CR2	CTS GLITCHES 1-10US AFTER RTS ISSUED
	LDAB	SR1	READ STATUS REGISTER TO GET CTS STATUS
	STAA	CR2	ACK CTS TO IGNORE INITIAL GLITCH
	LDX	#$1200-1
	LDAB	#$40
LL	INX
	LDAA	0,X
	CMPB	SR1
	BEQ	L2
	PSHA
	LDAA	#$0E
L0	CMPB	SR1
	BEQ	L1
	DECA
	BNE	L0
	LDX	SR1	GET COPY OF STATUS FOR DEBUG PURPOSES
	INS
	JMP	WANTXMIT
L1	PULA
L2	STAA	TXD
	CPX	#ENDMSG
	BNE	LL
	LDAA	#$10	SEND CRC, TAKE AWAY RTS
	STAA	CR2
	LDAA	SR1
	CMPA	#0
*	DON'T WE HAVE TO WAIT FOR MESSAGE COMPLETELY XMITTED BEFORE ISSUING TXRS?
	BNE	OOPS
	LDAA	#82	CLEAR TX, ENB INT
	STAA	CR1
	LDX	#1000
WAIT	DEX
	BNE	WAIT
	JMP	WANTXMIT
OOPS	JMP	BEGIN

SCREAM	LDAA	$FCF4
	BITA	#2
	BEQ	SCREAM
	LDAA	#7
	STAA	$FCF5
	JMP	WANTXMIT

	
	ORG	$1200
	FCB	$3	= ADDRESS BYTE
	FCC	'IRA WAS HERE!'
ENDMSG	EQU	*
	ORG	$2000
RECEIVE	EQU	*
	LDX	#RECVBUF	ZAP THE BUFFER
RECEIVEL	CLR	0,X
	INX
	CPX	#RECVBUFLIM
	BNE	RECEIVEL
RECV1	LDAA	#$C0	RESET BOTH XMIT AND RCV
	STAA	CR1
	LDAA	#$82	SET UP INT ON RCV
	STAA	CR1
	LDX	#(8*(2000/125)*3)/(4+4+4+4)	= 24 BIT TIMES...
RWIL	DEX
	BEQ	RIL	B/ IDLE DIDN'T COME (??)
	LDAA	SR1	WAIT FOR IDLE LOOP
	BPL	RWIL	B/ NOT YET
	LDAB	SR2	AN IDLE ?
	BITB	#4
	BNE	R0B	B/ YES, GO ACK
RIL	LDAA	SR1	ADLC?
	BPL	RIL
	LDX	SR1
	CPX	#$8381	ADLC ?
	BEQ	RD	B/ DATA RECEIVED
	LDAA	SR2	ADLC WANT OUR ATTENTION ?
	BEQ	RECEIVE
	BITA	#$DC	AN ERROR ?
	BNE	R0B	B/ NOPE
	BITA	#$20	DCD ?
	BEQ	BARF	NO, IMPOSSIBLE STATUS!
	JMP	RECV1

BARF	SWI

R0B	LDAA	#$20	ACK THE ERROR
	STAA	CR2
	JMP	RIL

RL6	LDAA	#$E
RL6A	CMPB	SR1	MORE DATA ARRIVE ?
	BEQ	RL7
	DECA
	BNE	RL6A
	LDAA	SR1
	CMPA	#$83
	BNE	R8
	LDAB	SR2
	CMPB	#$82
	BNE	R8
	LDAB	RDR	FETCH LAST BYTE
	STAB	0,X
R8	LDX	SR1	MESSAGE COMPLETE!
	JMP	RECEIVE

RD	LDX	#RECVBUF
	LDAB	#$81
RL7	LDAA	RDR	FETCH DATA BYTE
	STAA	0,X
	INX
	CPX	#RECVBUFLIM
	BNE	RL6	B/ OK TO RECV MORE
	JMP	R8	B/ RECEIVE BUFFER EXHAUSTED

RECVBUF	RMB	100
RECVBUFLIM	EQU	*
	END
