; 
; IEEE-488 DIAGNOSE PROGRAMM
;
R0 EQU 0000H ; I\O REG
R1 EQU 0001H ; INT1\STAT1
R2 EQU 0002H ; INT2\STAT2
R3 EQU 0003H ; SER.PO\SER.PO
R4 EQU 0004H ; ADDR STA\ADDR.MOD
R5 EQU 0005H ; COM.PA.TH\AUX.MOD
R6 EQU 0006H ; ADDR.0\ADDR.0/1
R7 EQU 0007H ; ADDR.1\EOS
ISL1 EQU 0038H ;INTERF.SEL.LINE
ISL2 EQU 0030H ;INTERF SEL. TOOL
;
; STEUER PROGRAMMTEIL
;
ORG 100H
;
ENTR:	LXI SP,STAE+256 ;STACK AREA
	CALL CLSC	;CLEAR SCREEN
	LXI D,IN1Z
	CALL ANZ	;PRINT HAED LINES
ENTY:	MVI C,1		;WAIT FOR INKEY
	CALL 5
	CPI 03H		;IF ^C IS HIT
	JZ 0		;EXIT TO OS
	CPI 0DH
	JNZ ENTY 
BUTE:	LXI H,ISTA	;INTF. TABLE
	LXI B,0637H	;ADAP. FOR TEST 
BAAD:	MOV A,M		;GET ADDRESS
	ADI 06H
	STA EING
	STA AUSG
	MOV A,C
	DB 0D3H		;OP FOR OUT
AUSG:	DB 0
	MVI A,0		;CLEAR ACCU
	DB 0DBH		;OP FOR IN
EING:	DB 0
	CMP C
	JZ ENTT
	DCR B
	JZ BERR		;BUS TEST ERRO
	INX H
	JMP BAAD
BERR:	CALL CLSC	;CLEAR SCREEN
	LXI D,IN7Z
	CALL ANZ	;DISP. IFSEL TABLE
BREN:	MVI C,1
	CALL 5		;RESET SYSTEM
	CPI 0DH
	JNZ BREN
	JMP ENTR
ENTT:	SHLD ISAT
	LXI D,BSPO+6	;BASE PO ADDR.
	LXI B,2		;FOR 2 BYTES
	CALL ERDE
	CALL CLSC	;CLAER SCREEN
	LXI D,IN6Z	;PRINT BASE PO ADDR.
	CALL ANZ	
ENT8:	MVI C,1
	CALL 5		;WAIT FOR INKEY
	CPI 0DH
	JNZ ENT8
ENTS:	CALL CLSC	;CLEAR SCREEN
	LXI D,IN3Z
	CALL INDIS	;DISPLAY MODE
	STA DIMO
	LXI D,IN4Z	;CONTI. ON ERRO
	CALL INDIS
	STA COMO	;CONT. ON ERRO YES
	LXI D,IN5Z	;PROGRAM LOOP
	CALL INDIS
	STA DILO	;SAVE LOOP CODE
	CALL CRLF	;CR LF	
	CALL CRLF
ENT4:	JMP ZWER	;START
INDIS:	CALL CRLF	;SET CURS.
	CALL ANZ
INDI2:	MVI C,1
	CALL 5		;GET CHR FROM KEYB.
	CPI 59H		;CHECK YES OR NO
	RZ
	CPI 4EH		;N
	MVI A,0		;IF NO	
	RZ
	JMP INDI2
ERRO:	LHLD ERCO	;ERROR COUNTER
	INX H
	SHLD ERCO
	CALL DELT
	LDA DIMO
	RRC		;IF DISLAY N
	JC ZWES
	LDA COMO	;CONTIN. ON ERROR
	RRC
	CNC ERDI	;DISPLAY ERROR COUNTER
	JMP ERST
ERRP:	JMP ZWES	;ERRO DISP ONLY
ERST:	LDA ELOO
	CPI 4CH		;TEST IF LOOP
	JZ ERLP
	CALL CLSC	;CLEAR SCREEN
ERSX:	MVI C,2		;CURSOR HOME
	MVI E,1EH
	CALL 5
	LXI D,IN8Y	; TEXT LINE
	CALL ANZ
ERSS:	CALL KEY	;INPUT FROM KEYBOARD
	CPI 44H
	JNZ ERSU
	CALL CRLF	;CR/LF
	CALL ERDO	;DIPLAY ERRO COUNTER
ERSU:	LDA KBY
	CPI 4CH		;TEST LOOP
	JZ ERLO
	CPI 43H		;CONTINUE
	JZ ERSO
	CPI 51H
	JZ ERSZ		;ABORT PROGRAM
	CPI 44H
	JZ ERSY		;DISPLAY ERR
	LDA ELOO
	CPI 4CH
	JZ ERLP		;IF LOOP IS PROGRAM.
	JMP ERSS
