.PAGE 'SER.LISTN'
;
;
;
ACPTR	LDA #8          ; SET BYTE BIT COUNT
	STA CONT
;
ACP00A	JSR TSTATN
	JSR DEBNC
	AND #CLKIN
	BNE ACP00A
;
	JSR DATHI       ; MAKE DATA LINE HI
;
	LDA #1          ; WAIT 255 US
;
;------ROM -05 8/18/83-------------
	JMP PATCH6
;----------------------------------
;
ACP00	JSR TSTATN
	LDA IFR1
	AND #$40        ; TEST IF TIME OUT
	BNE ACP00B      ; RAN OUT,ITS AN EOI
;
	JSR DEBNC       ; TEST CLOCK LOW
	AND #CLKIN
	BEQ ACP00       ; NO
	BNE ACP01       ; YES
;
ACP00B	JSR DATLOW      ; SET DATA LINE LOW AS RESPONSE
;
	LDX #10         ; DELAY FOR TALKER TURNAROUND
ACP02	DEX
	BNE ACP02
;
	JSR DATHI       ; SET DATA LINE HI
;
ACP02A	JSR TSTATN
	JSR DEBNC       ; WAIT FOR LOW CLOCK
	AND #CLKIN
	BEQ ACP02A
;
	LDA #0          ; SET EOI RECEIVED
	STA EOIFLG
;
ACP01
ACP03	LDA PB          ; WAIT FOR CLOCK HIGH
	EOR #01         ; COMPLEMENT DATAIN
	LSR A           ; SHIFT INTO CARRY
	AND #$02        ; CLKIN/2
	BNE ACP03
;
	NOP             ; FILL SPACE LEFT BY SPEED-UP
	NOP             ; TO FIX PAL VC20
	NOP             ;  901229-02 ROM
	ROR DATA
;
ACP03A	JSR TSTATN
	JSR DEBNC
	AND #CLKIN      ; WAIT FOR CLOCK LOW
	BEQ ACP03A
;
	DEC CONT        ; MORE TO DO?
	BNE ACP03
;
	JSR DATLOW      ; SET DATA LINE LOW
	LDA DATA
	RTS
;
;
;
LISTEN	SEI
;
	JSR FNDWCH      ; TEST IF ACTIVE WRITE CHANNEL
	BCS LSN15
;
	LDA CHNRDY,X
	ROR A
	BCS LSN30
;
LSN15	LDA ORGSA       ; TEST IF OPEN
	AND #$F0
	CMP #$F0
	BEQ LSN30       ; ITS AN OPEN
;
	JMP ILERR       ; NOT ACTIVE CHANNEL
;
LSN30	JSR ACPTR       ; GET A BYTE
;
	CLI
	JSR PUT         ; PUT(DATA,EOIFLG,SA)
;
	JMP LISTEN      ; AND KEEP ON LISTEN
;
;
FRMERR
ITERR
ILERR	LDA #00         ; RELEASE ALL BUS LINES
	STA PB
	JMP IDLE
;
;
;
ATNLOW	JMP ATNSRV
;
;
; TSTATN()
; [
;  IF(ATNMOD)
;  [
;   IF(PB & $80) ATNS20();
;   ELSE RETURN ;
;  ]
;  ELSE
;  [
;   IF(PB&$80) RETURN;
;   ELSE ATNSRV();
;  ]
; ]
;
;
TSTATN	LDA ATNMOD      ; TEST IF IN ATN MODE
	BEQ TSTA50      ; NO
;
	LDA PB          ; IN ATNMOD
	BPL TATN20      ; ATN GONE,DO WHAT WE ARE TOLD TO DO
TSTRTN	RTS             ; STILL IN ATN  MODE
;
TSTA50	LDA PB          ; NOT ATNMODE
	BPL TSTRTN      ; NO ATN PRESENT
;
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
;
	JMP PTCH30      ; *** ROM DS 03/12/85 ***
;	JMP ATNSRV      ; DO ATN COMMAND
;
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
;
TATN20	JMP ATNS20
;
;
;
.END