ERLO:	LDA KBY
	STA ELOO	;ERROR LOOP
	MVI A,0
	STA KBY
ERLP:	CALL KEY	;IN KEY
	CPI 0
	JZ ERLQ
	LDA KBY		;TEST INPUT
	CPI 51H		;IF Q
	JNZ ERLQ
	MVI A,0
	STA ELOO
	STA KBY		;CLEAR INPUT
ERLQ:	LHLD PRCO
	DCX H
	DCX H
	SHLD PRCO	;PROG. COUNTER
	LHLD STCO
	DCX H
	DCX H
	SHLD STCO	;ST COUNTER
	JMP ERRP
ERSO:	MVI A,0
	STA KBY
	STA ELOO	;CLEAR ERROR LOOP
	JMP ERRP
ERSY:	MVI A,0
	STA ELOO
	STA KBY
	JMP ERSX
ERSZ:	MVI A,0
	STA ELOO
	STA DILO
	JMP AEND	
ZWER:	CALL ERDH
	LXI D,EI2Y	;OK TO SCREEN
	CALL ANZ
ZWES:	LHLD PRCO	;PROGRAM COUNTER
	CALL ROUN	;START ADDRESS
	SHLD PRCO	;SAVE PROGRAM COUNTER
	PUSH D
	LDA DIMO	;TEST IF DISPLAY
	RRC
	CC  DSMO	;DISPLAY ALL STATUS
	MVI A,0		;CLEAR STATUS FIELD
	STA STBYM
	STA STBYM+1
	STA STBYS
	STA STBYS+1
	LXI H,BUFF0	;DAT.BUFFER ADDR.
	SHLD REARR
	LHLD STCO	;INDIC. COUNTER
	INX H
	INX H
	SHLD STCO	;SAVE NEW COUNT.
	POP H		;GET NEXT ROUTIN
	PCHL
AEND:	LXI H,ROGR	;START PROGR. AT STEP 2
	SHLD PRCO
	LXI H,0		;SET DISP. COUNTER
	SHLD STCO
	CALL CRLF	;CR LF. NEXT LINE
	LXI D,INCY
	CALL ANZ	;OPERATOR LEAD THROUGH
	LXI B,0FF0FH	;DELAY FOR DISPLAY
	CALL WAITA
AENE:	CALL KEY	;GET KEYB. INPUT
	CPI 0
	JZ AENF		;IF NOT KEY PRESSED
	LDA KBY	
	CPI 51H		;IF Q IS PRESSED
	CZ LOEO		;LOESHE LOOP
	LDA KBY 
	CPI 03H		;TEST ^C FOR TERMINATE
	JZ BENE
	CPI 0DH
	JZ BNDE		;IF CR CONTINUE
	CPI 52H
	JZ ENTS		;RESTART
AENF:	LDA DIMO
	RRC
	JC AENE		;IF DISP.IS ON
	LDA DILO	;IF CONT.RUN IS ON
	RRC
	JC BNDE
	JMP AENE
LOEO:	MVI A,0
	STA DILO
	RET		
BENE:	LXI H,000EH	;CURSOR TO LAST LINE
	SHLD STCO
	CALL ERDO
	LXI SP,0100H	;RESTORE SP
	CALL 5
BNDE:	CALL CLSC	;CLEAR SCREEN
	JMP ZWER	;NEXT TEST
DSMO:	LXI H,STBYM+2	;STATUS ARRAY MASTER
	MVI B,R4
	CALL COIP	;IN REG 4
	MOV M,A		;STORE STATUS BYTE
	INX H
	MVI B,R5	;COMMAND PAS THROUGH
	CALL COIP
	MOV M,A		;STORE STATUS BYTE
	INX H
	MVI B,R6	;READ ADDRESS REG.
	CALL COIP
	MOV E,A
	MVI B,R7	;READ EOI BIT
	CALL COIP
 	ANI 80H
	ORA E
	MOV M,A
	INX H
	MVI B,R3	;READ DEV. ADDRESS
	CALL COIP
	MOV M,A
	LXI H,STBYS+2	;STATUS SLAVE	
	IN ISL2+R4
	MOV M,A
	INX H
	IN ISL2+R5
	MOV M,A
	INX H
	IN ISL2+R6
	MOV C,A
	IN ISL2+R7	;READ EOI LINE STATUS
	ANI 80H
	ORA C
	MOV M,A		;SAVE EOI IN ADDRESS BYTE
	INX H
	IN ISL2+R3
	MOV M,A
	CALL DISP	;DISPLAY ALL STATUS
	LXI D,INDY	;DISP.LEAD THROUGH,
	CALL ANZ
	CALL ERDO
DSM1:	MVI C,1		;WAITE FOR KEY INPUT
	CALL 5
	CPI 0DH
	JNZ DSM1
	LXI H,POSI	;RESET DIP COUNTER
	SHLD PONO
	RET
ERDO:	LXI B,4		;SET EVENT COUNTER
	LXI D,EREN+6	;ERROR COUNT DIS.TEXT
	LXI H,ERCO	;ERROR COUNTER
	CALL ERDE
	CALL ERDH
	LXI D,EI1Y
	CALL ANZ	;OUT ERRO COUNT
	RET
ERDI:	CALL ERDO
	XTHL
	INX H
	INX H
	INX H
	XTHL
	RET
ROUN:	MOV E,M		;GET ADDR FROM MEMO.
	INX H
	MOV D,M
	INX H
	RET
ERDH:	LXI D,PONT	;DIS.TEXT
	LHLD STCO
	DAD D		;TEXT FOR COUNTER
	CALL ROUN	;ADDR FROM MEMO
	CALL ANZ
	RET
ERDE:	MOV A,M		;GET LOW BYTE
ERDF:	ANI 0FH		;CUT LOWER BITS
	CPI 09H
	CNC ERDG	;IF GRATER AS 9
	ORI 30H		;SET ZONE BITS
	DCX D
	STAX D		;STORE ASCI CODE
	DCR C		;BYTE COUNTER
	RZ		;CONV FINISH
	MOV A,C		;BYTE COU IN ACCU
	CPI 2
	JNZ ERDK
	INX H
	JMP ERDE	;NEXT BYTE
ERDK:	MOV A,M
	RRC
	RRC
	RRC
	RRC
	JMP ERDF
ERDG:	SUI 09H		;IF DIGI > 9
	JZ ERDM		;IF DIGI = 9
	ORI 40H		;SET ZONE BITS
ERDL:	XTHL		;VAR RETURN ADDR
	INX H
	INX H
	XTHL
	RET
ERDM:	MVI A,39H
	JMP ERDL
;
;INITIALISATION
;	 
INIT: 	LXI B,0502H  ;CHIP RESET
	CALL COOP
	MOV A,C		;CODE FOR SLAVE
      	OUT ISL2+R5
      	XRA A        ;CLEAR ACCU
      	OUT ISL2+R1  ;DISABLE TOOL INTERR.
      	LXI B,0100H     ;DISABLE INTERR.
	CALL COOP
	XRA A
      	OUT ISL2+R2 
      	LXI B,0200H     ;DISABLE DMA
      	CALL COOP
	MVI A,31H
	OUT ISL2+R4
      	LXI B,0431H     ;SET T/R MO3,SET ADDR.MO1
      	CALL COOP
      	MVI A,01H
	OUT ISL2+R6	;SLAVE ADDRESS
      	LXI B,0620H     ;MY TALK ADDRESS
	CALL COOP
      	MVI A,0E0H      ;DISABLE 2.ADDRESS
      	OUT ISL2+R6	;SEC. ADDR DISABLE
	LXI B,06E0H
	CALL COOP
      	MVI A,0AH	;TERMINATOR
	OUT ISL2+R7
	LXI B,070AH
      	CALL COOP
      	MVI A,26H    ;FREQ. COUNTER
      	OUT ISL2+R5
      	LXI B,0526H
	CALL COOP
      	MVI A,94H   ;MODE A REGISTER
      	OUT ISL2+R5
	LXI B,0594H
	CALL COOP
      	MVI A,0B0H  ;MODE B REGISTER
      	OUT ISL2+R5
      	LXI B,05A0H
	CALL COOP
	LXI B,0570H
	CALL COOP	;DISABLE PP RESP.	
	MVI A,14H
	OUT ISL2+R5 ;DISABLE CONTROLLER	
      	XRA A       ;CLEAR ACCU
      	OUT ISL2+R5
	IN ISL2+R4
	ANI 40H		;TEST ATN LINE OFF
	JZ ERRO 
      	LXI B,0500H 	 ;IMMEDIATE EXEC.
      	CALL COOP
	IN ISL2+R6
	CPI 01H
	JNZ ERRO	;SLAVE ADDR.TEST
	CALL IFC
	MVI B,04	;TEST CONTROLLER ON
	CALL COIP
	ANI 80H
	JZ ERRO
	IN ISL2+R4
	ANI 40H
	JNZ ERRO	;TEST ATN LINE ON
	JMP ZWER
;
; TEST STATUS MASTER
;
CSTM: 	PUSH H	;SAVE REG. H
      	PUSH B
	MVI C,0FH	;TIMEOUT COUNTER
CST1:  	LXI H,STBYM
	MOV A,E		;CLEAR STA. BIT
	CALL CSTX
      	MVI B,R1
	CALL COIP
      	ORA M      ;SAVE STATUS BYTE
	MOV M,A
	ANA E      ;TEST STATUS
      	JNZ CST2   ;IF STATUS IS OK
	INX H
	MOV A,D
	CALL CSTX	;TEST STATUS
      	MVI B,R2   ;GET 2.STATUS BYTE
      	CALL COIP
	ORA M      ;SAVE STATUS BYTE
      	MOV M,A
	ANA D      ;TEST STATUS
      	JNZ CST2
	DCR C	   ;DECREMENT TIMEOUT
	JNZ CST1	
      	MVI A,0    ;SET ERR. IND
CST2: 	POP B
      	POP H
      	RET
;
CSTX:	CMA	    	;TEST STATUS
	ANA M
	MOV M,A
	RET	
;
; TEST STATUS SLAVE
;
CSTS: 	PUSH H	;SAVE REG. H
      	PUSH B
	MVI C,0FH	;TIMEOUT COUNTER
CSS1:  	LXI H,STBYS
	MOV A,E
	CALL CSTX
      	IN ISL2+R1
      	ORA M      ;SAVE STATUS BYTE
      	MOV M,A	
	ANA E      ;TEST STATUS
      	JNZ CSS2   ;IF STATUS IS OK
	INX H
	MOV A,D
	CALL CSTX
      	IN ISL2+R2 ;GET 2.STATUS BYTE
      	ORA M      ;SAVE STATUS BYTE
      	MOV M,A
	ANA D      ;TEST STATUS
      	JNZ CSS2
	DCR C
	JNZ CSS1
      	MVI A,0    ;SET ERR. IND
CSS2: 	POP B
      	POP H
      	RET
;
; ADDRESS FOR RECEIVE
;
ADMS:	LXI D,0800H ;STATUS EXEPTED
	CALL CSTM	;GET STATUS
	CPI 00H
	RZ
	LXI B,0041H	;SEND TALKER ADDR.
	CALL COOP
	LXI B,0513H	;OUT MY LISTEN ADDR.
	CALL COOP
	RET  	
;
; ADDRESS FOR SEND
;
ADSS:	LXI D,0800H ;STATUS EXEPTED
	CALL CSTM	;GET STATUS
	CPI 00H
	RZ
	LXI B,003FH	;SEND UNLISTEN
	CALL COOP
	CALL CSTM	;TEST STATUS
	CPI 00H
	RZ
	LXI B,0021H	;SEND LISTEN ADDR.
	CALL COOP
	CALL CSTM
	CPI 00H
	RZ
	LXI B,0040H	;OUT MY TALKER ADDR.
	CALL COOP
	RET
;
; SET DMA CONTROLLER
;
DMA:	MVI A,0
	OUT 44		;RESET CONTOLLER
	OUT 40		;COMMAND REG.
	OUT 42
	OUT 33		;BYTE COUNT
	OUT 33
	MOV A,L		;BYTE ADDRESS
	OUT 32
	MOV A,H
	OUT 32
	RET  	
;
; SEND ROUTINES
;
SERE:	CALL IFC
	LXI B,04B0H	;TALK ONLY
	CALL COOP
	MVI A,70H
	OUT ISL2+R4
	LXI B,0510H
	CALL COOP	;CONTR IN STAND BY
	MVI A,08H 
SEN1:	STA SECO
	LXI D,0002H	;STATUS FOR DO
	CALL CSTM	;TEST STATUS
	CPI 00H
	JZ ERRO		;IF WRONG STATUS
	LDA SEBY	;GET SEND BYTE
	MOV C,A
	MVI B,R0
	CALL COOP	;SEND BYTE
	LHLD REARR	;RECEIVE ARRAY
	LXI D,0001H	;STATUS FOR DI
	CALL CSTS	;TEST STATUS
	CPI 00H
	JZ ERRO
	IN ISL2+R0	;RECEIVE BYTE
	MOV M,A		;SAVE BYTE
 	MOV C,A
	LDA SEBY	;GET REFER BYTE
	CMP C		;COMP WITH REFER.
	JNZ ERRO	;IF NOT EQUAL
	INX H
	RLC
	STA SEBY	;SAVE NEXT SENDBYTE
	SHLD REARR	;SAVE ARRAY ADDR.
	LDA SECO
	DCR A
	JNZ SEN1	;NEXT BYTE FOR SENDING
	LXI D,0002H
	CALL CSTM	;TEST STATUS FOR RECEIVE
	CPI 0
	JZ ERRO
	LXI H,TERA
	MVI M,0AH
	MVI A,08H	;DMA DIRECTION
	OUT 43
	CALL DMA	;SET DMA
	LXI B,0220H	;ENABLE DMA REQ.
	CALL COOP
	LXI D,0010H	;TEST END
	CALL CSTS
	CPI 0
	JZ ERRO 
	IN 40
	ANI 01H		;TEST DMA FINISH
	JZ ERRO
	LXI B,0200H
	CALL COOP
	IN ISL2+R0	;IN TERMINATOR
	CPI 0AH		;TEST TERM.
	JNZ ERRO
	CALL DELT
	JMP ZWER
;
SECO:	DB 0
TERA:	DB 0
;
; RECEIVE ROUTINE
;
RERE:	CALL IFC
	LXI B,0470H	;LISTEN ONLY ON
	CALL COOP
	MVI A,0B0H
	OUT ISL2+R4
	LXI B,0510H	;CONTR. STAND BY
	CALL COOP
	MVI A,08H 
REN1:	STA SECO
	LXI D,0002H	;STATUS FOR DO
	CALL CSTS	;TEST STATUS
	CPI 00H
	JZ ERRO		;IF WRONG STATUS
	LDA SEBY		;GET SEND BYTE
	OUT ISL2+R0	;SEND BYTE
	LHLD REARR	;RECEIVE ARRAY
	LXI D,0001H	;STATUS FOR DI
	CALL CSTM	;TEST STATUS
	CPI 00H
	JZ ERRO
	MVI B,R0
	CALL COIP	;RECIVE BYTE
	MOV C,A		;SAVE BYTE
 	MOV M,A
	LDA SEBY	;GET REFER BYTE
	CMP C		;COMP WITH REFER.
	JNZ ERRO	;IF NOT EQUAL
	INX H
	RLC
	STA SEBY	;SAVE NEXT SENDBYTE
	SHLD REARR	;SAVE ARRAY ADDR.
	LDA SECO
	DCR A
	JNZ REN1	;NEXT BYTE FOR OUTPUT
	LXI H,TERA
	MVI M,0
	MVI A,04H
	OUT 43
	CALL DMA
	MVI A,05H	;DMA LENGHT
	OUT 33
	LXI B,0110H
	CALL COOP
	LXI B,0210H	;ENABLE END INTERR.
	CALL COOP
	LXI D,0002H
	CALL CSTS	;TEST STATUS
	MVI A,0AH	;LOAD TERMINATOR
	OUT ISL2+R0	;SEND TERM.
	LXI D,0010H
	CALL CSTM
	CPI 0
	JZ ERRO
	IN 40		;TEST DMA FINISH
	ANI 01H
	JZ ERRO
	MVI B,R0
	CALL COIP	;GET TERMINATOR
	XRA A
	LDA TERA
	CPI 0AH
	JNZ ERRO	;IF NOT TERM.
	LXI B,0100H	;DIS DMA REQ.
	CALL COOP
	LXI B,0200H	;DIS END INTERR.
	CALL COOP
	IN 33		;DMA COUNT
	IN 33
	CPI 0FFH	;IF TC FAIL
	JZ ERRO
	OUT 44
	CALL DELT
	JMP ZWER
;
; SERIAL POLL TEST
;
SEPE:	CALL IFC
	LXI B,0018H	;ENABLE SERIAL POLL
	CALL COOP	
	CALL CSTM
	LXI B,0041H	;TOOL TALKER ADDR.
	CALL COOP
	LXI B,0513H	;CONTR LISTENER
	CALL COOP
	LXI B,0510H
	CALL COOP	;CONTR. IN STAND BY
	LXI D,00001H
	CALL CSTM
	CPI 0
	JZ ERRO
	MVI B,0
	CALL COIP	;IN PER. STATUS
	STA BUFF0
	CPI 46H		;TEST @ STORE DEV.STATUS
	JNZ ERRO
	LXI B,0511H
	CALL COOP	;TAKE CONTR.
	LXI D,0800H	;TEST CONTR. ON	
	CALL CSTM
	CPI 0
	JZ ERRO
	LXI B,0019H	;DISABLE SERIAL POLL
	CALL COOP
	JMP ZWER
;
; TEST PARALLEL POLL
;
PARE:	CALL IFC
	LXI B,0501H
	CALL COOP
	LXI B,0015H
	CALL COOP	;PP UNCONFIG.
	CALL ADSS
	CPI 0
	JZ ERRO
	CALL CSTM	;TEST STATUS
	LXI B,0005H	;PP ENABLE
	CALL COOP
	CALL CSTM	;TEST STATUS
	LXI B,0069H	;SET SENSE & LINE
	CALL COOP
	CALL IFC
	LXI B,051DH
	CALL COOP
	MVI B,R5
	CALL COIP
	CPI 0		;TEST PP LINE OFF
	JNZ ERRO
	MVI A,46H	;SET SRQ LINE
	OUT ISL2+R3
	LXI D,4000H	;TEST SRQ ON
	CALL CSTM
	CPI 0
	JZ ERRO
	LXI B,051DH	;PP IDENTY.
	CALL COOP
	LXI D,0800H	;TEST STATUS
	CALL CSTM
	CPI 0
	JZ ERRO
	MVI B,R5	;READ COM.PAS.THROUGH
	CALL COIP
	CPI 02H		;TEST PP LINE ON
	JNZ ERRO
	JMP ZWER
;
; TEST REMOTELINE DEVCLEAR EOILINE
;
RECT:	CALL IFC
	LXI B,051FH	;SET REMOTE LINE
	CALL COOP
	CALL ADSS	;ADDR. LISTENER
	CPI 0
	JZ ERRO
	LXI D,1000H	;TEST REN ON
	CALL CSTS
	CPI 0
	JZ ERRO
	LXI D,0800H
	CALL CSTM	;TEST CONTR. IN CHARGE
	LXI B,0014H
	CALL COOP	;SELEC DEV.CLEAR
	LXI D,0008H	;TEST STATUS
	CALL CSTM
	CPI 0
	JZ ERRO
	LXI B,0510H	;CONTR STAND BY
	CALL COOP	
	LXI B,0506H	;CHECK EOI SEND
	CALL COOP
	LXI D,0002H	;TEST STATUS
	CALL CSTM
	LXI B,0068H	;SEND CHAR WITH EOI
	CALL COOP	
	LXI D,0001H	;TEST RECEIVE
	CALL CSTS
	IN ISL2+R0
	LXI D,0002H
	CALL CSTM	;STATUS BUS READY
	CPI 0
	JZ ERRO
	LXI B,0511H
	CALL COOP	;TAKE CONTR.
	IN ISL2+R7
	ANI 80H
	JZ ERRO
	CALL ADMS
	LXI B,0510H	;CONTR STAND BY
	CALL COOP
	MVI A,06H
	OUT ISL2+R5	;EOI CHECK RECEIVE
	LXI D,0002H
	CALL CSTS
	MVI A,97H
	OUT ISL2+R0
	LXI D,0010H
	CALL CSTM	;TEST END STATUS BIT
	MVI B,07H
	CALL COIP	;GET EOI BIT
	ANI 80H
	JZ ERRO
	MVI B,00
	CALL COIP	;GET RECEIVED BYTE
	LXI B,0511H
	CALL COOP
	LXI B,0517H	;RESET REN
	CALL COOP
	LXI B,0110H	;DELAY COUNTER
	CALL WAITA
	LXI D,0200H
	CALL CSTS	;TEST REN DISA.
	CPI 0
	JZ ERRO
	JMP ZWER
;
KEY:	MVI C,0BH       ;INPUT STATUS
	CALL 5
	CPI 0
	RZ		;IF NOT KEY PRESSED
	MVI C,01H
	CALL 5
	STA KBY		;KEY IS PRESSED
	RET
;
IFC: 	LXI B,051EH	 ;SET IFC CODE
	CALL COOP
	LXI B,0110H 	 ;SET DELAY COUNTER 100 USEC
	CALL WAITA
	LXI B,0516H
	CALL COOP
	RET
;
WAITA: 	DCR C
	JNZ WAITA
	MVI C,0FFH
	DCR B
	JNZ WAITA
	RET
;
; OUTPUT ROUTINE
;
COOP:	PUSH H		;SAVE HL
	LHLD ISAT	;LOAD ADDR.TABLE
	MOV A,M		;GET DEV. ADDRESS
	ADD B		;ADD REG OFFSET
	STA BYAU
	MOV A,C		;GET BYTE FOR OUTP
	DB 0D3H
BYAU:	DB 0
	POP H
	RET
;
; INPUT ROUTINE
;
COIP:	PUSH H		;SAVE HL
	LHLD ISAT	;LOAD ADDR.TABLE
	MOV A,M		;GET DEV. ADDRESS
	ADD B
	STA BYEI
	DB 0DBH
BYEI:	DB 0		;REC BYTE IN REG A
	POP H
	RET
;
; CLEAR SCREEN
;
CLSC:	MVI C,2
	MVI E,1AH
	CALL 5
	RET
;
; DISPLAY STATUS
;
DISP:	MVI C,02H 	;CURS HOME
	MVI E,1AH
	CALL 0005H
	LXI D,DIMA	;PINT HAEDLINE
	CALL DIS2
	LXI B,0
DIAS:	LHLD PONO	;TEXT LINE POINTER
	CALL ROUN
	SHLD PONO
	MOV A,C		;FOR COMPARE
	CPI 6
	JZ DISC
	CALL ANZ	;PRINT LINE
	CALL DIS2	;PRINT AND CR&LF
	LXI H,STBYM	;STATUS UUT
	DAD B
	CALL DIS1
	LXI H,STBYS	;STATUS TOOL
	DAD B
	CALL DIS1
	CALL CRLF	;NEXT LINE
	INX B		;LINE COUNTER
	JMP DIAS
DISC:	CALL DIS2	;REC.HEAD LINE
	LXI H,BUFF0	;PRINT BUFF ADDR.
	LXI B,8
DISB:	LXI D,PSPA
	CALL ANZ	;SPACE FOR POSITION
	CALL DIS1
	CALL CRLF
	INX H		;NEXT LINE
	DCR C
	JNZ DISB	;8 LINE PRINTED	
	RET		;JMP DISC
;
DIS1:	PUSH H
	PUSH D
	PUSH B
	LXI D,SCH
	CALL STAT
	LXI D,SPAC
	MVI C,9
	CALL 5
	POP B
	POP D
	POP H
	RET
SPAC:	DB'    $'
;
DIS2:	PUSH H
	PUSH D
	PUSH B
	MVI C,9		;PRINT STRING
	CALL 5
	MVI C,2
	MVI E,0DH	;LINE FEED
	CALL 5
	MVI C,2		;CARRI. RETURN
	MVI E,0AH
	CALL 5
	POP B
	POP D
	POP H
	RET
;
SCH: DB'    $'
;
STAT:	MVI B,08H
STA1:	MOV A,M
	RAL
	MOV M,A
	CC STA2
	CNC STA3
	CALL ANZ
	DCR B
	JNZ STA1
	RET
STA3:	MVI A,30H
	STA SCH+1
	RET
STA2:	MVI A,31H
	STA SCH+1
	RET
;
ANZ:	PUSH H
	PUSH B
	PUSH D
	MVI C,09H
	CALL 0005H
	POP D
	POP B
	POP H
	RET
;
CRLF:	PUSH H
	PUSH D
	PUSH B
	MVI C,02H
	MVI E,0AH
	CALL 0005H
	MVI C,02H
	MVI E,0DH
	CALL 0005H
	POP B
	POP D
	POP H
	RET
;
DELT:	LXI B,0431H	;RESTORE TAL/LIS ONLY
	CALL COOP
	LXI B,0511H	;TAKE CONTROL
	CALL COOP
	MVI A,31H	;RESTORE SLAVE
	OUT ISL2+R4
	RET
;
; TEMPR. MEMORY
;
ISAT:	DW 0
SEBY:	DW 55FEH
REARR:	DW BUFF0
BUFF0:	DW 0,0,0,0,0
STBYM:	DW 0,0,0,0,0
STBYS	DW 0,0,0,0,0
ELOO:	DB 0
KBY:	DB 0
DIMO:	DB 0
DILO:	DB 0
COMO:	DB 0
ERCO:	DW 0
STCO:	DW 0
ISTA:	DB 70H,78H,38H,0B0H,0B8H,0C8H,00H
POTI:	DW PONT
PONT:	DW DI0Y,DI1Y,DI2Y,DI3Y,DI5Y,DI4Y,DI6Y,DI8Y
PONO:	DW POSI
POSI:	DW S1CH,S2CH,S3CH,S4CH,S5CH,S7CH,S6CH
PRCO:	DW ROGR
ROGR:	DW INIT,SERE,RERE,PARE,SEPE,RECT,AEND
;
PSPA:	DB'                 $'
S1CH: 	DB'CPT APT DET END DEC ERR DO  DI      $'
S2CH: 	DB'INT SRQ LOK REM CO  LOC REC ADS     $'
S3CH: 	DB'CIC ATN SPM LPA TPA LA  TA  MJM     $'
S4CH: 	DB'CP7 CP6 CP5 CP4 CP3 CP2 CP1 CP0     $'
S5CH: 	DB'EOI DTO DLO AD5 AD4 AD3 AD2 AD1     $'
S6CH: 	DB'*RECEIVED DATA*  D7  D6  D5  D4  D3  D2  D1  D0 $'
S7CH: 	DB'S7  PEN S5  S4  S3  S2  S1  S0      $'
DIMA:	DB'     **UNIT UNDER TEST**                  '
	DB' **DEVICE SIMULATOR** $'
IN4Z:	DB'STOP ON  ERROR: Y / N $'
IN5Z:	DB'CUNTINUOUS RUN: Y / N $'
DI0Y:	DB 'PHASE:1 DM V BUS     $'
DI1Y:	DB 'PHASE:2 INIT         $'
DI2Y:	DB 'PHASE:3 SEND         $'
DI3Y:   DB 'PHASE:4 RECEIVE      $'
DI4Y:	DB 'PHASE:6 SERIAL POLL  $'
DI5Y:	DB 'PHASE:5 PARALLEL POLL$'
DI6Y:	DB 'PHASE:7 REN:DEC:EOI  $'
DI8Y:	DB '   * END *           $'
EI1Y:	DB ' ERROR COUNTER:'
EREN:	DB '  XXXX ',0AH,0DH,'$'
EI2Y:	DB '    OK                 ',0AH,0DH,'$'
IN1Z:	DB'C3273-K804 IEEE-488 INTERFACE DIAGNOSTIC PROGAM',0AH,0DH
        DB'===============================================',0AH,0DH
DB'                       (Version PDR 001)',0AH,0DH,0AH,0DH
DB'          1. Unit Under Test            UUT  (controller)',0AH,0DH
DB'          2. Device Simulation Adapter  DSA  (talker/listener)',0ah,0dh,0AH,0DH
DB'Make sure that UUT and DSA do NOT use the same BASE-PORT-ADDRESS',0ah,0dh
DB'Remove all other adapters from slot 2-6',0ah,0dh
DB'Insert UUT and DSA to any slot 2-6',0ah,0dh,0AH,0DH
DB'The DSA must be switched to Port Address = 30Hex',0AH,0DH
DB'                                   IFSEL = 2A',0AH,0DH
DB§                                     4 2 1 A',0ah,0dh
DB'                                    _________',0AH,0DH
DB'                                       o   o  ON',0ah,0dh
DB'                                     o   o    OFF',0AH,0DH
DB'                                    _________',0AH,0DH 
DB'                                           B  ',0AH,0DH
DB'                                   IF/Selection',0AH,0DH
DB'For details see your K804 IEEE-488 Installation documentation',0AH,0ah,0dh
DB'CONTINUE:  CR ',0AH,0DH
DB'EXIT :  ^C $'
IN6Z:	DB'The UUT adapter is available on BASE ADDRESS:'
BSPO:	DB'    XX Hex ',0AH,0DH,0AH,0DH,0AH,0DH
	DB'CONTINUE:  CR $'
IN7Z:	DB' DM V BUS ERROR ',0AH,0DH
	DB' or wrong BASE PORT ADDRESS via IFSEL selected.',0AH,0AH,0DH
	DB' Table of Base Port Address ',0AH,0DH
	DB'        SWITCH       PORT ADDRESS in HEX',0AH,0DH
	DB'        0A           60  Reserved for K212/211',0AH,0DH
	DB'        0B           68  Reserved for K212/211',0AH,0DH
	DB'        1A           70',0AH,0DH
	DB'        1B           78',0AH,0DH
	DB'        2A           30  Reserved FOR DSA ',0AH,0DH
	DB'        2B           38',0AH,0DH
	DB'        3A           B0',0AH,0DH
	DB'        3B           B8',0AH,0DH
	DB'        4A           C0  Reserved for HARD DISK',0AH,0DH
	DB'        4B           C8',0AH,0AH,0DH
DB'Ceck your K-804 IFSEL Switch setting.',0ah,0dh
DB'For details see your K-804 IEEE488 Installation documentation.',0ah,0Ah,0dh
	DB'CONTINUE : CR$'    
IN3Z:   DB'With DISPLAY MODE ON.',0AH,0DH
        DB'All status information of UUT and DSA are shown on the screen.',0ah,0dh
	DB'DISPLAY MODE ON:  Y/N $'
IN8Y:	DB'Stop on error. Hit L=Loop  C=continue  Q=Quit  D=Display:$'
INCY:	DB'CONTINUE: CR',0AH,0DH
	DB'STOP CONT.RUN : Q',0AH,0DH
	DB'RESTART : R ',0AH,0DH
	DB'EXIT : ^C',0AH,0DH,'$'
INDY:	DB' CONTINUE: (CR)     $'   
STAE:	DS 256
;END
